Esempio n. 1
0
        public ActionResult CancelApp(int flowCaseId)
        {
            Applicant manager = new Applicant(WFEntities, this.Username);
            var       result  = manager.Cancel(flowCaseId);

            manager.NotificationSender.Send();
            ViewBag.CancelResult = result;
            ViewBag.PendingCount = manager.CountPending();//#TODO
            return(PartialView("_CancelResult", manager.GetFlowAndCase(flowCaseId)));
        }
        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));
        }
Esempio n. 3
0
        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."));
        }