public async Task <ActionResult> AddToBasket(AddToBasketViewModel model)
        {
            //TODO: Move to seperate handler
            var customer = _context.Customers.Include(c => c.Bags).ThenInclude(b => b.Items).SingleOrDefault();

            if (customer == null)
            {
                return(RedirectToAction("Login", "Account"));
            }

            var bag = customer.Bags.FirstOrDefault();

            if (bag == null)
            {
                bag = (await _context.ShoppingBags.AddAsync(new ShoppingBag
                {
                    Customer = customer,
                    Date = DateTime.Now
                })).Entity;
            }

            var product = await _context.Products.FindAsync(model.Product.Id);

            bag.AddToBag(new ShoppingItem {
                Product = product, Quantity = model.Quantity
            });
            //=====================

            await _context.SaveChangesAsync();

            MessageSuccess("This item was successfully added to your basket");

            return(RedirectToAction("Index"));
        }
        public ActionResult Index(AddToBasketViewModel model)
        {
            string variant = GetVariantFromPostData(model.Sku, "variation-");

            TransactionLibrary.AddToBasket(1, model.Sku, variant);

            return(RenderView(true));
        }
        public ActionResult AddToBasket(AddToBasketViewModel model)
        {
            var basket = HttpContext.Cache.Get("basket") as Basket;

            if (basket == null)
            {
                basket = new Basket();
                HttpContext.Cache.Add("basket", basket, null, Cache.NoAbsoluteExpiration, Cache.NoSlidingExpiration, CacheItemPriority.Normal, null);
            }

            basket.AddItem(model);

            return(RedirectToAction("Index"));
        }
Пример #4
0
        public async Task <IActionResult> AddToBasket(AddToBasketViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var command = _mapper.Map <AddToBasketViewModel, AddItemToBasketCommand>(viewModel);

            command.UserId = User.GetId();

            var result = await _mediator.Send(command);

            if (result.Success)
            {
                return(RedirectToAction("Index", "Home"));
            }

            ModelState.AddModelError(string.Empty, result.Error);
            return(BadRequest(ModelState));
        }
 public ActionResult Index(AddToBasketViewModel model)
 {
     TransactionLibrary.AddToBasket(1, model.Product, model.Variant);
     return(RenderView(true));
 }
Пример #6
0
 public ActionResult Index(AddToBasketViewModel model)
 {
     UCommerce.Api.TransactionLibrary.AddToBasket(1, model.Sku, model.VariantSku);
     return(Index());
 }
Пример #7
0
 public ActionResult Index(AddToBasketViewModel model)
 {
     return(Index());
 }
 public ActionResult Index(AddToBasketViewModel model)
 {
     return(Redirect(Request.Url.ToString()));
 }