static Reports AddReport(CarsDBContext context, string xmlText) { Reports report = new Reports { ReportData = xmlText, RequestedDateTime = DateTime.Now, AddedToDatabase = false }; context.Add(report); return(report); }
static void AddCarProductCarFeature(CarsDBContext context, DefaultDeserializer deserializer) { var carProductsQuery = context.CarProducts; var carFeaturesQuery = context.CarFeatures; foreach (var car in deserializer.Find("Car")) { int carID = carProductsQuery.Where(s => s.Vin == car.Attributes["VIN"]).First().Id; foreach (var feature in car.FindChildren("Feature")) { int featureID = carFeaturesQuery.Where(s => s.Code == feature.Attributes["Code"]).First().Id; context.Add(new CarProductCarFeature { CarProductId = carID, InstalledFeatureId = featureID }); } } }
static void AddCarProducts(CarsDBContext context, DefaultDeserializer deserializer) { var carModelsQuery = context.CarModels; var carFactoriesQuery = context.CarFactories; foreach (var factory in deserializer.Find("Factory")) { //finds factory id by correlating same factory name attribute and Name column in CarFactories int factoryID = carFactoriesQuery.Where(s => s.Name == factory.Attributes["Name"]).First().Id; foreach (var car in factory.FindChildren("Car")) { int carID = carModelsQuery.Where(s => s.Name == car.FindChildren("Model").First().Value).First().Id; short carYear = short.Parse(car.FindChildren("ProductionYear").First().Value); string carVIN = car.Attributes["VIN"]; context.Add(new CarProducts { CarModelId = carID, Year = carYear, Vin = carVIN, FactoryId = factoryID }); } } }