12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Runtime.Serialization;
- using System.Text;
- using System.Threading.Tasks;
- using System.Runtime.Serialization.Json;
- using System.IO;
- namespace exam.Model
- {
- public class JsonDataProvider : IDataProvider
- {
- private List<Clothes> clothes;
- public JsonDataProvider()
- {
- var serializer = new DataContractJsonSerializer(typeof(Clothes[]));
- using(var sr = new StreamReader("./clothes.json"))
- {
- clothes = ((Clothes[])serializer.ReadObject(sr.BaseStream)).ToList();
- }
- }
- public IEnumerable<Clothes> GetClothes()
- {
- return clothes;
- }
- public IEnumerable<ClothesBrand> GetClothesBrands()
- {
- return clothes.DistinctBy(b => b.Brand).Select(b=>new ClothesBrand {Title = b.Title});
- }
- public IEnumerable<ClothesCategory> GetClothesCategories()
- {
- return clothes.DistinctBy(b => b.Category).Select(b => new ClothesCategory { Title = b.Title});
- }
- public IEnumerable<ClothesPrice> GetClothesPrices()
- {
- return new ClothesPrice[]
- {
- new ClothesPrice{Title = "До 10.000", PriceFrom = 0, PriceTo = 10000},
- new ClothesPrice{Title = "От 10.000 до 30.000", PriceFrom = 10000, PriceTo = 30000},
- new ClothesPrice{Title = "От 30.000 до 70.000", PriceFrom = 30000, PriceTo = 80000},
- new ClothesPrice{Title = "Дороже 70.000", PriceFrom = 70000, PriceTo = 300000}
- };
- }
- }
- }
|