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 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}"); }