public IHttpActionResult PutDriver(int id, Driver driver) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != driver.DriverId) { return(BadRequest()); } var driverToBeUpdated = db.Drivers.Find(id); db.Entry(driverToBeUpdated).CurrentValues.SetValues(driver); db.Entry(driverToBeUpdated).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!DriverExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult PutDispensary(int id, Dispensary dispensary) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != dispensary.DispensaryId) { return(BadRequest()); } db.Entry(dispensary).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!DispensaryExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult PutPickUp(int driverId, int inventoryId, PickUp pickUp) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (driverId != pickUp.DriverId || inventoryId != pickUp.InventoryId) { return(BadRequest()); } db.Entry(pickUp).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!PickUpExists(pickUp.DriverId, pickUp.InventoryId)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult PutUser(int id, User user) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != user.UserId) { return(BadRequest()); } db.Entry(user).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!UserExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }