|
@@ -0,0 +1,243 @@
|
|
|
+using System;
|
|
|
+using System.Collections.Generic;
|
|
|
+using System.Diagnostics;
|
|
|
+using System.Formats.Asn1;
|
|
|
+using System.Globalization;
|
|
|
+using System.IO;
|
|
|
+using System.Linq;
|
|
|
+using System.Text;
|
|
|
+using System.Threading.Tasks;
|
|
|
+using CsvHelper;
|
|
|
+
|
|
|
+namespace wpf_template.Model
|
|
|
+{
|
|
|
+ public class Product
|
|
|
+ {
|
|
|
+ public string Title { get; set; }
|
|
|
+ public string Company { get; set; }
|
|
|
+ public int Price { get; set; }
|
|
|
+ public string Category { get; set; }
|
|
|
+ public bool Existence { get; set; }
|
|
|
+ public DateOnly ArrivalDate { get; set; }
|
|
|
+ public double Rating { get; set; }
|
|
|
+ public string Photo { get; set; }
|
|
|
+
|
|
|
+ public string ExistenceString
|
|
|
+ {
|
|
|
+ get {
|
|
|
+ return Existence ? "Да" : "Нет";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public class ProductCategory
|
|
|
+ {
|
|
|
+ public string title { get; set; }
|
|
|
+ }
|
|
|
+
|
|
|
+ public class ProductPrice
|
|
|
+ {
|
|
|
+ public string title { get; set; }
|
|
|
+ public int priceFrom { get; set; }
|
|
|
+ public int priceTo { get; set; }
|
|
|
+ }
|
|
|
+
|
|
|
+ public class ProductCompany
|
|
|
+ {
|
|
|
+ public string title { get; set; }
|
|
|
+ }
|
|
|
+
|
|
|
+ interface IDataProvider
|
|
|
+ {
|
|
|
+ IEnumerable<Product> GetProducts();
|
|
|
+ IEnumerable<ProductCategory> GetCategories();
|
|
|
+ IEnumerable<ProductPrice> GetPrices();
|
|
|
+ IEnumerable<ProductCompany> GetCompanies();
|
|
|
+ }
|
|
|
+
|
|
|
+ public class LocalDataProvider : IDataProvider
|
|
|
+ {
|
|
|
+ public IEnumerable<Product> GetProducts()
|
|
|
+ {
|
|
|
+ return new Product[]{
|
|
|
+ new Product
|
|
|
+ {
|
|
|
+ Category = "Смартфон",
|
|
|
+ Company = "Apple",
|
|
|
+ Title = "13 Pro Max",
|
|
|
+ Price = 84999
|
|
|
+ },
|
|
|
+ new Product
|
|
|
+ {
|
|
|
+ Category = "Смартфон",
|
|
|
+ Company = "Samsung",
|
|
|
+ Title = "S23",
|
|
|
+ Price = 89999
|
|
|
+ },
|
|
|
+ new Product
|
|
|
+ {
|
|
|
+ Category = "Смартфон",
|
|
|
+ Company = "Huawei",
|
|
|
+ Title = "Nova Y61",
|
|
|
+ Price = 9999
|
|
|
+ },
|
|
|
+ new Product
|
|
|
+ {
|
|
|
+ Category = "Смартфон",
|
|
|
+ Company = "POCO",
|
|
|
+ Title = "C51",
|
|
|
+ Price = 5599
|
|
|
+ },
|
|
|
+ new Product
|
|
|
+ {
|
|
|
+ Category = "Ноутбук",
|
|
|
+ Company = "Xiaomi",
|
|
|
+ Title = "RedmiBook 15",
|
|
|
+ Price = 49999
|
|
|
+ },
|
|
|
+ new Product
|
|
|
+ {
|
|
|
+ Category = "Ноутбук",
|
|
|
+ Company = "Asus",
|
|
|
+ Title = "Vivobook Go 15",
|
|
|
+ Price = 25999
|
|
|
+ },
|
|
|
+ new Product
|
|
|
+ {
|
|
|
+ Category = "Ноутбук",
|
|
|
+ Company = "Lenovo",
|
|
|
+ Title = "IdeaPad 1",
|
|
|
+ Price = 24999
|
|
|
+ },
|
|
|
+ new Product
|
|
|
+ {
|
|
|
+ Category = "Ноутбук",
|
|
|
+ Company = "Asus",
|
|
|
+ Title = "ExpertBook B1502",
|
|
|
+ Price = 32999
|
|
|
+ },
|
|
|
+ new Product
|
|
|
+ {
|
|
|
+ Category = "Смарт-Часы",
|
|
|
+ Company = "Apple",
|
|
|
+ Title = "SE 2023",
|
|
|
+ Price = 30599
|
|
|
+ },
|
|
|
+ new Product
|
|
|
+ {
|
|
|
+ Category = "Смарт-Часы",
|
|
|
+ Company = "Xiaomi",
|
|
|
+ Title = "Smart Band 8",
|
|
|
+ Price = 3999
|
|
|
+ },
|
|
|
+ new Product
|
|
|
+ {
|
|
|
+ Category = "Смарт-Часы",
|
|
|
+ Company = "Huawei",
|
|
|
+ Title = "Watch GT 4",
|
|
|
+ Price = 13999
|
|
|
+ },
|
|
|
+
|
|
|
+ };
|
|
|
+ }
|
|
|
+
|
|
|
+ public IEnumerable<ProductCategory> GetCategories()
|
|
|
+ {
|
|
|
+ return new ProductCategory[]
|
|
|
+ {
|
|
|
+ new ProductCategory {title = "Смартфон"},
|
|
|
+ new ProductCategory {title = "Ноутбук"},
|
|
|
+ new ProductCategory {title = "Смарт-Часы"},
|
|
|
+ new ProductCategory {title = "Монитор"}
|
|
|
+ };
|
|
|
+ }
|
|
|
+
|
|
|
+ public IEnumerable<ProductPrice> GetPrices()
|
|
|
+ {
|
|
|
+ return new ProductPrice[]
|
|
|
+ {
|
|
|
+ new ProductPrice{title="Все цены", priceFrom = 0, priceTo = 999999},
|
|
|
+ new ProductPrice{title="До 10.000", priceFrom = 0, priceTo = 10000},
|
|
|
+ new ProductPrice{title="От 10.000 до 20.000", priceFrom = 10000, priceTo = 20000},
|
|
|
+ new ProductPrice{title="От 20.000 до 50.000", priceFrom = 20000, priceTo = 50000},
|
|
|
+ new ProductPrice{title="Дороже 50.000", priceFrom = 50000, priceTo = 999999 }
|
|
|
+ };
|
|
|
+ }
|
|
|
+ public IEnumerable<ProductCompany> GetCompanies()
|
|
|
+ {
|
|
|
+ return new ProductCompany[]
|
|
|
+ {
|
|
|
+ new ProductCompany{title = "Apple"},
|
|
|
+ new ProductCompany{title = "Xiaomi"},
|
|
|
+ new ProductCompany{title = "Huawei"},
|
|
|
+ new ProductCompany{title = "POCO"},
|
|
|
+ new ProductCompany{title = "Asus"},
|
|
|
+ new ProductCompany{title = "Lenovo"},
|
|
|
+ new ProductCompany{title = "Samsung"},
|
|
|
+ new ProductCompany{title = "Acer"},
|
|
|
+ new ProductCompany{title = "AOC"}
|
|
|
+ };
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public class CSVDataProvider : IDataProvider
|
|
|
+ {
|
|
|
+ private List<Product> productList;
|
|
|
+ public CSVDataProvider()
|
|
|
+ {
|
|
|
+ using (var reader = new StreamReader("./products.csv"))
|
|
|
+ {
|
|
|
+ using (var csv = new CsvReader(
|
|
|
+ reader,
|
|
|
+ CultureInfo.InvariantCulture))
|
|
|
+ {
|
|
|
+ productList = csv.GetRecords<Product>().ToList();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public IEnumerable<Product> GetProducts()
|
|
|
+ {
|
|
|
+ return productList;
|
|
|
+ }
|
|
|
+
|
|
|
+ public IEnumerable<ProductCategory> GetCategories()
|
|
|
+ {
|
|
|
+ return new ProductCategory[]
|
|
|
+ {
|
|
|
+ new ProductCategory {title = "Смартфон"},
|
|
|
+ new ProductCategory {title = "Ноутбук"},
|
|
|
+ new ProductCategory {title = "Смарт-Часы"},
|
|
|
+ new ProductCategory {title = "Монитор"}
|
|
|
+ };
|
|
|
+ }
|
|
|
+
|
|
|
+ public IEnumerable<ProductPrice> GetPrices()
|
|
|
+ {
|
|
|
+ return new ProductPrice[]
|
|
|
+ {
|
|
|
+ new ProductPrice{title="Все цены", priceFrom = 0, priceTo = 999999},
|
|
|
+ new ProductPrice{title="До 10.000", priceFrom = 0, priceTo = 10000},
|
|
|
+ new ProductPrice{title="От 10.000 до 20.000", priceFrom = 10000, priceTo = 20000},
|
|
|
+ new ProductPrice{title="От 20.000 до 50.000", priceFrom = 20000, priceTo = 50000},
|
|
|
+ new ProductPrice{title="Дороже 50.000", priceFrom = 50000, priceTo = 999999 }
|
|
|
+ };
|
|
|
+ }
|
|
|
+ public IEnumerable<ProductCompany> GetCompanies()
|
|
|
+ {
|
|
|
+ return new ProductCompany[]
|
|
|
+ {
|
|
|
+ new ProductCompany{title = "Apple"},
|
|
|
+ new ProductCompany{title = "Xiaomi"},
|
|
|
+ new ProductCompany{title = "Huawei"},
|
|
|
+ new ProductCompany{title = "POCO"},
|
|
|
+ new ProductCompany{title = "Asus"},
|
|
|
+ new ProductCompany{title = "Lenovo"},
|
|
|
+ new ProductCompany{title = "Samsung"},
|
|
|
+ new ProductCompany{title = "Acer"},
|
|
|
+ new ProductCompany{title = "AOC"}
|
|
|
+ };
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|