Exemplo n.º 1
0
        public async Task <IActionResult> PutFeedback(string j, string r, [FromBody] CapturedFeedback model, CancellationToken cancellationToken)
        {
            int          jobId       = Base64Utils.Base64DecodeToInt(j);
            RequestRoles requestRole = (RequestRoles)Base64Utils.Base64DecodeToInt(r);

            if (!_authService.GetUrlIsSessionAuthorised(HttpContext))
            {
                return(StatusCode((int)HttpStatusCode.Unauthorized));
            }
            if (!ModelState.IsValid)
            {
                return(StatusCode((int)HttpStatusCode.InternalServerError));
            }

            model.JobId = jobId;
            model.RoleSubmittingFeedback = requestRole;

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

            var result = await _feedbackService.PostRecordFeedback(user, model);

            if (result == Result.Success || result == Result.Failure_FeedbackAlreadyRecorded)
            {
                return(StatusCode((int)HttpStatusCode.OK));
            }
            else
            {
                return(StatusCode((int)HttpStatusCode.InternalServerError));
            }
        }
Exemplo n.º 2
0
        public IActionResult ShowMessage(Result result, int referringGroupId, CapturedFeedback capturedFeedback = null)
        {
            var notification = result switch
            {
                Result.Success => new NotificationModel
                {
                    Type     = NotificationType.Success,
                    Title    = "Thank you",
                    Subtitle = "Your comments have been submitted",
                    Message  = $"<p>We’ll use your feedback to make HelpMyStreet {(capturedFeedback.FeedbackRating == FeedbackRating.HappyFace ? "even better" : "as good as it can be")}.</p>{(capturedFeedback.IncludesMessage ? "<p>We’ll pass your messages on to the people involved with this request.</p>" : "")}"
                },
                Result.Failure_IncorrectJobStatus => new NotificationModel
                {
                    Type     = NotificationType.Failure_Permanent,
                    Title    = "Sorry, that didn't work",
                    Subtitle = "We couldn’t record your feedback",
                    Message  = "<p>The request is not currently marked as complete in our system.</p><p>If you’d like to get in touch, please email <a href='mailto:[email protected]'>[email protected]</a>.</p>"
                },
                Result.Failure_FeedbackAlreadyRecorded => new NotificationModel
                {
                    Type     = NotificationType.Failure_Permanent,
                    Title    = "Sorry, that didn’t work",
                    Subtitle = "We couldn’t record your feedback",
                    Message  = "<p>We may already have feedback relating to that request.</p><p>If you’d like to get in touch, please email <a href='mailto:[email protected]'>[email protected]</a>.</p>"
                },
                Result.Failure_RequestArchived => new NotificationModel
                {
                    Type     = NotificationType.Failure_Permanent,
                    Title    = "Sorry, that didn't work",
                    Subtitle = "We couldn’t record your feedback",
                    Message  = "<p>That request may have been too long ago.</p><p>If you’d like to get in touch, please email <a href='mailto:[email protected]'>[email protected]</a>.</p>"
                },
                Result.Failure_ServerError => new NotificationModel
                {
                    Type     = NotificationType.Failure_Temporary,
                    Title    = "Sorry, that didn’t work",
                    Subtitle = "We couldn’t record your feedback at this time",
                    Message  = "<p>This is usually a temporary problem; please press your browser’s back button to try again.</p><p>Alternatively, you can email us at <a href='mailto:[email protected]'>[email protected]</a>.</p>"
                },
                _ => throw new ArgumentException($"Unexpected Result value: {result}", nameof(result))
            };

            var vm = new SuccessViewModel()
            {
                //TODO: Don't assume all groups have open request forms
                RequestLink   = $"/request-help/{Base64Utils.Base64Encode(referringGroupId)}",
                Notifications = new List <NotificationModel> {
                    notification
                },
            };

            return(View("PostTaskFeedbackCaptureMessage", vm));
        }
    }
Exemplo n.º 3
0
        public async Task <Result> PostRecordFeedback(User user, CapturedFeedback feedback)
        {
            var job = await _requestHelpRepository.GetJobDetailsAsync(feedback.JobId, -1);

            if (job == null || job.JobSummary == null)
            {
                throw new Exception($"Attempt to submit feedback for job {feedback.JobId} which could not be found");
            }

            if (job.JobSummary.JobStatus.Incomplete())
            {
                return(Result.Failure_IncorrectJobStatus);
            }



            bool success = await _feedbackRepository.PostRecordFeedback(feedback.JobId, feedback.RoleSubmittingFeedback, user?.ID, feedback.FeedbackRating);

            if (!success)
            {
                if (await _feedbackRepository.GetFeedbackExists(feedback.JobId, feedback.RoleSubmittingFeedback, user?.ID))
                {
                    return(Result.Failure_FeedbackAlreadyRecorded);
                }
                else
                {
                    return(Result.Failure_ServerError);
                }
            }

            MessageParticipant from = GetFromBlock(user, feedback.RoleSubmittingFeedback, job);

            if (!string.IsNullOrEmpty(feedback.RecipientMessage))
            {
                var to = GetToBlock(job, RequestRoles.Recipient);
                success &= await _communicationService.SendInterUserMessage(from, to, feedback.RecipientMessage, feedback.JobId);
            }

            if (!string.IsNullOrEmpty(feedback.RequestorMessage))
            {
                var to = GetToBlock(job, RequestRoles.Requestor);
                success &= await _communicationService.SendInterUserMessage(from, to, feedback.RequestorMessage, feedback.JobId);
            }

            if (!string.IsNullOrEmpty(feedback.VolunteerMessage))
            {
                var to = GetToBlock(job, RequestRoles.Volunteer);
                success &= await _communicationService.SendInterUserMessage(from, to, feedback.VolunteerMessage, feedback.JobId);
            }

            if (!string.IsNullOrEmpty(feedback.GroupMessage))
            {
                var to = GetToBlock(job, RequestRoles.GroupAdmin);
                success &= await _communicationService.SendInterUserMessage(from, to, feedback.GroupMessage, feedback.JobId);
            }

            if (!string.IsNullOrEmpty(feedback.HMSMessage))
            {
                var to = new MessageParticipant
                {
                    GroupRoleType = new GroupRoleType
                    {
                        GroupId    = (int)HelpMyStreet.Utils.Enums.Groups.Generic,
                        GroupRoles = GroupRoles.Owner
                    },
                    RequestRoleType = new RequestRoleType {
                        RequestRole = RequestRoles.GroupAdmin
                    }
                };
                success &= await _communicationService.SendInterUserMessage(from, to, feedback.HMSMessage, feedback.JobId);
            }

            return(success ? Result.Success : Result.Failure_ServerError);
        }
Exemplo n.º 4
0
 public IActionResult FeedbackThanksPopup([FromBody] CapturedFeedback capturedFeedback)
 {
     return(ViewComponent("FeedbackCaptureThanks", capturedFeedback));
 }
 public async Task <IViewComponentResult> InvokeAsync(CapturedFeedback capturedFeedback)
 {
     return(View("FeedbackCaptureThanksPopup", capturedFeedback));
 }