Ejemplo n.º 1
0
        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
                    });
                }
            }
        }
Ejemplo n.º 2
0
        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
                    });
                }
            }
        }
Ejemplo n.º 3
0
        static void AddToDatabase(Stream stream)
        {
            DefaultDeserializer deserializer = new DefaultDeserializer(stream);

            deserializer.Deserialize();

            CarsDBContext db = new CarsDBContext();

            //gets reference to added report for later
            Reports addedReport;

            try
            {
                addedReport = AddReport(db, deserializer.Document.ToString());
                db.SaveChanges();
            }
            catch (Exception e)
            {
                throw e;
            }

            try
            {
                AddCarProducts(db, deserializer);
                db.SaveChanges();

                AddCarProductCarFeature(db, deserializer);
                db.SaveChanges();
            }
            catch (Exception e)
            {
                throw e;
            }

            ConfirmReport(context: db, reportToConfirm: addedReport);
            db.SaveChanges();
        }