コード例 #1
0
        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));
        }
コード例 #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}");
        }
コード例 #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}");
        }
コード例 #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}");
        }