private void ValidateRecipient(RequestHelpDetailStageViewModel vm, List <string> errors, bool onlyRecipient)
 {
     if (vm.Recipient == null)
     {
         errors.Add($"Recipient cannot be null");
     }
     else
     {
         if (!vm.NeedBothNames)
         {
             if (string.IsNullOrEmpty(vm.Recipient.Firstname) && string.IsNullOrEmpty(vm.Recipient.Lastname))
             {
                 errors.Add("One name for recipient must be supplied");
             }
         }
         else
         {
             if (string.IsNullOrEmpty(vm.Recipient.Firstname))
             {
                 errors.Add("Recipient's firstname must be supplied");
             }
             if (string.IsNullOrEmpty(vm.Recipient.Lastname))
             {
                 errors.Add("Recipient's lastname must be supplied");
             }
         }
         if (string.IsNullOrEmpty(vm.Recipient.MobileNumber) && string.IsNullOrEmpty(vm.Recipient.AlternatePhoneNumber) && onlyRecipient)
         {
             errors.Add("Recipient's contact number must be supplied");
         }
         if (string.IsNullOrEmpty(vm.Recipient.Email) && onlyRecipient)
         {
             errors.Add("Recipient's email must be supplied");
         }
         if (vm.FullRecipientAddressRequired)
         {
             if (string.IsNullOrEmpty(vm.Recipient.AddressLine1))
             {
                 errors.Add("Recipient's Address Line 1 must be supplied");
             }
             if (string.IsNullOrEmpty(vm.Recipient.Town))
             {
                 errors.Add("Recipient's Town must be supplied");
             }
         }
         if (string.IsNullOrEmpty(vm.Recipient.Postcode))
         {
             errors.Add("Recipient's postcode must be supplied");
         }
     }
 }
예제 #2
0
        private async Task <RequestHelpDetailStageViewModel> BindDetailStage(ModelBindingContext bindingContext, RequestHelpFormVariant requestHelpFormVariant, SupportActivities selectedSupportActivity, int groupId)
        {
            RequestHelpDetailStageViewModel model = JsonConvert.DeserializeObject <RequestHelpDetailStageViewModel>(bindingContext.ValueProvider.GetValue("DetailStep").FirstValue);
            var recpientnamePrefix = "currentStep.Recipient.";

            model.Recipient = new RecipientDetails
            {
                Firstname            = bindingContext.ValueProvider.GetValue(recpientnamePrefix + nameof(model.Recipient.Firstname)).FirstValue,
                Lastname             = bindingContext.ValueProvider.GetValue(recpientnamePrefix + nameof(model.Recipient.Lastname)).FirstValue,
                MobileNumber         = bindingContext.ValueProvider.GetValue(recpientnamePrefix + nameof(model.Recipient.MobileNumber)).FirstValue,
                AlternatePhoneNumber = bindingContext.ValueProvider.GetValue(recpientnamePrefix + nameof(model.Recipient.AlternatePhoneNumber)).FirstValue,
                AddressLine1         = bindingContext.ValueProvider.GetValue(recpientnamePrefix + nameof(model.Recipient.AddressLine1)).FirstValue,
                AddressLine2         = bindingContext.ValueProvider.GetValue(recpientnamePrefix + nameof(model.Recipient.AddressLine2)).FirstValue,
                County   = bindingContext.ValueProvider.GetValue(recpientnamePrefix + nameof(model.Recipient.County)).FirstValue,
                Postcode = bindingContext.ValueProvider.GetValue(recpientnamePrefix + nameof(model.Recipient.Postcode)).FirstValue,
                Email    = bindingContext.ValueProvider.GetValue(recpientnamePrefix + nameof(model.Recipient.Email)).FirstValue,
                Town     = bindingContext.ValueProvider.GetValue(recpientnamePrefix + nameof(model.Recipient.Town)).FirstValue,
            };


            var requestorPrefix = "currentStep.Requestor.";

            model.Requestor = new RequestorDetails
            {
                Firstname            = bindingContext.ValueProvider.GetValue(requestorPrefix + nameof(model.Recipient.Firstname)).FirstValue,
                Lastname             = bindingContext.ValueProvider.GetValue(requestorPrefix + nameof(model.Recipient.Lastname)).FirstValue,
                MobileNumber         = bindingContext.ValueProvider.GetValue(requestorPrefix + nameof(model.Recipient.MobileNumber)).FirstValue,
                AlternatePhoneNumber = bindingContext.ValueProvider.GetValue(requestorPrefix + nameof(model.Recipient.AlternatePhoneNumber)).FirstValue,
                Postcode             = bindingContext.ValueProvider.GetValue(requestorPrefix + nameof(model.Recipient.Postcode)).FirstValue,
                Email = bindingContext.ValueProvider.GetValue(requestorPrefix + nameof(model.Recipient.Email)).FirstValue,
            };

            model.Organisation = bindingContext.ValueProvider.GetValue("currentStep.Organisation").FirstValue;

            model.Questions = new QuestionsViewModel()
            {
                Questions = await _requestHelpBuilder.GetQuestionsForTask(requestHelpFormVariant, RequestHelpFormStage.Detail, selectedSupportActivity, groupId)
            };

            foreach (RequestHelpQuestion question in model.Questions.Questions)
            {
                question.Model = bindingContext.ValueProvider.GetValue($"currentStep.Questions.[{question.ID}].Model").FirstValue;
            }

            return(model);
        }
 private void ValidateRequestor(RequestHelpDetailStageViewModel vm, List <string> errors)
 {
     if (vm.Requestor == null)
     {
         errors.Add($"Requestor cannot be null");
     }
     else
     {
         if (!vm.NeedBothNames)
         {
             if (string.IsNullOrEmpty(vm.Requestor.Firstname) && string.IsNullOrEmpty(vm.Requestor.Lastname))
             {
                 errors.Add("One name for requester must be supplied");
             }
         }
         else
         {
             if (string.IsNullOrEmpty(vm.Requestor.Firstname))
             {
                 errors.Add("Requestor's firstname must be supplied");
             }
             if (string.IsNullOrEmpty(vm.Requestor.Lastname))
             {
                 errors.Add("Requestor's lastname must be supplied");
             }
         }
         if (string.IsNullOrEmpty(vm.Requestor.MobileNumber) && string.IsNullOrEmpty(vm.Requestor.AlternatePhoneNumber))
         {
             errors.Add("Requestor's contact number must be supplied");
         }
         if (string.IsNullOrEmpty(vm.Requestor.Email))
         {
             errors.Add("Requestor's email must be supplied");
         }
         if (string.IsNullOrEmpty(vm.Requestor.Postcode))
         {
             errors.Add("Requestor's postcode must be supplied");
         }
     }
 }
예제 #4
0
        public async Task <LogRequestResponse> LogRequestAsync(RequestHelpRequestStageViewModel requestStage, RequestHelpDetailStageViewModel detailStage, int referringGroupID, string source, int userId, CancellationToken cancellationToken)
        {
            _logger.LogInformation($"Logging Request");

            var selectedTask = requestStage.Tasks.Where(x => x.IsSelected).First();
            var selectedTime = requestStage.Timeframes.Where(x => x.IsSelected).FirstOrDefault();

            bool heathCritical          = false;
            var  healthCriticalQuestion = requestStage.Questions.Questions.Where(a => a.ID == (int)Questions.IsHealthCritical).FirstOrDefault();

            if (healthCriticalQuestion != null && healthCriticalQuestion.Model == "true")
            {
                heathCritical = true;
            }

            RequestPersonalDetails            recipient = null;
            RequestPersonalDetails            requestor = null;
            IEnumerable <RequestHelpQuestion> questions = requestStage.Questions.Questions;

            if (detailStage != null)
            {
                recipient = _requestHelpBuilder.MapRecipient(detailStage);
                if (detailStage.ShowRequestorFields)
                {
                    requestor = detailStage.Type == RequestorType.Myself ? recipient : _requestHelpBuilder.MapRequestor(detailStage);
                }
                questions = questions.Union(detailStage.Questions.Questions);
            }

            var request = new PostNewRequestForHelpRequest
            {
                HelpRequest = new HelpRequest
                {
                    Guid              = requestStage.RequestGuid,
                    AcceptedTerms     = requestStage.AgreeToPrivacyAndTerms,
                    ConsentForContact = requestStage.AgreeToPrivacyAndTerms,
                    OrganisationName  = detailStage?.Organisation ?? "",
                    RequestorType     = detailStage?.Type ?? RequestorType.Organisation,
                    ReadPrivacyNotice = requestStage.AgreeToPrivacyAndTerms,
                    CreatedByUserId   = userId,
                    Recipient         = recipient,
                    Requestor         = requestor,
                    ReferringGroupId  = referringGroupID,
                    Source            = source
                },
                NewJobsRequest = new NewJobsRequest
                {
                    Jobs = new List <Job>
                    {
                        new Job
                        {
                            DueDateType     = selectedTime.DueDateType,
                            DueDays         = selectedTime.DueDateType == DueDateType.On ? Convert.ToInt32((selectedTime.Date.Date - DateTime.Now.Date).TotalDays) : selectedTime.Days,
                            StartDate       = selectedTime.DueDateType.HasStartTime() ? selectedTime.StartTime.ToUTCFromUKTime() : (DateTime?)null,
                            EndDate         = selectedTime.DueDateType.HasEndTime() ? selectedTime.EndTime.ToUTCFromUKTime() : (DateTime?)null,
                            HealthCritical  = heathCritical,
                            SupportActivity = selectedTask.SupportActivity,
                            Questions       = questions.Where(x => x.InputType != QuestionType.LabelOnly).Select(x => new Question {
                                Id             = x.ID,
                                Answer         = GetAnswerToQuestion(x),
                                Name           = x.Label,
                                Required       = x.Required,
                                AddtitonalData = x.AdditionalData,
                                Type           = x.InputType
                            }).ToList()
                        }
                    }
                }
            };


            var response = await _requestHelpRepository.PostNewRequestForHelpAsync(request);

            if (response != null && userId != 0)
            {
                TriggerCacheRefresh(userId, cancellationToken);
            }

            return(response);
        }