예제 #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}");
        }
예제 #2
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}");
        }
예제 #3
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}");
        }
예제 #4
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}");
        }
예제 #5
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}");
        }