public ActionResult SaveToCart(ProductCartViewModel productCartViewModel)
 {
     if (productCartViewModel.CartLineItem.Id == 0)
     {
         productCartViewModel.CartLineItem.CartId    = productCartViewModel.cartId;
         productCartViewModel.CartLineItem.ProductId = productCartViewModel.productId;
         _context.CartLineItems.Add(productCartViewModel.CartLineItem);
     }
     _context.SaveChanges();
     return(RedirectToAction("cart", "Item"));
 }
示例#2
0
        public IActionResult ProductDetailsWithoutLogin(int id)
        {
            var product = _reposProduct.GetProduct(id);

            ProductCartViewModel model = new ProductCartViewModel
            {
                Id          = product.Id,
                ProductName = product.Name,
                Price       = product.Price,
                PhotoPath   = product.ProductImagePath,
                Brand       = product.Brand.Name,
                Category    = product.Category.Name
            };

            return(View(nameof(ProductDetailsWithoutLogin), model));
        }
 public ActionResult SaveToBasket(ProductCartViewModel productCartViewModel)
 {
     if (productCartViewModel.UserBasket.Id == 0)
     {
         //var userId = TempData["Id"];
         Cart   cart        = (Cart)Session["Cart"];
         string currentUser = User.Identity.GetUserId();
         string custId      = Session["Id"].ToString();
         productCartViewModel.UserBasket.CustomerId = Convert.ToInt32(custId);
         productCartViewModel.UserBasket.ProductId  = productCartViewModel.productId;
         int price   = _context.Products.Single(m => m.Id == productCartViewModel.productId).Price;
         int amoount = productCartViewModel.UserBasket.Qty * price;
         productCartViewModel.UserBasket.Amount = amoount;
         _context.UserBaskets.Add(productCartViewModel.UserBasket);
     }
     _context.SaveChanges();
     return(RedirectToAction("Items", "Item"));
 }
 public ActionResult Details(int id)
 {
     if (id == null)
     {
         throw new Exception("not found");
     }
     else
     {
         var viewModel = new ProductCartViewModel
         {
             Product   = _context.Products.Include(m => m.brand).Include(m => m.Size).SingleOrDefault(m => m.Id == id),
             cartId    = Convert.ToInt32(_context.Carts.Max(m => m.Id)),
             productId = id,
             Size      = _context.Sizes.ToList()
         };
         return(View(viewModel));
     }
 }
        private List <ProductCartViewModel> GetItemsModel(string shoppingCartId)
        {
            var cartItems = this._shoppingCartManager.GetItems(shoppingCartId).ToList();

            var itemIds = cartItems.Select(i => i.ProductId);

            var products = new List <Product>();

            var cartViewModels = new List <ProductCartViewModel>();

            foreach (var id in itemIds)
            {
                var product = this._dbContext.Products.SingleOrDefault(x => x.Id == id);
                products.Add(product);
            }
            foreach (var product in products)
            {
                var model1 = new ProductCartViewModel()
                {
                    Discount   = product.Discount,
                    Id         = product.Id,
                    Name       = product.Name,
                    PictureUrl = product.PictureUrl,
                    Price      = product.Price,
                    Quantity   = 0,
                    Weight     = product.Weight
                };
                cartViewModels.Add(model1);
            }

            for (int i = 0; i < cartViewModels.Count; i++)
            {
                cartViewModels[i].Quantity = cartItems[i].Quantity;
                cartViewModels[i].Weight   = products[i].Weight * cartItems[i].Quantity;
                cartViewModels[i].Price    = Math.Round(cartViewModels[i].Price - ((cartViewModels[i].Price * cartViewModels[i].Discount) / 100), 2);
            }


            return(cartViewModels);
        }
示例#6
0
        public IActionResult ProductDetails(int id)
        {
            var product     = _reposProduct.GetProduct(id);
            var selectLista = _context.ProductSizes.Where(p => p.ProductId == product.Id).Select(s => new SelectListItem
            {
                Value = s.ProductSizeId.ToString(),
                Text  = s.Size.Name
            }).ToList();
            ProductCartViewModel model = new ProductCartViewModel
            {
                Id           = product.Id,
                ProductName  = product.Name,
                Price        = product.Price,
                Quantity     = product.Quantity,
                PhotoPath    = product.ProductImagePath,
                Brand        = product.Brand.Name,
                Category     = product.Category.Name,
                UserId       = int.Parse(_userManager.GetUserId(HttpContext.User)),
                ProductSizes = selectLista
            };

            return(View(nameof(ProductDetails), model));
        }
示例#7
0
        public IActionResult AddToCart(ProductCartViewModel model)
        {
            var listOfCartDetails = _reposCartDetails.GetCartDetails();

            foreach (var item in listOfCartDetails)
            {
                if (item.ProductSizeId == model.ProductSizeId)
                {
                    item.Quantity += model.QuantityForBuy;
                    _reposCartDetails.UpdateCartDetail(item);
                    return(Ok());
                }
            }
            CartDetails newCartDetail = new CartDetails
            {
                UserId        = model.UserId,
                Quantity      = model.QuantityForBuy,
                ProductSizeId = model.ProductSizeId
            };

            _reposCartDetails.Add(newCartDetail);
            return(Ok());
        }
示例#8
0
        public IActionResult Cart(ProductCartViewModel model)
        {
            CartDetails newCartDetail = new CartDetails
            {
                UserId        = model.UserId,
                Quantity      = model.QuantityForBuy,
                ProductSizeId = model.ProductSizeId
            };

            _reposCartDetails.Add(newCartDetail);

            var listOfCartDetails = _context.CartDetails.Where(cd => cd.UserId == model.UserId).Select(s => new CartDetailsViewModel
            {
                CartDetailsId = s.Id,
                PhotoPath     = s.ProductSize.Product.ProductImagePath,
                ProductName   = s.ProductSize.Product.Name,
                Quantity      = s.Quantity,
                Price         = s.ProductSize.Product.Price
            }).ToList();

            ViewData["userId"] = newCartDetail.UserId;
            return(View(listOfCartDetails));
        }
示例#9
0
        public async Task <IActionResult> Index()
        {
            var carts = await _context.Carts.Include(c => c.Product).ToListAsync();

            decimal subCategoryPrice = 0;

            foreach (var item in carts)
            {
                subCategoryPrice += item.SubTotalPrice;
            }

            decimal subTotal   = carts.Sum(c => c.Product.Price);
            int     cartsCount = carts.Count();

            ProductCartViewModel vm = new ProductCartViewModel()
            {
                Products      = await _context.Products.ToListAsync(),
                Carts         = carts,
                SubTotalPrice = subCategoryPrice,
                CartsCount    = cartsCount
            };

            return(View(vm));
        }
示例#10
0
        public async Task <IViewComponentResult> InvokeAsync()
        {
            var carts = await _context.Carts.Include(c => c.Product).ToListAsync();

            decimal subCategoryPrice = 0;

            foreach (var item in carts)
            {
                subCategoryPrice += item.SubTotalPrice;
            }

            decimal subTotal   = carts.Sum(c => c.Product.Price);
            int     cartsCount = carts.Count();

            ProductCartViewModel model = new ProductCartViewModel()
            {
                Products      = await _context.Products.ToListAsync(),
                Carts         = carts,
                SubTotalPrice = subCategoryPrice,
                CartsCount    = cartsCount
            };

            return(await Task.FromResult((IViewComponentResult)View("Cart", model)));
        }
        public ProductCartPage()
        {
            InitializeComponent();

            BindingContext = new ProductCartViewModel();
        }