private async Task <ProcessRequestEntity> ProcessManualAddress( Dictionary <string, dynamic> viewModel, Page currentPage, FormSchema baseForm, string guid, string path) { _pageHelper.SaveAnswers(viewModel, guid, baseForm.BaseURL, null, currentPage.IsValid); if (!currentPage.IsValid) { var cachedAnswers = _distributedCache.GetString(guid); var convertedAnswers = cachedAnswers == null ? new FormAnswers { Pages = new List <PageAnswers>() } : JsonConvert.DeserializeObject <FormAnswers>(cachedAnswers); var cachedSearchResults = convertedAnswers.FormData[$"{path}{LookUpConstants.SearchResultsKeyPostFix}"] as IEnumerable <object>; var model = await _pageFactory.Build(currentPage, viewModel, baseForm, guid, convertedAnswers, cachedSearchResults.ToList()); return(new ProcessRequestEntity { Page = currentPage, ViewModel = model }); } return(new ProcessRequestEntity { Page = currentPage }); }
private async Task <ProcessRequestEntity> ProccessAutomaticStreet( Dictionary <string, dynamic> viewModel, Page currentPage, FormSchema baseForm, string guid, string path) { var cachedAnswers = _distributedCache.GetString(guid); var streetElement = currentPage.Elements.Where(_ => _.Type.Equals(EElementType.Street)).FirstOrDefault(); var convertedAnswers = cachedAnswers is null ? new FormAnswers { Pages = new List <PageAnswers>() } : JsonConvert.DeserializeObject <FormAnswers>(cachedAnswers); var street = (string)convertedAnswers .Pages .FirstOrDefault(_ => _.PageSlug.Equals(path)) .Answers .FirstOrDefault(_ => _.QuestionId.Equals($"{streetElement.Properties.QuestionId}")) .Response; if (currentPage.IsValid && streetElement.Properties.Optional && string.IsNullOrEmpty(street)) { _pageHelper.SaveAnswers(viewModel, guid, baseForm.BaseURL, null, currentPage.IsValid); return(new ProcessRequestEntity { Page = currentPage }); } if (!currentPage.IsValid) { var cachedSearchResults = convertedAnswers.FormData[$"{path}{LookUpConstants.SearchResultsKeyPostFix}"] as IEnumerable <object>; var model = await _pageFactory.Build(currentPage, viewModel, baseForm, guid, convertedAnswers, cachedSearchResults.ToList()); return(new ProcessRequestEntity { Page = currentPage, ViewModel = model }); } _pageHelper.SaveAnswers(viewModel, guid, baseForm.BaseURL, null, currentPage.IsValid); return(new ProcessRequestEntity { Page = currentPage }); }
private async Task <ProcessRequestEntity> ProcessDateAndTime(Dictionary <string, dynamic> viewModel, Page currentPage, FormSchema baseForm, string guid, string path, Booking element) { if (!currentPage.IsValid) { var cachedAnswers = _distributedCache.GetString(guid); var convertedAnswers = cachedAnswers is null ? new FormAnswers { Pages = new List <PageAnswers>() } : JsonConvert.DeserializeObject <FormAnswers>(cachedAnswers); var cachedBookingInformation = JsonConvert.DeserializeObject <BookingInformation>(convertedAnswers.FormData[$"{element.Properties.QuestionId}{BookingConstants.APPOINTMENT_TYPE_SEARCH_RESULTS}"].ToString()); var bookingInformation = new List <object> { cachedBookingInformation }; var model = await _pageFactory.Build(currentPage, viewModel, baseForm, guid, null, bookingInformation); return(new ProcessRequestEntity { Page = currentPage, ViewModel = model }); } if (!element.Properties.CheckYourBooking) { await ReserveAppointment(element, viewModel, baseForm.BaseURL, guid); _pageHelper.SaveAnswers(viewModel, guid, baseForm.BaseURL, null, currentPage.IsValid); return(new ProcessRequestEntity { Page = currentPage }); } _pageHelper.SaveAnswers(viewModel, guid, baseForm.BaseURL, null, currentPage.IsValid); return(new ProcessRequestEntity { RedirectToAction = true, RedirectAction = "Index", RouteValues = new { form = baseForm.BaseURL, path, subPath = BookingConstants.CHECK_YOUR_BOOKING } }); }
public async Task <ProcessRequestEntity> ProcessAddAnother( Dictionary <string, dynamic> viewModel, Page dynamicCurrentPage, FormSchema baseForm, string guid, string path) { string removeKey = viewModel.Keys.FirstOrDefault(_ => _.Contains("remove")); bool addEmptyFieldset = viewModel.Keys.Any(_ => _.Equals(AddAnotherConstants.AddAnotherButtonKey)); FormAnswers convertedFormAnswers = _pageHelper.GetSavedAnswers(guid); var maximumFieldsets = dynamicCurrentPage.Elements.FirstOrDefault(_ => _.Type.Equals(EElementType.AddAnother)).Properties.MaximumFieldsets; if (dynamicCurrentPage.IsValid || !string.IsNullOrEmpty(removeKey)) { var formDataIncrementKey = $"{AddAnotherConstants.IncrementKeyPrefix}{dynamicCurrentPage.Elements.FirstOrDefault(_ => _.Type.Equals(EElementType.AddAnother)).Properties.QuestionId}"; var currentIncrement = convertedFormAnswers.FormData.ContainsKey(formDataIncrementKey) ? int.Parse(convertedFormAnswers.FormData.GetValueOrDefault(formDataIncrementKey).ToString()) : 1; if (addEmptyFieldset && currentIncrement >= maximumFieldsets) { throw new ApplicationException("AddAnotherService::ProcessAddAnother, maximum number of fieldsets exceeded"); } if (addEmptyFieldset) { currentIncrement++; } if (!string.IsNullOrEmpty(removeKey)) { currentIncrement--; } _pageHelper.SaveFormData(formDataIncrementKey, currentIncrement, guid, baseForm.BaseURL); } if (!string.IsNullOrEmpty(removeKey)) { _pageHelper.RemoveFieldset(viewModel, baseForm.BaseURL, guid, path, removeKey); return(new ProcessRequestEntity { RedirectToAction = true, RedirectAction = "Index", RouteValues = new { form = baseForm.BaseURL, path, } }); } _pageHelper.SaveAnswers(viewModel, guid, baseForm.BaseURL, null, dynamicCurrentPage.IsValid); if (!dynamicCurrentPage.IsValid) { var invalidFormModel = await _pageContentFactory.Build(dynamicCurrentPage, viewModel, baseForm, guid); return(new ProcessRequestEntity { Page = dynamicCurrentPage, ViewModel = invalidFormModel }); } if (dynamicCurrentPage.IsValid && addEmptyFieldset) { return(new ProcessRequestEntity { RedirectToAction = true, RedirectAction = "Index", RouteValues = new { form = baseForm.BaseURL, path } }); } return(new ProcessRequestEntity { Page = dynamicCurrentPage }); }
private async Task <ProcessRequestEntity> ProcessSelectedFiles( Dictionary <string, dynamic> viewModel, Page currentPage, FormSchema baseForm, string guid, string path, IEnumerable <CustomFormFile> files, bool modelStateIsValid) { if (!currentPage.IsValid) { var formModel = await _pageFactory.Build(currentPage, new Dictionary <string, dynamic>(), baseForm, guid); return(new ProcessRequestEntity { Page = currentPage, ViewModel = formModel }); } if (currentPage.IsValid && viewModel.ContainsKey(ButtonConstants.SUBMIT) && (files is null || !files.Any()) && modelStateIsValid) { if (currentPage.Elements.Where(_ => _.Type.Equals(EElementType.MultipleFileUpload)).Any(_ => _.Properties.Optional)) { _pageHelper.SaveAnswers(viewModel, guid, baseForm.BaseURL, files, currentPage.IsValid, true); } return(new ProcessRequestEntity { Page = currentPage }); } if (!viewModel.ContainsKey(ButtonConstants.SUBMIT) && (files is null || !files.Any())) { return(new ProcessRequestEntity { RedirectToAction = true, RedirectAction = "Index", RouteValues = new { form = baseForm.BaseURL, path } }); } if (files is not null && files.Any()) { _pageHelper.SaveAnswers(viewModel, guid, baseForm.BaseURL, files, currentPage.IsValid, true); } if (viewModel.ContainsKey(ButtonConstants.SUBMIT) && modelStateIsValid) { return(new ProcessRequestEntity { Page = currentPage }); } if (!modelStateIsValid) { var newViewModel = new Dictionary <string, dynamic> { { "modelStateInvalid", null } }; var formModel = await _pageFactory.Build(currentPage, newViewModel, baseForm, guid); return(new ProcessRequestEntity { Page = currentPage, ViewModel = formModel, UseGeneratedViewModel = true }); } return(new ProcessRequestEntity { RedirectToAction = true, RedirectAction = "Index", RouteValues = new { form = baseForm.BaseURL, path } }); }
public async Task <ProcessRequestEntity> ProcessRequest( string form, string path, Dictionary <string, dynamic> viewModel, IEnumerable <CustomFormFile> files, bool modelStateIsValid) { FormSchema baseForm = await _schemaFactory.Build(form); if (!baseForm.IsAvailable(_environment.EnvironmentName)) { throw new ApplicationException($"Form: {form} is not available in this Environment: {_environment.EnvironmentName.ToS3EnvPrefix()}"); } var currentPage = baseForm.GetPage(_pageHelper, path); var sessionGuid = _sessionHelper.GetSessionGuid(); if (sessionGuid == null) { throw new NullReferenceException($"Session guid null."); } if (currentPage == null) { throw new NullReferenceException($"Current page '{path}' object could not be found."); } if (currentPage.HasIncomingPostValues) { viewModel = _incomingDataHelper.AddIncomingFormDataValues(currentPage, viewModel); } currentPage.Validate(viewModel, _validators, baseForm); if (currentPage.Elements.Any(_ => _.Type == EElementType.Address)) { return(await _addressService.ProcessAddress(viewModel, currentPage, baseForm, sessionGuid, path)); } if (currentPage.Elements.Any(_ => _.Type == EElementType.Street)) { return(await _streetService.ProcessStreet(viewModel, currentPage, baseForm, sessionGuid, path)); } if (currentPage.Elements.Any(_ => _.Type == EElementType.Organisation)) { return(await _organisationService.ProcessOrganisation(viewModel, currentPage, baseForm, sessionGuid, path)); } if (currentPage.Elements.Any(_ => _.Type == EElementType.MultipleFileUpload)) { return(await _fileUploadService.ProcessFile(viewModel, currentPage, baseForm, sessionGuid, path, files, modelStateIsValid)); } if (currentPage.Elements.Any(_ => _.Type == EElementType.Booking)) { return(await _bookingService.ProcessBooking(viewModel, currentPage, baseForm, sessionGuid, path)); } _pageHelper.SaveAnswers(viewModel, sessionGuid, baseForm.BaseURL, files, currentPage.IsValid); if (!currentPage.IsValid) { var formModel = await _pageContentFactory.Build(currentPage, viewModel, baseForm, sessionGuid); return(new ProcessRequestEntity { Page = currentPage, ViewModel = formModel }); } return(new ProcessRequestEntity { Page = currentPage }); }
public async Task <SuccessPageEntity> Build(string form, FormSchema baseForm, string sessionGuid, FormAnswers formAnswers, EBehaviourType behaviourType) { var page = baseForm.GetPage(_pageHelper, "success"); _distributedCache.Remove(sessionGuid); _sessionHelper.RemoveSessionGuid(); if (page == null && behaviourType == EBehaviourType.SubmitAndPay) { page = GenerateGenericPaymentPage(); baseForm.Pages.Add(page); } if (page == null) { return(new SuccessPageEntity { ViewName = "Submit", FormAnswers = formAnswers, CaseReference = formAnswers.CaseReference, FeedbackFormUrl = baseForm.FeedbackForm, FeedbackPhase = baseForm.FeedbackPhase, FormName = baseForm.FormName, StartPageUrl = baseForm.StartPageUrl }); } if (baseForm.DocumentDownload) { baseForm.DocumentType.ForEach((docType) => { var element = new ElementBuilder() .WithType(EElementType.DocumentDownload) .WithLabel($"Download {docType} document") .WithSource($"/v2/document/Summary/{docType}/{sessionGuid}") .WithDocumentType(docType) .Build(); page.Elements.Add(element); }); var successIndex = baseForm.Pages.IndexOf(page); baseForm.Pages[successIndex] = page; } var result = await _pageFactory.Build(page, new Dictionary <string, dynamic>(), baseForm, sessionGuid, formAnswers); return(new SuccessPageEntity { HtmlContent = result.RawHTML, CaseReference = formAnswers.CaseReference, FeedbackFormUrl = result.FeedbackForm, FeedbackPhase = result.FeedbackPhase, FormName = result.FormName, StartPageUrl = result.StartPageUrl, PageTitle = result.PageTitle, BannerTitle = page.BannerTitle, LeadingParagraph = page.LeadingParagraph, DisplayBreadcrumbs = page.DisplayBreadCrumbs, Breadcrumbs = baseForm.BreadCrumbs }); }