Esempio n. 1
0
        public AddItemResult AddItem(AddItemCommand command)
        {
            ShoppingCart cart;

            if (command.SessionId.HasValue)
            {
                cart = dbContext.ShoppingCart.Include(x => x.Items).SingleOrDefault(x => x.SessionId == command.SessionId);
            }
            else
            {
                Guid newCartSessionId = Guid.NewGuid();
                cart = new ShoppingCart {
                    SessionId = newCartSessionId, CreatedOn = DateTime.Now
                };
                dbContext.ShoppingCart.Add(cart);
            }

            cart.Add(command.ProductId, command.Quantity);
            dbContext.SaveChanges();

            return(new AddItemResult {
                SessionId = cart.SessionId
            });
        }
Esempio n. 2
0
        public IActionResult AddItem(AddItemCommand command)
        {
            var result = cartService.AddItem(command);

            return(Ok(result));
        }