Ejemplo n.º 1
0
        public ActionResult Index(string id)
        {
            var products = _unitOfWork.ProductRepository.Get().ToList();
            var product = _unitOfWork.ProductRepository.GetById(new Guid(id));

            if (product == null)
            {
                return View("Error");
            }

            var image800x640Paths = product.Image800x640Paths.ToList();
            var imageAdditional = GetImageAdditionalModels(image800x640Paths);

            var relatedProductIds = _unitOfWork.RelatedProductRepository.Get(i=>i.ProductId==new Guid(id)).Select(r=>r.RelatedProductId);

            var relatedProducts = _unitOfWork.ProductRepository.Get(p => relatedProductIds.Contains(p.Id)).ToList();
            var relatedProductBlocks = GetRelatedProductBlocks(relatedProducts);

            var categoryViewModels = GetCategories(product, products);

            var specialProduct = products.First(i => i.Id == new Guid("CD4879A0-C210-4DAA-A6DE-A59E9CC153BF"));
            var specialProductViewModel = new SpecialProductViewModel
            {
                Id = specialProduct.Id.ToString(),
                Name = specialProduct.Name,
                OldPrice = specialProduct.OldPrice.HasValue ? specialProduct.OldPrice.Value.ToString("C") : string.Empty,
                NewPrice = specialProduct.NewPrice.ToString("C"),
                RatingImagePath = specialProduct.RatingImagePath,
                Image240x192Path = specialProduct.Image240x192Path
            };

            var productInfo = new ProductInfo
            {
                Id = product.Id.ToString(),
                Name = product.Name,
                DefaultImage = image800x640Paths.First(i => i.IsActive).Path,
                OldPrice = product.OldPrice.HasValue ? product.OldPrice.Value.ToString("C") : string.Empty,
                NewPrice = product.NewPrice.ToString("C"),
                ExTax = (product.NewPrice - product.NewPrice*.15m).ToString("C"),
                Brand = product.Brand.Name,
                BrandId = product.Brand.Id.ToString(),
                Description = product.Description,
                ImageAdditionals = imageAdditional,
                Availability = "In Stock"
            };

            var productModel = new ProductModel
            {
                ProductInfo=productInfo,
                RelatedProductBlocks = relatedProductBlocks,
                RelatedProductCount=relatedProducts.Count,
                CategoryViewModels=categoryViewModels,
                SpecialProductViewModel=specialProductViewModel
            };
            return View(productModel);
        }
Ejemplo n.º 2
0
        public ActionResult Category(string id,string sort="default",string order="asc",int pageIndex=0,int pageSize=2)
        {
            var products = _unitOfWork.ProductRepository.Get().ToList();//new ProductsBuilder().Build());

            @ViewBag.Sort = sort;
            @ViewBag.Order = order;
            @ViewBag.PageSize = pageSize;
            
            var category = _categories.First(i => i.Id==new Guid(id));
            var allCategories = category.GetAllCategories();
            var selectedProducts = products.Where(p => allCategories.Contains(p.CategoryId)).ToList();
            var paginatedProducts = new PaginatedList<Product>(selectedProducts, pageIndex, pageSize);
            
            var categoryViewModels = GetCategoriesByCategory(category, products);

            var specialProduct = products.First(i => i.Id == new Guid("CD4879A0-C210-4DAA-A6DE-A59E9CC153BF"));
            var specialProductViewModel = new SpecialProductViewModel
            {
                Id = specialProduct.Id.ToString(),
                Name = specialProduct.Name,
                OldPrice = specialProduct.OldPrice.HasValue? specialProduct.OldPrice.Value.ToString("C"):string.Empty,
                NewPrice = specialProduct.NewPrice.ToString("C"),
                RatingImagePath = specialProduct.RatingImagePath,
                Image240x192Path = specialProduct.Image240x192Path
            };

            var refineSearchs = new List<RefineSearch>();
            foreach (var childCategory in _categories.Where(c=>c.ParentCategory==category))
            {
                var refineSearch = new RefineSearch
                {
                    Id = childCategory.Id.ToString(),
                    Name = childCategory.Name,
                    Total = products.Count(p => p.CategoryId == childCategory.Id)
                };
                refineSearchs.Add(refineSearch);
            }

            var productsBlock = GetProductsBlocks(paginatedProducts.ToList());

            var categoryModel = new CategoryModel
            {
                Id=id,
                Name=category.Name,
                Description = category.Description,
                ImagePath=category.ImagePath,
                RefineSearches=refineSearchs,
                CategoryViewModels=categoryViewModels,
                SpecialProductViewModel=specialProductViewModel,
                ProductsBlock=productsBlock,
                PaginatedList=paginatedProducts
            };

            return View(categoryModel);
        }