Пример #1
0
        /// <summary>
        /// CONTROLLER: ShoppingCardController
        /// </summary>

        public ShoppingCardViewModel GetShoppingCardData()
        {
            int userID = userService.Get(CurrentUserLoginName).ID;

            ShoppingCardViewModel shoppingCardViewModel = new ShoppingCardViewModel();

            shoppingCardViewModel.TotalPrice = 0;

            List <ShoppingCardInfoViewModel> list = new List <ShoppingCardInfoViewModel>();
            var shoppingCardModelList             = orderService.GetUserShoppingCard(userID);

            foreach (var item in shoppingCardModelList)
            {
                var product = productService.GetDetails(item.ProductID);
                list.Add(new ShoppingCardInfoViewModel()
                {
                    ID          = item.ID,
                    ProductID   = product.ID,
                    ProductName = product.Name,
                    Price       = product.Price,
                    Quantity    = item.Quantity
                });

                shoppingCardViewModel.TotalPrice += product.Price * item.Quantity;
            }

            shoppingCardViewModel.ShoppingCardProducts = list;

            return(shoppingCardViewModel);
        }
Пример #2
0
 public ShoppingCardController(ApplicationDbContext db)
 {
     _db            = db;
     ShoppingCardvm = new ShoppingCardViewModel()
     {
         Products = new List <Products>()
     };
     orm = 0;
     qdb = new Qdatabase();
 }
        public IViewComponentResult Invoke()
        {
            _shoppingCard.ShoppingCardItems = _shoppingCard.GetShoppingCardItems();
            var shoppingcardVM = new ShoppingCardViewModel
            {
                ShoppingCard      = _shoppingCard,
                ShoppingCardTotal = _shoppingCard.GetTotal()
            };

            return(View(shoppingcardVM));
        }
        public ViewResult Index()
        {
            _shoppingCard.ShoppingCardItems = _shoppingCard.GetShoppingCardItems();

            var shoppingcardVM = new ShoppingCardViewModel
            {
                ShoppingCard      = _shoppingCard,
                ShoppingCardTotal = _shoppingCard.GetTotal()
            };

            return(View(shoppingcardVM));
        }
Пример #5
0
        public IActionResult AddToCart(int productId, int colorId, int sizeId, int quantity)
        {
            var shoppingCart = HttpContext.Session.GetList <ShoppingCardViewModel>(CommonConstants.SesstionCart);

            if (shoppingCart == null)
            {
                shoppingCart = new List <ShoppingCardViewModel>();
            }

            SizeViewModel  sizeVm  = _productQuantityService.GetSizeById(sizeId);
            ColorViewModel colorVm = _productQuantityService.GetColorById(colorId);

            if (shoppingCart.Any(x => x.ProductId == productId && x.SizeVm.Id == sizeId && x.ColorVm.Id == colorId))
            {
                foreach (var item in shoppingCart)
                {
                    if (item.ProductId == productId && item.SizeVm.Id == sizeId && item.ColorVm.Id == colorId)
                    {
                        item.Quantity += quantity;
                        break;
                    }
                }
            }
            else
            {
                ProductViewModel      product = _productService.GetById(productId);
                ShoppingCardViewModel cart    = new ShoppingCardViewModel()
                {
                    ProductId = productId,
                    SizeVm    = sizeVm,
                    ColorVm   = colorVm,
                    Quantity  = quantity,
                    ProductVm = product,
                };
                shoppingCart.Add(cart);
            }
            HttpContext.Session.SetList <ShoppingCardViewModel>(CommonConstants.SesstionCart, shoppingCart);
            return(new OkObjectResult(productId));
        }