public override async Task <string> RenderAsync(IViewRender viewRender, IElementHelper elementHelper, string guid, Dictionary <string, dynamic> viewModel, Page page, FormSchema formSchema, IWebHostEnvironment environment, FormAnswers formAnswers, List <object> results = null) { elementHelper.CheckForQuestionId(this); elementHelper.CheckForProvider(this); viewModel.TryGetValue(LookUpConstants.SubPathViewModelKey, out var subPath); switch (subPath as string) { case LookUpConstants.Automatic: IsSelect = true; Properties.Value = elementHelper.CurrentValue(Properties.QuestionId, viewModel, formAnswers); ReturnURL = environment.EnvironmentName.Equals("local") || environment.EnvironmentName.Equals("uitest") ? $"{environment.EnvironmentName.ToReturnUrlPrefix()}/{formSchema.BaseURL}/{page.PageSlug}" : $"{environment.EnvironmentName.ToReturnUrlPrefix()}/v2/{formSchema.BaseURL}/{page.PageSlug}"; var selectedStreet = elementHelper.CurrentValue(Properties.QuestionId, viewModel, formAnswers, StreetConstants.SELECT_SUFFIX); var searchSuffix = results?.Count == 1 ? "street found" : "streets found"; Items = new List <SelectListItem> { new SelectListItem($"{results?.Count} {searchSuffix}", string.Empty) }; results?.ForEach((objectResult) => { AddressSearchResult searchResult; if (objectResult as JObject != null) { searchResult = (objectResult as JObject).ToObject <AddressSearchResult>(); } else { searchResult = objectResult as AddressSearchResult; } Items.Add(new SelectListItem(searchResult.Name, $"{searchResult.UniqueId}|{searchResult.Name}", searchResult.UniqueId.Equals(selectedStreet))); }); return(await viewRender.RenderAsync("StreetSelect", this)); default: Properties.Value = elementHelper.CurrentValue(Properties.QuestionId, viewModel, formAnswers); return(await viewRender.RenderAsync("StreetSearch", this)); } }
public async Task <IActionResult> Get() { //render the razor file. //NB: file must be in a folder with the same name as the controller. string htmlSource = await _viewRender.RenderAsync <User>("HelloBuddy", new User { FirstName = "Mehdi", LastName = "Rifi" }); //load file with absolute url string htmlSource2 = await _viewRender.RenderAsync("~/Views/Heros/TheFlash.cshtml"); //create pdf from html string byte[] pdf = _pdfGenerator.GeneratePdfFromHtml(htmlSource); //write the pdf stream into a file => test only System.IO.File.WriteAllBytes("test.pdf", pdf); //return the string html source => test only return(Ok(htmlSource)); }
public override Task <string> RenderAsync(IViewRender viewRender, IElementHelper elementHelper, string guid, Dictionary <string, dynamic> viewModel, Page page, FormSchema formSchema, IWebHostEnvironment environment, FormAnswers formAnswers, List <object> results = null) { var currentAnswer = elementHelper.CurrentValue <JArray>(Properties.QuestionId, viewModel, formAnswers, FileUploadConstants.SUFFIX); SubmitButtonText = SetSubmitButtonText(page); IsModelStateValid = !viewModel.ContainsKey("modelStateInvalid"); if (currentAnswer != null) { List <FileUploadModel> response = JsonConvert.DeserializeObject <List <FileUploadModel> >(currentAnswer.ToString()); CurrentFilesUploaded = response.Select(_ => _.TrustedOriginalFileName).ToList(); } Properties.HideOptionalText = true; elementHelper.CheckForQuestionId(this); elementHelper.CheckForLabel(this); return(viewRender.RenderAsync(Type.ToString(), this)); }
public async Task <FormBuilderViewModel> GenerateHtml( Page page, Dictionary <string, dynamic> viewModel, FormSchema baseForm, string guid, FormAnswers formAnswers, List <object> results = null) { var formModel = new FormBuilderViewModel(); if (!page.PageSlug.Equals("success", StringComparison.OrdinalIgnoreCase) && !page.HideTitle) { formModel.RawHTML += await _viewRender .RenderAsync("H1", new Element { Properties = new BaseProperty { Text = page.GetPageTitle(), Optional = page.DisplayOptionalInTitle } }); } foreach (var element in page.Elements) { string html = await element.RenderAsync(_viewRender, _elementHelper, guid, viewModel, page, baseForm, _environment, formAnswers, results); if (element.Properties is not null && element.Properties.isConditionalElement) { formModel.RawHTML = formModel.RawHTML.Replace($"{SystemConstants.CONDITIONAL_ELEMENT_REPLACEMENT}{element.Properties.QuestionId}", html); }
public override Task <string> RenderAsync(IViewRender viewRender, IElementHelper elementHelper, string guid, Dictionary <string, dynamic> viewModel, Page page, FormSchema formSchema, IWebHostEnvironment environment, FormAnswers formAnswers, List <object> results = null) { Properties.ClassName ??= "smbc-!-font-word-break"; if (Properties.FileUploadQuestionIds.Any()) { Properties.FileUploadQuestionIds.ForEach((questionId) => { var model = elementHelper.CurrentValue <JArray>(questionId, viewModel, formAnswers, FileUploadConstants.SUFFIX); if (model != null && model.Any()) { List <FileUploadModel> response = JsonConvert.DeserializeObject <List <FileUploadModel> >(model.ToString()); Properties.ListItems.AddRange(response.Select(_ => _.TrustedOriginalFileName)); } }); } return(viewRender.RenderAsync(Type.ToString(), this)); }
public virtual Task <string> RenderAsync(IViewRender viewRender, IElementHelper elementHelper, string guid, Dictionary <string, dynamic> viewModel, Page page, FormSchema formSchema, IWebHostEnvironment environment, FormAnswers formAnswers, List <object> results = null) => viewRender.RenderAsync(Type.ToString(), this, null);
public async Task <IActionResult> FormSubmit(ContactForm model) { string html = await _viewRender.RenderAsync("~/Emails/Email.cshtml", model); await _emailSender.SendContactDetails(model.email, html, model.name); await _emailSender.contactedNotifation(SD.Email, model.email, model.message, model.name); return(View(model)); }
public override Task <string> RenderAsync(IViewRender viewRender, IElementHelper elementHelper, string guid, Dictionary <string, dynamic> viewModel, Page page, FormSchema formSchema, IWebHostEnvironment environment, FormAnswers formAnswers, List <object> results = null) { Properties.Value = JsonConvert.SerializeObject(elementHelper.CurrentValue <object>(Properties.QuestionId, viewModel, formAnswers)); return(viewRender.RenderAsync(Type.ToString(), this)); }
public override Task <string> RenderAsync(IViewRender viewRender, IElementHelper elementHelper, string guid, Dictionary <string, dynamic> viewModel, Page page, FormSchema formSchema, IWebHostEnvironment environment, FormAnswers formAnswers, List <object> results = null) { elementHelper.CheckIfLabelAndTextEmpty(this); return(viewRender.RenderAsync(Type.ToString(), this)); }
public string GetBanner(string countryCode, string trades, string badges) { var bannerModel = new Banner() { CountryCode = "US", EnterpriseCompanyId = 1, EnterpriseCompanyName = "Test", UiCulture = "en-en", UserName = "******", UserId = 1, Trades = null }; return(_viewRender.RenderAsync("BannerTemplate", bannerModel).Result); }
public async Task <bool> TryRenderAndSendMail(MailModel mail, CancellationToken cancellationToken = default) { string from = string.Format(_mailOptions.MailFromTemplate, mail.Environment); string to = string.Format(_mailOptions.MailToTemplate, mail.Environment); string subject; string body; _logger.LogInformation($"Trying to render mail: {mail.Id}"); try { subject = await _viewRender.RenderAsync(_mailOptions.MailSubjectTemplatePath, mail); body = await _viewRender.RenderAsync(_mailOptions.MailBodyTemplatePath, mail); } catch (Exception ex) { _logger.LogError(ex, $"Mail {mail.Id} render is failed!"); _sentry.CaptureException(ex); return(false); } _logger.LogInformation($"Mail {mail.Id} has been render successfully!"); var mailMessage = new MailMessage(from, to, subject, body) { IsBodyHtml = true }; _logger.LogInformation($"Trying to send mail: {mail.Id}"); try { var smtpClient = _serviceProvider.GetRequiredService <ISmtpClient>(); await smtpClient.SendMailAsync(mailMessage, cancellationToken); } catch (Exception ex) { _logger.LogError(ex, $"Mail {mail.Id} send is failed!"); _sentry.CaptureException(ex); return(false); } _logger.LogInformation($"Mail {mail.Id} has been send successfully!"); return(true); }
public override Task <string> RenderAsync(IViewRender viewRender, IElementHelper elementHelper, string guid, Dictionary <string, dynamic> viewModel, Page page, FormSchema formSchema, IWebHostEnvironment environment, FormAnswers formAnswers, List <object> results = null) { Properties.Text ??= ButtonConstants.DOCUMENT_UPLOAD_TEXT; Properties.DocumentUploadUrl = elementHelper.GenerateDocumentUploadUrl(this, formSchema, formAnswers); return(viewRender.RenderAsync(Type.ToString(), this)); }
public override Task <string> RenderAsync(IViewRender viewRender, IElementHelper elementHelper, string guid, Dictionary <string, dynamic> viewModel, Page page, FormSchema formSchema, IWebHostEnvironment environment, FormAnswers formAnswers, List <object> results = null) { Properties.Value = elementHelper.CurrentValue(Properties.QuestionId, viewModel, formAnswers); elementHelper.CheckForQuestionId(this); elementHelper.CheckForLabel(this); elementHelper.CheckForMaxLength(this); return(viewRender.RenderAsync(Type.ToString(), this)); }
public override Task <string> RenderAsync(IViewRender viewRender, IElementHelper elementHelper, string guid, Dictionary <string, dynamic> viewModel, Page page, FormSchema formSchema, IWebHostEnvironment environment, FormAnswers formAnswers, List <object> results = null) { Properties.Hours = elementHelper.CurrentValue(Properties.QuestionId, viewModel, formAnswers, TimeConstants.HOURS_SUFFIX); Properties.Minutes = elementHelper.CurrentValue(Properties.QuestionId, viewModel, formAnswers, TimeConstants.MINUTES_SUFFIX); Properties.AmPm = elementHelper.CurrentValue(Properties.QuestionId, viewModel, formAnswers, TimeConstants.AM_PM_SUFFIX); elementHelper.CheckForQuestionId(this); elementHelper.CheckForLabel(this); return(viewRender.RenderAsync(Type.ToString(), this)); }
public override Task <string> RenderAsync(IViewRender viewRender, IElementHelper elementHelper, string guid, Dictionary <string, dynamic> viewModel, Page page, FormSchema formSchema, IWebHostEnvironment environment, FormAnswers formAnswers, List <object> results = null) { Properties.Text = GetButtonText(page.Elements, viewModel, page); if (!Properties.DisableOnClick) { Properties.DisableOnClick = DisableIfSubmitOrLookup(page.Behaviours, page.Elements, viewModel); } return(viewRender.RenderAsync("Button", this)); }
public override Task <string> RenderAsync(IViewRender viewRender, IElementHelper elementHelper, string guid, Dictionary <string, dynamic> viewModel, Page page, FormSchema formSchema, IWebHostEnvironment environment, FormAnswers formAnswers, List <object> results = null) { Properties.Day = elementHelper.CurrentValue(Properties.QuestionId, viewModel, formAnswers, DAY_EXTENSION); Properties.Month = elementHelper.CurrentValue(Properties.QuestionId, viewModel, formAnswers, MONTH_EXTENSION); Properties.Year = elementHelper.CurrentValue(Properties.QuestionId, viewModel, formAnswers, YEAR_EXTENSION); elementHelper.CheckForQuestionId(this); elementHelper.CheckForLabel(this); elementHelper.CheckAllDateRestrictionsAreNotEnabled(this); return(viewRender.RenderAsync(Type.ToString(), this)); }
public async Task <FormBuilderViewModel> GenerateHtml( Page page, Dictionary <string, dynamic> viewModel, FormSchema baseForm, string guid, FormAnswers formAnswers, List <object> results = null) { var formModel = new FormBuilderViewModel(); if (page.PageSlug.ToLower() != "success" && !page.HideTitle) { formModel.RawHTML += await _viewRender.RenderAsync("H1", new Element { Properties = new BaseProperty { Text = page.GetPageTitle() } }); } foreach (var element in page.Elements) { string html = await element.RenderAsync( _viewRender, _elementHelper, guid, viewModel, page, baseForm, _environment, formAnswers, results ); if (element.Properties.isConditionalElement) { formModel.RawHTML = formModel.RawHTML.Replace(SystemConstants.ConditionalElementReplacementString + element.Properties.QuestionId, html); } else { formModel.RawHTML += html; } } return(formModel); }
public override async Task <string> RenderAsync(IViewRender viewRender, IElementHelper elementHelper, string guid, Dictionary <string, dynamic> viewModel, Page page, FormSchema formSchema, IWebHostEnvironment environment, FormAnswers formAnswers, List <object> results = null) { SetAddressProperties(elementHelper, formAnswers, page.PageSlug, guid, viewModel); if (results != null && results.Count == 0) { Properties.DisplayNoResultsIAG = true; } ReturnURL = environment.EnvironmentName.Equals("local") || environment.EnvironmentName.Equals("uitest") ? $"{environment.EnvironmentName.ToReturnUrlPrefix()}/{formSchema.BaseURL}/{page.PageSlug}" : $"{environment.EnvironmentName.ToReturnUrlPrefix()}/v2/{formSchema.BaseURL}/{page.PageSlug}"; return(await viewRender.RenderAsync("AddressManual", this)); }
public async Task <IActionResult> Edit() { string html = await _viewRender.RenderAsync("Emails/VenuePublished", venue.Name); return(Ok()); }