public HttpResponseMessage Put(HttpRequestMessage request, PhieuSangLocViewModel phieuSangLocVm) { return(CreateHttpResponse(request, () => { HttpResponseMessage response = null; if (!ModelState.IsValid) { request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } else { var phieuDB = phieuSangLocService.GetById(phieuSangLocVm.IDPhieu); 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 static void UpdatePhieuSangLoc(this PhieuSangLoc phieusangloc, PhieuSangLocViewModel phieusanglocVm) { phieusangloc.RowIDPhieu = phieusanglocVm.RowIDPhieu; phieusangloc.IDPhieu = phieusanglocVm.IDPhieu; phieusangloc.NgayTaoPhieu = phieusanglocVm.NgayTaoPhieu; phieusangloc.IDNhanVienTaoPhieu = phieusanglocVm.IDNhanVienTaoPhieu; phieusangloc.IDCoSo = phieusanglocVm.IDCoSo; if (phieusanglocVm.NgayGioLayMau != null && phieusanglocVm.NgayGioLayMauTime != null) { DateTime NgayGioLayMau = DateTime.ParseExact(phieusanglocVm.NgayGioLayMau, "dd/MM/yyyy", CultureInfo.InvariantCulture); DateTime NgayGioLayMauTime = Convert.ToDateTime(phieusanglocVm.NgayGioLayMauTime); phieusangloc.NgayGioLayMau = new DateTime(NgayGioLayMau.Year, NgayGioLayMau.Month, NgayGioLayMau.Day, NgayGioLayMauTime.Hour, NgayGioLayMauTime.Minute, NgayGioLayMauTime.Second); } phieusangloc.IDViTriLayMau = phieusanglocVm.IDViTriLayMau; phieusangloc.IDNhanVienLayMau = phieusanglocVm.IDNhanVienLayMau; phieusangloc.isLayMauLan2 = phieusanglocVm.isLayMauLan2; phieusangloc.IDPhieuLan1 = phieusanglocVm.IDPhieuLan1; phieusangloc.TinhTrangLucLayMau = phieusanglocVm.TinhTrangLucLayMau; phieusangloc.SLTruyenMau = phieusanglocVm.SLTruyenMau; if (!string.IsNullOrEmpty(phieusanglocVm.NgayTruyenMau)) { DateTime NgayTruyenMau = DateTime.ParseExact(phieusanglocVm.NgayTruyenMau.Substring(0, 16), "dd/MM/yyyy HH:mm", mFomatter); phieusangloc.NgayTruyenMau = NgayTruyenMau; } phieusangloc.CheDoDinhDuong = phieusanglocVm.CheDoDinhDuong; phieusangloc.TrangThaiPhieu = phieusanglocVm.TrangThaiPhieu; phieusangloc.TrangThaiMau = phieusanglocVm.TrangThaiMau; phieusangloc.isKhongDat = phieusanglocVm.isKhongDat; phieusangloc.NgayNhanMau = phieusanglocVm.NgayNhanMau; phieusangloc.MaXetNghiem = phieusanglocVm.MaXetNghiem; phieusangloc.Para = phieusanglocVm.Para; phieusangloc.isTruoc24h = phieusanglocVm.isTruoc24h; phieusangloc.isSinhNon = phieusanglocVm.isSinhNon; phieusangloc.isNheCan = phieusanglocVm.isNheCan; phieusangloc.isGuiMauTre = phieusanglocVm.isGuiMauTre; phieusangloc.IDChuongTrinh = phieusanglocVm.IDChuongTrinh; phieusangloc.MaGoiXN = phieusanglocVm.MaGoiXN; phieusangloc.TenNhanVienLayMau = phieusanglocVm.TenNhanVienLayMau; phieusangloc.SDTNhanVienLayMau = phieusanglocVm.SDTNhanVienLayMau; phieusangloc.NoiLayMau = phieusanglocVm.NoiLayMau; phieusangloc.isHuyMau = phieusanglocVm.isHuyMau; phieusangloc.LyDoKhongDat = phieusanglocVm.LyDoKhongDat; phieusangloc.isDongBo = phieusanglocVm.isDongBo; phieusangloc.isXoa = phieusanglocVm.isXoa; phieusangloc.DiaChiLayMau = phieusanglocVm.DiaChiLayMau; phieusangloc.isXNLan2 = phieusanglocVm.isXNLan2; phieusangloc.IDNhanVienXoa = phieusanglocVm.IDNhanVienXoa; phieusangloc.NgayGioXoa = phieusanglocVm.NgayGioXoa; phieusangloc.MaDVCS = phieusanglocVm.MaDVCS; }
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) { var userName = HttpContext.Current.GetOwinContext().Authentication.User.Identity.Name; var user = userManager.FindByNameAsync(userName).Result; 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); 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); } } return response; })); }
public static void UpdatePatient(this Patient patient, PhieuSangLocViewModel phieusanglocVm) { patient.FatherName = phieusanglocVm.FatherName; patient.MotherName = phieusanglocVm.MotherName; if (!string.IsNullOrEmpty(phieusanglocVm.FatherBirthday)) { patient.FatherBirthday = DateTime.ParseExact(phieusanglocVm.FatherBirthday.Substring(0, 10), "dd/MM/yyyy", CultureInfo.InvariantCulture); } if (!string.IsNullOrEmpty(phieusanglocVm.MotherBirthday)) { patient.MotherBirthday = DateTime.ParseExact(phieusanglocVm.MotherBirthday.Substring(0, 10), "dd/MM/yyyy", CultureInfo.InvariantCulture); } patient.FatherPhoneNumber = phieusanglocVm.FatherPhoneNumber; patient.MotherPhoneNumber = phieusanglocVm.MotherPhoneNumber; patient.MaKhachHang = phieusanglocVm.MaKhachHang; patient.DiaChi = phieusanglocVm.DiaChi; patient.Para = phieusanglocVm.Para; patient.TenBenhNhan = phieusanglocVm.TenBenhNhan; if (phieusanglocVm.NgayGioSinh != null && phieusanglocVm.NgayGioSinhTime != null) { DateTime NgayGioSinh = DateTime.ParseExact(phieusanglocVm.NgayGioSinh, "dd/MM/yyyy", CultureInfo.InvariantCulture); DateTime NgayGioSinhTime = Convert.ToDateTime(phieusanglocVm.NgayGioSinhTime); patient.NgayGioSinh = new DateTime(NgayGioSinh.Year, NgayGioSinh.Month, NgayGioSinh.Day, NgayGioSinhTime.Hour, NgayGioSinhTime.Minute, NgayGioSinhTime.Second); } patient.CanNang = phieusanglocVm.CanNang; patient.TuanTuoiKhiSinh = phieusanglocVm.TuanTuoiKhiSinh; patient.NoiSinh = phieusanglocVm.NoiSinh; patient.QuocTichID = phieusanglocVm.QuocTichID; patient.DanTocID = phieusanglocVm.DanTocID; patient.PhuongPhapSinh = phieusanglocVm.PhuongPhapSinh; patient.GioiTinh = phieusanglocVm.GioiTinh; patient.isDongBo = phieusanglocVm.isDongBo; patient.isXoa = phieusanglocVm.isXoa; patient.IDThaiPhuTienSoSinh = phieusanglocVm.IDThaiPhuTienSoSinh; patient.IDNhanVienXoa = phieusanglocVm.IDNhanVienXoa; patient.NgayGioXoa = phieusanglocVm.NgayGioXoa; patient.Email = patient.Email; }