Ejemplo n.º 1
0
        public IActionResult Index()
        {
            ProductViewModel productViewModel = new ProductViewModel();

            List <Product>    products   = _productBusinessService.GetAllWithBrand();
            List <Categories> categories = _categoriesBusinessService.GetAllWithSubCategories();

            //linq lambda
            productViewModel.Categories = categories.Select(x => new CategoryModel
            {
                Id            = x.Id,
                Description   = x.Description,
                Image         = x.Image,
                Name          = x.Name,
                Code          = x.Code,
                SubCategories = x.SubCategories.Select(y => new SubCategoryModel
                {
                    Description  = y.Description,
                    Name         = y.Name,
                    Code         = y.Code,
                    CategoryCode = y.Category.Code
                }).ToList()
            }).ToList();

            productViewModel.Brands = (from p in products
                                       group p by p.BrandModel.Brand into b
                                       select new BrandQuantityModel
            {
                BrandId = b.Key.Id,
                BrandName = b.Key.Name,
                BrandQuantity = b.Count()
            }).OrderBy(x => x.BrandName).ToList();

            return(View(productViewModel));
        }
Ejemplo n.º 2
0
        public IActionResult Index()
        {
            HomeViewModel     homeViewModel = new HomeViewModel();
            List <Categories> categories    = _categoriesBusinessService.GetAllWithSubCategories();
            List <Product>    products      = _productBusinessService.GetAllWithBrand();
            List <Sliders>    sliders       = _sliderBusinessService.GetAll();

            homeViewModel.Categories = categories.Select(x => new CategoryModel
            {
                Id            = x.Id,
                Description   = x.Description,
                Image         = x.Image,
                Code          = x.Code,
                Name          = x.Name,
                SubCategories = x.SubCategories.Select(y => new SubCategoryModel
                {
                    Description  = y.Description,
                    Name         = y.Name,
                    Code         = y.Code,
                    CategoryCode = y.Category.Code
                }).ToList()
            }).ToList();

            //homeViewModel.Products = products.Select(x => new ProductModel
            //{
            //    Id = x.Id,
            //    Image = x.Image,
            //    Model = x.BrandModel.Name,
            //    Brand = x.BrandModel.Brand.Name,
            //    ProductCode = x.ProductCode,
            //    CategoryCode = x.BrandModel.ProductType.SubCategory.Category.Code,
            //    SubCategoryCode = x.BrandModel.ProductType.SubCategory.Code,
            //    ProductTypeCode = x.BrandModel.ProductType.Code,
            //    Price = x.Price,
            //    Currency = x.Currency
            //}).ToList();

            homeViewModel.Sliders = sliders.Select(x => new SliderModel
            {
                Description = x.Description,
                Image       = x.Image,
                LinkTitle   = x.LinkTitle,
                Title       = x.Title
            }).ToList();

            return(View(homeViewModel));
        }