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}"); }
public static string GetUsersWithProducts(ProductShopContext context) { var usersArray = context .Users //.ToArray() <- For Judge to work .Where(x => x.ProductsSold.Count > 0) .OrderByDescending(x => x.ProductsSold.Count) .Select(x => new Task8UserDTO { FirstName = x.FirstName, LastName = x.LastName, Age = x.Age, SoldProducts = new Task8SoldProductsDTO { Count = x.ProductsSold.Count, products = MapperApplier .MapCollection <Product, Task6ProductDTO>(x.ProductsSold) .ToArray() } }) .Take(10) .ToArray(); var usersObject = MapperApplier.MapElement <Task8UserDTO[], Task8UsersDTO>(usersArray); return(XmlApplier.SerializeOne(usersObject)); }
public static string GetSalesWithAppliedDiscount(CarDealerContext context) { var sales = context .Sales .ProjectTo <DTOs.Export.SaleDTO>(MapperApplier.Configuration) .ToArray(); return(XmlApplier.SerializeCollection(sales, "sales")); }
public static string GetLocalSuppliers(CarDealerContext context) { var suppliers = context .Suppliers .Where(x => !x.IsImporter) .ProjectTo <DTOs.Export.SupplierDTO>(MapperApplier.Configuration) .ToArray(); return(XmlApplier.SerializeCollection(suppliers, "suppliers")); }
public static string GetCategoriesByProductsCount(ProductShopContext context) { var categories = context .Categories .ProjectTo <Task7CategoryDTO>(MapperApplier.MapperConfiguration) .OrderByDescending(x => x.Count) .ThenBy(x => x.TotalRevenue) .ToArray(); return(XmlApplier.SerializeMany("Categories", categories)); }
public static string GetProductsInRange(ProductShopContext context) { var products = context .Products .Where(x => x.Price >= 500 && x.Price <= 1000) .ProjectTo <Task5ProductDTO>(MapperApplier.MapperConfiguration) .OrderBy(x => x.Price) .Take(10) .ToArray(); return(XmlApplier.SerializeMany("Products", products)); }
public static string GetCarsWithTheirListOfParts(CarDealerContext context) { var cars = context .Cars .OrderByDescending(x => x.TravelledDistance) .ThenBy(x => x.Model) .ProjectTo <Task17CarDTO>(MapperApplier.Configuration) .Take(5) .ToArray(); return(XmlApplier.SerializeCollection(cars, "cars")); }
public static string GetCarsFromMakeBmw(CarDealerContext context) { var cars = context .Cars .Where(x => x.Make == "BMW") .OrderBy(x => x.Model) .ThenByDescending(x => x.TravelledDistance) .ProjectTo <Task15CarDTO>(MapperApplier.Configuration) .ToArray(); return(XmlApplier.SerializeCollection(cars, "cars")); }
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}"); }
public static string GetCarsWithDistance(CarDealerContext context) { var cars = context .Cars .Where(x => x.TravelledDistance > 2_000_000) .ProjectTo <DTOs.Export.Task14CarDTO>(MapperApplier.Configuration) .OrderBy(x => x.Make) .ThenBy(x => x.Model) .Take(10) .ToArray(); return(XmlApplier.SerializeCollection(cars, "cars")); }
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}"); }
public static string GetSoldProducts(ProductShopContext context) { var users = context .Users .Where(x => x.ProductsSold.Any(x => x.Buyer != null)) .ProjectTo <Task6UserDTO>(MapperApplier.MapperConfiguration) .OrderBy(x => x.LastName) .ThenBy(x => x.FirstName) .Take(5) .ToArray(); return(XmlApplier.SerializeMany("Users", users)); }
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}"); }
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}"); }
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}"); }
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}"); }
public static string GetTotalSalesByCustomer(CarDealerContext context) { var customers = context .Customers .Where(x => x.Sales.Count > 0) .Select(x => new CustomerDTO { FullName = x.Name, BoughtCarsCount = x.Sales.Count, SpentMoney = x.Sales.Sum(s => s.Car.PartCars.Sum(p => p.Part.Price)) }) .OrderByDescending(x => x.SpentMoney) .ToArray(); return(XmlApplier.SerializeCollection(customers, "customers")); }
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}"); }