public object CreateCancel(CreateCancelParameterModel model) { Applicant applicant = new Applicant(Entities, User.Identity.Name); ApplicationUser applicationUser = new ApplicationUser(Entities, User.Identity.Name); var flowcase = Entities.WF_FlowCases.FirstOrDefault(p => p.FlowCaseId == model.flowcaseid && p.StatusId > 0); if (flowcase == null) { return(new { ret_code = RetCode.Error, ret_msg = "Can not find workflow" }); } if (Entities.WF_FlowCases.FirstOrDefault(p => p.StatusId > 0 && p.RelatedFlowCaseId == model.flowcaseid) != null) { return(new { ret_code = RetCode.Error, ret_msg = "Cancelled already" }); } CreateFlowCaseInfo create = new CreateFlowCaseInfo(); if (model.approvers != null && model.approvers.Length > 0) { create.Approver = model.approvers; if (model.approvers.GroupBy(p => p).Any(p => p.Count() > 1)) { return(new { ret_code = RetCode.Error, ret_msg = "Duplicate approvers" }); } } create.FlowId = flowcase.FlowId; create.Properties = applicationUser.GetPropertyValues(model.flowcaseid); create.Subject = flowcase.Subject + "[Cancel]"; create.RelatedCaseId = model.flowcaseid; create.Deadline = flowcase.Deadline; create.Dep = flowcase.Department; create.NotifyUsers = flowcase.WF_CaseNotificateUsers.Where(p => p.StatusId > 0).Select(p => p.UserNo) .ToArray(); create.CoverDuties = flowcase.WF_CaseCoverUsers.Where(p => p.StatusId > 0).Select(p => p.UserNo) .ToArray(); try { (CreateFlowResult result, int flowCaseId)res = applicant.CreateFlowCase(create); if (res.result == CreateFlowResult.Success) { if (create.Approver != null) { EmailService.SendWorkFlowEmail( Entities.GlobalUserView.FirstOrDefault(p => p.EmployeeID == User.Identity.Name)?.EmployeeName, create.Approver, create.Subject, null); applicant.NotificationSender.PushInboxMessages(create.Approver, res.flowCaseId); applicant.NotificationSender.Send(); } return(new { ret_code = RetCode.Success }); } } catch (Exception ex) { return(new { ret_code = RetCode.Error, ret_msg = ex.Message }); } return(new { ret_code = RetCode.Error, ret_msg = "Can not create application" }); }
public (CreateFlowResult result, int flowCaseId) SaveDraft(CreateFlowCaseInfo info) { WF_FlowCases flowCase = new WF_FlowCases { Created = DateTime.UtcNow, Deadline = info.Deadline?.ToUniversalTime(), Department = info.Dep, LastUpdated = DateTime.UtcNow, LastChecked = DateTime.UtcNow, FlowId = info.FlowId, Subject = info.Subject, UserNo = CurrentUser, IsDissmissed = 0, IsRead = 0, StatusId = 0, Ver = 0, BaseFlowCaseId = null }; Entities.WF_FlowCases.Add(flowCase); if (info.Attachments != null) { foreach (Attachment att in info.Attachments) { Entities.WF_FlowCases_Attachments.Add(new WF_FlowCases_Attachments() { Created = DateTime.UtcNow, FileName = att.FileName, OriFileName = att.OriFilName, FileSize = att.FileSize, WF_FlowCases = flowCase, LastUpdated = DateTime.UtcNow, StatusId = 1 }); } } AddFlowProperties(flowCase, info.Properties); AddFinalNotifyUser(info.NotifyUsers, flowCase); AddCoverDuties(info.CoverDuties, flowCase); bool success = Entities.SaveChanges() > 0; if (success) { return(CreateFlowResult.Success, flowCase.FlowCaseId); } return(CreateFlowResult.InvalidData, 0); }
public ActionResult SaveDraft(int flowTypeId, CreateFlowCaseInfo caseInfo) { Applicant manager = new Applicant(WFEntities, this.Username); int selectedFlowId = manager.SelectFlow(flowTypeId, caseInfo); if (selectedFlowId > 0) { caseInfo.FlowId = selectedFlowId; (CreateFlowResult result, int flowCaseId)result = manager.SaveDraft(caseInfo); if (result.result == CreateFlowResult.Success) { ViewBag.PendingCount = manager.CountPending(); ViewBag.FlowCaseId = result.flowCaseId; return(PartialView("_SaveDraftResult", manager.GetFlowAndCase(result.flowCaseId))); } else { ViewBag.DisplayButtons = false; return(View("_PartialError", "~/Views/Shared/_ModalLayout.cshtml", StringResource.UNABLE_TO_CREATE_YOUR_APPLICATION)); } } ViewBag.DisplayButtons = false; return(View("_PartialError", "~/Views/Shared/_ModalLayout.cshtml", StringResource.NO_ELIGIBLE_WORKFLOW_FOUND)); }
public ActionResult SaveApp(int flowTypeId, int flowCaseId, CreateFlowCaseInfo caseinfo, string[] nextApprover) { Applicant manager = new Applicant(WFEntities, this.Username); FlowCaseInfo @case = manager.GetFlowCaseInfo(flowCaseId); if ([email protected](this.Username)) { ViewBag.DisplayButtons = false; return(View("_PartialError", "_ModalLayout", StringResource.YOU_CAN_NOT_MODIFY_APPLATION)); } if (caseinfo.Deadline.HasValue && caseinfo.Deadline <= DateTime.Now) { ViewBag.DisplayButtons = false; return(View("_PartialError", "~/Views/Shared/_ModalLayout.cshtml", StringResource.INVALID_DEADLINE)); } //if (!manager.CheckCancelLeaveBalance(caseinfo.Properties, flowTypeId)) //{ // ViewBag.DisplayButtons = false; // return View("_PartialError", "~/Views/Shared/_ModalLayout.cshtml", StringResource.ALREADY_CANCELED); //} if (nextApprover != null && nextApprover.Length > 0) { caseinfo.Approver = nextApprover; if (nextApprover.GroupBy(p => p).Any(p => p.Count() > 1)) { ViewBag.DisplayButtons = false; return(View("_PartialError", "~/Views/Shared/_ModalLayout.cshtml", StringResource.DUPLICATE_APPROVERS)); } } int selectedFlowId = manager.SelectFlow(flowTypeId, caseinfo); if (selectedFlowId == 0 || selectedFlowId != caseinfo.FlowId) { ViewBag.DisplayButtons = false; return(View("_PartialError", "~/Views/Shared/_ModalLayout.cshtml", StringResource.TEMPLATE_OUT_OF_DATE)); } if (selectedFlowId > 0) { caseinfo.FlowId = selectedFlowId; if ((nextApprover == null || nextApprover.Length == 0) && manager.HasSteps(selectedFlowId)) { NextStepData nsd = manager.GetNextStepApprovers(selectedFlowId, caseinfo.Properties, this.Username); if (nsd == null || nsd.EmployeeList == null || nsd.EmployeeList.Count == 0 || nsd.EmployeeList.Any(p => p == null || p.Length == 0)) { ViewBag.DisplayButtons = false; return(View("_PartialError", "_ModalLayout", StringResource.NO_NEXT_APPROVER_FOUND)); } return(View("~/Views/Application/SelectNextApprover.cshtml", "_ModalLayout", nsd.EmployeeList)); //if (nsd.EmployeeList.Count == 1 && nsd.EmployeeList[0].Length == 1) //{ // caseinfo.Approver = new string[] {nsd.EmployeeList.FirstOrDefault()?.FirstOrDefault()?.UserNo}; //} //else //{ // return View("~/Views/Application/SelectNextApprover.cshtml", "~/Views/Shared/_ModalLayout.cshtml", nsd.EmployeeList); //} } (CreateFlowResult result, int flowCaseId)result; if (@case.IsDraft) { manager.MarkFlowAsObsolete(flowCaseId); result = manager.CreateFlowCase(caseinfo); } else { int version = (@case.Ver ?? 0) + 1; int baseId = @case.BaseFlowCaseId ?? @case.FlowCaseId; manager.MarkFlowAsObsolete(flowCaseId); result = manager.CreateFlowCase(caseinfo, version, baseId); } ViewBag.FlowCaseId = result.flowCaseId; ViewBag.NextApprovers = caseinfo.Approver; if (result.result == CreateFlowResult.Success) { if (caseinfo.Approver != null) { EmailService.SendWorkFlowEmail( WFEntities.GlobalUserView.FirstOrDefault(p => p.EmployeeID == User.Identity.Name)?.EmployeeName, caseinfo.Approver, caseinfo.Subject, null); manager.NotificationSender.PushInboxMessages(caseinfo.Approver, result.flowCaseId); manager.NotificationSender.Send(); } ViewBag.PendingCount = manager.CountPending(); return(PartialView("_CreateResult", manager.GetFlowAndCase(result.flowCaseId))); } } else { ViewBag.DisplayButtons = false; return(View("_PartialError", "_ModalLayout", StringResource.NO_ELIGIBLE_WORKFLOW_FOUND)); } ViewBag.DisplayButtons = false; return(View("_PartialError", "~/Views/Shared/_ModalLayout.cshtml", StringResource.UNABLE_TO_CREATE_YOUR_APPLICATION)); }
public ActionResult SaveApp(int flowTypeId, CreateFlowCaseInfo caseInfo, string[] nextApprover) { if (caseInfo.Deadline.HasValue && caseInfo.Deadline <= DateTime.Now) { ViewBag.DisplayButtons = false; return(View("_PartialError", "~/Views/Shared/_ModalLayout.cshtml", StringResource.INVALID_DEADLINE)); } Applicant manager = new Applicant(WFEntities, this.Username); //if (!manager.CheckCancelLeaveBalance(caseInfo.Properties, flowTypeId)) //{ // ViewBag.DisplayButtons = false; // return View("_PartialError", "~/Views/Shared/_ModalLayout.cshtml", StringResource.ALREADY_CANCELED); //} if (nextApprover != null && nextApprover.Length > 0) { caseInfo.Approver = nextApprover; if (nextApprover.GroupBy(p => p).Any(p => p.Count() > 1)) { ViewBag.DisplayButtons = false; return(View("_PartialError", "~/Views/Shared/_ModalLayout.cshtml", StringResource.DUPLICATE_APPROVERS)); } } int selectedFlowId = manager.SelectFlow(flowTypeId, caseInfo); if (selectedFlowId > 0) { caseInfo.FlowId = selectedFlowId; bool HasStep = manager.HasSteps(selectedFlowId); if ((nextApprover == null || nextApprover.Length == 0) && HasStep) { NextStepData nsd = manager.GetNextStepApprovers(selectedFlowId, caseInfo.Properties, this.Username); if (nsd == null || nsd.EmployeeList == null || nsd.EmployeeList.Count == 0 || nsd.EmployeeList.Any(p => p == null || p.Length == 0)) { ViewBag.DisplayButtons = false; return(View("_PartialError", "_ModalLayout", StringResource.NO_NEXT_APPROVER_FOUND)); } return(View("SelectNextApprover", "_ModalLayout", nsd.EmployeeList)); } (CreateFlowResult result, int flowCaseId)res = manager.CreateFlowCase(caseInfo); ViewBag.FlowCaseId = res.flowCaseId; ViewBag.NextApprovers = caseInfo.Approver; if (res.result == CreateFlowResult.Success) { EmailService.SendWorkFlowEmail( WFEntities.GlobalUserView.FirstOrDefault(p => p.EmployeeID == User.Identity.Name)?.EmployeeName, caseInfo.Approver, caseInfo.Subject, null); manager.NotificationSender.PushInboxMessages(caseInfo.Approver, res.flowCaseId); manager.NotificationSender.Send(); ViewBag.PendingCount = manager.CountPending(); return(PartialView("_CreateResult", manager.GetFlowAndCase(res.flowCaseId))); } } else { ViewBag.DisplayButtons = false; return(View("_PartialError", "_ModalLayout", StringResource.NO_ELIGIBLE_WORKFLOW_FOUND)); } ViewBag.DisplayButtons = false; return(View("_PartialError", "~/Views/Shared/_ModalLayout.cshtml", StringResource.UNABLE_TO_CREATE_YOUR_APPLICATION)); }
public ReturnApproveResult Approve(int flowCaseId, string[] nextApprovers) { ReturnApproveResult result = new ReturnApproveResult(); var action = Entities.WF_CaseUserActions.Where( p => p.FlowCaseId == flowCaseId && p.UserNo == CurrentUser && p.ActionId == 0 && p.StatusId > 0) .Select(p => new { UserAction = p, Step = p.WF_FlowSteps, Group = p.WF_FlowSteps.WF_StepGroups, FlowCase = p.WF_FlowCases }).FirstOrDefault(); PropertyInfo[] propertyValues = GetPropertyValues(flowCaseId); //using (TransactionScope scope = new TransactionScope()) //{ if (action == null) { result.Result = ApproveResult.InvalidUserAction; return(result); } if (action.FlowCase == null || action.FlowCase.StatusId <= 0) { result.Result = ApproveResult.InvalidFlowCase; return(result); } if (action.FlowCase.Approved != null || action.FlowCase.Rejected != null || action.FlowCase.ReviseAbort != null) { result.Result = ApproveResult.FlowCaseTerminate; return(result); } if (action.Step == null || action.Step.StatusId <= 0) { result.Result = ApproveResult.InvalidFlowStep; return(result); } NextStepData nsd = GetNextStepApprovers(action.FlowCase.FlowId, propertyValues, action.FlowCase.UserNo, action.Group.StepGroupId); //#TODO if (nsd.EmployeeList?.Count != nextApprovers?.Length && nextApprovers?.Length > 0) { result.Result = ApproveResult.InvalidApprover; return(result); } if (nextApprovers != null && nextApprovers.Length > 0) { for (int i = 0; i < nextApprovers.Length; i++) { string userno = nextApprovers[i]; if (nsd.EmployeeList[i].All(p => p.UserNo != userno)) { result.Result = ApproveResult.InvalidApprover; return(result); } } result.NextApprovers = nextApprovers; } action.UserAction.ActionId = Consts.Approved; action.UserAction.LastUpdated = DateTime.UtcNow; AddCaseLog(CurrentUser, action.FlowCase, CaseLogType.AppStepApproved); var secretary = action.Step.WF_Secretary.Where(p => p.StatusId > 0).ToArray(); if (secretary?.Length > 0) { if (secretary.Any(p => CurrentUser.EqualsIgnoreCase(p.UserId))) { WF_CaseNotifications notification = NotificationManager.CreateNotification(flowCaseId, action.UserAction.FlowStepId, null, NotificationTypes.SecretaryNotification); foreach (var rule in secretary) { if (CurrentUser.EqualsIgnoreCase(rule.UserId)) { NotificationManager.PushNotification(notification, rule.SecretaryId, NotificationSources.Secretary); } } } } bool isCurrentStepApproved = action.Group.ConditionId == Consts.ConditionAny; if (!isCurrentStepApproved) { var otherSteps = Entities.WF_FlowSteps.Where( p => p.StepGroupId == action.Group.StepGroupId && p.FlowStepId != action.UserAction.FlowStepId && p.StatusId > 0); isCurrentStepApproved = !otherSteps.Any(); if (!isCurrentStepApproved) { isCurrentStepApproved = otherSteps.All( p => Entities.WF_CaseUserActions.Any( q => q.FlowCaseId == flowCaseId && q.FlowStepId == p.FlowStepId && q.ActionId == Consts.Approved && q.StatusId > 0)); } } //if current is finished if (isCurrentStepApproved) { if (nsd.NextStepGroupId == 0) //All steps finished { action.FlowCase.Approved = DateTime.UtcNow; action.FlowCase.LastUpdated = DateTime.UtcNow; WF_CaseNotifications notification = NotificationManager.CreateNotification(flowCaseId, action.UserAction.FlowStepId, null, NotificationTypes.AppFinishedApproved); NotificationManager.PushNotification(notification, action.FlowCase.UserNo, NotificationSources.ApproverApproved); NotificationManager.PushNotification(notification, CurrentUser, NotificationSources.ApproverApproved, n => n.IsDissmissed = 1); AddNotificationToPrevApprovers(flowCaseId, action.UserAction.FlowStepId, notification); AddFinalUserNotifications(flowCaseId, notification); AddCoverPersonNotifications(flowCaseId, flowCaseId, notification); AddLastStepNotifyUserNotifications(action.FlowCase.FlowId, notification, propertyValues, action.FlowCase.UserNo); //获取当前flowcase的templateid var flowCase = Entities.WF_FlowCases.FirstOrDefault(fc => fc.FlowCaseId == flowCaseId); int?groupId = flowCase?.WF_Flows.FlowGroupId; var flowType = Entities.WF_FlowGroups.Where(p => p.FlowGroupId == groupId) .Select(p => p.WF_FlowTypes) .FirstOrDefault(); int?templateId = flowType?.TemplateType; if (templateId.HasValue) { //如果是overseas trip application则在最后的审核者审核以后自动创建一个overseas claim application if (templateId.Value == (int)FlowTemplateType.OverSeasTripTemplate) { Applicant applicant = new Applicant(Entities, flowCase.UserNo); CreateFlowCaseInfo info = new CreateFlowCaseInfo(); var userInfo = SearStaffInfo(applicant.CurrentUser); //var user = Entities.Users.FirstOrDefault(p => p.UserNo == applicant.CurrentUser); //info.Dep = user?.DeptCode; info.Dep = userInfo?.Department; info.Subject = PresetValues.OverseasClaimSubjectPrefix + " " + userInfo.StaffName; PropertyInfo[] infos = new PropertyInfo[6]; var flowtype = Entities.WF_FlowTypes.FirstOrDefault( ft => ft.TemplateType == (int)FlowTemplateType.OverSeasClaimTemplate && ft.StatusId > 0); if (flowtype != null) { var claimGroup = Entities.WF_FlowGroups.FirstOrDefault( fg => fg.StatusId > 0 && fg.FlowTypeId == flowtype.FlowTypeId); var flow = Entities.WF_Flows.FirstOrDefault( f => f.FlowGroupId == claimGroup.FlowGroupId && f.StatusId > 0); if (claimGroup != null && flow != null) { int i = 0; foreach (var propertyValue in propertyValues) { string code = GetPropertyCode(propertyValue); int codeId = GetOverseasClaimCodeId(code); if (codeId > 0) { int propertyId = GetPropertyId(claimGroup.FlowGroupId, codeId); PropertyInfo newInfo = new PropertyInfo(); newInfo.Value = propertyValue.Value; newInfo.Type = propertyValue.Type; newInfo.Id = propertyId; infos[i] = newInfo; i++; } } info.Properties = infos; info.FlowId = flow.FlowId; applicant.SaveDraft(info); } } } else if (templateId.Value == (int)FlowTemplateType.LeaveTemplate) { float hours = 0f; string reason = null; var dict = GetLeaveProperties(flowCaseId); foreach (var propertyValue in propertyValues) { if (dict.ContainsKey("Leave_Type") && propertyValue.Id == dict["Leave_Type"]) { reason = propertyValue.Value; } if (dict.ContainsKey("Total_Hours") && propertyValue.Id == dict["Total_Hours"]) { hours = float.Parse(propertyValue.Value); } } if (hours > 0) { var uInfo = SearStaffInfo(flowCase.UserNo); if (reason.EqualsIgnoreCaseAndBlank(PresetValues.AnnualLeave) && (flowCase.RelatedFlowCaseId == null || flowCase.RelatedFlowCaseId == 0)) { UpdateLeaveBalance(uInfo.Country, flowCase.UserNo, hours / 8); } else if (reason.EqualsIgnoreCaseAndBlank(PresetValues.AnnualLeave) && flowCase.RelatedFlowCaseId != null) { UpdateLeaveBalance(uInfo.Country, flowCase.UserNo, -hours / 8); } } } //如果是User Data Change form,在通过所有审核后,需要插入或更新一条current的数据到StaffInfo表 else if (templateId.Value == (int)FlowTemplateType.UserDataChangeTemplate) { string eFirstName = null; string eLastName = null; string lFirstName = null; string lLastName = null; string address = null; string cAddress = null; string homeTel = null; string mobile = null; string bankName = null; string bankAccount = null; string maritalStatus = null; string familyMembers = null; string qualification = null; string email = null; DateTime effectiveDate = DateTime.UtcNow; var dict = GetPdcProperties(flowCaseId); foreach (var propertyValue in propertyValues) { if (dict.ContainsKey("PDC_EffectiveDateForChanges") && propertyValue.Id == dict["PDC_EffectiveDateForChanges"]) { effectiveDate = DateTime.Parse(propertyValue.Value).ToUniversalTime(); continue; } //var model = JsonConvert.DeserializeObject<dynamic>(propertyValue.Value); //if (model == null) //continue; if (dict.ContainsKey("PDC_EnglishFirstName") && propertyValue.Id == dict["PDC_EnglishFirstName"]) { eFirstName = propertyValue.Value; } else if (dict.ContainsKey("PDC_EnglishLastName") && propertyValue.Id == dict["PDC_EnglishLastName"]) { eLastName = propertyValue.Value; } else if (dict.ContainsKey("PDC_LocalLanguageFirstName") && propertyValue.Id == dict["PDC_LocalLanguageFirstName"]) { lFirstName = propertyValue.Value; } else if (dict.ContainsKey("PDC_LocalLanguageLastName") && propertyValue.Id == dict["PDC_LocalLanguageLastName"]) { lLastName = propertyValue.Value; } else if (dict.ContainsKey("PDC_ResidentialAddress") && propertyValue.Id == dict["PDC_ResidentialAddress"]) { address = propertyValue.Value; } else if (dict.ContainsKey("PDC_CorrespondenceAddress") && propertyValue.Id == dict["PDC_CorrespondenceAddress"]) { cAddress = propertyValue.Value; } else if (dict.ContainsKey("PDC_HomeTelephone") && propertyValue.Id == dict["PDC_HomeTelephone"]) { homeTel = propertyValue.Value; } else if (dict.ContainsKey("PDC_MobileTelephone") && propertyValue.Id == dict["PDC_MobileTelephone"]) { mobile = propertyValue.Value; } else if (dict.ContainsKey("PDC_BankName") && propertyValue.Id == dict["PDC_BankName"]) { bankName = propertyValue.Value; } else if (dict.ContainsKey("PDC_BankAccountNumber") && propertyValue.Id == dict["PDC_BankAccountNumber"]) { bankAccount = propertyValue.Value; } else if (dict.ContainsKey("PDC_MaritalStatus") && propertyValue.Id == dict["PDC_MaritalStatus"]) { maritalStatus = propertyValue.Value; } else if (dict.ContainsKey("PDC_FamilyMembers") && propertyValue.Id == dict["PDC_FamilyMembers"]) { StringBuilder sb = new StringBuilder(); //#TODO //foreach (var member in model) //{ // sb.Append(member.Value); // sb.Append("|"); //} //sb.Remove(sb.Length - 1, 1); familyMembers = propertyValue.Value; } else if (dict.ContainsKey("PDC_Qualification") && propertyValue.Id == dict["PDC_Qualification"]) { StringBuilder sb = new StringBuilder(); //#TODO //foreach (var qual in model) //{ // sb.Append(qual.Value); // sb.Append("|"); //} //sb.Remove(sb.Length - 1, 1); qualification = propertyValue.Value; } else if (dict.ContainsKey("PDC_EmailAddress") && propertyValue.Id == dict["PDC_EmailAddress"]) { email = propertyValue.Value; } } var staffInfo = Entities.StaffInfo.FirstOrDefault( si => si.StaffId.Equals(flowCase.UserNo) && si.StatusId > 0); if (staffInfo != null) { if (eFirstName != null) { staffInfo.EnglishFirstName = eFirstName; } if (eLastName != null) { staffInfo.EnglishLastName = eLastName; } if (lFirstName != null) { staffInfo.LocalFirstName = lFirstName; } if (lLastName != null) { staffInfo.LocalLastName = lLastName; } if (address != null) { staffInfo.ResidentialAddress = address; } if (cAddress != null) { staffInfo.CorrespondenceAddress = cAddress; } if (homeTel != null) { staffInfo.HomeTelephone = homeTel; } if (mobile != null) { staffInfo.MobileTelephone = mobile; } if (bankName != null) { staffInfo.BankName = bankName; } if (bankAccount != null) { staffInfo.BankAccountNumber = bankAccount; } if (maritalStatus != null) { staffInfo.MaritalStatus = maritalStatus; } if (familyMembers != null) { staffInfo.FamilyMembers = familyMembers; } if (qualification != null) { staffInfo.Qualification = qualification; } if (effectiveDate != null) { staffInfo.EffectiveDate = effectiveDate; } staffInfo.LastUpdated = DateTime.UtcNow; } else { Entities.StaffInfo.Add(new StaffInfo { Created = DateTime.UtcNow, LastUpdated = DateTime.UtcNow, StatusId = 1, StaffId = flowCase.UserNo, EnglishFirstName = eFirstName, EnglishLastName = eLastName, LocalFirstName = lFirstName, LocalLastName = lLastName, ResidentialAddress = address, CorrespondenceAddress = cAddress, HomeTelephone = homeTel, MobileTelephone = mobile, BankName = bankName, BankAccountNumber = bankAccount, MaritalStatus = maritalStatus, FamilyMembers = familyMembers, Qualification = qualification, EmailAddress = email, EffectiveDate = effectiveDate }); } } } } else { if (nextApprovers != null) { EmailService.SendWorkFlowEmail( Entities.GlobalUserView.FirstOrDefault(p => p.EmployeeID == CurrentUser)?.EmployeeName, nextApprovers, action.FlowCase.Subject, null); NotificationSender.PushInboxMessages(nextApprovers, flowCaseId); for (int i = 0; i < nsd.NextSteps.Length; i++) { WF_FlowSteps currentStep = nsd.NextSteps[i]; string currentUser = nextApprovers[i]; if (currentStep.ApproverType == (int)ApproverType.Person && currentStep.UserNo.EqualsIgnoreCaseAndBlank(currentUser)) { continue; } //string dep #TODO var userInfo = SearStaffInfo(currentUser); Entities.WF_CaseSteps.Add(new WF_CaseSteps { Created = DateTime.UtcNow, FlowStepId = currentStep.FlowStepId, Department = userInfo?.DepartmentName ?? string.Empty, //Department = Entities.Users.FirstOrDefault(p => p.UserNo == currentUser)?.DeptCode, UserNo = currentUser, FlowCaseId = flowCaseId, LastUpdated = DateTime.UtcNow, StatusId = 1 }); } for (int i = 0; i < nsd.NextSteps.Length; i++) { AddCaseUserAction(action.FlowCase, nsd.NextSteps[i].FlowStepId, nextApprovers[i]); } } } } if (action.FlowCase.Approved == null) { WF_CaseNotifications notification = NotificationManager.CreateNotification(flowCaseId, action.UserAction.FlowStepId, null, NotificationTypes.ApproveApp); AddNotificationToStepGroup(action.Group.StepGroupId, notification, propertyValues, action.FlowCase.UserNo); NotificationManager.PushNotification(notification, action.FlowCase.UserNo, NotificationSources.ApproverApproved); NotificationManager.PushNotification(notification, CurrentUser, NotificationSources.ApproverApproved, n => n.IsDissmissed = 1); } else { try { using (WorkFlowApiClient client = new WorkFlowApiClient()) { var fileBytes = ApprovedCasePdfExporter.GenerateFlowCase(GetPDFFlowModel(action.FlowCase.FlowCaseId), CurrentUser); var fileName = $"PDF FORM {action.FlowCase.Subject}-{action.FlowCase.FlowCaseId}.pdf"; string ret = client.UploadFile(fileName, Convert.ToBase64String(fileBytes)); JObject obj = JObject.Parse(ret); AddCaseAttachment(action.FlowCase, new Attachment { FileName = obj["fileName"].ToString(), OriFilName = fileName, FileSize = fileBytes.Length }); } } catch (Exception ex) { Singleton <ILogWritter> .Instance?.WriteLog("generate pdf error", ex.Message, $"flowcaseid: {action.FlowCase.FlowCaseId}"); } } action.FlowCase.CurrentStepGroup = action.Group.StepGroupId; try { Entities.SaveChanges(); //scope.Complete(); } catch (Exception e) { result.Result = ApproveResult.Error; return(result); } if (action.FlowCase.Approved != null) { using (WorkFlowApiClient client = new WorkFlowApiClient()) { client.ArchiveApproved(action.FlowCase.FlowCaseId); } result.Result = ApproveResult.FlowApproved; } else { result.Result = ApproveResult.Approved; } //} AutoApprove(action.FlowCase.FlowCaseId, action.FlowCase.FlowId, propertyValues, action.FlowCase.UserNo, action.Group.StepGroupId); var subsequents = GetSubsequentSteps(action.FlowCase.FlowId, propertyValues, action.FlowCase.UserNo, action.Group.StepGroupId); if (nextApprovers != null && nextApprovers.Length == 1 && subsequents != null && subsequents.Count > 0 && subsequents[0].EmployeeList != null) { var firstList = subsequents[0].EmployeeList[0]; string autoNextApprover = firstList[0].UserNo; bool shouldAutoApprove = false; foreach (var nextStepData in subsequents) { var employee = nextStepData.EmployeeList[0].First(); //因为只添加了只有一个审批者的步骤 if (nextApprovers.Contains(employee.UserNo)) { shouldAutoApprove = true; break; } } if (shouldAutoApprove) { Approver approver = new Approver(Entities, nextApprovers[0]); approver.Approve(flowCaseId, new string[] { autoNextApprover }); } } return(result); }
public ActionResult CreateCancel(int flowcaseid, string[] nextApprover) { Applicant applicant = new Applicant(WFEntities, this.Username); ApplicationUser applicationUser = new ApplicationUser(WFEntities, this.Username); var flowcase = WFEntities.WF_FlowCases.FirstOrDefault(p => p.FlowCaseId == flowcaseid && p.StatusId > 0); if (WFEntities.WF_FlowCases.FirstOrDefault(p => p.StatusId > 0 && p.RelatedFlowCaseId == flowcaseid) != null) { ViewBag.DisplayButtons = false; return(View("_PartialError", "~/Views/Shared/_ModalLayout.cshtml", "Cancelled already.")); } if (flowcase?.FlowId > 0) { bool HasStep = applicant.HasSteps(flowcase.FlowId); if ((nextApprover == null || nextApprover.Length == 0) && HasStep) { NextStepData nsd = applicant.GetNextStepApprovers(flowcase.FlowId, applicationUser.GetPropertyValues(flowcaseid), this.Username); if (nsd == null || nsd.EmployeeList == null || nsd.EmployeeList.Count == 0 || nsd.EmployeeList.Any(p => p == null || p.Length == 0)) { ViewBag.DisplayButtons = false; return(View("_PartialError", "~/Views/Shared/_ModalLayout.cshtml", StringResource.NO_NEXT_APPROVER_FOUND)); } return(View("SelectNextApprover", "~/Views/Shared/_ModalLayout.cshtml", nsd.EmployeeList)); } CreateFlowCaseInfo create = new CreateFlowCaseInfo(); if (nextApprover != null && nextApprover.Length > 0) { create.Approver = nextApprover; if (nextApprover.GroupBy(p => p).Any(p => p.Count() > 1)) { ViewBag.DisplayButtons = false; return(View("_PartialError", "~/Views/Shared/_ModalLayout.cshtml", StringResource.DUPLICATE_APPROVERS)); } } create.FlowId = flowcase.FlowId; create.Properties = applicationUser.GetPropertyValues(flowcaseid); create.Subject = flowcase.Subject + "[Cancel]"; create.RelatedCaseId = flowcaseid; create.Deadline = flowcase.Deadline; create.Dep = flowcase.Department; create.NotifyUsers = flowcase.WF_CaseNotificateUsers.Where(p => p.StatusId > 0).Select(p => p.UserNo) .ToArray(); create.CoverDuties = flowcase.WF_CaseCoverUsers.Where(p => p.StatusId > 0).Select(p => p.UserNo) .ToArray(); (CreateFlowResult result, int flowCaseId)res = applicant.CreateFlowCase(create); ViewBag.FlowCaseId = res.flowCaseId; ViewBag.NextApprovers = create.Approver; if (res.result == CreateFlowResult.Success) { EmailService.SendWorkFlowEmail( WFEntities.GlobalUserView.FirstOrDefault(p => p.EmployeeID == User.Identity.Name)?.EmployeeName, create.Approver, create.Subject, null); applicant.NotificationSender.PushInboxMessages(create.Approver, res.flowCaseId); applicant.NotificationSender.Send(); ViewBag.PendingCount = applicant.CountPending(); return(PartialView("_CreateResult", applicant.GetFlowAndCase(res.flowCaseId))); } } ViewBag.DisplayButtons = false; return(View("_PartialError", "~/Views/Shared/_ModalLayout.cshtml", "Cancel flowcase failed.")); }
public (CreateFlowResult result, int flowCaseId) CreateFlowCase(CreateFlowCaseInfo info, int version = 0, int?baseId = null) { NextStepData nsd = GetNextStepApprovers(info.FlowId, info.Properties, CurrentUser); if ((nsd.EmployeeList.Count == 0 || nsd.EmployeeList.Count != info.Approver.Length) && nsd.NextSteps != null && nsd.NextSteps.Length > 0) { return(CreateFlowResult.InvalidSelectedApprovers, 0); } if (info.Approver != null) { for (int i = 0; i < info.Approver.Length; i++) { string userno = info.Approver[i]; if (nsd.EmployeeList[i].All(p => p.UserNo != userno)) { return(CreateFlowResult.InvalidSelectedApprovers, 0); } } } //没有step的也允许创建,并且创建的时候设置通过了审核 WF_FlowCases flowCase = new WF_FlowCases { Created = DateTime.UtcNow, Deadline = info.Deadline?.ToUniversalTime(), Department = info.Dep, LastUpdated = DateTime.UtcNow, LastChecked = DateTime.UtcNow, FlowId = info.FlowId, Subject = info.Subject, UserNo = CurrentUser, IsDissmissed = 0, IsRead = 0, StatusId = 1, Ver = version, BaseFlowCaseId = baseId, RelatedFlowCaseId = info.RelatedCaseId }; Entities.WF_FlowCases.Add(flowCase); AddCaseLog(CurrentUser, flowCase, CaseLogType.AppCreated); if (info.Attachments != null) { foreach (Attachment att in info.Attachments) { AddCaseAttachment(flowCase, att); } } AddFlowProperties(flowCase, info.Properties); AddCoverDuties(info.CoverDuties, flowCase); AddFinalNotifyUser(info.NotifyUsers, flowCase); bool hasSteps = true; if (nsd.NextSteps != null && nsd.NextSteps.Length > 0) { for (int i = 0; i < nsd.NextSteps.Length; i++) { WF_FlowSteps currentStep = nsd.NextSteps[i]; string currentUser = info.Approver[i]; if (currentStep.ApproverType == (int)ApproverType.Person && currentStep.UserNo.EqualsIgnoreCaseAndBlank(currentUser)) { continue; } UserStaffInfo userInfo = SearStaffInfo(currentUser); Entities.WF_CaseSteps.Add(new WF_CaseSteps { Created = DateTime.UtcNow, FlowStepId = currentStep.FlowStepId, Department = userInfo?.DepartmentName ?? string.Empty, UserNo = currentUser, WF_FlowCases = flowCase, LastUpdated = DateTime.UtcNow, StatusId = 1 }); } for (int i = 0; i < nsd.NextSteps.Length; i++) { AddCaseUserAction(flowCase, nsd.NextSteps[i].FlowStepId, info.Approver[i]); } } else { hasSteps = false; flowCase.Approved = DateTime.UtcNow; flowCase.IsDissmissed = 1; } if (!hasSteps) { WF_CaseNotifications notification = NotificationManager.CreateNotification(flowCase, null, null, NotificationTypes.AppFinishedApproved); NotificationManager.PushNotification(notification, CurrentUser, NotificationSources.ApproverApproved); } bool hasNotifyUsers = Entities.WF_ApplicantNotificationUsers.Local.Any(); if (hasNotifyUsers) { WF_CaseNotifications applicantNotification = NotificationManager.CreateNotification(flowCase, null, null, NotificationTypes.ApplicantNotification); PropertyInfo[] propertyInfos = info.Properties .Where(p => p.Value != null) .ToArray(); AddApplicantNotification(info.FlowId, applicantNotification, propertyInfos, CurrentUser); } try { Entities.SaveChanges(); } catch (Exception ex) { Debug.WriteLine(ex.Message); return(CreateFlowResult.InvalidData, 0); } AutoApprove(flowCase.FlowCaseId, info.FlowId, info.Properties, CurrentUser); List <NextStepData> subsequents = GetSubsequentSteps(info.FlowId, info.Properties, CurrentUser); if (info.Approver != null && info.Approver.Length == 1 && subsequents != null && subsequents.Count > 0 && subsequents[0].EmployeeList != null) { Employee[] firstList = subsequents[0].EmployeeList[0]; string autoNextApprover = firstList[0].UserNo; bool shouldAutoApprove = false; foreach (var nextStepData in subsequents) { Employee employee = nextStepData.EmployeeList[0].First(); //因为只添加了只有一个审批者的步骤 if (info.Approver.Contains(employee.UserNo)) { shouldAutoApprove = true; break; } } if (shouldAutoApprove) { Approver approver = new Approver(Entities, info.Approver[0]); approver.Approve(flowCase.FlowCaseId, new string[] { autoNextApprover }); } } return(CreateFlowResult.Success, flowCase.FlowCaseId); }