public ActionResult MarkFlag(int flowCaseId, int flag) { WF_FlowCases flow = WFEntities.WF_FlowCases.FirstOrDefault(p => p.StatusId > 0 && p.FlowCaseId == flowCaseId); if (flow != null) { flow.IsFlagged = flag == 1 ? 0 : 1; } WFEntities.SaveChanges(); return(RedirectToAction("Index")); }
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 void PushNotification(WF_FlowCases flowCase, int?flowstepId, string comments, string receiver, NotificationTypes type, NotificationSources source) { WF_CaseNotificationReceivers not = new WF_CaseNotificationReceivers { WF_CaseNotifications = CreateNotification(flowCase, flowstepId, comments, type), SourceType = (int)source, Created = DateTime.UtcNow, LastUpdated = DateTime.UtcNow, IsRead = 0, IsDissmissed = 0, Receiver = receiver, StatusId = 1 }; _entities.WF_CaseNotificationReceivers.Add(not); NotificationSender.PushNotificationMessages(new[] { receiver }, () => not.CaseNotificationReceiverId); }
public WF_CaseNotifications CreateNotification(WF_FlowCases flowCase, int?flowStepId, string comments, NotificationTypes type) { WF_CaseNotifications message = new WF_CaseNotifications { Created = DateTime.UtcNow, WF_FlowCases = flowCase, FlowStepId = flowStepId, LastUpdated = DateTime.UtcNow, NotificationType = (int)type, Comments = comments, Sender = _currentUser, StatusId = 1 }; _entities.WF_CaseNotifications.Add(message); return(message); }
public object set_flag_status(int flowCaseId, int flag) { WF_FlowCases flow = Entities.WF_FlowCases.FirstOrDefault(p => p.StatusId > 0 && p.FlowCaseId == flowCaseId); if (flow != null) { if (flag == 1) { flow.IsFlagged = 1; } if (flag == 0) { flow.IsFlagged = 0; } Entities.SaveChanges(); return(new { ret_code = RetCode.Success, ret_msg = string.Empty }); } return(new { ret_code = RetCode.Failure, ret_msg = "Unable set to read" });; }
public CommentStepResult CommentStep(int flowCaseId, string comments, bool?ccToPrev) { WF_FlowCases flowCase = Entities.WF_FlowCases.AsNoTracking().FirstOrDefault(p => p.FlowCaseId == flowCaseId); if (flowCase == null || flowCase.StatusId <= 0) { return(CommentStepResult.InvalidCase); } if (flowCase.Approved != null || flowCase.Rejected != null || flowCase.Canceled != null) { return(CommentStepResult.CaseTerminate); } WF_CaseUserActions userAction = Entities.WF_CaseUserActions.AsNoTracking().FirstOrDefault(p => p.ActionId == 0 && p.StatusId > 0 && p.UserNo == CurrentUser); if (userAction == null || !userAction.UserNo.EqualsIgnoreCaseAndBlank(CurrentUser)) { return(CommentStepResult.NotAllowed); } WF_CaseNotifications message = NotificationManager.CreateNotification(flowCaseId, userAction.FlowStepId, comments, NotificationTypes.Comments); string[] users = Entities.WF_CaseUserActions.AsNoTracking().Where(p => p.FlowCaseId == flowCaseId && p.StatusId > 0 && p.UserNo != CurrentUser).Select(p => p.UserNo).ToArray(); //把comment的statusid设置成2,这样在获取notification的时候如果只获取statusid=1的,就不会获取到comment的notification,参考ApplicationUser.GetNotifications NotificationManager.PushNotification(message, flowCase.UserNo, NotificationSources.ApproverCommentted, p => { p.IsDissmissed = 1; p.StatusId = 2; }); if (ccToPrev == true) { foreach (string userno in users) { NotificationManager.PushNotification(message, userno, NotificationSources.ApproverCommentted); } } Entities.SaveChanges(); return(CommentStepResult.Success); }
public CancelFlowResult Cancel(int flowCaseId) { WF_FlowCases flowCase = Entities.WF_FlowCases.FirstOrDefault(p => p.FlowCaseId == flowCaseId); if (flowCase == null || flowCase.StatusId < 0) { return(CancelFlowResult.InvalidFlowCase); } if (flowCase.Approved != null || flowCase.Rejected != null || flowCase.ReviseAbort != null || flowCase.Canceled != null) { return(CancelFlowResult.InvalidFlowCaseStatus); } if (!flowCase.UserNo.EqualsIgnoreCaseAndBlank(CurrentUser)) { return(CancelFlowResult.InvalidUser); } if (flowCase.StatusId == 0) // is draft ? { flowCase.StatusId = Consts.ApplicationDeleted; Entities.SaveChanges(); return(CancelFlowResult.Canceled); } flowCase.LastUpdated = DateTime.UtcNow; flowCase.Canceled = DateTime.UtcNow; flowCase.StatusId = Consts.ApplicationCancelled; AddCaseLog(CurrentUser, flowCase, CaseLogType.AppCancelled); WF_CaseNotifications not = NotificationManager.CreateNotification(flowCaseId, null, null, NotificationTypes.CancelApp); NotificationManager.PushNotification(not, flowCase.UserNo, NotificationSources.ApplicantCancelled, p => p.IsDissmissed = 1);//Dissmissed the message of cancelled app for current user. AddNotificationToPrevApprovers(flowCaseId, 0, not); Entities.SaveChanges(); if (flowCase.Approved != null) { return(CancelFlowResult.Error); } return(CancelFlowResult.Canceled); }
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); }