示例#1
0
        // GET: Shop
        //[Route("Shop")]
        public async Task <ActionResult> Shop(int?pageSize, string categoryName, int?pageNumber = 1)
        {
            var user = await GetloggedInUser();

            IEnumerable <CartItem> carts = null;
            var cart = new ShoppingCart(HttpContext);

            if (user == null)
            {
                carts = await cart.GetCartItemsAsync(String.Empty);
            }
            else
            {
                carts = await cart.GetCartItemsAsync(user.Id);
            }

            pageSize = 9;

            pageNumber = pageNumber == null || pageNumber == 1 ? 1 : pageNumber;

            IEnumerable <Product> bestProducts = new List <Product>();

            if (string.IsNullOrEmpty(categoryName))
            {
                bestProducts = await _product.GetPageAsync((int)pageNumber, (int)pageSize);
            }
            else
            {
                bestProducts = await _product.GetPageByCategoryAsync((int)pageNumber, (int)pageSize, categoryName);
            }

            var model = new ProductsManagerViewModel
            {
                Categories = await _category.GetAllAsync(),
                BestSeller = bestProducts.Shuffle(),
                CartItems  = carts
            };

            var products = string.IsNullOrEmpty(categoryName) ? await _product.GetAllAsync() : await _product.GetAllByCategoryAsync(categoryName);

            ViewBag.CountTotalPages = CalucutePageNumbers((int)pageSize, products.Count());

            return(View(model));
        }
示例#2
0
        //[Route("AddToCart/{productId}")]
        //public async Task<ActionResult> AddToCart(ProductsViewModel model)
        public async Task <JsonResult> AddToCart(int productId)
        {
            var cart = new ShoppingCart(HttpContext);
            var user = await GetloggedInUser();


            await cart.AddAsync(productId, user.Id);

            var carts = await cart.GetCartItemsAsync(user.Id);

            var model = new ProductsManagerViewModel
            {
                CartItems              = carts,
                TotalPriceItems        = CalcuateCartSubtotal(carts),
                TotalPriceWithDiscount = CalcuateCartWithDiscount(carts)
            };

            //return Json(RedirectToAction("Index", "Home"));
            return(Json(model, JsonRequestBehavior.AllowGet));
            //return RedirectToAction("Index", "Home");
        }
示例#3
0
        public async Task <ActionResult> Index()
        {
            var bestProducts = await _product.GetPageAsync(1, 8);

            var freeProducts = await _product.GetPageAsync(1, 8);

            var bookProducts = await _product.GetPageByCategoryTypeAsync(1, 5, "book");

            var artistProducts = await _product.GetPageByCategoryAsync(1, 5, "گرافیک");

            var engeenierProducts = await _product.GetPageByCategoryAsync(1, 5, "کامپیوتر");

            var user = await GetloggedInUser();

            IEnumerable <CartItem> carts = null;
            var cart = new ShoppingCart(HttpContext);

            if (user == null)
            {
                carts = await cart.GetCartItemsAsync(String.Empty);
            }
            else
            {
                carts = await cart.GetCartItemsAsync(user.Id);
            }

            var model = new ProductsManagerViewModel
            {
                BestSeller        = bestProducts.Shuffle(),
                FreeProducts      = freeProducts.Where(p => p.Price == 0).Shuffle(),
                BookProducts      = bookProducts.Shuffle(),
                ArtisticProducts  = artistProducts.Shuffle(),
                EngeenierProducts = engeenierProducts.Shuffle(),
                CartItems         = carts
            };

            return(View(model));
        }