public IHttpActionResult PutProduct(int id, Product product) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != product.PId) { return(BadRequest()); } db.Entry(product).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!ProductExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult PutBook(string id, Book book) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != book.Title) { return(BadRequest()); } db.Entry(book).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!BookExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult PutEmployee(int id, Employee employee) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != employee.EmployeeID) { return(BadRequest()); } db.Entry(employee).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!EmployeeExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult PutUsuarios(int id, Usuarios usuarios) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != usuarios.id) { return(BadRequest("Los Ids deben ser iguales para realizar la actualizacion.")); } db.Entry(usuarios).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!UsuariosExists(id)) { return(NotFound()); } else { throw; } } return(Ok(usuarios)); }
//delete-delete a record base on id public IHttpActionResult Delete(int id) { if (id <= 0) { return(BadRequest("please enter valid customer id")); } using (var x = new webapiEntities()) { var customer = x.Customers .Where(c => c.id == id).FirstOrDefault(); x.Entry(customer).State = System.Data.Entity.EntityState.Deleted; x.SaveChanges(); } return(Ok()); }
public void UpdateModel(T model) { _context.Entry(model).State = System.Data.Entity.EntityState.Modified; }