public HttpResponseMessage Create(HttpRequestMessage request, DanhMucDonViCoSoViewModel donviVm) { return(CreateHttpResponse(request, () => { HttpResponseMessage response = null; if (!ModelState.IsValid) { response = request.CreateResponse(HttpStatusCode.BadRequest, ModelState); } else { if (donviVm.isLocked == null) { donviVm.isLocked = false; } var newDonVi = new DanhMucDonViCoSo(); newDonVi.UpdateDonViCoSo(donviVm); donViCoSoService.Add(newDonVi); donViCoSoService.Save(); var gdv = goidvtheotrungtamService.getAllTheoMaTT(newDonVi.MaDVCS.Substring(0, 3)); var gdvdvcs = Mapper.Map <IEnumerable <DanhMucGoiDichVuTrungTam>, IEnumerable <DanhMucGoiDichVuChung> >(gdv); goidvtheodvcsService.Add(newDonVi.MaDVCS, gdvdvcs.ToList()); goidvtheodvcsService.Save(); var responseData = Mapper.Map <DanhMucDonViCoSo, DanhMucDonViCoSoViewModel>(newDonVi); response = request.CreateResponse(HttpStatusCode.Created, responseData); } return response; })); }
public HttpResponseMessage Create(HttpRequestMessage request, DanhMucDonViCoSoViewModel donviVm) { return(CreateHttpResponse(request, () => { HttpResponseMessage response = null; if (!ModelState.IsValid) { response = request.CreateResponse(HttpStatusCode.BadRequest, ModelState); } else { if (donviVm.isLocked == null) { donviVm.isLocked = false; } var newDonVi = new DanhMucDonViCoSo(); newDonVi.UpdateDonViCoSo(donviVm); donViCoSoService.Add(newDonVi); donViCoSoService.Save(); var responseData = Mapper.Map <DanhMucDonViCoSo, DanhMucDonViCoSoViewModel>(newDonVi); response = request.CreateResponse(HttpStatusCode.Created, responseData); } return response; })); }
public HttpResponseMessage addupFromApp(HttpRequestMessage request) { HttpContent requestContent = Request.Content; string jsonContent = requestContent.ReadAsStringAsync().Result; PhieuSangLocViewModel phieuSangLocVm = JsonConvert.DeserializeObject <PhieuSangLocViewModel>(jsonContent); var userName = HttpContext.Current.GetOwinContext().Authentication.User.Identity.Name; var user = userManager.FindByNameAsync(userName).Result; if (phieuSangLocVm.MaTrungTam != user.LevelCode && !phieuSangLocVm.IDPhieu.Contains(user.LevelCode)) { return(request.CreateResponse(HttpStatusCode.ExpectationFailed, "Phiếu " + phieuSangLocVm.IDPhieu + "không thuộc trung tâm " + user.LevelCode)); } HttpResponseMessage response = null; var phieuDB = phieuSangLocService.GetById(phieuSangLocVm.IDPhieu); if (phieuDB == null) { var newPhieu = new PhieuSangLoc(); newPhieu.UpdatePhieuSangLoc(phieuSangLocVm); var lvcode = user.LevelCode; newPhieu.IDNhanVienTaoPhieu = user.Id; var newPatient = new Patient(); newPatient.UpdatePatient(phieuSangLocVm); newPhieu.MaBenhNhan = lvcode[1] + lvcode[2] + Guid.NewGuid().ToString(); newPatient.MaBenhNhan = newPhieu.MaBenhNhan; phieuSangLocService.Add(newPhieu); patientService.Add(newPatient); phieuSangLocService.Save(); response = request.CreateResponse(HttpStatusCode.Created, phieuSangLocVm); } else { phieuDB.UpdatePhieuSangLoc(phieuSangLocVm); var patientDB = patientService.GetByMaBN(phieuSangLocVm.MaBenhNhan); patientDB.UpdatePatient(phieuSangLocVm); this.phieuSangLocService.Update(phieuDB); this.patientService.Update(patientDB); donViCoSoService.Save(); response = request.CreateResponse(HttpStatusCode.OK); } return(response); }
public HttpResponseMessage Create(HttpRequestMessage request, PhieuSangLocViewModel phieuSangLocVm) { return(CreateHttpResponse(request, () => { HttpResponseMessage response = null; if (!ModelState.IsValid) { response = request.CreateResponse(HttpStatusCode.BadRequest, ModelState); } else { var phieuDB = phieuSangLocService.GetById(phieuSangLocVm.IDPhieu); if (phieuDB != null) { phieuDB.UpdatePhieuSangLoc(phieuSangLocVm); var patientDB = patientService.GetByMaBN(phieuSangLocVm.MaBenhNhan); patientDB.UpdatePatient(phieuSangLocVm); this.phieuSangLocService.Update(phieuDB); this.patientService.Update(patientDB); donViCoSoService.Save(); response = request.CreateResponse(HttpStatusCode.OK); } else { var newPhieu = new PhieuSangLoc(); newPhieu.UpdatePhieuSangLoc(phieuSangLocVm); ApplicationUser user = this.userManager.FindByNameAsync(phieuSangLocVm.Username).Result; newPhieu.IDNhanVienTaoPhieu = user.Id; var newPatient = new Patient(); newPatient.UpdatePatient(phieuSangLocVm); newPhieu.MaBenhNhan = Guid.NewGuid().ToString(); newPatient.MaBenhNhan = newPhieu.MaBenhNhan; phieuSangLocService.Add(newPhieu); patientService.Add(newPatient); phieuSangLocService.Save(); response = request.CreateResponse(HttpStatusCode.Created, phieuSangLocVm); } } return response; })); }