CSVDataProvider.cs 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. using CsvHelper;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Globalization;
  5. using System.IO;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. namespace wpf_app.Model
  10. {
  11. public class CSVDataProvider : IDataProvider
  12. {
  13. private List<Product> productList;
  14. public CSVDataProvider()
  15. {
  16. using (var reader = new StreamReader("./products.csv"))
  17. {
  18. using (var csv = new CsvReader(
  19. reader,
  20. CultureInfo.InvariantCulture))
  21. {
  22. productList = csv.GetRecords<Product>().ToList();
  23. }
  24. }
  25. }
  26. public IEnumerable<Product> GetProducts()
  27. {
  28. return productList;
  29. }
  30. public IEnumerable<ProductCategory> GetCategories()
  31. {
  32. return new ProductCategory[]
  33. {
  34. new ProductCategory {title = "Смартфон"},
  35. new ProductCategory {title = "Ноутбук"},
  36. new ProductCategory {title = "Смарт-Часы"},
  37. new ProductCategory {title = "Монитор"}
  38. };
  39. }
  40. public IEnumerable<ProductPrice> GetPrices()
  41. {
  42. return new ProductPrice[]
  43. {
  44. new ProductPrice{title="Все цены", priceFrom = 0, priceTo = 999999},
  45. new ProductPrice{title="До 10.000", priceFrom = 0, priceTo = 10000},
  46. new ProductPrice{title="От 10.000 до 20.000", priceFrom = 10000, priceTo = 20000},
  47. new ProductPrice{title="От 20.000 до 50.000", priceFrom = 20000, priceTo = 50000},
  48. new ProductPrice{title="Дороже 50.000", priceFrom = 50000, priceTo = 999999 }
  49. };
  50. }
  51. public IEnumerable<ProductCompany> GetCompanies()
  52. {
  53. return new ProductCompany[]
  54. {
  55. new ProductCompany{title = "Apple"},
  56. new ProductCompany{title = "Xiaomi"},
  57. new ProductCompany{title = "Huawei"},
  58. new ProductCompany{title = "POCO"},
  59. new ProductCompany{title = "Asus"},
  60. new ProductCompany{title = "Lenovo"},
  61. new ProductCompany{title = "Samsung"},
  62. new ProductCompany{title = "Acer"},
  63. new ProductCompany{title = "AOC"}
  64. };
  65. }
  66. }
  67. }