コード例 #1
0
        public async System.Threading.Tasks.Task <RedirectToRouteResult> AddToCart(Domain.Entities.Cart cart, int productId, string returnUrl)
        {
            string key = ConfigurationManager.AppSettings.Get("ProductListCacheKey");
            IEnumerable <Domain.Entities.Product> productList = await _productRepository.Products(key);

            Domain.Entities.Product product = productList.FirstOrDefault(p => p.ProductId == productId);
            if (product != null)
            {
                cart.AddItem(product, 1);
            }
            return(RedirectToAction("Index", new { returnUrl }));
        }
コード例 #2
0
        public async Task <ViewResult> List(string category, int page = 1)
        {
            string key = ConfigurationManager.AppSettings.Get("ProductListCacheKey");
            IEnumerable <Domain.Entities.Product> productList = await _productRepository.Products(key);

            Models.ProductsViewModel model = new Models.ProductsViewModel()
            {
                Products = productList
                           .Where(p => p.Category == category || category == null)
                           .OrderBy(P => P.ProductId)
                           .Skip((page - 1) * _PageSize)
                           .Take(_PageSize),
                PagingInfo = new Models.PagingInfo {
                    CurrentPage = page, ItemsPerPage = _PageSize, TotalItems = productList.Where(p => p.Category == category || category == null).Count()
                },
                CurrentCategory = category
            };
            return(View(model));
        }
コード例 #3
0
 public async Task <ActionResult> Index()
 {
     return(View("Index", await _productRepository.Products()));
 }