public async Task <IActionResult> PutCustomer(int id, Customer customer) { if (id != customer.Id) { return(BadRequest()); } _context.Entry(customer).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CustomerExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutProduct(int id, Product product) { if (id != product.Id) { return(BadRequest()); } _context.Entry(product).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ProductExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutOrderLine(int id, OrderLine orderLine) { if (id != orderLine.Id) { return(BadRequest()); } _context.Entry(orderLine).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!OrderLineExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public IHttpActionResult PutProduct(int id, Product product) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != product.ID) { return(BadRequest()); } db.Entry(product).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!ProductExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
/// <summary> /// Deletes the specified entity automatic delete. /// </summary> /// <param name="entityToDelete">The entity automatic delete.</param> public virtual void Delete(TEntity entityToDelete) { if (entityToDelete == null) { throw new ArgumentNullException("entityToDelete"); } if (Context.Entry(entityToDelete).State == EntityState.Detached) { DbSet.Attach(entityToDelete); } DbSet.Remove(entityToDelete); var data = new JavaScriptSerializer().Serialize(entityToDelete); Logger.Log(Level.Debug, "Removed entity to context", String.Format("Type: {0}. Data: {1}", typeof(TEntity), data)); }
public ActionResult Edit([Bind(Include = "ID,Name")] ProductCategory productCategory) { if (ModelState.IsValid) { db.Entry(productCategory).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(productCategory)); }
public ActionResult Edit([Bind(Include = "ID,ProductCategoryID,Name,Description,Price,OwnerName,OwnerEmail,CreatedOn,UpdatedOn")] Product product) { if (ModelState.IsValid) { product.Update(); db.Entry(product).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.ProductCategoryID = new SelectList(db.ProductCategories, "ID", "Name", product.ProductCategoryID); return(View(product)); }
public InvoiceDetail Modify(InvoiceDetail t) { try { _webshopContext._InvoiceDetails.AddOrUpdate(t); _webshopContext.Entry(t).State = EntityState.Modified; return(t); } catch (Exception e) { throw new Exception(e.Message); } }
public Order UpdateOrder(Order orderUpdate) { var newOrderLines = new List <OrderLine>(orderUpdate.OrderLines); _ctx.Attach(orderUpdate).State = EntityState.Modified; _ctx.OrderLines.RemoveRange( _ctx.OrderLines.Where(ol => ol.OrderId == orderUpdate.OrderId) ); foreach (var ol in newOrderLines) { _ctx.Entry(ol).State = EntityState.Added; } _ctx.SaveChanges(); return(orderUpdate); }
public Product UpdateProduct(Product productUpdate) { var newOrderLines = new List <OrderLine>(productUpdate.OrderLines); _ctx.Attach(productUpdate).State = EntityState.Modified; _ctx.OrderLines.RemoveRange( _ctx.OrderLines.Where(ol => ol.ProductId == productUpdate.ProductId) ); foreach (var ol in newOrderLines) { _ctx.Entry(ol).State = EntityState.Added; } _ctx.SaveChanges(); return(productUpdate); }
public async Task <IActionResult> PutLogin(int id, Login login) { if (id != login.Id) { return(BadRequest()); } // prevent updateing a Login and removing the attached role if (login.Role == null && login.RoleId < 1) { return(BadRequest()); } _context.Entry(login).State = EntityState.Modified; if (login.Password != null) { login.Password = BC.HashPassword(login.Password); } try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!LoginExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }