Beispiel #1
0
        public async Task AddToCartAsync(Books book, int amount)
        {
            var shoppingCartItem =
                await _appDbContext.ShoppingCartItems.SingleOrDefaultAsync(
                    s => s.Book.Id == book.Id && s.ShoppingCartId == ShoppingCartId);

            if (shoppingCartItem == null)
            {
                shoppingCartItem = new ShoppingCartItem
                {
                    ShoppingCartId = ShoppingCartId,
                    Book           = book,
                    Amount         = 1
                };

                _appDbContext.ShoppingCartItems.Add(shoppingCartItem);
            }
            else
            {
                shoppingCartItem.Amount++;
            }

            await _appDbContext.SaveChangesAsync();
        }
Beispiel #2
0
 public async Task SaveChangesAsync()
 {
     await _context.SaveChangesAsync();
 }