public IHttpActionResult PostKhoSo(KhoSo khoSo) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.KhoSo.Add(khoSo); try { db.SaveChanges(); } catch (DbUpdateException) { if (KhoSoExists(khoSo.SoHieu)) { return(Conflict()); } else { throw; } } return(CreatedAtRoute("DefaultApi", new { id = khoSo.SoHieu }, khoSo)); }
public IHttpActionResult PutKhoSo(string id, KhoSo khoSo) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != khoSo.SoHieu) { return(BadRequest()); } db.Entry(khoSo).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!KhoSoExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult GetKhoSo(string id) { KhoSo khoSo = db.KhoSo.Find(id); if (khoSo == null) { return(NotFound()); } return(Ok(khoSo)); }
public IHttpActionResult DeleteKhoSo(string id) { KhoSo khoSo = db.KhoSo.Find(id); if (khoSo == null) { return(NotFound()); } db.KhoSo.Remove(khoSo); db.SaveChanges(); return(Ok(khoSo)); }