Exemplo n.º 1
0
        private async Task <JobFeedbackStatus> GetJobFeedbackStatus(int jobId, int userId, RequestRoles role, CancellationToken cancellationToken)
        {
            var job = await _requestService.GetJobSummaryAsync(jobId, cancellationToken);

            if (job.JobStatus == JobStatuses.Done || job.JobStatus == JobStatuses.Cancelled)
            {
                bool feedbackSubmitted = await _feedbackService.GetFeedbackExists(jobId, role, userId);

                if (feedbackSubmitted)
                {
                    return(new JobFeedbackStatus
                    {
                        FeedbackSubmitted = true,
                        FeedbackDue = false,
                    });
                }
                else if (!job.Archive)
                {
                    _authService.PutSessionAuthorisedUrl(HttpContext, $"/api/feedback/get-post-task-feedback-popup?j={Base64Utils.Base64Encode(jobId)}&r={Base64Utils.Base64Encode((int)role)}");
                    _authService.PutSessionAuthorisedUrl(HttpContext, $"/api/feedback/put-feedback?j={Base64Utils.Base64Encode(jobId)}&r={Base64Utils.Base64Encode((int)role)}");

                    return(new JobFeedbackStatus
                    {
                        FeedbackSubmitted = false,
                        FeedbackDue = true,
                    });
                }
            }

            return(new JobFeedbackStatus
            {
                FeedbackSubmitted = false,
                FeedbackDue = false,
            });
        }
Exemplo n.º 2
0
        public async Task <IActionResult> RequestHelp(
            [ModelBinder(BinderType = typeof(RequestHelpModelBinder))] RequestHelpViewModel requestHelp,
            [ModelBinder(BinderType = typeof(RequestHelpStepsViewModelBinder))] IRequestHelpStageViewModel step,
            CancellationToken cancellationToken)
        {
            try
            {
                requestHelp.Errors = new List <string>();
                requestHelp.Steps[requestHelp.CurrentStepIndex] = step;
                if (requestHelp.Action == "EditRequest")
                {
                    requestHelp.CurrentStepIndex = 0;
                    return(View(requestHelp));
                }
                if (requestHelp.Action == "EditDetails")
                {
                    requestHelp.CurrentStepIndex = 1;
                    return(View(requestHelp));
                }
                if (requestHelp.Action == "back")
                {
                    requestHelp.CurrentStepIndex--;
                    return(View(requestHelp));
                }

                if (!ModelState.IsValid)
                {
                    throw new ValidationException("Model Validation failed");
                }


                if (requestHelp.Action == "next")
                {
                    requestHelp.CurrentStepIndex++;
                    if (step is RequestHelpRequestStageViewModel)
                    {
                        var requestStep = (RequestHelpRequestStageViewModel)step;
                        var detailStage = (RequestHelpDetailStageViewModel)requestHelp.Steps.Where(x => x is RequestHelpDetailStageViewModel).FirstOrDefault();
                        var reviewStage = (RequestHelpReviewStageViewModel)requestHelp.Steps.Where(x => x is RequestHelpReviewStageViewModel).First();

                        if (detailStage != null)
                        {
                            detailStage.Type      = requestStep.Requestors.Where(x => x.IsSelected).First().Type;
                            detailStage.Questions = await UpdateQuestionsViewModel(detailStage.Questions, requestHelp.RequestHelpFormVariant, RequestHelpFormStage.Detail, (SupportActivities)requestHelp.SelectedSupportActivity(), requestHelp.ReferringGroupID);

                            detailStage.NeedBothNames = requestStep.Tasks.Where(x => x.IsSelected).Any(x => x.SupportActivity == SupportActivities.CollectingPrescriptions);

                            var loggedInUser = await _authService.GetCurrentUser(HttpContext, cancellationToken);

                            if (loggedInUser != null)
                            {
                                switch (detailStage.Type)
                                {
                                case RequestorType.Myself:
                                    if (detailStage.Recipient == null)
                                    {
                                        detailStage.Recipient = new RecipientDetails
                                        {
                                            Firstname            = loggedInUser.UserPersonalDetails.FirstName,
                                            Lastname             = loggedInUser.UserPersonalDetails.LastName,
                                            AddressLine1         = loggedInUser.UserPersonalDetails.Address.AddressLine1,
                                            AddressLine2         = loggedInUser.UserPersonalDetails.Address.AddressLine2,
                                            AlternatePhoneNumber = loggedInUser.UserPersonalDetails.OtherPhone,
                                            MobileNumber         = loggedInUser.UserPersonalDetails.MobilePhone,
                                            Email    = loggedInUser.UserPersonalDetails.EmailAddress,
                                            Postcode = loggedInUser.UserPersonalDetails.Address.Postcode,
                                            Town     = loggedInUser.UserPersonalDetails.Address.Locality
                                        };
                                    }
                                    break;

                                case RequestorType.Organisation:
                                case RequestorType.OnBehalf:
                                    if (detailStage.Requestor == null)
                                    {
                                        detailStage.Requestor = new RequestorDetails
                                        {
                                            Firstname            = loggedInUser.UserPersonalDetails.FirstName,
                                            Lastname             = loggedInUser.UserPersonalDetails.LastName,
                                            AlternatePhoneNumber = loggedInUser.UserPersonalDetails.OtherPhone,
                                            MobileNumber         = loggedInUser.UserPersonalDetails.MobilePhone,
                                            Email    = loggedInUser.UserPersonalDetails.EmailAddress,
                                            Postcode = loggedInUser.UserPersonalDetails.Address.Postcode,
                                        };
                                    }
                                    break;
                                }
                            }
                        }

                        reviewStage.Task                  = requestStep.Tasks.Where(x => x.IsSelected).FirstOrDefault();
                        reviewStage.TimeRequested         = requestStep.Timeframes.Where(X => X.IsSelected).FirstOrDefault();
                        reviewStage.RequestedFor          = requestStep.Requestors.Where(x => x.IsSelected).FirstOrDefault();
                        reviewStage.RequestStageQuestions = requestStep.Questions.Questions;
                    }
                    if (step is RequestHelpDetailStageViewModel)
                    {
                        var requestStage = (RequestHelpRequestStageViewModel)requestHelp.Steps.Where(x => x is RequestHelpRequestStageViewModel).First();
                        var detailStage  = (RequestHelpDetailStageViewModel)step;
                        var reviewStage  = (RequestHelpReviewStageViewModel)requestHelp.Steps.Where(x => x is RequestHelpReviewStageViewModel).First();
                        reviewStage.Recipient             = detailStage.Recipient;
                        reviewStage.Requestor             = detailStage.Requestor;
                        reviewStage.OrganisationName      = detailStage.Organisation;
                        reviewStage.DetailsStageQuestions = detailStage.Questions.Questions;
                        reviewStage.ShowRequestor         = detailStage.ShowRequestorFields && (reviewStage.RequestedFor.Type != RequestorType.Myself);
                    }
                }
                if (requestHelp.Action == "finish")
                {
                    var requestStage = (RequestHelpRequestStageViewModel)requestHelp.Steps.Where(x => x is RequestHelpRequestStageViewModel).First();
                    var detailStage  = (RequestHelpDetailStageViewModel)requestHelp.Steps.Where(x => x is RequestHelpDetailStageViewModel).FirstOrDefault();
                    var user         = await _authService.GetCurrentUser(HttpContext, cancellationToken);

                    var response = await _requestService.LogRequestAsync(requestStage, detailStage, requestHelp.ReferringGroupID, requestHelp.Source, user?.ID ?? 0, cancellationToken);

                    if (response != null && response.Fulfillable.Equals(Fulfillable.Accepted_ManualReferral))
                    {
                        return(RedirectToRoute("request-help/success", new
                        {
                            fulfillable = response.Fulfillable,
                            requestHelpFormVariant = requestHelp.RequestHelpFormVariant,
                            referringGroup = Base64Utils.Base64Encode(requestHelp.ReferringGroupID),
                            source = requestHelp.Source
                        }));
                    }
                    else
                    {
                        throw new Exception($"Bad response from PostNewRequestForHelpRequest: {response?.Fulfillable}");
                    }
                }
            }
            catch (ValidationException vex)
            {
                _logger.LogError(vex, "a validation error occured in request help form action");
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "an error occured in request help form action");
                requestHelp.Errors.Add("Oops! An error occured submitting your request; please try again later.");
            }


            return(View(requestHelp));
        }
        private string GetJobUrl(int jobId, int requestId, int jobCount)
        {
            string baseUrl   = _sendGridConfig.Value.BaseUrl;
            string encodedId = jobCount == 1 ? Base64Utils.Base64Encode(jobId.ToString()) : Base64Utils.Base64Encode(requestId.ToString());

            string tailUrl = jobCount == 1 ? $"/link/j/{encodedId}" : $"/link/r/{encodedId}";
            var    token   = _linkRepository.CreateLink(tailUrl, _linkConfig.Value.ExpiryDays).Result;

            return($"{baseUrl}/link/{token}");
        }
        public void Base64Encode_Base64DecodeToInt_Invalid()
        {
            string encodedString = Base64Utils.Base64Encode("Not a number");

            Assert.Throws <FormatException>(() => { Base64Utils.Base64DecodeToInt(encodedString); });
        }
        public void Base64Encode_TryBase64DecodeToInt()
        {
            int?result = Base64Utils.TryBase64DecodeToInt(Base64Utils.Base64Encode(1000));

            Assert.AreEqual(1000, result);
        }
        public void Base64Encode_Base64DecodeToInt_Negative()
        {
            int result = Base64Utils.Base64DecodeToInt(Base64Utils.Base64Encode(-1));

            Assert.AreEqual(-1, result);
        }
        public void Base64Encode_Base64DecodeToInt_Zero()
        {
            int result = Base64Utils.Base64DecodeToInt(Base64Utils.Base64Encode(0));

            Assert.AreEqual(0, result);
        }
        public void Base64Encode_Base64DecodeToInt()
        {
            int result = Base64Utils.Base64DecodeToInt(Base64Utils.Base64Encode(123));

            Assert.AreEqual(123, result);
        }
        public void Base64Encode_Base64Decode_HelloWorld()
        {
            string result = Base64Utils.Base64Decode(Base64Utils.Base64Encode("Hello World!"));

            Assert.AreEqual("Hello World!", result);
        }
Exemplo n.º 10
0
        public void Base64Encode_Base64Decode_EmptyString()
        {
            string result = Base64Utils.Base64Decode(Base64Utils.Base64Encode(""));

            Assert.AreEqual("", result);
        }