public IHttpActionResult PostCareType(CareType careType) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.CareTypes.Add(careType); try { db.SaveChanges(); } catch (DbUpdateException) { if (CareTypeExists(careType.Id)) { return(Conflict()); } else { throw; } } return(CreatedAtRoute("DefaultApi", new { id = careType.Id }, careType)); }
public IHttpActionResult PutCareType(int id, CareType careType) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != careType.Id) { return(BadRequest()); } db.Entry(careType).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!CareTypeExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult GetCareType(int id) { CareType careType = db.CareTypes.Find(id); if (careType == null) { return(NotFound()); } return(Ok(careType)); }
public IHttpActionResult DeleteCareType(int id) { CareType careType = db.CareTypes.Find(id); if (careType == null) { return(NotFound()); } db.CareTypes.Remove(careType); db.SaveChanges(); return(Ok(careType)); }
public async Task <int> SaveCareType(CareType careType) { if (careType.Id != 0) { _context.CareTypes.Update(careType); await _context.SaveChangesAsync(); return(1); } else { await _context.CareTypes.AddAsync(careType); await _context.SaveChangesAsync(); return(1); } }