Пример #1
0
        public ActionResult Create(RegionalPSNPPlan regionalpsnpplan)
        {
            var         planName           = regionalpsnpplan.Plan.PlanName;
            var         startDate          = regionalpsnpplan.Plan.StartDate;
            var         firstDayOfTheMonth = startDate.AddDays(1 - startDate.Day);
            var         endDate            = firstDayOfTheMonth.AddMonths(regionalpsnpplan.Duration).AddDays(-1);
            UserProfile user = _userProfileService.GetUser(User.Identity.Name);

            if (ModelState.IsValid)
            {
                _regionalPSNPPlanService.AddPsnpPlan(planName, firstDayOfTheMonth, endDate);
                var plan = _planService.Get(m => m.PlanName == planName, null, "Program").FirstOrDefault();
                regionalpsnpplan.Plan = plan;

                //check if this psnp plan exitsts for this year and Plan
                var exists = plan != null && _regionalPSNPPlanService.DoesPsnpPlanExistForThisRegion(plan.PlanID, regionalpsnpplan.Year);

                if (!exists)
                {
                    int BP_PSNP = _ApplicationSettingService.getPSNPWorkflow();
                    if (BP_PSNP != 0)
                    {
                        BusinessProcessState createdstate = new BusinessProcessState
                        {
                            DatePerformed = DateTime.Now,
                            PerformedBy   = "System",
                            Comment       = "Created workflow for PSNP Plan"
                        };

                        var psnpPlan = _regionalPSNPPlanService.CreatePsnpPlan(regionalpsnpplan.Year, regionalpsnpplan.Duration, regionalpsnpplan.RationID, regionalpsnpplan.StatusID, plan.PlanID, user.UserProfileID);
                        //_planService.ChangePlanStatus(regionalpsnpplan.PlanId);
                        BusinessProcess bp = _BusinessProcessService.CreateBusinessProcess(BP_PSNP,
                                                                                           regionalpsnpplan.
                                                                                           RegionalPSNPPlanID,
                                                                                           "PSNP", createdstate);
                        psnpPlan.StatusID = bp.BusinessProcessID;
                        _regionalPSNPPlanService.UpdateRegionalPSNPPlan(psnpPlan);
                        return(RedirectToAction("Index"));
                    }
                    ViewBag.ErrorMessage1 = "The workflow assosiated with PSNP planning doesnot exist.";
                    ViewBag.ErrorMessage2 = "Please make sure the workflow is created and configured.";
                }
                LoadLookups();
                ModelState.AddModelError("Errors", @"PSNP plan already made for this period and plan Name.");
                return(View(regionalpsnpplan));
            }
            LoadLookups();

            return(View(regionalpsnpplan));
        }