public async Task <IHttpActionResult> PostAction(CHM.Services.Models.Action action) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.Actions.Add(action); try { await db.SaveChangesAsync(); } catch (DbUpdateException) { if (ActionExists(action.ID)) { return(Conflict()); } else { throw; } } return(CreatedAtRoute("DefaultApi", new { id = action.ID }, action)); }
public async Task <IHttpActionResult> PutAction(Guid id, CHM.Services.Models.Action action) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != action.ID) { return(BadRequest()); } db.Entry(action).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ActionExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public async Task <IHttpActionResult> GetAction(Guid id) { CHM.Services.Models.Action action = await db.Actions.FindAsync(id); if (action == null) { return(NotFound()); } return(Ok(action)); }
public async Task <IHttpActionResult> DeleteAction(Guid id) { CHM.Services.Models.Action action = await db.Actions.FindAsync(id); if (action == null) { return(NotFound()); } db.Actions.Remove(action); await db.SaveChangesAsync(); return(Ok(action)); }