1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- using CsvHelper;
- using System;
- using System.Collections.Generic;
- using System.Globalization;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace wpf_template.Model
- {
- 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"}
- };
- }
- }
- }
|