public void Delete(Guid Id) { var prod = GetById(Id); _dbContext.Products.Remove(prod); _dbContext.SaveChanges(); }
public async void AddToCart(Product product, int amount) { var shoppingCartItem = _dbContext.ShoppingCartItems.Where(x => x.Product.ProductId == product.ProductId && x.ShoppingCartId == _ShoppingCartId).FirstOrDefault(); if (shoppingCartItem == null) { var Shoppingcartitem = new ShoppingCartItem { Amount = amount, Product = product, ShoppingCartId = _ShoppingCartId }; await _dbContext.ShoppingCartItems.AddAsync(Shoppingcartitem); } else { shoppingCartItem.Amount++; } _dbContext.SaveChanges(); }
public void CreateOrder(Order order) { order.PlacedAt = DateTime.Now; _dbContext.Orders.Add(order); var cartItems = _shoppingCart.ShoppingCartItems; foreach (var item in cartItems) { var orderInfo = new OrderInfo { Amount = item.Amount, OrderId = order.OrderId, ProductId = item.Product.ProductId, Price = item.Product.Price }; _dbContext.OrderDetails.Add(orderInfo); _dbContext.SaveChanges(); } }