public string SetCar(Stream stream) { string json; using (var reader = new StreamReader(stream)) { json = reader.ReadToEnd(); } var vm = Newtonsoft.Json.JsonConvert.DeserializeObject<CarViewModel>(json, new Newtonsoft.Json.JsonSerializerSettings() { TypeNameHandling = Newtonsoft.Json.TypeNameHandling.Objects, DateTimeZoneHandling = Newtonsoft.Json.DateTimeZoneHandling.Local }); var car = Cars.Where(c => c.Id == vm.id).FirstOrDefault(); if (car == null) { car = new Car() { Id = Guid.NewGuid() }; Cars.Add(car); } car.Brand = vm.brand; car.Model = vm.model; car.ImportDate = vm.importdate; car.CO2 = vm.co2; car.IsActive = vm.isactive; return serializeToJson(car); }
static CarService() { var car1 = new Car() { Id = Guid.NewGuid(), Brand = "VW", Model = "Golf", CO2 = 110, ImportDate = new DateTime(2013, 5, 10, 18, 30, 0), IsActive = true }; car1.Options.Add(new Option() { Id = Guid.NewGuid(), Name = "Heated seats", CatalogPrice = 500 }); car1.Options.Add(new Option() { Id = Guid.NewGuid(), Name = "Ashtray defroster", CatalogPrice = 75 }); car1.AvailableYears = new List<int>() { 2011, 2012, 2013 }; car1.AvailableCountries = new List<string>() { "GB", "BE", "NL", "DE" }; var car2 = new Car() { Id = Guid.NewGuid(), Brand = "Ford", Model = "Mondeo", CO2 = 135, ImportDate = new DateTime(2013, 4, 18, 9, 5, 0), IsActive = true }; car2.Options.Add(new Option() { Id = Guid.NewGuid(), Name = "Open windshield", CatalogPrice = 2100 }); car2.Options.Add(new Option() { Id = Guid.NewGuid(), Name = "Wheels", CatalogPrice = 15000 }); car2.AvailableYears = new List<int>() { 2012, 2013 }; car2.AvailableCountries = new List<string>() { "FR", "BE", "NL" }; Cars = new List<Car>() { car1, car2 }; }