Beispiel #1
0
        public Task <PlanningApp> NextState(PlanningApp planningApp)
        {
            if (!planningApp.Completed())
            {
                var prevState = planningApp.Current();
                if (!planningApp.isLastState(prevState))
                {
                    planningApp.SeekNext().CurrentState = true;       //move to next state
                }

                var daysDiff = PlanningAppStateService.CompleteState(prevState);
                if (planningApp.Completed())
                {
                    planningApp.CurrentPlanningStatus = statusList.Where(s => s.Name == StatusList.Complete).SingleOrDefault();
                }
                else
                {
                    //If Overran then roll all future completion dates by business days overdue
                    if (daysDiff > 0)
                    {
                        RollForwardDueByDates(planningApp, daysDiff);
                    }
                }
            }
            PlanningAppRepository.UpdatePlanningApp(planningApp);

            return(GetPlanningApp(planningApp.Id));
        }
Beispiel #2
0
        public async Task <PlanningApp> Create(CreatePlanningAppResource planningResource)
        {
            var planningApp = Mapper.Map <CreatePlanningAppResource, PlanningApp>(planningResource);

            //Use when gui setup to create multiple generators
            //planningApp.ProjectGenerator = ProjectGeneratorRepository.GetProjectGenerator(planningResource.ProjectGeneratorId).Result;
            //Console.WriteLine("Creating New Planning App, Project Generator -> " + planningApp.ProjectGenerator.Name);

            //Dummy project multi generator for now
            planningApp.ProjectGeneratorId = planningResource.ProjectGeneratorId;

            planningApp.StartDate = SystemDate.Instance.date;
            //Create Customer
            planningApp.Customer = CustomerRepository.GetCustomer(planningResource.CustomerId).Result;

            //Set Status
            planningApp.CurrentPlanningStatus = statusList.Where(s => s.Name == StatusList.AppInProgress).SingleOrDefault();

            //Create States
            planningApp = await AddSingleGeneratorStates(planningApp);

            Console.WriteLine("Generated " + planningApp.PlanningAppStates.Count + " Planning States");

            //Refactor!!!!!!!
            if (planningResource.Surveyors != null)
            {
                foreach (string surveyorId in planningResource.Surveyors)
                {
                    PlanningAppSurveyors planningAppSurveyors = new PlanningAppSurveyors();
                    planningAppSurveyors.PlanningApp = planningApp;
                    planningAppSurveyors.AppUser     = await UserManager.FindByIdAsync(surveyorId);

                    planningApp.Surveyors.Add(planningAppSurveyors);
                }
            }
            if (planningResource.Drawers != null)
            {
                foreach (string surveyorId in planningResource.Drawers)
                {
                    PlanningAppDrawers planningAppDrawers = new PlanningAppDrawers();
                    planningAppDrawers.PlanningApp = planningApp;
                    planningAppDrawers.AppUser     = await UserManager.FindByIdAsync(surveyorId);

                    planningApp.Drawers.Add(planningAppDrawers);
                }
            }
            if (planningResource.Admins != null)
            {
                foreach (string adminId in planningResource.Admins)
                {
                    PlanningAppAdmins planningAppAdmins = new PlanningAppAdmins();
                    planningAppAdmins.PlanningApp = planningApp;
                    planningAppAdmins.AppUser     = await UserManager.FindByIdAsync(adminId);

                    planningApp.Admins.Add(planningAppAdmins);
                }
            }
            //Create Fees
            foreach (var fee in FeeRepository.GetFeesDefault())
            {
                PlanningAppFees planningAppFees = new PlanningAppFees {
                    Amount = fee.DefaultAmount, Fee = fee
                };
                planningApp.Fees.Add(planningAppFees);
            }

            //Persist planning app
            PlanningAppRepository.Add(planningApp);
            await UnitOfWork.CompleteAsync();

            //Create Reference using planning id
            planningApp.PlanningReferenceId = genCustomerReferenceId(planningApp);
            PlanningAppRepository.UpdatePlanningApp(planningApp);
            await UnitOfWork.CompleteAsync();

            //Retrieve planning app from database and return results to controller
            return(await PlanningAppRepository.GetPlanningApp(planningApp.Id, includeRelated : false));
        }
Beispiel #3
0
 public void Terminate(PlanningApp planningApp)
 {
     planningApp.CurrentPlanningStatus = statusList.Where(s => s.Name == StatusList.AppTerminated).SingleOrDefault();
     //planningApp.Current().StateStatus = planningApp.CurrentPlanningStatus;
     PlanningAppRepository.UpdatePlanningApp(planningApp);
 }