public object GetNextApprovers(int flowcaseid)
        {
            Singleton <ILogWritter> .Instance?.WriteLog("WorkFlow-get_next_approvers_by_caseid", flowcaseid.ToString());

            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 == flowcaseid && p.StatusId > 0);

            if (flowcase == null)
            {
                return(new { ret_code = RetCode.Error, ret_msg = "Can not find workflow" });
            }

            try
            {
                NextStepData nsd = applicant.GetNextStepApprovers(flowcase.FlowId, applicationUser.GetPropertyValues(flowcaseid), User.Identity.Name);
                if (nsd == null || nsd.EmployeeList == null || nsd.EmployeeList.Count == 0 ||
                    nsd.EmployeeList.Any(p => p == null || p.Length == 0))
                {
                    return(new { ret_code = RetCode.Error, ret_msg = "未找到符合条件的审批者" });
                }
                return(new { ret_code = RetCode.Success, ret_objects = nsd.EmployeeList.ToArray() });
            }
            catch (Exception e)
            {
                return(new { ret_code = RetCode.Error, ret_msg = e.Message });
            }
        }
Exemple #2
0
        public object get_next_approvers(int flowCaseId)
        {
            Approver     approver   = new Approver(Entities, User.Identity.Name);
            int          curGroupId = approver.GetCurrentStepGroupId(flowCaseId);
            NextStepData nsd        = approver.GetNextStepApprovers(flowCaseId, curGroupId);

            if (nsd.EmployeeList == null)
            {
                return(null);
            }
            return(new { data = nsd.EmployeeList.Select(p => p.Select(q => q)) });
        }
        public object GetNextApprovers(NextApproverParameterModel model)
        {
            Singleton <ILogWritter> .Instance?.WriteLog("WorkFlow-get_next_approvers", JsonConvert.SerializeObject(model));

            if (model.caseInfo.Deadline.HasValue && model.caseInfo.Deadline.Value.ToUniversalTime() <= DateTime.UtcNow)
            {
                return(new { ret_code = RetCode.Error, ret_msg = "Invalid dead line" });
            }

            Applicant manager        = new Applicant(Entities, User.Identity.Name);
            int       selectedFlowId = manager.SelectFlow(model.flowTypeId, model.caseInfo);

            if (selectedFlowId > 0)
            {
                if (!manager.HasSteps(selectedFlowId))
                {
                    //如果没有step,允许用户在没有nextapprover的情况下创建case,此时返回成功,但是nextapprover是空数组
                    string[] empty = new string[0];
                    return(new { ret_code = RetCode.Success, ret_objects = empty });
                }

                try
                {
                    NextStepData nsd = manager.GetNextStepApprovers(selectedFlowId, model.caseInfo.Properties,
                                                                    User.Identity.Name);
                    if (nsd == null || nsd.EmployeeList == null || nsd.EmployeeList.Count == 0 ||
                        nsd.EmployeeList.Any(p => p == null || p.Length == 0))
                    {
                        return(new { ret_code = RetCode.Error, ret_msg = "未找到符合条件的审批者" });
                    }

                    return(new { ret_code = RetCode.Success, ret_objects = nsd.EmployeeList.ToArray() });
                }
                catch (Exception ex)
                {
                    return(new { ret_code = RetCode.Error, ret_msg = ex.Message });
                }
            }
            else
            {
                return(new { ret_code = RetCode.Error, ret_msg = "Can not find workflow" });
            }
        }
        public ActionResult Approve(int flowCaseId, string[] nextApprover)
        {
            Approver manager = new Approver(WFEntities, this.Username);

            if (nextApprover == null || nextApprover.Length == 0)
            {
                int          curGroupId = manager.GetCurrentStepGroupId(flowCaseId);
                NextStepData nsd        = manager.GetNextStepApprovers(flowCaseId, curGroupId);
                if (nsd.EmployeeList.Count > 0)
                {
                    ViewBag.flowCaseId = flowCaseId;
                    return(View("SelectNextApprover", "~/Views/Shared/_ModalLayout.cshtml", nsd.EmployeeList));
                }
            }
            ReturnApproveResult returnValue = manager.Approve(flowCaseId, nextApprover);

            manager.NotificationSender.Send();
            ViewBag.nextStepUsers = returnValue.NextApprovers;
            ViewBag.approveResult = returnValue.Result;
            ViewBag.InboxCount    = manager.CountInbox();
            return(PartialView("Result", manager.GetFlowAndCase(flowCaseId)));
        }
        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 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."));
        }