예제 #1
0
        public async Task <PlanningAppStateFullResource> GetPlanningAppState(int id)
        {
            var planningAppState = await repository.GetPlanningAppState(id);

            var planningApp = await planningAppRepository.GetPlanningApp(planningAppState.PlanningAppId);

            var planningAppStateResource = mapper.Map <PlanningAppState, PlanningAppStateFullResource>(planningAppState);

            //populate the custom fields with values set in 'customStateValue'
            foreach (var customFieldResource in planningAppStateResource.PlanningAppStateCustomFieldsResource)
            {
                var customField = planningAppState.getPlanningAppStateCustomField(customFieldResource.Id);
                if (customField != null)
                {
                    customFieldResource.Value = planningAppState.getPlanningAppStateCustomField(customFieldResource.Id).StrValue;
                }
            }

            //If a live state set the min due by date
            planningAppStateResource.DueByDateEditable = false;
            planningAppStateResource.MinDueByDate      = DateTime.Now.Date.ToString(); //TODO: Remove when fix front end
            if (!planningAppState.Completed())
            {
                DateTime minDueDate = PlanningAppStateService.SetMinDueByDate(planningApp, planningAppState);
                planningAppStateResource.MinDueByDate      = minDueDate.SettingDateFormat();
                planningAppStateResource.DueByDateEditable = minDueDate > SystemDate.Instance.date;
            }
            return(planningAppStateResource);
        }
예제 #2
0
        public async Task <PlanningAppStateFullResource> GetPlanningAppState(int id)
        {
            var planningAppState = await repository.GetPlanningAppState(id);

            var planningApp = await planningAppRepository.GetPlanningApp(planningAppState.PlanningAppId);

            var planningAppStateResource = Mapper.Map <PlanningAppState, PlanningAppStateFullResource>(planningAppState);

            //populate the custom fields with values set in 'customStateValue'
            foreach (var customFieldResource in planningAppStateResource.PlanningAppStateCustomFieldsResource)
            {
                var customField = planningAppState.getPlanningAppStateCustomField(customFieldResource.Id);
                if (customField != null)
                {
                    customFieldResource.Value = planningAppState.getPlanningAppStateCustomField(customFieldResource.Id).StrValue;
                }
            }

            DateTime minDueDate = planningAppState.SetMinDueByDate(planningApp);

            planningAppStateResource.MinDueByDate      = minDueDate.SettingDateFormat();
            planningAppStateResource.DueByDateEditable = minDueDate > SystemDate.Instance.date;

            return(planningAppStateResource);
        }
예제 #3
0
        public async Task <IActionResult> UpdatePlanningAppState(int id, [FromBody] UpdatePlanningAppResource planningResource)
        {
            DateTime currentDate     = DateTime.Now;
            var      stateStatusList = await statusListRepository.GetStateStatusList(); //List of possible statuses

            var planningApp = await repository.GetPlanningApp(id, includeRelated : true);

            if (planningApp == null)
            {
                return(NotFound());
            }

            //TODO!!!!!!!Inject Logger to say what changed state by which user
            if (planningResource.method == (int)StateAction.NextState)
            {
                //Validate that custom mandatory fields have been set
                var currentStateId = planningApp.Current().Id;

                //get full entities, including custom state rules
                var currentState = await planningAppStateRepository.GetPlanningAppState(currentStateId);

                if (currentState.isValid())
                {
                    planningApp.NextState(stateStatusList);
                }
                else
                {
                    return(BadRequest(new { message = "bad request for next state" }));
                }
            }
            else if (planningResource.method == (int)StateAction.PrevState)
            {
                planningApp.PrevState(stateStatusList);
            }

            else if (planningResource.method == (int)StateAction.Terminate)
            {
                planningApp.Terminate(stateStatusList);
            }
            else
            {
                //No state specified just save details that can be modified by the user
                //PlanningApp res = mapper.Map<UpdatePlanningAppResource, PlanningApp>(planningResource);

                //Refactor!!!!!!
                planningApp.Notes = planningResource.Notes;
                planningApp.Developer.FirstName       = planningResource.Developer.FirstName;
                planningApp.Developer.LastName        = planningResource.Developer.LastName;
                planningApp.Developer.EmailAddress    = planningResource.Developer.EmailAddress;
                planningApp.Developer.TelephoneMobile = planningResource.Developer.TelephoneMobile;
                planningApp.Developer.TelephoneWork   = planningResource.Developer.TelephoneWork;

                planningApp.DevelopmentAddress.CompanyName  = planningResource.DevelopmentAddress.CompanyName;
                planningApp.DevelopmentAddress.AddressLine1 = planningResource.DevelopmentAddress.AddressLine1;
                planningApp.DevelopmentAddress.AddressLine2 = planningResource.DevelopmentAddress.AddressLine2;
                planningApp.DevelopmentAddress.Postcode     = planningResource.DevelopmentAddress.Postcode;
                planningApp.DevelopmentAddress.GeoLocation  = planningResource.DevelopmentAddress.GeoLocation;
            }

            repository.UpdatePlanningApp(planningApp);
            await unitOfWork.CompleteAsync();

            var result = mapper.Map <PlanningApp, PlanningAppResource>(planningApp);

            result.BusinessDate = CurrentDate.SettingDateFormat();

            planningApp = await repository.GetPlanningApp(id, includeRelated : true);

            return(Ok(result));
        }