PhoneClass.cs 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics;
  4. using System.Formats.Asn1;
  5. using System.Globalization;
  6. using System.IO;
  7. using System.Linq;
  8. using System.Runtime.Serialization;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. using CsvHelper;
  12. namespace wpf_template.Model
  13. {
  14. [DataContract]
  15. public class Product
  16. {
  17. [DataMember]
  18. public string Title { get; set; }
  19. [DataMember]
  20. public string Company { get; set; }
  21. [DataMember]
  22. public int Price { get; set; }
  23. [DataMember]
  24. public string Category { get; set; }
  25. [DataMember]
  26. public bool Existence { get; set; }
  27. [DataMember(Name = "ArrivalDate")]
  28. private string? stringArrivalDate { get; set; }
  29. [IgnoreDataMember]
  30. public DateOnly? ArrivalDate
  31. {
  32. get
  33. {
  34. return stringArrivalDate == null ? null : DateOnly.Parse(stringArrivalDate);
  35. }
  36. set
  37. {
  38. stringArrivalDate = value.ToString();
  39. }
  40. }
  41. [DataMember]
  42. public double Rating { get; set; }
  43. [DataMember]
  44. public string Photo { get; set; }
  45. [IgnoreDataMember]
  46. public string ExistenceString
  47. {
  48. get {
  49. return Existence ? "Да" : "Нет";
  50. }
  51. }
  52. public Uri? ImageBitmap
  53. {
  54. get
  55. {
  56. var imageName = Environment.CurrentDirectory + "/img/" + (Photo ?? "");
  57. return System.IO.File.Exists(imageName) ? new Uri(imageName) : null;
  58. }
  59. }
  60. }
  61. public class ProductCategory
  62. {
  63. public string title { get; set; }
  64. }
  65. public class ProductPrice
  66. {
  67. public string title { get; set; }
  68. public int priceFrom { get; set; }
  69. public int priceTo { get; set; }
  70. }
  71. public class ProductCompany
  72. {
  73. public string title { get; set; }
  74. }
  75. interface IDataProvider
  76. {
  77. IEnumerable<Product> GetProducts();
  78. IEnumerable<ProductCategory> GetCategories();
  79. IEnumerable<ProductPrice> GetPrices();
  80. IEnumerable<ProductCompany> GetCompanies();
  81. }
  82. public class LocalDataProvider : IDataProvider
  83. {
  84. public IEnumerable<Product> GetProducts()
  85. {
  86. return new Product[]{
  87. new Product
  88. {
  89. Category = "Смартфон",
  90. Company = "Apple",
  91. Title = "13 Pro Max",
  92. Price = 84999
  93. },
  94. new Product
  95. {
  96. Category = "Смартфон",
  97. Company = "Samsung",
  98. Title = "S23",
  99. Price = 89999
  100. },
  101. new Product
  102. {
  103. Category = "Смартфон",
  104. Company = "Huawei",
  105. Title = "Nova Y61",
  106. Price = 9999
  107. },
  108. new Product
  109. {
  110. Category = "Смартфон",
  111. Company = "POCO",
  112. Title = "C51",
  113. Price = 5599
  114. },
  115. new Product
  116. {
  117. Category = "Ноутбук",
  118. Company = "Xiaomi",
  119. Title = "RedmiBook 15",
  120. Price = 49999
  121. },
  122. new Product
  123. {
  124. Category = "Ноутбук",
  125. Company = "Asus",
  126. Title = "Vivobook Go 15",
  127. Price = 25999
  128. },
  129. new Product
  130. {
  131. Category = "Ноутбук",
  132. Company = "Lenovo",
  133. Title = "IdeaPad 1",
  134. Price = 24999
  135. },
  136. new Product
  137. {
  138. Category = "Ноутбук",
  139. Company = "Asus",
  140. Title = "ExpertBook B1502",
  141. Price = 32999
  142. },
  143. new Product
  144. {
  145. Category = "Смарт-Часы",
  146. Company = "Apple",
  147. Title = "SE 2023",
  148. Price = 30599
  149. },
  150. new Product
  151. {
  152. Category = "Смарт-Часы",
  153. Company = "Xiaomi",
  154. Title = "Smart Band 8",
  155. Price = 3999
  156. },
  157. new Product
  158. {
  159. Category = "Смарт-Часы",
  160. Company = "Huawei",
  161. Title = "Watch GT 4",
  162. Price = 13999
  163. },
  164. };
  165. }
  166. public IEnumerable<ProductCategory> GetCategories()
  167. {
  168. return new ProductCategory[]
  169. {
  170. new ProductCategory {title = "Смартфон"},
  171. new ProductCategory {title = "Ноутбук"},
  172. new ProductCategory {title = "Смарт-Часы"},
  173. new ProductCategory {title = "Монитор"}
  174. };
  175. }
  176. public IEnumerable<ProductPrice> GetPrices()
  177. {
  178. return new ProductPrice[]
  179. {
  180. new ProductPrice{title="Все цены", priceFrom = 0, priceTo = 999999},
  181. new ProductPrice{title="До 10.000", priceFrom = 0, priceTo = 10000},
  182. new ProductPrice{title="От 10.000 до 20.000", priceFrom = 10000, priceTo = 20000},
  183. new ProductPrice{title="От 20.000 до 50.000", priceFrom = 20000, priceTo = 50000},
  184. new ProductPrice{title="Дороже 50.000", priceFrom = 50000, priceTo = 999999 }
  185. };
  186. }
  187. public IEnumerable<ProductCompany> GetCompanies()
  188. {
  189. return new ProductCompany[]
  190. {
  191. new ProductCompany{title = "Apple"},
  192. new ProductCompany{title = "Xiaomi"},
  193. new ProductCompany{title = "Huawei"},
  194. new ProductCompany{title = "POCO"},
  195. new ProductCompany{title = "Asus"},
  196. new ProductCompany{title = "Lenovo"},
  197. new ProductCompany{title = "Samsung"},
  198. new ProductCompany{title = "Acer"},
  199. new ProductCompany{title = "AOC"}
  200. };
  201. }
  202. }
  203. }