public HttpResponseMessage Create(HttpRequestMessage request, DanhMucThongSoXNViewModel thongsoxetnghiemVm) { return(CreateHttpResponse(request, () => { HttpResponseMessage response = null; if (!ModelState.IsValid) { response = request.CreateResponse(HttpStatusCode.BadRequest, ModelState); } else { if (thongsoxetnghiemVm.isLocked == null) { thongsoxetnghiemVm.isLocked = false; } var newThongSo = new DanhMucThongSoXN(); newThongSo.UpdateThongSoXN(thongsoxetnghiemVm); danhMucThongSoXNService.Add(newThongSo); danhMucThongSoXNService.Save(); var responseData = Mapper.Map <DanhMucThongSoXN, DanhMucThongSoXNViewModel>(newThongSo); response = request.CreateResponse(HttpStatusCode.Created, responseData); } return response; })); }
public static void UpdateThongSoXN(this DanhMucThongSoXN thongso, DanhMucThongSoXNViewModel thongsoVm) { thongso.RowIDThongSo = thongsoVm.RowIDThongSo; thongso.IDThongSoXN = thongsoVm.IDThongSoXN; thongso.TenThongSo = thongsoVm.TenThongSo; thongso.MaDonViTinh = thongsoVm.MaDonViTinh; thongso.GiaTriMinNu = thongsoVm.GiaTriMinNu; thongso.GiaTriMaxNu = thongsoVm.GiaTriMaxNu; thongso.GiaTriTrungBinhNu = thongsoVm.GiaTriTrungBinhNu; thongso.GiaTriMacDinh = thongsoVm.GiaTriMacDinh; thongso.GiaTriMinNam = thongsoVm.GiaTriMinNam; thongso.GiaTriMaxNam = thongsoVm.GiaTriMaxNam; thongso.GiaTriTrungBinhNam = thongsoVm.GiaTriTrungBinhNam; thongso.MaNhom = thongsoVm.MaNhom; thongso.Stt = thongsoVm.Stt; thongso.GiaTri = thongsoVm.GiaTri; thongso.isLocked = thongsoVm.isLocked; thongso.DonViTinh = thongsoVm.DonViTinh; thongso.MaDVCS = thongsoVm.MaDVCS; thongso.MaTrungTam = thongsoVm.MaTrungTam; }
public HttpResponseMessage Put(HttpRequestMessage request, DanhMucThongSoXNViewModel thongsoxetnghiemVm) { return(CreateHttpResponse(request, () => { HttpResponseMessage response = null; if (!ModelState.IsValid) { request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } else { var thongsoxetnghiemDb = danhMucThongSoXNService.GetById(thongsoxetnghiemVm.RowIDThongSo); thongsoxetnghiemDb.UpdateThongSoXN(thongsoxetnghiemVm); danhMucThongSoXNService.Update(thongsoxetnghiemDb); danhMucThongSoXNService.Save(); response = request.CreateResponse(HttpStatusCode.OK); } return response; })); }