public async Task <IActionResult> PutCartItems(int id, CartItems cartItems) { if (id != cartItems.Id) { return(BadRequest()); } _context.Entry(cartItems).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CartItemsExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutCarts([FromRoute] int id, [FromBody] Carts carts) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != carts.Id) { return(BadRequest()); } _context.Entry(carts).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CartsExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task AddItem(ShoppingCart shoppingCart, ShoppingCartItem newItem) { if (shoppingCart.Items.Any(i => i.ExternalId == newItem.ExternalId)) { var item = shoppingCart.Items.Single(i => i.ExternalId == newItem.ExternalId); item.ExternalSource = newItem.ExternalSource; item.Contents = newItem.Contents; item.UnitPrice = newItem.UnitPrice; item.Quantity += newItem.Quantity; _context.Entry(item).State = EntityState.Modified; await _context.SaveChangesAsync(); } else { shoppingCart.Items.Add(newItem); await _context.SaveChangesAsync(); } }
public ActionResult Edit([Bind(Include = "id,UserName,itemId,itemName,itemImageUrl,itemPrice")] Cart cart) { if (ModelState.IsValid) { db.Entry(cart).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(cart)); }
public ActionResult Edit([Bind(Include = "ProductID,Name,Price,Quantity")] Product product) { if (ModelState.IsValid) { db.Entry(product).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(product)); }
public async Task <IActionResult> PutCartItem(int id, CartItem item) {//204(No Content) if (id != item.id) { return(BadRequest()); } _context.Entry(item).State = EntityState.Modified; await _context.SaveChangesAsync(); return(NoContent()); }
public IHttpActionResult PutCarts(int id, Carts carts) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != carts.Id) { return(BadRequest()); } var userId = User.Identity.GetUserId(); if (userId != carts.UserId) { return(StatusCode(HttpStatusCode.Conflict)); } db.Entry(carts).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!CartsExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public void Update(T entity) { _dbContext.Entry(entity).State = EntityState.Modified; }