public IActionResult Index(SearchVm vm) { _sessionService.SetLastPage("search/find-a-service"); ViewBag.BackLink = new BackLinkVM { Show = true, Url = _config.Value.GFCUrls.StartPage, Text = _config.Value.SiteTextStrings.BackLinkText }; //Make Sure we have a clean session _sessionService.ClearSession(); if (!ModelState.IsValid) { ViewBag.title = $"Error: Find a service" + _config.Value.SiteTextStrings.SiteTitleSuffix; return(View(vm)); } var cleanSearch = _gdsValidate.CleanText(vm.SearchTerm, true, restrictedWords, allowedChars); if (string.IsNullOrEmpty(cleanSearch)) { ModelState.AddModelError("SearchTerm", _config.Value.SiteTextStrings.EmptySearchError); ModelState.SetModelValue("SearchTerm", null, string.Empty); return(View(vm)); } return(RedirectToAction(nameof(SearchResults), new { search = cleanSearch })); }
[HttpGet, Route("/search/results")]//searches public IActionResult SearchResults(string search, int pageNo = 1, string selectedFacets = "") { var cleanSearch = _gdsValidate.CleanText(search, true, restrictedWords, allowedChars); var errorMessage = ValidateSearch(cleanSearch); if (errorMessage != null) { return(RedirectToAction("Index", new { errorMessage, search = cleanSearch })); } ViewBag.Title = "Results for " + cleanSearch + " - Give feedback on care"; return(GetSearchResult(cleanSearch, pageNo, selectedFacets)); }
public IActionResult SubmitFeedback([FromForm(Name = "url-referer")] string urlReferer) { PageVM pageViewModel = null; try { pageViewModel = GetPage(); if (pageViewModel == null) { return(GetCustomErrorCode(EnumStatusCode.RPSubmissionJsonError, "Error submitting service feedback. Json form not loaded")); } urlReferer = _gdsValidate.CleanText(urlReferer, true, _restrictedWords, _allowedChars); if (urlReferer.IsEmpty()) { urlReferer = _configuration.GetSection("ApplicationSettings:GFCUrls").GetValue <string>("StartPage"); } _gdsValidate.ValidatePage(pageViewModel, Request.Form, true, _restrictedWords, _allowedChars); if (pageViewModel.Questions.Any(m => m.Validation?.IsErrored == true)) { var cleanUrlReferer = urlReferer.Replace("feedback-thank-you", ""); ViewBag.BackLink = new BackLinkVM { Show = true, Url = cleanUrlReferer, Text = _configuration.GetSection("ApplicationSettings:SiteTextStrings").GetValue <string>("BackLinkText") }; ViewBag.UrlReferer = cleanUrlReferer; ViewBag.HideHelpLink = true; ViewBag.Title = "Error: Report a problem" + _configuration.GetSection("ApplicationSettings:SiteTextStrings").GetValue <string>("SiteTitleSuffix"); return(View(nameof(Feedback), pageViewModel)); } var emailAddress = pageViewModel? .Questions?.FirstOrDefault(x => x.QuestionId.Equals("email-address"))? .Answer ?? string.Empty; Task.Run(async() => { await SendEmailNotificationAsync(pageViewModel, urlReferer, emailAddress) .ContinueWith(notificationTask => { if (notificationTask.IsFaulted) { _logger.LogError(notificationTask.Exception, "Error sending service feedback email."); } }) .ConfigureAwait(false); }); return(RedirectToAction(nameof(FeedbackThankYou), new { urlReferer })); } catch (Exception ex) { ex.Data.Add("GFCError", "Unexpected error submitting service feedback"); throw ex; } }
public IActionResult SubmitWhatDoYouThink([FromForm(Name = "url-referer")] string urlReferer) { //Validate and populate request var lastPage = _sessionService.GetLastPage(); if (lastPage == null || !lastPage.Contains("you-have-sent-your-feedback")) { return(GetCustomErrorCode(EnumStatusCode.ExitSurveyOutOfSequence, "Post-completion survey hit out of //sequence")); } FormVM formViewModel = null; PageVM pageViewModel = null; try { formViewModel = GetForm(); pageViewModel = formViewModel.Pages.FirstOrDefault() ?? null; if (pageViewModel == null) { return(GetCustomErrorCode(EnumStatusCode.ExitSurveySubmissionJsonError, "Error submitting post-completion feedback. Json form not loaded")); } urlReferer = _gdsValidate.CleanText(urlReferer, true, _restrictedWords, _allowedChars); if (urlReferer.IsEmpty()) { urlReferer = _configuration.GetSection("ApplicationSettings:GFCUrls").GetValue <string>("StartPage"); } _gdsValidate.ValidatePage(pageViewModel, Request.Form, true, _restrictedWords, _allowedChars); if (pageViewModel.Questions.Any(m => m.Validation?.IsErrored == true)) { var cleanUrlReferer = urlReferer.Replace("feedback-thank-you", ""); ViewBag.BackLink = new BackLinkVM { Show = false, Url = cleanUrlReferer, Text = _configuration.GetSection("ApplicationSettings:SiteTextStrings").GetValue <string>("BackLinkText") }; ViewBag.UrlReferer = cleanUrlReferer; ViewBag.HideHelpLink = true; ViewBag.Title = "Error: Feedback" + _configuration.GetSection("ApplicationSettings:SiteTextStrings").GetValue <string>("SiteTitleSuffix"); return(View(nameof(WhatDoYouThink), pageViewModel)); } //Post to database, email user var submission = GenerateSinglePageSubmission(formViewModel); submission = _submissionService.CreateAsync(submission).Result; Task.Run(async() => { await SendEmailNotificationAsync(pageViewModel) .ContinueWith(notificationTask => { if (notificationTask.IsFaulted) { _logger.LogError(notificationTask.Exception, "Error sending post completion feedback email"); } }) .ConfigureAwait(false); }); //Send user to thank you page _sessionService.SetLastPage("what-do-you-think-of-this-form"); return(RedirectToAction(nameof(ThanksForYourFeedback), new { urlReferer })); } catch (Exception ex) { ex.Data.Add("GFCError", "Unexpected error submitting post-completion feedback"); throw ex; } }