public IHttpActionResult PostDutyPosition(DutyPosition dutyPosition) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.DutyPositions.Add(dutyPosition); try { db.SaveChanges(); } catch (DbUpdateException) { if (DutyPositionExists(dutyPosition.id)) { return(Conflict()); } else { throw; } } return(CreatedAtRoute("DefaultApiPost", new { id = dutyPosition.id }, dutyPosition)); }
public IHttpActionResult PutDutyPosition(int id, DutyPosition dutyPosition) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != dutyPosition.id) { return(BadRequest()); } db.Entry(dutyPosition).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!DutyPositionExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult DeleteDutyPosition(int id) { DutyPosition dutyPosition = db.DutyPositions.Find(id); if (dutyPosition == null) { return(NotFound()); } db.DutyPositions.Remove(dutyPosition); db.SaveChanges(); return(Ok(dutyPosition)); }
public IHttpActionResult GetDutyPosition(int id) { DutyPosition dutyPosition = db.DutyPositions.Find(id); if (dutyPosition == null) { return(NotFound()); } return(Ok(new DropDownDTO { id = dutyPosition.id.ToString(), description = dutyPosition.description })); }