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; public JsonDataProvider() { var serializer = new DataContractJsonSerializer(typeof(Clothes[])); using(var sr = new StreamReader("./clothes.json")) { clothes = ((Clothes[])serializer.ReadObject(sr.BaseStream)).ToList(); } } public IEnumerable GetClothes() { return clothes; } public IEnumerable GetClothesBrands() { return clothes.DistinctBy(b => b.Brand).Select(b=>new ClothesBrand {Title = b.Title}); } public IEnumerable GetClothesCategories() { return clothes.DistinctBy(b => b.Category).Select(b => new ClothesCategory { Title = b.Title}); } public IEnumerable 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} }; } } }