public async Task PreProcessSubmission(string form, string sessionGuid) { var baseForm = await _schemaFactory.Build(form); if (baseForm.GenerateReferenceNumber) { _pageHelper.SaveCaseReference(sessionGuid, _referenceNumberProvider.GetReference(baseForm.ReferencePrefix), true, baseForm.GeneratedReferenceNumberMapping); } }
public async Task <IActionResult> Index( string form, string path, Dictionary <string, string[]> formData) { var viewModel = formData.ToNormaliseDictionary(string.Empty); var queryParamters = Request.Query; var baseForm = await _schemaFactory.Build(form); if (baseForm == null) { throw new ApplicationException($"Requested form '{form}' could not be found."); } var page = baseForm.GetPage(_pageHelper, path); if (page == null) { throw new ApplicationException($"Requested path '{path}' object could not be found for form '{form}'"); } var sessionGuid = _sessionHelper.GetSessionGuid(); await _bookingService.ProcessMonthRequest(viewModel, baseForm, page, sessionGuid); var routeValuesDictionary = new RouteValueDictionaryBuilder() .WithValue("path", path) .WithValue("form", form) .WithQueryValues(queryParamters) .Build(); return(RedirectToAction("Index", "Home", routeValuesDictionary)); }
public async Task Process(List <IAction> actions, FormSchema formSchema, string formName) { if (formSchema is null) { formSchema = await _schemaFactory.Build(formName); } if (actions.Any(_ => _.Type.Equals(EActionType.RetrieveExternalData))) { await _retrieveExternalDataService.Process(actions.Where(_ => _.Type.Equals(EActionType.RetrieveExternalData)).ToList(), formSchema, formName); } if (actions.Any(_ => _.Type.Equals(EActionType.UserEmail) || _.Type.Equals(EActionType.BackOfficeEmail))) { await _emailService.Process(actions.Where(_ => _.Type.Equals(EActionType.UserEmail) || _.Type.Equals(EActionType.BackOfficeEmail)).ToList()); } if (actions.Any(_ => _.Type.Equals(EActionType.Validate))) { await _validateService.Process(actions.Where(_ => _.Type.Equals(EActionType.Validate)).ToList(), formSchema, formName); } if (actions.Any(_ => _.Type.Equals(EActionType.TemplatedEmail))) { _ = _templatedEmailService.ProcessTemplatedEmail(actions.Where(_ => _.Type.Equals(EActionType.TemplatedEmail)).ToList()); } }
private async Task <(FormAnswers convertedAnswers, FormSchema baseForm)> GetFormAnswers(string form, string sessionGuid) { var baseForm = await _schemaFactory.Build(form); if (string.IsNullOrEmpty(sessionGuid)) { throw new ApplicationException("MappingService::GetFormAnswers Session has expired"); } var sessionData = _distributedCache.GetString(sessionGuid); if (sessionData is null) { throw new ApplicationException("MappingService::GetFormAnswers, Session data is null"); } var convertedAnswers = JsonConvert.DeserializeObject <FormAnswers>(sessionData); convertedAnswers.Pages = convertedAnswers.GetReducedAnswers(baseForm); convertedAnswers.FormName = form; if (convertedAnswers.Pages is null || !convertedAnswers.Pages.Any()) { var deviceInformation = $"Device Type: {_detectionService.Device.Type}, Browser Name/Version: {_detectionService.Browser.Name}/{_detectionService.Browser.Version}, Platform Name: {_detectionService.Platform.Name}, Engine Name: {_detectionService.Engine.Name}, Crawler: {_detectionService.Crawler.IsCrawler}/{_detectionService.Crawler.Name}"; _logger.LogWarning($"MappingService::GetFormAnswers, Reduced Answers returned empty or null list, Creating submit data but no answers collected. Form {form}, Session {sessionGuid}, {deviceInformation}"); } return(convertedAnswers, baseForm); }
public async Task <SuccessPageEntity> Process(EBehaviourType behaviourType, string form) { var baseForm = await _schemaFactory.Build(form); if (baseForm.FormActions.Any()) { await _actionsWorkflow.Process(baseForm.FormActions, baseForm, form); } return(await _pageService.FinalisePageJourney(form, behaviourType, baseForm)); }
public async Task <IActionResult> CannotCancel(string formName) { var formSchema = await _schemaFactory.Build(formName); return(View("CannotCancel", new FormBuilderViewModel { FormName = formSchema.FormName, StartPageUrl = formSchema.StartPageUrl, PageTitle = "Appointment cannot be cancelled", DisplayBreadCrumbs = false, HideBackButton = true })); }
private async Task <(FormAnswers convertedAnswers, FormSchema baseForm)> GetFormAnswers(string form, string sessionGuid) { var baseForm = await _schemaFactory.Build(form); var convertedAnswers = JsonConvert.DeserializeObject <FormAnswers>(_distributedCache.GetString(sessionGuid)); convertedAnswers.Pages = convertedAnswers.GetReducedAnswers(baseForm); convertedAnswers.FormName = form; if (convertedAnswers.Pages == null || !convertedAnswers.Pages.Any()) { _logger.LogWarning($"MappingService::GetFormAnswers, Reduced Answers returned empty or null list, Creating submit data but no answers collected. Form {form}, Session {sessionGuid}"); } return(convertedAnswers, baseForm); }
public async Task <byte[]> GenerateSummaryDocumentAsync(EDocumentType documentType, Guid id) { var formData = _distributedCache.GetString($"document-{id.ToString()}"); if (formData is null) { throw new DocumentExpiredException($"DocumentWorkflow::GenerateSummaryDocument, Previous answers has expired, unable to generate {documentType.ToString()} document for summary"); } var previousAnswers = JsonConvert.DeserializeObject <FormAnswers>(formData); var baseForm = await _schemaFactory.Build(previousAnswers.FormName); return(await _documentSummaryService.GenerateDocument(new DocumentSummaryEntity { DocumentType = documentType, PreviousAnswers = previousAnswers, FormSchema = baseForm })); }
public async Task ProcessMonthRequest(Dictionary <string, object> viewModel, string form, string path) { var baseForm = await _schemaFactory.Build(form); if (baseForm is null) { throw new ApplicationException($"Requested form '{form}' could not be found."); } var currentPage = baseForm.GetPage(_pageHelper, path); if (currentPage is null) { throw new ApplicationException($"Requested path '{path}' object could not be found for form '{form}'"); } if (!viewModel.ContainsKey(BookingConstants.BOOKING_MONTH_REQUEST)) { throw new ApplicationException("BookingService::ProcessMonthRequest, request for appointment did not contain requested month"); } var requestedMonth = DateTime.Parse(viewModel[BookingConstants.BOOKING_MONTH_REQUEST].ToString()); var currentDate = DateTime.Now; var bookingElement = (Booking)currentPage.Elements .First(element => element.Type. Equals(EElementType.Booking)); if (requestedMonth.Month.Equals(currentDate.Month) && requestedMonth.Year.Equals(currentDate.Year)) { requestedMonth = currentDate; } if (requestedMonth > new DateTime(currentDate.Year, currentDate.Month, 1).AddMonths(bookingElement.Properties.SearchPeriod)) { throw new ApplicationException("BookingService::ProcessMonthRequest, Invalid request for appointment search, Start date provided is after allowed search period"); } if (requestedMonth < currentDate) { throw new ApplicationException("BookingService::ProcessMonthRequest, Invalid request for appointment search, Start date provided is before today"); } var guid = _sessionHelper.GetSessionGuid(); if (string.IsNullOrEmpty(guid)) { throw new ApplicationException("BookingService::ProcessMonthRequest Session has expired"); } var cachedAnswers = _distributedCache.GetString(guid); if (cachedAnswers is null) { throw new ApplicationException("BookingService::ProcessMonthRequest, Session data is null"); } var bookingInformationCacheKey = $"{bookingElement.Properties.QuestionId}{BookingConstants.APPOINTMENT_TYPE_SEARCH_RESULTS}"; var convertedAnswers = JsonConvert.DeserializeObject <FormAnswers>(cachedAnswers); var appointmentType = bookingElement.Properties.AppointmentTypes .GetAppointmentTypeForEnvironment(_environment.EnvironmentName); if (appointmentType.NeedsAppointmentIdMapping) { _mappingService.MapAppointmentId(appointmentType, convertedAnswers); } var appointmentTimes = await _bookingProviders.Get(bookingElement.Properties.BookingProvider) .GetAvailability(new AvailabilityRequest { StartDate = requestedMonth.Date, EndDate = requestedMonth.Date.LastDayOfTheMonth(), AppointmentId = appointmentType.AppointmentId, OptionalResources = appointmentType.OptionalResources }); var cachedBookingInformation = JsonConvert.DeserializeObject <BookingInformation>(convertedAnswers.FormData[bookingInformationCacheKey].ToString()); BookingInformation bookingInformation = new() { AppointmentTypeId = appointmentType.AppointmentId, Appointments = appointmentTimes, CurrentSearchedMonth = requestedMonth, FirstAvailableMonth = cachedBookingInformation.FirstAvailableMonth, IsFullDayAppointment = cachedBookingInformation.IsFullDayAppointment, AppointmentEndTime = cachedBookingInformation.AppointmentEndTime, AppointmentStartTime = cachedBookingInformation.AppointmentStartTime }; _pageHelper.SaveFormData(bookingInformationCacheKey, bookingInformation, guid, baseForm.BaseURL); }
public async Task <ProcessPageEntity> ProcessPage(string form, string path, string subPath, IQueryCollection queryParamters) { if (string.IsNullOrEmpty(path)) { _sessionHelper.RemoveSessionGuid(); } var sessionGuid = _sessionHelper.GetSessionGuid(); if (string.IsNullOrEmpty(sessionGuid)) { sessionGuid = Guid.NewGuid().ToString(); _sessionHelper.SetSessionGuid(sessionGuid); } var baseForm = await _schemaFactory.Build(form); if (baseForm == null) { return(null); } if (!baseForm.IsAvailable(_environment.EnvironmentName)) { throw new ApplicationException($"Form: {form} is not available in this Environment: {_environment.EnvironmentName.ToS3EnvPrefix()}"); } var formData = _distributedCache.GetString(sessionGuid); if (formData == null && path != baseForm.FirstPageSlug && (!baseForm.HasDocumentUpload || path != FileUploadConstants.DOCUMENT_UPLOAD_URL_PATH)) { return new ProcessPageEntity { ShouldRedirect = true, TargetPage = baseForm.FirstPageSlug } } ; if (string.IsNullOrEmpty(path)) { return new ProcessPageEntity { ShouldRedirect = true, TargetPage = baseForm.FirstPageSlug } } ; if (formData != null && path == baseForm.FirstPageSlug) { var convertedFormData = JsonConvert.DeserializeObject <FormAnswers>(formData); if (form.ToLower() != convertedFormData.FormName.ToLower()) { _distributedCache.Remove(sessionGuid); } } var page = baseForm.GetPage(_pageHelper, path); if (page == null) { throw new ApplicationException($"Requested path '{path}' object could not be found for form '{form}'"); } await baseForm.ValidateFormSchema(_pageHelper, form, path); List <object> searchResults = null; if (subPath.Equals(LookUpConstants.Automatic) || subPath.Equals(LookUpConstants.Manual)) { var convertedAnswers = new FormAnswers { Pages = new List <PageAnswers>() }; if (!string.IsNullOrEmpty(formData)) { convertedAnswers = JsonConvert.DeserializeObject <FormAnswers>(formData); } if (convertedAnswers.FormData.ContainsKey($"{path}{LookUpConstants.SearchResultsKeyPostFix}")) { searchResults = ((IEnumerable <object>)convertedAnswers.FormData[$"{path}{LookUpConstants.SearchResultsKeyPostFix}"])?.ToList(); } } if (page.Elements.Any(_ => _.Type == EElementType.PaymentSummary)) { var data = await _mappingService.Map(sessionGuid, form); var paymentAmount = await _payService.GetFormPaymentInformation(data, form, page); page.Elements.First(_ => _.Type == EElementType.PaymentSummary).Properties.Value = paymentAmount.Settings.Amount; } if (page.HasIncomingGetValues) { var convertedAnswers = new FormAnswers { Pages = new List <PageAnswers>() }; if (!string.IsNullOrEmpty(formData)) { convertedAnswers = JsonConvert.DeserializeObject <FormAnswers>(formData); } var result = _incomingDataHelper.AddIncomingFormDataValues(page, queryParamters, convertedAnswers); _pageHelper.SaveNonQuestionAnswers(result, form, path, sessionGuid); } if (page.HasPageActionsGetValues) { await _actionsWorkflow.Process(page.PageActions, null, form); } if (page.Elements.Any(_ => _.Type.Equals(EElementType.Booking))) { var bookingProcessEntity = await _bookingService.Get(baseForm.BaseURL, page, sessionGuid); if (bookingProcessEntity.BookingHasNoAvailableAppointments) { return(new ProcessPageEntity { ShouldRedirect = true, TargetPage = BookingConstants.NO_APPOINTMENT_AVAILABLE }); } searchResults = bookingProcessEntity.BookingInfo; } var viewModel = await GetViewModel(page, baseForm, path, sessionGuid, subPath, searchResults); return(new ProcessPageEntity { ViewModel = viewModel }); }
public async Task <ProcessPageEntity> ProcessPage(string form, string path, string subPath, IQueryCollection queryParameters) { if (string.IsNullOrEmpty(path)) { _sessionHelper.RemoveSessionGuid(); } var sessionGuid = _sessionHelper.GetSessionGuid(); if (string.IsNullOrEmpty(sessionGuid)) { sessionGuid = Guid.NewGuid().ToString(); _sessionHelper.SetSessionGuid(sessionGuid); } var baseForm = await _schemaFactory.Build(form); if (baseForm is null) { return(null); } if (!_formAvailabilityService.IsAvailable(baseForm.EnvironmentAvailabilities, _environment.EnvironmentName)) { _logger.LogWarning($"Form: {form} is not available in this Environment: {_environment.EnvironmentName.ToS3EnvPrefix()}"); return(null); } if (string.IsNullOrEmpty(path)) { return new ProcessPageEntity { ShouldRedirect = true, TargetPage = baseForm.FirstPageSlug } } ; var formData = _distributedCache.GetString(sessionGuid); if (string.IsNullOrEmpty(formData) && !path.Equals(baseForm.FirstPageSlug) && (!baseForm.HasDocumentUpload || !path.Equals(FileUploadConstants.DOCUMENT_UPLOAD_URL_PATH))) { return new ProcessPageEntity { ShouldRedirect = true, TargetPage = baseForm.FirstPageSlug } } ; if (!string.IsNullOrEmpty(formData) && path.Equals(baseForm.FirstPageSlug)) { var convertedFormData = JsonConvert.DeserializeObject <FormAnswers>(formData); if (!form.Equals(convertedFormData.FormName, StringComparison.OrdinalIgnoreCase)) { _distributedCache.Remove(sessionGuid); } } var page = baseForm.GetPage(_pageHelper, path); if (page is null) { throw new ApplicationException($"Requested path '{path}' object could not be found for form '{form}'"); } List <object> searchResults = null; var convertedAnswers = new FormAnswers { Pages = new List <PageAnswers>() }; if (!string.IsNullOrEmpty(formData)) { convertedAnswers = JsonConvert.DeserializeObject <FormAnswers>(formData); } if (page.Elements.Any(_ => _.Type.Equals(EElementType.Summary))) { var journeyPages = baseForm.GetReducedPages(convertedAnswers); foreach (var schemaPage in journeyPages) { await _schemaFactory.TransformPage(schemaPage, convertedAnswers); } } else { await _schemaFactory.TransformPage(page, convertedAnswers); } if (subPath.Equals(LookUpConstants.Automatic) || subPath.Equals(LookUpConstants.Manual)) { if (convertedAnswers.FormData.ContainsKey($"{path}{LookUpConstants.SearchResultsKeyPostFix}")) { searchResults = ((IEnumerable <object>)convertedAnswers.FormData[$"{path}{LookUpConstants.SearchResultsKeyPostFix}"])?.ToList(); } } if (page.HasIncomingGetValues) { var result = _incomingDataHelper.AddIncomingFormDataValues(page, queryParameters, convertedAnswers); _pageHelper.SaveNonQuestionAnswers(result, form, path, sessionGuid); } if (page.HasPageActionsGetValues) { await _actionsWorkflow.Process(page.PageActions, null, form); } if (page.Elements.Any(_ => _.Type.Equals(EElementType.Booking))) { var bookingProcessEntity = await _bookingService.Get(baseForm.BaseURL, page, sessionGuid); if (bookingProcessEntity.BookingHasNoAvailableAppointments) { return(new ProcessPageEntity { ShouldRedirect = true, TargetPage = BookingConstants.NO_APPOINTMENT_AVAILABLE }); } searchResults = bookingProcessEntity.BookingInfo; } var viewModel = await GetViewModel(page, baseForm, path, sessionGuid, subPath, searchResults); return(new ProcessPageEntity { ViewModel = viewModel }); }