public Wine Add(Wine wine) { m_context.Wines.Add(wine); // commit changes to DB m_context.SaveChanges(); return(wine); }
public void AddToCart(int id) { // Retrieve the product from the database. ShoppingCartId = GetCartId(); var cartItem = _db.ShoppingCartItems.SingleOrDefault( c => c.CartId == ShoppingCartId && c.WineId == id); if (cartItem == null) { // Create a new cart item if no cart item exists. cartItem = new CartItem { ItemId = Guid.NewGuid().ToString(), WineId = id, CartId = ShoppingCartId, Wine = _db.Wines.SingleOrDefault(w => w.WineID == id), Quantity = 1, DateCreated = DateTime.Now }; _db.ShoppingCartItems.Add(cartItem); } else { // If the item does exist in the cart, // then add one to the quantity. cartItem.Quantity++; } _db.SaveChanges(); }
public IActionResult Add(WineryViewModel nw) { if (ModelState.IsValid) { Winery newWinery = new Winery { Name = nw.Name, Address = nw.Address, Phone = nw.Phone, Email = nw.Email, Website = nw.Website, Notes = nw.Notes }; if (!newWinery.Website.StartsWith("http://") || !newWinery.Website.StartsWith("https://")) { newWinery.Website = "http://" + newWinery.Website; } context.Wineries.Add(newWinery); context.SaveChanges(); return(Redirect("/Winery")); } return(View(nw)); }
public IActionResult Add(WineTypeViewModel nt) { if (ModelState.IsValid) { WineType newType = new WineType { Name = nt.Name, Description = nt.Description }; context.WineTypes.Add(newType); context.SaveChanges(); return(Redirect("/WineType")); } return(View(nt)); }
public IActionResult Add(WineViewModel newWineModel) { if (ModelState.IsValid) { Wine newWine = new Wine { Name = newWineModel.Name, Description = newWineModel.Description, Notes = newWineModel.Notes, Rating = newWineModel.Rating, WineryID = newWineModel.WineryID, TypeID = newWineModel.TypeID, InStock = false }; context.Wines.Add(newWine); context.SaveChanges(); return(Redirect("/Wine/ViewAll")); } return(View(newWineModel)); }
public void RemoveItem(string removeCartID, int removeProductID) { using (var _db = new WineDbContext()) { try { var myItem = (from c in _db.ShoppingCartItems where c.CartId == removeCartID && c.Wine.WineID == removeProductID select c).FirstOrDefault(); if (myItem != null) { // Remove Item. _db.ShoppingCartItems.Remove(myItem); _db.SaveChanges(); } } catch (Exception exp) { throw new Exception("ERROR: Unable to Remove Cart Item - " + exp.Message.ToString(), exp); } } }