Exemple #1
0
        public static string ImportCars(CarDealerContext context, string inputXml)
        {
            var carsDto = XmlApplier
                          .Deserialize <DTOs.Import.CarDTO>(inputXml, "Cars");

            var cars = MapperApplier.MapCollection <DTOs.Import.CarDTO, Car>(carsDto);

            context.Cars.AddRange(cars);
            context.SaveChanges();

            for (int i = 0; i < cars.Length; i++)
            {
                int carId = cars[i].Id;

                var carParts = carsDto[i].Parts
                               .Select(x => new PartCar
                {
                    PartId = x.Id,
                    CarId  = carId
                });

                foreach (var part in carParts)
                {
                    cars[i].PartCars.Add(part);
                }
            }

            context.SaveChanges();

            return($"Successfully imported {cars.Length}");
        }
Exemple #2
0
        public static string ImportCategoryProducts(ProductShopContext context, string inputXml)
        {
            var categoryProductsInput = XmlApplier
                                        .Deserialize <Task4CategoryProductDTO>("CategoryProducts", inputXml);

            var categoryProducts = MapperApplier
                                   .MapCollection <Task4CategoryProductDTO, CategoryProduct>(categoryProductsInput);

            context.CategoryProducts.AddRange(categoryProducts);
            context.SaveChanges();

            return($"Successfully imported {categoryProducts.Count}");
        }
Exemple #3
0
        public static string ImportProducts(ProductShopContext context, string inputXml)
        {
            var productsInputData = XmlApplier
                                    .Deserialize <Task2ProductDTO>("Products", inputXml);

            var products = MapperApplier
                           .MapCollection <Task2ProductDTO, Product>(productsInputData);

            context.Products.AddRange(products);
            context.SaveChanges();

            return($"Successfully imported {products.Count}");
        }
Exemple #4
0
        public static string ImportUsers(ProductShopContext context, string inputXml)
        {
            var usersInputData = XmlApplier
                                 .Deserialize <Task1UserDTO>("Users", inputXml);

            var users = MapperApplier
                        .MapCollection <Task1UserDTO, User>(usersInputData);

            context.Users.AddRange(users);
            context.SaveChanges();

            return($"Successfully imported {users.Count}");
        }
Exemple #5
0
        public static string ImportCustomers(CarDealerContext context, string inputXml)
        {
            var customersDto = XmlApplier
                               .Deserialize <CustommerDTO>(inputXml, "Customers");

            var customers = MapperApplier
                            .MapCollection <CustommerDTO, Customer>(customersDto);

            context.Customers.AddRange(customers);
            context.SaveChanges();

            return($"Successfully imported {customers.Length}");
        }
Exemple #6
0
        public static string ImportSuppliers(CarDealerContext context, string inputXml)
        {
            var suppliersDto = XmlApplier
                               .Deserialize <DTOs.Export.SupplierDTO>(inputXml, "Suppliers");

            var suppliers = MapperApplier
                            .MapCollection <DTOs.Export.SupplierDTO, Supplier>(suppliersDto);

            context.Suppliers.AddRange(suppliers);
            context.SaveChanges();

            return($"Successfully imported {suppliers.Length}");
        }
Exemple #7
0
        public static string ImportSales(CarDealerContext context, string inputXml)
        {
            HashSet <int> carsIds = context.Cars.Select(x => x.Id).ToHashSet();

            var salesDto = XmlApplier
                           .Deserialize <DTOs.Import.SaleDTO>(inputXml, "Sales")
                           .Where(x => carsIds.Contains(x.CarId));

            var sales = MapperApplier
                        .MapCollection <DTOs.Import.SaleDTO, Sale>(salesDto);

            context.Sales.AddRange(sales);
            context.SaveChanges();

            return($"Successfully imported {sales.Length}");
        }
Exemple #8
0
        public static string ImportParts(CarDealerContext context, string inputXml)
        {
            HashSet <int> usersIds = context.Suppliers
                                     .Select(x => x.Id)
                                     .ToHashSet();

            var partsDto = XmlApplier
                           .Deserialize <DTOs.Import.PartDTO>(inputXml, "Parts")
                           .Where(x => usersIds.Contains(x.SupplierId));

            var parts = MapperApplier
                        .MapCollection <DTOs.Import.PartDTO, Part>(partsDto);

            context.Parts.AddRange(parts);
            context.SaveChanges();

            return($"Successfully imported {parts.Length}");
        }