public void AddToCart(Phone phone, string amount) { var shoppingCartItem = _appPhoneDBContext.ShoppingCartItems.SingleOrDefault(s => s.Phone.Id == phone.Id && s.ShoppingCartId == ShoppingCartId); if (shoppingCartItem == null) { shoppingCartItem = new ShoppingCartItem { ShoppingCartId = ShoppingCartId, Phone = phone, Amount = 1 }; _appPhoneDBContext.ShoppingCartItems.Add(shoppingCartItem); } else { shoppingCartItem.Amount++; } _appPhoneDBContext.SaveChanges(); }
public Phone Add(Phone phone) { context.Phones.Add(phone); context.SaveChanges(); return(phone); }