public async Task <JsonResult> AuditDoctor(JsonDoctorAudit audit) { var jsonResult = new VM_JsonOnlyResult(); var modelState = (new JsonDoctorAuditValidator()).Validate(audit); if (!modelState.IsValid) { jsonResult.Value = -1001; jsonResult.Err = string.Join(",", modelState.Errors.Select(m => m.ErrorMessage)); return(await Task.FromResult(Json(jsonResult))); } m_DoctorManagerService.PreOnUpdateHandler = () => m_DoctorManagerService.GetDoctor(audit.DoctorId); m_DoctorManagerService.OnUpdatingHandler = (expDoctor, a) => { ((Person)expDoctor).Doctor.AuditStatus = audit.IsPass ? DoctorAuditStatus.Pass : DoctorAuditStatus.Fail; ((Person)expDoctor).Doctor.AuditDate = DateTime.Now; }; var updatedStatus = await m_DoctorManagerService.UpdateObject <Person>(isAsync : true); if (updatedStatus == AppServiceExecuteStatus.Success) { jsonResult.Result = true; return(Json(jsonResult)); } jsonResult.Err = string.Format(updatedStatus.ToDescription(), "审核失败"); return(Json(jsonResult)); }
public async Task <JsonResult> AddProduct(VmProduct product) { var ret = new VM_JsonOnlyResult(); var modelState = (new VmProductValidator()).Validate(product); if (!modelState.IsValid) { ret.Value = -1001; ret.Err = string.Join(",", modelState.Errors.Select(m => m.ErrorMessage)); return(await Task.FromResult(Json(ret))); } m_ProductService.PreOnAddHandler = () => !m_ProductService.ProductIsExists(product.NagigatedDomainObject.Name); var added = await m_ProductService.AddObject(product.NagigatedDomainObject, true); if (added == AppServiceExecuteStatus.Success) { ret.Value = product.NagigatedDomainObject.ID; ret.Result = true; return(Json(ret)); } ret.Err = added.ToDescription(); return(Json(ret)); }
public async Task <JsonResult> UpdateDoctor(VmUserDoctor doctor) { var jsonResult = new VM_JsonOnlyResult(); var val = new VmDoctorValidator(); var modelState = val.Validate(doctor); if (!modelState.IsValid) { jsonResult.Err = string.Join(",", modelState.Errors.Select(e => e.ErrorMessage)); return(await Task.FromResult(Json(jsonResult))); } m_DoctorManagerService.PreOnUpdateHandler = () => m_DoctorManagerService.GetDoctor(doctor.NagigatedDomainObject.ID); m_DoctorManagerService.OnUpdatingHandler = (o, n) => { VmDoctorMapper.MapTo(((Person)n), (Person)o); }; var updateStatus = await m_DoctorManagerService.UpdateObject(doctor.NagigatedDomainObject); if (updateStatus == AppServiceExecuteStatus.Success) { jsonResult.Result = true; return(Json(jsonResult)); } jsonResult.Err = string.Format(updateStatus.ToDescription(), "更新医生信息失败"); return(Json(jsonResult)); }
public async Task <JsonResult> DeleteDoctor(long doctorId) { var jsonResult = new VM_JsonOnlyResult(); var selectedDoctor = m_DoctorManagerService.GetDoctor(doctorId); var parentPersonId = selectedDoctor?.Doctor.WithPerson.ID ?? 0L; m_DoctorManagerService.PreLogicDeleteHandler = () => { if (selectedDoctor != null && selectedDoctor.Doctor.AuditStatus != DoctorAuditStatus.Pass) { parentPersonId = selectedDoctor.ID; return(true); } return(false); }; var deleteStatus = await m_DoctorManagerService.LogicObjectDelete <Person, long>(parentPersonId); if (deleteStatus == AppServiceExecuteStatus.Success) { jsonResult.Result = true; return(Json(jsonResult)); } jsonResult.Err = string.Format(deleteStatus.ToDescription(), "当前审核状态不是待审核或者审核不通过"); return(Json(jsonResult)); }
public async Task <JsonResult> GetProductTypeListByParentId(long parentId, string parentName = "") { var ret = new VM_JsonOnlyResult(); VmProductTree productTree = new VmProductTree(); productTree.Id = parentId; productTree.Name = parentName; IList <ProductTypeInfo> productTypes = m_ProductService.GetProductTypeListByParentId(parentId); productTree.children = new List <ProductTreeChildren>(); if (productTypes != null && productTypes.Count > 0) { foreach (var pt in productTypes) { ProductTreeChildren pc = new ProductTreeChildren() { Name = pt.Name, Id = pt.ID }; productTree.children.Add(pc); } } ret.Value = productTree; ret.Result = true; return(Json(ret, JsonRequestBehavior.AllowGet)); }
public async Task <JsonResult> AddDepartment(VmDepartment dep) { var jsonResult = new VM_JsonOnlyResult(); var modelState = (new VmDepartmentValidator()).Validate(dep); if (!modelState.IsValid) { jsonResult.Err = string.Join(",", modelState.Errors.Select(m => m.ErrorMessage)); return(await Task.FromResult(Json(jsonResult))); } m_DepartmentService.PreOnAddHandler = () => !m_DepartmentService.DepartmentExists(dep.NagigatedDomainObject.Name); var addedRet = await m_DepartmentService.AddObject(dep.NagigatedDomainObject, true); if (addedRet == AppServiceExecuteStatus.Success) { jsonResult.Value = dep.NagigatedDomainObject.ID; jsonResult.Result = true; return(Json(jsonResult)); } jsonResult.Err = string.Format(addedRet.ToDescription(), "部门名称已存在"); return(Json(jsonResult)); }
public async Task <JsonResult> AddStaff(VmStaff staff) { var ret = new VM_JsonOnlyResult(); var modelState = (new VmStaffValidator()).Validate(staff); if (!modelState.IsValid) { ret.Value = -1001; ret.Err = string.Join("<br>", modelState.Errors.Select(m => m.ErrorMessage)); return(await Task.FromResult(Json(ret))); } var errorMsg = ""; m_UserManagerService.PreOnAddHandler = () => { var retCheck = true; if (m_UserManagerService.UserIsExists(staff.NagigatedDomainObject.Name)) { errorMsg += "用户名已存在,请重新输入!"; retCheck = false; } if (m_UserManagerService.UserIdCardIsExists(staff.NagigatedDomainObject.IdCard)) { errorMsg += "$身份证号已存在,请重新输入!"; retCheck = false; } return(retCheck); }; var dep = m_DepartmentManagerService.GetDepartment(staff.NagigatedDomainObject.DepartmentName); staff.NagigatedDomainObject.DepartmentId = dep?.ID; var role = m_UserManagerService.GetRole(staff.NagigatedDomainObject.Role.Name); staff.NagigatedDomainObject.Role = role; staff.NagigatedDomainObject.RoleId = role?.ID; var added = await m_UserManagerService.AddObject(staff.NagigatedDomainObject, true); if (added == AppServiceExecuteStatus.Success) { ret.Value = staff.NagigatedDomainObject.ID; ret.Result = true; return(Json(ret)); } ret.Err = errorMsg.Trim('$').Replace("$", "<br>");//string.Format(added.ToDescription(), "员工信息已存在"); if (string.IsNullOrEmpty(ret.Err)) { ret.Err = string.Format(added.ToDescription(), "员工信息添加失败"); } return(Json(ret)); }
public async Task <JsonResult> DeleteStaff(long staffId) { var ret = new VM_JsonOnlyResult(); var deleted = await m_UserManagerService.LogicObjectDelete <Person, long>(staffId, true); if (deleted == AppServiceExecuteStatus.Success) { ret.Value = staffId; ret.Result = true; return(Json(ret)); } ret.Err = string.Format(deleted.ToDescription(), "员工信息不存在"); return(Json(ret)); }
public Task <JsonResult> UploadFile(string uploadType = "resources") { if (Request.Files == null || Request.Files.Count == 0) { return(Task.FromResult(Json(new VM_JsonOnlyResult { Result = false, Err = "No file requested" }))); } return(Task <JsonResult> .Factory.StartNew(() => { var ret = new VM_JsonOnlyResult(); var toUploadFile = Request.Files[0]; if (toUploadFile == null) { ret.Err = "File can't be found."; return Json(ret); } if (toUploadFile.ContentLength > FileSize * 1024 * 1024) { ret.Err = "上传的文件超过限制标准,请重新上传!"; return Json(ret); } var saveFileDir = GetOrCreateStorageDir( LocalStorageConfiguration.Instance.UploadRootPath, uploadType); string outputFullFileName = ""; var allowed = IsAllowedExtension(toUploadFile, saveFileDir, out outputFullFileName); if (!allowed) { ret.Err = "上传的文件类型不符合,请重新上传!"; return Json(ret); } var outFile = new FileInfo(outputFullFileName); var visitUrl = LocalStorageConfiguration.Instance.VisitBaseUrl + "/" + uploadType.Replace(":", "/") + "/" + outFile.Name; ret.Result = true; ret.Value = visitUrl; return Json(ret); })); }
public async Task <JsonResult> UpdateProduct(VmProduct product) { var ret = new VM_JsonOnlyResult(); var modelState = (new VmProductValidator()).Validate(product); if (!modelState.IsValid) { ; ret.Value = -1001; ret.Err = string.Join(",", modelState.Errors.Select(m => m.ErrorMessage)); return(await Task.FromResult(Json(ret))); } m_ProductService.PreOnUpdateHandler = () => { var selfProduct = m_ProductService.GetProduct(product.NagigatedDomainObject.ID); if (selfProduct == null) { return(null); } var otherUser = m_ProductService.GetProduct(product.NagigatedDomainObject.Name); if (otherUser == null || otherUser.ID == selfProduct.ID) { return(selfProduct); } return(null); }; m_ProductService.OnUpdatingHandler = (existOject, newObject) => { ((Product)newObject).MapTo((Product)existOject); }; var updatedRet = await m_ProductService.UpdateObject(product.NagigatedDomainObject, true); if (updatedRet == AppServiceExecuteStatus.Success) { ret.Value = product.NagigatedDomainObject.ID; ret.Result = true; return(Json(ret)); } ret.Err = updatedRet.ToDescription(); return(Json(ret)); }
public async Task <JsonResult> UpdateDepartment(VmDepartment dep) { var jsonResult = new VM_JsonOnlyResult(); var modelState = (new VmDepartmentValidator()).Validate(dep); if (!modelState.IsValid) { jsonResult.Err = string.Join(",", modelState.Errors.Select(m => m.ErrorMessage)); return(await Task.FromResult(Json(jsonResult))); } m_DepartmentService.PreOnUpdateHandler = () => { var existDep = m_DepartmentService.GetDepartment(dep.NagigatedDomainObject.ID); if (existDep == null) { return(null); } var otherDep = m_DepartmentService.GetDepartment(dep.NagigatedDomainObject.Name); if (otherDep == null || otherDep.ID == dep.NagigatedDomainObject.ID) { return(existDep); } return(null); }; m_DepartmentService.OnUpdatingHandler = (oDep, nDep) => { ((Department)oDep).Name = ((Department)nDep).Name; ((Department)oDep).Desc = ((Department)nDep).Desc; }; var updatedRet = await m_DepartmentService.UpdateObject(dep.NagigatedDomainObject, true); if (updatedRet == AppServiceExecuteStatus.Success) { jsonResult.Value = dep.NagigatedDomainObject.ID; jsonResult.Result = true; } jsonResult.Err = string.Format(updatedRet.ToDescription(), "部门名称重复"); return(Json(jsonResult)); }
public async Task <JsonResult> BindHospital(VmDoctorBind preBind) { var jsonResult = new VM_JsonOnlyResult(); var modelState = (new VmDoctorBindValidator()).Validate(preBind); if (!modelState.IsValid) { jsonResult.Value = -1001; jsonResult.Err = string.Join(",", modelState.Errors.Select(m => m.ErrorMessage)); return(await Task.FromResult(Json(jsonResult))); } var toBindHospital = m_HospitalManagerService.GetHospital(preBind.HospitalId); if (toBindHospital == null) { jsonResult.Value = -1002; jsonResult.Err = "绑定医院不存在"; return(await Task.FromResult(Json(jsonResult))); } m_DoctorManagerService.PreOnUpdateHandler = () => m_DoctorManagerService.GetDoctor(preBind.DoctorId); m_DoctorManagerService.OnUpdatingHandler = (doctor, newDoctor) => { var expDoctor = (Person)doctor; var preBindInfo = expDoctor.Doctor.InHospital?.FirstOrDefault(h => h.ID == preBind.PreBindId && h.PersonDoctorId == preBind.DoctorId); if (preBindInfo != null) { preBindInfo.BindedHospitalId = toBindHospital.ID; preBindInfo.BindedHospitalName = toBindHospital.Name; preBindInfo.IsBinded = true; } }; var updatedStatus = await m_DoctorManagerService.UpdateObject <Person>(isAsync : true); if (updatedStatus == AppServiceExecuteStatus.Success) { jsonResult.Result = true; return(Json(jsonResult)); } jsonResult.Err = string.Format(updatedStatus.ToDescription(), "医院绑定失败"); return(Json(jsonResult)); }
public async Task <JsonResult> DeleteHospital(long hId) { var jsonResult = new VM_JsonOnlyResult(); m_HospitalService.PreLogicDeleteHandler = () => { var hospitalExists = m_HospitalService.GetHospitalCount(m => m.ID == hId).Result > 0; var hospitalHasDoctor = m_DoctorService.GetDoctorCount(p => p.IsDoctor && p.Doctor.InHospital.Any(h => h.BindedHospitalId == hId)).Result > 0; return(!hospitalExists || !hospitalHasDoctor); }; var deleteResult = await m_HospitalService.LogicObjectDelete <Hospital, long>(hId); if (deleteResult == AppServiceExecuteStatus.Success) { jsonResult.Result = true; return(Json(jsonResult)); } jsonResult.Err = string.Format(deleteResult.ToDescription(), "医院不存在"); return(Json(jsonResult)); }
public async Task <JsonResult> DelDepartment(long depId) { var ret = new VM_JsonOnlyResult(); var existUserInDep = m_UserService.HasUserInDepartment(depId); if (existUserInDep) { ret.Err = "该部门下已存在员工信息,无法删除部门信息!"; return(Json(ret)); } var deleted = await m_DepartmentService.LogicObjectDelete <Department, long>(depId, true); if (deleted == AppServiceExecuteStatus.Success) { ret.Value = depId; ret.Result = true; return(Json(ret)); } ret.Err = string.Format(deleted.ToDescription(), "部门信息不存在"); return(Json(ret)); }
public async Task <JsonResult> UpdateHospital(VmHospital vm) { var jsonResult = new VM_JsonOnlyResult(); var val = new VmHospitalValidator(); var modelState = val.Validate(vm); if (!modelState.IsValid) { jsonResult.Err = string.Join("<br>", modelState.Errors.Select(e => e.ErrorMessage)); return(await Task.FromResult(Json(jsonResult))); } m_HospitalService.PreOnUpdateHandler = () => { var ret = m_HospitalService.GetHospital(vm.NagigatedDomainObject.ID); var existHospital = m_HospitalService.GetHospital(vm.NagigatedDomainObject.Name); if (existHospital == null || existHospital.ID == vm.NagigatedDomainObject.ID) { return(ret); } return(null); }; m_HospitalService.OnUpdatingHandler = (existOject, newObject) => { ((Hospital)newObject).MapTo((Hospital)existOject); }; var updateStatus = await m_HospitalService.UpdateObject <Hospital>(vm.NagigatedDomainObject, true); if (updateStatus == AppServiceExecuteStatus.Success) { jsonResult.Result = true; return(Json(jsonResult)); } jsonResult.Err = string.Format(updateStatus.ToDescription(), "修改医院信息失败"); return(Json(jsonResult)); }
public async Task <JsonResult> AddHospital(VmHospital vm) { var jsonResult = new VM_JsonOnlyResult(); var val = new VmHospitalValidator(); var modelState = val.Validate(vm); if (!modelState.IsValid) { jsonResult.Err = string.Join("<br>", modelState.Errors.Select(e => e.ErrorMessage)); return(await Task.FromResult(Json(jsonResult))); } m_HospitalService.PreOnAddHandler = () => !m_HospitalService.HospitalExists(vm.NagigatedDomainObject.Name); var addResult = await m_HospitalService.AddObject(vm.NagigatedDomainObject, true); if (addResult == AppServiceExecuteStatus.Success) { jsonResult.Result = true; return(Json(jsonResult)); } jsonResult.Err = string.Format(addResult.ToDescription(), "医院名称已存在"); return(Json(jsonResult)); }
public async Task <JsonResult> UpdateStaff(VmStaff staff) { var ret = new VM_JsonOnlyResult(); var modelState = (new VmStaffValidator()).Validate(staff); if (!modelState.IsValid) { ret.Value = -1001; ret.Err = string.Join("<br>", modelState.Errors.Select(m => m.ErrorMessage)); return(await Task.FromResult(Json(ret))); } var errorMsg = ""; m_UserManagerService.PreOnUpdateHandler = () => { //var selfUser = m_UserManagerService.GetUser(staff.NagigatedDomainObject.ID); //if (selfUser == null) // return null; //var otherUser = m_UserManagerService.GetUser(staff.NagigatedDomainObject.Name); //if (otherUser == null || otherUser.ID == selfUser.ID) // return selfUser; var existUserName = m_UserManagerService.UserIsExists(staff.NagigatedDomainObject.Name, staff.NagigatedDomainObject.ID); if (existUserName) { errorMsg += "用户名已存在,请重新输入!"; } var existIdCard = m_UserManagerService.UserIdCardIsExists(staff.NagigatedDomainObject.IdCard, staff.NagigatedDomainObject.ID); if (existIdCard) { errorMsg += "$身份证号已存在,请重新输入!"; } if (!existUserName && !existIdCard) { return(m_UserManagerService.GetUser(staff.NagigatedDomainObject.ID)); } return(null); }; m_UserManagerService.OnUpdatingHandler = (existOject, newObject) => { var n = VmPersonMapper.MapTo(((Person)newObject), (Person)existOject); var dep = m_DepartmentManagerService.GetDepartment(staff.NagigatedDomainObject.DepartmentName); n.DepartmentId = dep?.ID; var role = m_UserManagerService.GetRole(staff.NagigatedDomainObject.Role.Name); n.Role = role; n.RoleId = role?.ID; }; var updatedRet = await m_UserManagerService.UpdateObject(staff.NagigatedDomainObject, true); if (updatedRet == AppServiceExecuteStatus.Success) { ret.Value = staff.NagigatedDomainObject.ID; ret.Result = true; return(Json(ret)); } ret.Err = errorMsg.Trim('$').Replace("$", "<br>"); if (string.IsNullOrEmpty(ret.Err)) { ret.Err = string.Format(updatedRet.ToDescription(), "更新员工信息失败"); } return(Json(ret)); }