Esempio n. 1
0
        public async Task Add(AddProductToCartViewModel model)
        {
            Product prod = await _productRepository.FindOne(model.Id);

            if (prod == null)
            {
                return;
            }

            model.Name  = prod.Name;
            model.Image = prod.Image;
            if (prod.IsDiscounted)
            {
                model.Price = (double)prod.NewPrice;
            }
            else
            {
                model.Price = prod.Price;
            }

            Cart cart = GetCartFromSession();

            if (cart == null)
            {
                cart = new Cart();
            }

            cart.AddItem(new CartItem(model));

            SessionHelper.Set(HttpContext.Session, "cart", cart);
        }
Esempio n. 2
0
 public CartItem(AddProductToCartViewModel model)
 {
     Id       = model.Id;
     Name     = model.Name;
     Price    = model.Price;
     Image    = model.Image;
     Size     = model.SelectedSize;
     Quantity = model.Quantity;
 }
Esempio n. 3
0
        public async Task <bool> AddProduct([FromBody] AddProductToCartViewModel model)
        {
            if (ModelState.IsValid)
            {
                Cart cart  = new Cart(HttpContext);
                var  goods = await _streinger.Goods();

                var prod = (goods).First(g => g.Product.Name == model.ProductName &&
                                         g.Supplier.Name == model.Supplier &&
                                         g.Supplier.Address == model.AddressSupplier);
                cart.AddProduct(prod);
                return(true);
            }

            return(false);
        }