public IHttpActionResult PutRoom(int id, Room room) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != room.Room_ID) { return(BadRequest()); } db.Entry(room).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!RoomExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult PutAddress(int id, Address address) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != address.Address_ID) { return(BadRequest()); } db.Entry(address).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!AddressExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult PutCard(string id, Card card) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != card.Card_Number) { return(BadRequest()); } db.Entry(card).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!CardExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult PutClientType(int id, ClientType clientType) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != clientType.ClientType_ID) { return(BadRequest()); } db.Entry(clientType).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!ClientTypeExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public bool UpdateEntityInDb(object updatedUser) { bool entityUpdated = false; using (var db = new BookingDBEntities()) { db.Entry(updatedUser).State = EntityState.Modified; bool saveFailed; do { saveFailed = false; try { db.SaveChanges(); // saves changes in DB entityUpdated = true; } catch (DbUpdateConcurrencyException ex) { saveFailed = true; ex.Entries.Single().Reload(); // reloads entity from DB entityUpdated = false; } } while (saveFailed); } return(entityUpdated); }
public IHttpActionResult PutBookingRecord(int id, BookingRecord bookingRecord) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != bookingRecord.BookingRecord_ID) { return(BadRequest()); } db.Entry(bookingRecord).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!BookingRecordExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult PutProperty(int id, Property property) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != property.Property_ID) { return(BadRequest()); } db.Entry(property).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!PropertyExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }