public async Task <IHttpActionResult> PutClass(string id, Class @class) { ComputerEntities db = new ComputerEntities(); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != @class.ClassCode) { return(BadRequest()); } db.Entry(@class).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ClassExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public async Task <IHttpActionResult> PostClass(Class @class) { ComputerEntities db = new ComputerEntities(); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.Classes.Add(@class); try { await db.SaveChangesAsync(); } catch (DbUpdateException) { if (ClassExists(@class.ClassCode)) { return(Conflict()); } else { throw; } } return(CreatedAtRoute("DefaultApi", new { id = @class.ClassCode }, @class)); }
public async Task <IHttpActionResult> DeleteClass(string id) { ComputerEntities db = new ComputerEntities(); Class @class = await db.Classes.FindAsync(id); if (@class == null) { return(NotFound()); } db.Classes.Remove(@class); await db.SaveChangesAsync(); return(Ok(@class)); }