public int RemoveFromCart(Tech tech) { var shoppingCartItem = _appDbContext.ShoppingCartItems.SingleOrDefault( s => s.Tech.TechId == tech.TechId && s.ShoppingCartId == ShoppingCartId); var localAmount = 0; if (shoppingCartItem != null) { if (shoppingCartItem.Amount > 1) { shoppingCartItem.Amount--; localAmount = shoppingCartItem.Amount; } else { _appDbContext.ShoppingCartItems.Remove(shoppingCartItem); } } _appDbContext.SaveChanges(); return(localAmount); }
public void AddToCart(Tech tech, int amount) { var shoppingCartItem = _appDbContext.ShoppingCartItems.SingleOrDefault( s => s.Tech.TechId == tech.TechId && s.ShoppingCartId == ShoppingCartId); if (shoppingCartItem == null) { shoppingCartItem = new ShoppingCartItem { ShoppingCartId = ShoppingCartId, Tech = tech, Amount = 1 }; _appDbContext.ShoppingCartItems.Add(shoppingCartItem); } else { shoppingCartItem.Amount++; } _appDbContext.SaveChanges(); }
public void CreateTech(Tech tech) { _appDbContext.Tech.Add(tech); _appDbContext.SaveChanges(); }
public void UpdateTech(Tech tech) { _appDbContext.Tech.Update(tech); _appDbContext.SaveChanges(); }