public IHttpActionResult PutNCC_PUR_PHU_TRACH(int id, PurPhuTrach pur) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != pur.ID) { return(BadRequest()); } var nv = db.NCC_PUR_PHU_TRACH.Where(x => x.ID == id).FirstOrDefault(); nv.ID_LIEN_HE = pur.ID_LIEN_HE; nv.PUR_PHU_TRACH = pur.PUR_PHU_TRACH; if (pur.NGAY_KET_THUC_PHU_TRACH != null) { nv.NGAY_KET_THUC_PHU_TRACH = xlnt.Xulydatetime(pur.NGAY_KET_THUC_PHU_TRACH); } if (pur.NGAY_BAT_DAU_PHU_TRACH != null) { nv.NGAY_BAT_DAU_PHU_TRACH = xlnt.Xulydatetime(pur.NGAY_BAT_DAU_PHU_TRACH); } nv.TRANG_THAI = pur.TRANG_THAI; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!NCC_PUR_PHU_TRACHExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult PostNCC_PUR_PHU_TRACH(PurPhuTrach pur) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } NCC_PUR_PHU_TRACH nv = new NCC_PUR_PHU_TRACH(); nv.ID_LIEN_HE = pur.ID_LIEN_HE; nv.PUR_PHU_TRACH = pur.PUR_PHU_TRACH; if (pur.NGAY_BAT_DAU_PHU_TRACH != null) { nv.NGAY_BAT_DAU_PHU_TRACH = xlnt.Xulydatetime(pur.NGAY_BAT_DAU_PHU_TRACH); } if (pur.NGAY_KET_THUC_PHU_TRACH != null) { nv.NGAY_KET_THUC_PHU_TRACH = xlnt.Xulydatetime(pur.NGAY_KET_THUC_PHU_TRACH); } nv.TRANG_THAI = pur.TRANG_THAI; db.NCC_PUR_PHU_TRACH.Add(nv); try { db.SaveChanges(); } catch (DbUpdateException) { if (NCC_PUR_PHU_TRACHExists(pur.ID_LIEN_HE)) { return(Conflict()); } else { throw; } } return(CreatedAtRoute("DefaultApi", new { id = nv.ID_LIEN_HE }, nv)); }