PhoneClass.cs 7.5 KB

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