/// <summary> /// The default action to render the front-end view /// </summary> /// <param name="model"/> /// <returns/> public new async Task <ActionResult> Index(RenderModel model) { if (model == null) { throw new ArgumentNullException(nameof(model)); } var mediaUrlTransformer = new RemoveMediaDomainUrlTransformer(); var viewModel = new JobsHomeViewModelFromUmbraco(model.Content, new RelatedLinksService(mediaUrlTransformer, new RemoveAzureDomainUrlTransformer())).BuildModel(); // Add common properties to the model var expiryDate = new ExpiryDateFromExamine(model.Content.Id, ExamineManager.Instance.SearchProviderCollection["ExternalSearcher"], new ExpiryDateMemoryCache(TimeSpan.FromHours(1))); var modelBuilder = new BaseViewModelBuilder(new EastSussexGovUKTemplateRequest(Request, webChatSettingsService: new UmbracoWebChatSettingsService(model.Content, new UrlListReader()))); await modelBuilder.PopulateBaseViewModel(viewModel, model.Content, new ContentExperimentSettingsService(), expiryDate.ExpiryDate, UmbracoContext.Current.InPreviewMode); modelBuilder.PopulateBaseViewModelWithInheritedContent(viewModel, new UmbracoLatestService(model.Content), new UmbracoSocialMediaService(model.Content), null, null, null); new HttpCachingService().SetHttpCacheHeadersFromUmbracoContent(model.Content, UmbracoContext.Current.InPreviewMode, Response.Cache, new IExpiryDateSource[] { expiryDate, new ExpiryDateFromPropertyValue(model.Content, "latestUnpublishDate_Latest") }); return(CurrentTemplate(viewModel)); }
/// <summary> /// The default action to render the front-end view /// </summary> /// <param name="model"/> /// <returns/> public new async Task <ActionResult> Index(RenderModel model) { if (model == null) { throw new ArgumentNullException(nameof(model)); } if (ExamineManager.Instance.SearchProviderCollection["RightsOfWayDepositsSearcher"] == null) { throw new ConfigurationErrorsException("The RightsOfWayDepositsSearcher is not configured in Examine config"); } var viewModel = new RightsOfWayDepositsViewModelFromExamine(model.Content.Parent.Id, new Uri(model.Content.Parent.UrlAbsolute()), ExamineManager.Instance.SearchProviderCollection["RightsOfWayDepositsSearcher"], Request.QueryString["q"], new ISearchFilter[] { new SearchTermSanitiser() }, Umbraco).BuildModel(); var rss = new RssViewModel <RightsOfWayDepositViewModel>(); foreach (var deposit in viewModel.Deposits) { rss.Items.Add(deposit); } var expiryDate = new ExpiryDateFromExamine(model.Content.Id, ExamineManager.Instance.SearchProviderCollection["ExternalSearcher"], new ExpiryDateMemoryCache(TimeSpan.FromHours(1))); var modelBuilder = new BaseViewModelBuilder(null); await modelBuilder.PopulateBaseViewModel(rss, model.Content, null, expiryDate.ExpiryDate, UmbracoContext.Current.InPreviewMode); if (!String.IsNullOrEmpty(Request.QueryString["q"])) { rss.Metadata.Title += $" matching '{Request.QueryString["q"]}'"; } new HttpCachingService().SetHttpCacheHeadersFromUmbracoContent(model.Content, UmbracoContext.Current.InPreviewMode, Response.Cache, new[] { expiryDate }); return(CurrentTemplate(rss)); }
/// <summary> /// The default action to render the front-end view /// </summary> /// <param name="model"></param> /// <returns></returns> /// <exception cref="System.ArgumentNullException">model</exception> public override ActionResult Index(RenderModel model) { if (model == null) { throw new ArgumentNullException(nameof(model)); } var viewModel = new HomePageViewModelFromUmbraco(model.Content, new UmbracoOnAzureRelatedLinksService(new RemoveMediaDomainUrlTransformer())).BuildModel(); var modelBuilder = new BaseViewModelBuilder(); modelBuilder.PopulateBaseViewModel(viewModel, model.Content, new ContentExperimentSettingsService(), UmbracoContext.Current.InPreviewMode); var jobsData = new JobsLookupValuesFromExamine(ExamineManager.Instance.SearchProviderCollection["PublicJobsLookupValuesSearcher"]); viewModel.JobLocations = Task.Run(async() => await jobsData.ReadLocations()).Result; viewModel.JobTypes = Task.Run(async() => await jobsData.ReadJobTypes()).Result; // Jobs close at midnight, so don't cache beyond then var untilMidnightTonight = DateTime.Today.ToUkDateTime().AddDays(1) - DateTime.Now.ToUkDateTime(); new HttpCachingService().SetHttpCacheHeadersFromUmbracoContent(model.Content, UmbracoContext.Current.InPreviewMode, Response.Cache, new List <string>() { "latestUnpublishDate_Latest" }, (int)untilMidnightTonight.TotalSeconds); return(CurrentTemplate(viewModel)); }
public async new Task <ActionResult> Index(RenderModel model) { if (model == null) { throw new ArgumentNullException(nameof(model)); } var modelBuilder = new JobsSearchViewModelFromUmbraco(model.Content, new JobsSearchViewModel()); var viewModel = modelBuilder.BuildModel(); var lookupValuesDataSource = new JobsLookupValuesFromApi(new Uri(ConfigurationManager.AppSettings["JobsApiBaseUrl"]), viewModel.JobsSet, new MemoryJobCacheStrategy(MemoryCache.Default, Request.QueryString["ForceCacheRefresh"] == "1")); await modelBuilder.AddLookupValuesToModel(lookupValuesDataSource, viewModel); var expiryDate = new ExpiryDateFromExamine(model.Content.Id, ExamineManager.Instance.SearchProviderCollection["ExternalSearcher"], new ExpiryDateMemoryCache(TimeSpan.FromHours(1))); var baseModelBuilder = new BaseViewModelBuilder(new EastSussexGovUKTemplateRequest(Request, webChatSettingsService: new UmbracoWebChatSettingsService(model.Content, new UrlListReader()))); await baseModelBuilder.PopulateBaseViewModel(viewModel, model.Content, new ContentExperimentSettingsService(), expiryDate.ExpiryDate, UmbracoContext.Current.InPreviewMode); baseModelBuilder.PopulateBaseViewModelWithInheritedContent(viewModel, new UmbracoLatestService(model.Content), new UmbracoSocialMediaService(model.Content), null, null, null); viewModel.Metadata.Description = String.Empty; // Jobs close at midnight, so don't cache beyond then var untilMidnightTonight = DateTime.Today.ToUkDateTime().AddDays(1) - DateTime.Now.ToUkDateTime(); new HttpCachingService().SetHttpCacheHeadersFromUmbracoContent(model.Content, UmbracoContext.Current.InPreviewMode, Response.Cache, new IExpiryDateSource[] { expiryDate, new ExpiryDateFromPropertyValue(model.Content, "latestUnpublishDate_Latest") }, (int)untilMidnightTonight.TotalSeconds); return(CurrentTemplate(viewModel)); }
/// <summary> /// The default action to render the front-end view /// </summary> /// <param name="model"/> /// <returns/> public override ActionResult Index(RenderModel model) { if (model == null) { throw new ArgumentNullException(nameof(model)); } var mediaUrlTransformer = new RemoveMediaDomainUrlTransformer(); var viewModel = new JobsHomeViewModelFromUmbraco(model.Content, new UmbracoOnAzureRelatedLinksService(mediaUrlTransformer)).BuildModel(); // Add common properties to the model var modelBuilder = new BaseViewModelBuilder(); modelBuilder.PopulateBaseViewModel(viewModel, model.Content, new ContentExperimentSettingsService(), UmbracoContext.Current.InPreviewMode); modelBuilder.PopulateBaseViewModelWithInheritedContent(viewModel, new UmbracoLatestService(model.Content), new UmbracoSocialMediaService(model.Content), null, new UmbracoWebChatSettingsService(model.Content, new UrlListReader()), null); new HttpCachingService().SetHttpCacheHeadersFromUmbracoContent(model.Content, UmbracoContext.Current.InPreviewMode, Response.Cache, new List <string>() { "latestUnpublishDate_Latest" }); return(CurrentTemplate(viewModel)); }
private static async Task <LandingViewModel> MapUmbracoContentToViewModel(HttpRequestBase request, IPublishedContent content, DateTime?expiryDate, latest.ILatestService latestService, ISocialMediaService socialMediaService, IEastSussex1SpaceService eastSussex1SpaceService, IWebChatSettingsService webChatSettingsService, IRelatedLinksService relatedLinksService, IContentExperimentSettingsService contentExperimentSettingsService, IEscisService escisService, IRatingSettingsProvider ratingSettings, ISkinToApplyService skinService) { var model = new LandingViewModel(); model.Navigation.Sections = BuildLandingLinksViewModelFromUmbracoContent(content, relatedLinksService); model.Navigation.LandingNavigationLayout = LandingNavigationLayout.ThreeColumn; var selectedLayout = content.GetPropertyValue <string>("layout_Content"); if (!String.IsNullOrEmpty(selectedLayout)) { var selectedOption = umbraco.library.GetPreValueAsString(Int32.Parse(selectedLayout, CultureInfo.InvariantCulture)); if (selectedOption.ToUpperInvariant().Contains("TWO")) { model.Navigation.LandingNavigationLayout = LandingNavigationLayout.TwoColumn; } } // Add common properties to the model var modelBuilder = new BaseViewModelBuilder(new EastSussexGovUKTemplateRequest(request, webChatSettingsService: webChatSettingsService)); await modelBuilder.PopulateBaseViewModel(model, content, contentExperimentSettingsService, expiryDate, UmbracoContext.Current.InPreviewMode, skinService); modelBuilder.PopulateBaseViewModelWithInheritedContent(model, latestService, socialMediaService, eastSussex1SpaceService, escisService, ratingSettings); return(model); }
// GET: TalentLinkComponent public override ActionResult Index(RenderModel model) { if (model == null) { throw new ArgumentNullException(nameof(model)); } var viewModel = new SearchViewModelFromUmbraco(model.Content).BuildModel(); var modelBuilder = new BaseViewModelBuilder(); modelBuilder.PopulateBaseViewModel(viewModel, model.Content, new ContentExperimentSettingsService(), UmbracoContext.Current.InPreviewMode); modelBuilder.PopulateBaseViewModelWithInheritedContent(viewModel, new UmbracoLatestService(model.Content), new UmbracoSocialMediaService(model.Content), null, new UmbracoWebChatSettingsService(model.Content, new UrlListReader()), null); viewModel.Metadata.Description = String.Empty; var dataSource = new JobsLookupValuesFromExamine(ExamineManager.Instance.SearchProviderCollection[viewModel.ExamineSearcher]); var locations = Task.Run(async() => await dataSource.ReadLocations()); foreach (var location in locations.Result) { viewModel.Locations.Add(location); } var jobTypes = Task.Run(async() => await dataSource.ReadJobTypes()); foreach (var jobType in jobTypes.Result) { viewModel.JobTypes.Add(jobType); } var salaryRanges = Task.Run(async() => await dataSource.ReadSalaryRanges()); foreach (var salaryRange in salaryRanges.Result) { viewModel.SalaryRanges.Add(salaryRange); } var workPatterns = Task.Run(async() => await dataSource.ReadWorkPatterns()); foreach (var workPattern in workPatterns.Result) { viewModel.WorkPatterns.Add(workPattern); } // Jobs close at midnight, so don't cache beyond then var untilMidnightTonight = DateTime.Today.ToUkDateTime().AddDays(1) - DateTime.Now.ToUkDateTime(); new HttpCachingService().SetHttpCacheHeadersFromUmbracoContent(model.Content, UmbracoContext.Current.InPreviewMode, Response.Cache, new List <string>() { "latestUnpublishDate_Latest" }, (int)untilMidnightTonight.TotalSeconds); return(CurrentTemplate(viewModel)); }
private static LandingViewModel MapUmbracoContentToViewModel(IPublishedContent content, ILatestService latestService, ISocialMediaService socialMediaService, IEastSussex1SpaceService eastSussex1SpaceService, IWebChatSettingsService webChatSettingsService, IRelatedLinksService relatedLinksService, IContentExperimentSettingsService contentExperimentSettingsService, IEscisService escisService) { var model = new LandingViewModel(); model.Navigation.Sections = BuildLandingLinksViewModelFromUmbracoContent(content, relatedLinksService); model.Navigation.LandingNavigationLayout = LandingNavigationLayout.ThreeColumn; var selectedLayout = content.GetPropertyValue <string>("layout_Content"); if (!String.IsNullOrEmpty(selectedLayout)) { var selectedOption = umbraco.library.GetPreValueAsString(Int32.Parse(selectedLayout, CultureInfo.InvariantCulture)); if (selectedOption.ToUpperInvariant().Contains("TWO")) { model.Navigation.LandingNavigationLayout = LandingNavigationLayout.TwoColumn; } } // Add common properties to the model var modelBuilder = new BaseViewModelBuilder(); modelBuilder.PopulateBaseViewModel(model, content, contentExperimentSettingsService, UmbracoContext.Current.InPreviewMode); modelBuilder.PopulateBaseViewModelWithInheritedContent(model, latestService, socialMediaService, eastSussex1SpaceService, webChatSettingsService, escisService); return(model); }
/// <summary> /// The default action to render the front-end view /// </summary> /// <param name="model"/> /// <returns/> public async new Task <ActionResult> Index(RenderModel model) { if (model == null) { throw new ArgumentNullException(nameof(model)); } var viewModel = new JobsRssViewModelFromUmbraco(model.Content).BuildModel(); // Add common properties to the model var modelBuilder = new BaseViewModelBuilder(); modelBuilder.PopulateBaseViewModel(viewModel, model.Content, new ContentExperimentSettingsService(), UmbracoContext.Current.InPreviewMode); var jobsProvider = new JobsDataFromExamine(ExamineManager.Instance.SearchProviderCollection[viewModel.ExamineSearcher], new QueryBuilder(new LuceneTokenisedQueryBuilder(), new KeywordsTokeniser(), new LuceneStopWordsRemover(), new WildcardSuffixFilter()), new RelativeJobUrlGenerator(viewModel.JobAdvertPage.Url)); var jobs = await jobsProvider.ReadProblemJobs(); foreach (var job in jobs) { viewModel.Items.Add(job); } // Jobs close at midnight, so don't cache beyond then var untilMidnightTonight = DateTime.Today.ToUkDateTime().AddDays(1) - DateTime.Now.ToUkDateTime(); new HttpCachingService().SetHttpCacheHeadersFromUmbracoContent(model.Content, UmbracoContext.Current.InPreviewMode, Response.Cache, null, (int)untilMidnightTonight.TotalSeconds); return(CurrentTemplate(viewModel)); }
/// <summary> /// The default action to render the front-end view /// </summary> /// <param name="model"/> /// <returns/> public async new Task <ActionResult> Index(RenderModel model) { if (model == null) { throw new ArgumentNullException(nameof(model)); } var viewModel = new JobsRssViewModelFromUmbraco(model.Content).BuildModel(); // Add common properties to the model var expiryDate = new ExpiryDateFromExamine(model.Content.Id, ExamineManager.Instance.SearchProviderCollection["ExternalSearcher"], new ExpiryDateMemoryCache(TimeSpan.FromHours(1))); var modelBuilder = new BaseViewModelBuilder(null); await modelBuilder.PopulateBaseViewModel(viewModel, model.Content, null, expiryDate.ExpiryDate, UmbracoContext.Current.InPreviewMode); var jobsProvider = new JobsDataFromApi(new Uri(ConfigurationManager.AppSettings["JobsApiBaseUrl"]), viewModel.JobsSet, viewModel.JobAdvertPage.Url, new HttpClientProvider(), null); var jobs = await jobsProvider.ReadProblemJobs(); foreach (var job in jobs) { viewModel.Items.Add(job); } // Jobs close at midnight, so don't cache beyond then var untilMidnightTonight = DateTime.Today.ToUkDateTime().AddDays(1) - DateTime.Now.ToUkDateTime(); new HttpCachingService().SetHttpCacheHeadersFromUmbracoContent(model.Content, UmbracoContext.Current.InPreviewMode, Response.Cache, new[] { expiryDate }, (int)untilMidnightTonight.TotalSeconds); return(CurrentTemplate(viewModel)); }
private async Task <PersonViewModel> MapUmbracoContentToViewModel(IPublishedContent content, DateTime?expiryDate, latest.ILatestService latestService, ISocialMediaService socialMediaService, IEastSussex1SpaceService eastSussex1SpaceService, IWebChatSettingsService webChatSettingsService, IRelatedLinksService relatedLinksService, IContentExperimentSettingsService contentExperimentSettingsService, IEscisService escisService, IRatingSettingsProvider ratingSettings, IMediaUrlTransformer mediaUrlTransformer) { var model = new PersonViewModel { JobTitle = content.GetPropertyValue <string>("jobTitle_Content"), LeadingText = new HtmlString(mediaUrlTransformer.ParseAndTransformMediaUrlsInHtml(content.GetPropertyValue <string>("leadingText_Content"))), Subheading1 = content.GetPropertyValue <string>("subheading1_Content"), Content1 = new HtmlString(mediaUrlTransformer.ParseAndTransformMediaUrlsInHtml(content.GetPropertyValue <string>("content1_Content"))), Subheading2 = content.GetPropertyValue <string>("subheading2_Content"), Content2 = new HtmlString(mediaUrlTransformer.ParseAndTransformMediaUrlsInHtml(content.GetPropertyValue <string>("content2_Content"))), Contact = new HtmlString(mediaUrlTransformer.ParseAndTransformMediaUrlsInHtml(content.GetPropertyValue <string>("contact_Content"))) }; model.Metadata.PersonAbout.Name.Titles.Add(content.GetPropertyValue <string>("HonorificTitle_Content")); model.Metadata.PersonAbout.Name.GivenNames.Add(content.GetPropertyValue <string>("GivenName_Content")); model.Metadata.PersonAbout.Name.FamilyName = content.GetPropertyValue <string>("FamilyName_Content"); model.Metadata.PersonAbout.Name.Suffixes.Add(content.GetPropertyValue <string>("HonorificSuffix_Content")); model.Metadata.PersonAbout.EmailAddresses.Add(content.GetPropertyValue <string>("email_Content")); model.Metadata.PersonAbout.TelephoneNumbers.Add(content.GetPropertyValue <string>("phone_Content")); model.Metadata.Person = model.Metadata.PersonAbout.Name.ToString(); if (!String.IsNullOrEmpty(model.JobTitle)) { model.Metadata.Person += ", " + model.JobTitle; } var relatedLinksGroups = new RelatedLinksModelBuilder().OrganiseAsHeadingsAndSections(relatedLinksService.BuildRelatedLinksViewModelFromUmbracoContent(content, "relatedLinks_Content")); foreach (var linkGroup in relatedLinksGroups) { model.RelatedLinksGroups.Add(linkGroup); } var imageData = content.GetPropertyValue <IPublishedContent>("photo_Content"); if (imageData != null) { model.Photo = new Image() { AlternativeText = imageData.Name, ImageUrl = new Uri(imageData.Url, UriKind.Relative), Width = imageData.GetPropertyValue <int>("umbracoWidth"), Height = imageData.GetPropertyValue <int>("umbracoHeight") }; model.Metadata.PageImageUrl = new Uri(Request.Url, model.Photo.ImageUrl).ToString(); } // Add common properties to the model var modelBuilder = new BaseViewModelBuilder(new EastSussexGovUKTemplateRequest(Request, webChatSettingsService: webChatSettingsService)); await modelBuilder.PopulateBaseViewModel(model, content, contentExperimentSettingsService, expiryDate, UmbracoContext.Current.InPreviewMode); modelBuilder.PopulateBaseViewModelWithInheritedContent(model, latestService, socialMediaService, eastSussex1SpaceService, escisService, ratingSettings); return(model); }
private static MicrosoftCmsViewModel MapUmbracoContentToViewModel(IPublishedContent content, ILatestService latestService, ISocialMediaService socialMediaService, IEastSussex1SpaceService eastSussex1SpaceService, IWebChatSettingsService webChatSettingsService, IContentExperimentSettingsService contentExperimentSettingsService, IEscisService escisService) { var model = new MicrosoftCmsViewModel(); var modelBuilder = new BaseViewModelBuilder(); modelBuilder.PopulateBaseViewModel(model, content, contentExperimentSettingsService, UmbracoContext.Current.InPreviewMode); modelBuilder.PopulateBaseViewModelWithInheritedContent(model, latestService, socialMediaService, eastSussex1SpaceService, webChatSettingsService, escisService); return(model); }
private static async Task <MicrosoftCmsViewModel> MapUmbracoContentToViewModel(HttpRequestBase request, IPublishedContent content, DateTime?expiryDate, latest.ILatestService latestService, ISocialMediaService socialMediaService, IEastSussex1SpaceService eastSussex1SpaceService, IWebChatSettingsService webChatSettingsService, IContentExperimentSettingsService contentExperimentSettingsService, IEscisService escisService, IRatingSettingsProvider ratingSettings, ISkinToApplyService skinService) { var model = new MicrosoftCmsViewModel(); var modelBuilder = new BaseViewModelBuilder(new EastSussexGovUKTemplateRequest(request, webChatSettingsService: webChatSettingsService)); await modelBuilder.PopulateBaseViewModel(model, content, contentExperimentSettingsService, expiryDate, UmbracoContext.Current.InPreviewMode, skinService); modelBuilder.PopulateBaseViewModelWithInheritedContent(model, latestService, socialMediaService, eastSussex1SpaceService, escisService, ratingSettings); return(model); }
/// <summary> /// The default action to render the front-end view /// </summary> /// <param name="model"/> /// <returns/> public async new Task <ActionResult> Index(RenderModel model) { var modelBuilder = new JobsSearchViewModelFromUmbraco(model.Content, new JobAlertsViewModel()); var viewModel = (JobAlertsViewModel)modelBuilder.BuildModel(); var lookupValuesDataSource = new JobsLookupValuesFromApi(new Uri(ConfigurationManager.AppSettings["JobsApiBaseUrl"]), viewModel.JobsSet, new MemoryJobCacheStrategy(MemoryCache.Default, Request.QueryString["ForceCacheRefresh"] == "1")); await modelBuilder.AddLookupValuesToModel(lookupValuesDataSource, viewModel); var converter = new JobSearchQueryConverter(ConfigurationManager.AppSettings["TranslateObsoleteJobTypes"]?.ToUpperInvariant() == "TRUE"); var alertId = new JobAlertIdEncoder(converter).ParseIdFromUrl(Request.Url); if (!string.IsNullOrEmpty(alertId)) { if (ConfigurationManager.ConnectionStrings["Escc.EastSussexGovUK.Umbraco.AzureStorage"] == null || String.IsNullOrEmpty(ConfigurationManager.ConnectionStrings["Escc.EastSussexGovUK.Umbraco.AzureStorage"].ConnectionString)) { var error = new ConfigurationErrorsException("The Escc.EastSussexGovUK.Umbraco.AzureStorage connection string is missing from web.config"); LogHelper.Error <JobAlertsController>(error.Message, error); error.ToExceptionless().Submit(); } else { var alertsRepo = new AzureTableStorageAlertsRepository(converter, ConfigurationManager.ConnectionStrings["Escc.EastSussexGovUK.Umbraco.AzureStorage"].ConnectionString); viewModel.Alert = alertsRepo.GetAlertById(alertId); viewModel.Query = viewModel.Alert?.Query; if (viewModel.Alert == null && Request.QueryString["cancelled"] != "1" && string.IsNullOrEmpty(Request.QueryString["altTemplate"])) { // Returning HttpNotFoundResult() ends up with a generic browser 404, // so to get our custom one we need to look it up and transfer control to it. var notFoundUrl = new HttpStatusFromConfiguration().GetCustomUrlForStatusCode(404); if (notFoundUrl != null && Server != null) { Server.TransferRequest(notFoundUrl + "?404;" + HttpUtility.UrlEncode(Request.Url.ToString())); } } } } var baseModelBuilder = new BaseViewModelBuilder(new EastSussexGovUKTemplateRequest(Request, webChatSettingsService: new UmbracoWebChatSettingsService(model.Content, new UrlListReader()))); await baseModelBuilder.PopulateBaseViewModel(viewModel, model.Content, new ContentExperimentSettingsService(), new ExpiryDateFromExamine(model.Content.Id, ExamineManager.Instance.SearchProviderCollection["ExternalSearcher"], new ExpiryDateMemoryCache(TimeSpan.FromHours(1))).ExpiryDate, UmbracoContext.Current.InPreviewMode); baseModelBuilder.PopulateBaseViewModelWithInheritedContent(viewModel, new UmbracoLatestService(model.Content), new UmbracoSocialMediaService(model.Content), null, null); return(CurrentTemplate(viewModel)); }
/// <summary> /// The default action to render the front-end view /// </summary> /// <param name="model"></param> /// <returns></returns> /// <exception cref="System.ArgumentNullException">model</exception> public async new Task <ActionResult> Index(RenderModel model) { if (model == null) { throw new ArgumentNullException(nameof(model)); } var viewModel = new HomePageViewModelFromUmbraco(model.Content, new RelatedLinksService(new RemoveMediaDomainUrlTransformer(), new ElibraryUrlTransformer(), new RemoveAzureDomainUrlTransformer())).BuildModel(); var expiryDate = new ExpiryDateFromExamine(model.Content.Id, ExamineManager.Instance.SearchProviderCollection["ExternalSearcher"], new ExpiryDateMemoryCache(TimeSpan.FromHours(1))); var modelBuilder = new BaseViewModelBuilder(new EastSussexGovUKTemplateRequest(Request, webChatSettingsService: new UmbracoWebChatSettingsService(model.Content, new UrlListReader()))); await modelBuilder.PopulateBaseViewModel(viewModel, model.Content, new ContentExperimentSettingsService(), expiryDate.ExpiryDate, UmbracoContext.Current.InPreviewMode); modelBuilder.PopulateBaseViewModelWithInheritedContent(viewModel, null, null, null, null, new RatingSettingsFromUmbraco(model.Content)); try { var forceCacheRefresh = Request.QueryString["ForceCacheRefresh"] == "1"; var jobsData = new JobsLookupValuesFromApi(new Uri(ConfigurationManager.AppSettings["JobsApiBaseUrl"]), JobsSet.PublicJobs, new MemoryJobCacheStrategy(MemoryCache.Default, forceCacheRefresh)); var locationsTask = jobsData.ReadLocations(); var jobTypesTask = jobsData.ReadJobTypes(); var wasteTypesDataSource = new UmbracoWasteTypesDataSource(new Uri(Request.Url, ConfigurationManager.AppSettings["WasteTypesDataUrl"]), new ConfigurationProxyProvider(), forceCacheRefresh ? null : new ApplicationCacheStrategy <List <string> >(TimeSpan.FromDays(1))); var wasteTypesTask = wasteTypesDataSource.LoadWasteTypes(); await Task.WhenAll(locationsTask, jobTypesTask, wasteTypesTask); viewModel.JobLocations = locationsTask.Result; viewModel.JobTypes = jobTypesTask.Result; viewModel.RecyclingSiteSearch.WasteTypes = wasteTypesTask.Result; } catch (Exception ex) { // Report an error fetching jobs or waste site data, but don't cause the page to fail to load ex.ToExceptionless().Submit(); } // Jobs close at midnight, so don't cache beyond then var untilMidnightTonight = DateTime.Today.ToUkDateTime().AddDays(1) - DateTime.Now.ToUkDateTime(); new HttpCachingService().SetHttpCacheHeadersFromUmbracoContent(model.Content, UmbracoContext.Current.InPreviewMode, Response.Cache, new IExpiryDateSource[] { expiryDate, new ExpiryDateFromPropertyValue(model.Content, "latestUnpublishDate_Latest") }, (int)untilMidnightTonight.TotalSeconds); return(CurrentTemplate(viewModel)); }
/// <summary> /// The default action to render the front-end view /// </summary> /// <param name="model"/> /// <returns/> public new async Task <ActionResult> Index(RenderModel model) { if (model == null) { throw new ArgumentNullException(nameof(model)); } var viewModel = new RightsOfWayDepositsViewModelFromExamine(model.Content.Parent.Id, new Uri(model.Content.Parent.UrlAbsolute()), Request.QueryString["q"], new ISearchFilter[] { new SearchTermSanitiser() }, Umbraco).BuildModel(); var expiryDate = new ExpiryDateFromExamine(model.Content.Id, ExamineManager.Instance.SearchProviderCollection["ExternalSearcher"], new ExpiryDateMemoryCache(TimeSpan.FromHours(1))); var modelBuilder = new BaseViewModelBuilder(null); await modelBuilder.PopulateBaseViewModel(viewModel, model.Content, null, expiryDate.ExpiryDate, UmbracoContext.Current.InPreviewMode); new HttpCachingService().SetHttpCacheHeadersFromUmbracoContent(model.Content, UmbracoContext.Current.InPreviewMode, Response.Cache, new[] { expiryDate }); return(CurrentTemplate(viewModel)); }
public override ActionResult Index(RenderModel model) { if (model == null) { throw new ArgumentNullException(nameof(model)); } var viewModel = new ComponentViewModelFromUmbraco(model.Content, new RemoveMediaDomainUrlTransformer()).BuildModel(); var modelBuilder = new BaseViewModelBuilder(); modelBuilder.PopulateBaseViewModel(viewModel, model.Content, new ContentExperimentSettingsService(), UmbracoContext.Current.InPreviewMode); modelBuilder.PopulateBaseViewModelWithInheritedContent(viewModel, new UmbracoLatestService(model.Content), new UmbracoSocialMediaService(model.Content), null, new UmbracoWebChatSettingsService(model.Content, new UrlListReader()), null); return(CurrentTemplate(viewModel)); }
public new async Task <ActionResult> Index(RenderModel model) { if (model == null) { throw new ArgumentNullException(nameof(model)); } var viewModel = new ComponentViewModelFromUmbraco(model.Content, new RemoveMediaDomainUrlTransformer()).BuildModel(); var modelBuilder = new BaseViewModelBuilder(new EastSussexGovUKTemplateRequest(Request, webChatSettingsService: new UmbracoWebChatSettingsService(model.Content, new UrlListReader()))); await modelBuilder.PopulateBaseViewModel(viewModel, model.Content, new ContentExperimentSettingsService(), new ExpiryDateFromExamine(model.Content.Id, ExamineManager.Instance.SearchProviderCollection["ExternalSearcher"], new ExpiryDateMemoryCache(TimeSpan.FromHours(1))).ExpiryDate, UmbracoContext.Current.InPreviewMode); modelBuilder.PopulateBaseViewModelWithInheritedContent(viewModel, new UmbracoLatestService(model.Content), new UmbracoSocialMediaService(model.Content), null, null); return(CurrentTemplate(viewModel)); }
private static GuideStepViewModel MapUmbracoContentToGuideStepViewModel(IPublishedContent content) { var mediaUrlTransformer = new RemoveMediaDomainUrlTransformer(); var viewModel = new GuideStepViewModelFromUmbraco(content, new UmbracoOnAzureRelatedLinksService(mediaUrlTransformer), mediaUrlTransformer ).BuildModel(); // Add common properties to the model var modelBuilder = new BaseViewModelBuilder(); modelBuilder.PopulateBaseViewModel(viewModel, content, new ContentExperimentSettingsService(), UmbracoContext.Current.InPreviewMode); modelBuilder.PopulateBaseViewModelWithInheritedContent(viewModel, new UmbracoLatestService(content), new UmbracoSocialMediaService(content), new UmbracoEastSussex1SpaceService(content), new UmbracoWebChatSettingsService(content, new UrlListReader()), new UmbracoEscisService(content)); return(viewModel); }
/// <summary> /// The default action to render the front-end view /// </summary> /// <param name="model"/> /// <returns/> public override ActionResult Index(RenderModel model) { if (model == null) { throw new ArgumentNullException(nameof(model)); } var urlTransformer = new RemoveMediaDomainUrlTransformer(); var viewModel = new CampaignContentViewModelFromUmbraco(model.Content, urlTransformer).BuildModel(); // Add common properties to the model var modelBuilder = new BaseViewModelBuilder(); modelBuilder.PopulateBaseViewModel(viewModel, model.Content, new ContentExperimentSettingsService(), UmbracoContext.Current.InPreviewMode); new HttpCachingService().SetHttpCacheHeadersFromUmbracoContent(model.Content, UmbracoContext.Current.InPreviewMode, Response.Cache, new List <string>() { "latestUnpublishDate_Latest" }); return(CurrentTemplate(viewModel)); }
private async static Task <GuideStepViewModel> MapUmbracoContentToGuideStepViewModel(IPublishedContent content, IEastSussexGovUKTemplateRequest templateRequest) { var mediaUrlTransformer = new RemoveMediaDomainUrlTransformer(); var viewModel = new GuideStepViewModelFromUmbraco(content, new RelatedLinksService(mediaUrlTransformer, new RemoveAzureDomainUrlTransformer()), mediaUrlTransformer ).BuildModel(); // Add common properties to the model var modelBuilder = new BaseViewModelBuilder(templateRequest); await modelBuilder.PopulateBaseViewModel(viewModel, content, new ContentExperimentSettingsService(), new ExpiryDateFromExamine(content.Id, ExamineManager.Instance.SearchProviderCollection["ExternalSearcher"], new ExpiryDateMemoryCache(TimeSpan.FromHours(1))).ExpiryDate, UmbracoContext.Current.InPreviewMode, new SkinFromUmbraco()); modelBuilder.PopulateBaseViewModelWithInheritedContent(viewModel, new UmbracoLatestService(content), new UmbracoSocialMediaService(content), new UmbracoEastSussex1SpaceService(content), new UmbracoEscisService(content)); return(viewModel); }
/// <summary> /// The default action to render the front-end view /// </summary> /// <param name="model"/> /// <returns/> public async new Task <ActionResult> Index(RenderModel model) { if (model == null) { throw new ArgumentNullException(nameof(model)); } var viewModel = new JobsRssViewModelFromUmbraco(model.Content).BuildModel(); // Add common properties to the model var expiryDate = new ExpiryDateFromExamine(model.Content.Id, ExamineManager.Instance.SearchProviderCollection["ExternalSearcher"], new ExpiryDateMemoryCache(TimeSpan.FromHours(1))); var modelBuilder = new BaseViewModelBuilder(null); await modelBuilder.PopulateBaseViewModel(viewModel, model.Content, null, expiryDate.ExpiryDate, UmbracoContext.Current.InPreviewMode); viewModel.Query = new JobSearchQueryConverter(ConfigurationManager.AppSettings["TranslateObsoleteJobTypes"]?.ToUpperInvariant() == "TRUE").ToQuery(Request.QueryString); viewModel.Query.ClosingDateFrom = DateTime.Today; viewModel.Query.JobsSet = viewModel.JobsSet; var jobsProvider = new JobsDataFromApi(new Uri(ConfigurationManager.AppSettings["JobsApiBaseUrl"]), viewModel.JobsSet, viewModel.JobAdvertPage.Url, new HttpClientProvider(), new MemoryJobCacheStrategy(MemoryCache.Default, Request.QueryString["ForceCacheRefresh"] == "1")); var jobs = await jobsProvider.ReadJobs(viewModel.Query); foreach (var job in jobs.Jobs) { viewModel.Items.Add(job); } // Jobs close at midnight, so don't cache beyond then. // But we reindex every 2 hours, so expire then if it's sooner. var untilMidnightTonight = DateTime.Today.ToUkDateTime().AddDays(1) - DateTime.Now.ToUkDateTime(); var untilNextReindex = TimeUntilNextReindex(); var cacheDuration = untilMidnightTonight > untilNextReindex ? untilNextReindex : untilMidnightTonight; new HttpCachingService().SetHttpCacheHeadersFromUmbracoContent(model.Content, UmbracoContext.Current.InPreviewMode, Response.Cache, new[] { expiryDate }, (int)cacheDuration.TotalSeconds); return(CurrentTemplate(viewModel)); }
public override ActionResult Index(RenderModel model) { var viewModel = new FormModel(); var mediaUrlTransformer = new RemoveMediaDomainUrlTransformer(); viewModel.LeadingText = new HtmlString(mediaUrlTransformer.ParseAndTransformMediaUrlsInHtml(model.Content.GetPropertyValue <string>("LeadingText_Content"))); viewModel.FormGuid = model.Content.GetPropertyValue <Guid>("Form_Content"); var modelBuilder = new BaseViewModelBuilder(new EastSussexGovUKTemplateRequest(Request, webChatSettingsService: new UmbracoWebChatSettingsService(model.Content, new UrlListReader()))); // Unfortunately we can't use async/await in this action as it causes an error when navigating multi-page forms, or when using the default submit message. // As a workaround, add a return value to the following two methods purely so that .Result can be used to run them synchronously in this controller. // https://github.com/umbraco/Umbraco.Forms.Issues/issues/86 var asyncMethodCompletedSynchronously = modelBuilder.PopulateBaseViewModel(viewModel, model.Content, null, new ExpiryDateFromExamine(model.Content.Id, ExamineManager.Instance.SearchProviderCollection["ExternalSearcher"], new ExpiryDateMemoryCache(TimeSpan.FromHours(1))).ExpiryDate, UmbracoContext.Current.InPreviewMode, new SkinFromUmbraco()).Result; modelBuilder.PopulateBaseViewModelWithInheritedContent(viewModel, new UmbracoLatestService(model.Content), null, null, null, null); return(CurrentTemplate(viewModel)); }
public override ActionResult Index(RenderModel model) { var viewModel = new FormModel(); var mediaUrlTransformer = new RemoveMediaDomainUrlTransformer(); viewModel.LeadingText = new HtmlString(mediaUrlTransformer.ParseAndTransformMediaUrlsInHtml(model.Content.GetPropertyValue <string>("LeadingText_Content"))); viewModel.FormGuid = model.Content.GetPropertyValue <Guid>("Form_Content"); var modelBuilder = new BaseViewModelBuilder(new EastSussexGovUKTemplateRequest(Request, webChatSettingsService: new UmbracoWebChatSettingsService(model.Content, new UrlListReader()))); // Unfortunately we can't use async/await in this action as it causes an error when navigating multi-page forms, or when using the default submit message. // As a workaround, add a return value to the following two methods purely so that .Result can be used to run them synchronously in this controller. // https://github.com/umbraco/Umbraco.Forms.Issues/issues/86 var asyncMethodCompletedSynchronously = modelBuilder.PopulateBaseViewModel(viewModel, model.Content, null, new ExpiryDateFromExamine(model.Content.Id, ExamineManager.Instance.SearchProviderCollection["ExternalSearcher"], new ExpiryDateMemoryCache(TimeSpan.FromHours(1))).ExpiryDate, UmbracoContext.Current.InPreviewMode, new SkinFromUmbraco()).Result; modelBuilder.PopulateBaseViewModelWithInheritedContent(viewModel, new UmbracoLatestService(model.Content), null, null, null, null); // Prevent the sitewide JQuery from loading because Umbraco Forms needs a newer one, and can't cope with both being on the same page. // The version loaded for use by Umbraco Forms handles the sitewide requirements. if (viewModel.TemplateHtml.Scripts != null) { var sitewideScripts = new HtmlDocument(); sitewideScripts.LoadHtml(viewModel.TemplateHtml.Scripts.ToHtmlString()); var jquery = sitewideScripts.DocumentNode.ChildNodes.FirstOrDefault(x => x.Attributes["src"] != null && x.Attributes["src"].Value.EndsWith("jquery.min.js", StringComparison.OrdinalIgnoreCase)); if (jquery != null) { jquery.ParentNode.RemoveChild(jquery); } viewModel.TemplateHtml.Scripts = new HtmlString(sitewideScripts.DocumentNode.OuterHtml); } return(CurrentTemplate(viewModel)); }
/// <summary> /// The default action to render the front-end view /// </summary> /// <param name="model"/> /// <returns/> public new async Task <ActionResult> Index(RenderModel model) { if (model == null) { throw new ArgumentNullException(nameof(model)); } var viewModel = new RightsOfWayModificationViewModelFromUmbraco(model.Content).BuildModel(); var where = "in " + viewModel.Parishes.Humanize() + " parish(es)"; if (viewModel.Addresses.Any()) { where = "at " + viewModel.Addresses[0].BS7666Address.ToString(); if (viewModel.Addresses.Count > 1) { where += " and other addresses"; } } viewModel.Metadata.Title = "Rights of way definitive map modification application: " + viewModel.Reference; viewModel.Metadata.Description = "A application to modify the definitive map of rights of way over land " + where; // Add common properties to the model var expiryDate = new ExpiryDateFromExamine(model.Content.Id, ExamineManager.Instance.SearchProviderCollection["ExternalSearcher"], new ExpiryDateMemoryCache(TimeSpan.FromHours(1))); var modelBuilder = new BaseViewModelBuilder(new EastSussexGovUKTemplateRequest(Request, webChatSettingsService: new UmbracoWebChatSettingsService(model.Content, new UrlListReader()))); await modelBuilder.PopulateBaseViewModel(viewModel, model.Content, new ContentExperimentSettingsService(), expiryDate.ExpiryDate, UmbracoContext.Current.InPreviewMode); modelBuilder.PopulateBaseViewModelWithInheritedContent(viewModel, new UmbracoLatestService(model.Content), new UmbracoSocialMediaService(model.Content), null, null); new HttpCachingService().SetHttpCacheHeadersFromUmbracoContent(model.Content, UmbracoContext.Current.InPreviewMode, Response.Cache, new[] { expiryDate }); return(CurrentTemplate(viewModel)); }
public new async Task <ActionResult> Index(RenderModel model) { if (model == null) { throw new ArgumentNullException(nameof(model)); } var expiryDate = new ExpiryDateFromExamine(model.Content.Id, ExamineManager.Instance.SearchProviderCollection["ExternalSearcher"], new ExpiryDateMemoryCache(TimeSpan.FromHours(1))); var templateRequest = new EastSussexGovUKTemplateRequest(Request, webChatSettingsService: new UmbracoWebChatSettingsService(model.Content, new UrlListReader())); var viewModel = await MapUmbracoContentToViewModel(model.Content, expiryDate.ExpiryDate, templateRequest); var modelBuilder = new BaseViewModelBuilder(templateRequest); await modelBuilder.PopulateBaseViewModel(viewModel, model.Content, new ContentExperimentSettingsService(), expiryDate.ExpiryDate, UmbracoContext.Current.InPreviewMode, new SkinFromUmbraco()); if (!viewModel.Steps.Any()) { return(new HttpNotFoundResult()); } // This only has one view, for printing, so if not requested as such, redirect if (Request.Url != null && !Request.Url.AbsolutePath.EndsWith("/print", StringComparison.OrdinalIgnoreCase)) { var firstStep = viewModel.Steps.First(); if (firstStep != null && firstStep.Steps.Any()) { Response.Headers.Add("Location", new Uri(Request.Url, firstStep.Steps.First().Url).ToString()); return(new HttpStatusCodeResult(303)); } } new HttpCachingService().SetHttpCacheHeadersFromUmbracoContent(model.Content, UmbracoContext.Current.InPreviewMode, Response.Cache, new IExpiryDateSource[] { expiryDate, new ExpiryDateFromPropertyValue(model.Content, "latestUnpublishDate_Latest") }); return(CurrentTemplate(viewModel)); }
/// <summary> /// The default action to render the front-end view /// </summary> /// <param name="model"/> /// <returns/> public new async Task <ActionResult> Index(RenderModel model) { if (model == null) { throw new ArgumentNullException(nameof(model)); } if (ExamineManager.Instance.SearchProviderCollection["RightsOfWayDepositsSearcher"] == null) { throw new ConfigurationErrorsException("The RightsOfWayDepositsSearcher is not configured in Examine config"); } var paging = new PagingController() { ResultsTextSingular = "deposit", ResultsTextPlural = "deposits", PageSize = 30 }; var query = HttpUtility.ParseQueryString(Request.Url.Query); var sort = RightsOfWayDepositsSortOrder.DateDepositedDescending; RightsOfWayDepositsSortOrder parsedSort; if (Enum.TryParse(query["sort"], true, out parsedSort)) { sort = parsedSort; } var viewModel = new RightsOfWayDepositsViewModelFromExamine(model.Content.Id, Request.Url, ExamineManager.Instance.SearchProviderCollection["RightsOfWayDepositsSearcher"], Request.QueryString["q"], new ISearchFilter[] { new SearchTermSanitiser() }, paging.CurrentPage, paging.PageSize, sort).BuildModel(); viewModel.Paging = paging; viewModel.Paging.TotalResults = viewModel.TotalDeposits; viewModel.SortOrder = sort; viewModel.LeadingText = new HtmlString(model.Content.GetPropertyValue <string>("leadingText_Content")); // Add common properties to the model var expiryDate = new ExpiryDateFromExamine(model.Content.Id, ExamineManager.Instance.SearchProviderCollection["ExternalSearcher"], new ExpiryDateMemoryCache(TimeSpan.FromHours(1))); var modelBuilder = new BaseViewModelBuilder(new EastSussexGovUKTemplateRequest(Request, webChatSettingsService: new UmbracoWebChatSettingsService(model.Content, new UrlListReader()))); await modelBuilder.PopulateBaseViewModel(viewModel, model.Content, new ContentExperimentSettingsService(), expiryDate.ExpiryDate, UmbracoContext.Current.InPreviewMode); modelBuilder.PopulateBaseViewModelWithInheritedContent(viewModel, new UmbracoLatestService(model.Content), new UmbracoSocialMediaService(model.Content), null, null); // Look for an RSS feed and CSV download var rss = model.Content.Children.Where <IPublishedContent>(child => child.DocumentTypeAlias == "RightsOfWayDepositsRss").FirstOrDefault(); if (rss != null) { viewModel.RssUrl = new Uri(rss.Url, UriKind.Relative); } var csv = model.Content.Children.Where <IPublishedContent>(child => child.DocumentTypeAlias == "RightsOfWayDepositsCsv").FirstOrDefault(); if (csv != null) { viewModel.CsvUrl = new Uri(csv.Url, UriKind.Relative); } new HttpCachingService().SetHttpCacheHeadersFromUmbracoContent(model.Content, UmbracoContext.Current.InPreviewMode, Response.Cache, new IExpiryDateSource[] { expiryDate, new ExpiryDateFromPropertyValue(model.Content, "latestUnpublishDate_Latest") }); return(CurrentTemplate(viewModel)); }
/// <summary> /// The default action to render the front-end view /// </summary> /// <param name="model"/> /// <returns/> public override ActionResult Index(RenderModel model) { if (model == null) { throw new ArgumentNullException(nameof(model)); } var viewModel = new AdvertViewModelFromUmbraco(model.Content).BuildModel(); // Add common properties to the model var modelBuilder = new BaseViewModelBuilder(); modelBuilder.PopulateBaseViewModel(viewModel, model.Content, new ContentExperimentSettingsService(), UmbracoContext.Current.InPreviewMode); modelBuilder.PopulateBaseViewModelWithInheritedContent(viewModel, new UmbracoLatestService(model.Content), new UmbracoSocialMediaService(model.Content), null, new UmbracoWebChatSettingsService(model.Content, new UrlListReader()), null); // Redirect non-preferred URL - these are sent out in job alerts, and linked from the TalentLink back office if (!String.IsNullOrEmpty(Request.QueryString["nPostingTargetID"])) { var jobsProvider = new JobsDataFromExamine(ExamineManager.Instance.SearchProviderCollection[viewModel.ExamineSearcher], null, new RelativeJobUrlGenerator(new Uri(model.Content.UrlAbsolute()))); viewModel.Job = Task.Run(async() => await jobsProvider.ReadJob(Request.QueryString["nPostingTargetID"])).Result; if (!String.IsNullOrEmpty(viewModel.Job.Id)) { return(new RedirectResult(viewModel.Job.Url.ToString(), true)); } } // Show page for preferred URL var jobUrlSegment = Regex.Match(Request.Url.AbsolutePath, "/([0-9]+)/"); if (jobUrlSegment.Success) { var jobsProvider = new JobsDataFromExamine(ExamineManager.Instance.SearchProviderCollection[viewModel.ExamineSearcher], new QueryBuilder(new LuceneTokenisedQueryBuilder(), new KeywordsTokeniser(), new LuceneStopWordsRemover(), new WildcardSuffixFilter()), new RelativeJobUrlGenerator(new Uri(model.Content.UrlAbsolute()))); viewModel.Job = Task.Run(async() => await jobsProvider.ReadJob(jobUrlSegment.Groups[1].Value)).Result; if (String.IsNullOrEmpty(viewModel.Job.Id) || viewModel.Job.ClosingDate < DateTime.Today) { // The job URL looks valid but the job isn't in the index, so it's probably closed. // Find some similar jobs to suggest the user may want to apply for instead. FindSimilarJobs(jobsProvider, viewModel); } } else { // The page was accessed by its default Umbraco URL with no parameters. Returning HttpNotFoundResult() ends up with a generic browser 404, // so to get our custom one we need to look it up and transfer control to it. var notFoundUrl = new HttpStatusFromConfiguration().GetCustomUrlForStatusCode(404); if (notFoundUrl != null && Server != null) { Server.TransferRequest(notFoundUrl + "?404;" + HttpUtility.UrlEncode(Request.Url.ToString())); } } // The page should expire when the job closes var expirySeconds = 86400; // one day if (viewModel.Job != null && viewModel.Job.ClosingDate != null) { var secondsToClosingDate = (int)(viewModel.Job.ClosingDate.Value.AddDays(1).Date.ToUkDateTime() - DateTime.Now.ToUkDateTime()).TotalSeconds; if (secondsToClosingDate >= 0) { expirySeconds = secondsToClosingDate; } } new HttpCachingService().SetHttpCacheHeadersFromUmbracoContent(model.Content, UmbracoContext.Current.InPreviewMode, Response.Cache, new List <string>() { "latestUnpublishDate_Latest" }, expirySeconds); return(CurrentTemplate(viewModel)); }
/// <summary> /// The default action to render the front-end view /// </summary> /// <param name="model"/> /// <returns/> public async new Task <ActionResult> Index(RenderModel model) { if (model == null) { throw new ArgumentNullException(nameof(model)); } var viewModel = new JobSearchResultsViewModelFromUmbraco(model.Content).BuildModel(); // Add common properties to the model var expiryDate = new ExpiryDateFromExamine(model.Content.Id, ExamineManager.Instance.SearchProviderCollection["ExternalSearcher"], new ExpiryDateMemoryCache(TimeSpan.FromHours(1))); var modelBuilder = new BaseViewModelBuilder(new EastSussexGovUKTemplateRequest(Request, webChatSettingsService: new UmbracoWebChatSettingsService(model.Content, new UrlListReader()))); await modelBuilder.PopulateBaseViewModel(viewModel, model.Content, new ContentExperimentSettingsService(), expiryDate.ExpiryDate, UmbracoContext.Current.InPreviewMode); modelBuilder.PopulateBaseViewModelWithInheritedContent(viewModel, new UmbracoLatestService(model.Content), new UmbracoSocialMediaService(model.Content), null, null, null); if (String.IsNullOrEmpty(Request.QueryString["altTemplate"])) { viewModel.Query = new JobSearchQueryConverter(ConfigurationManager.AppSettings["TranslateObsoleteJobTypes"]?.ToUpperInvariant() == "TRUE").ToQuery(Request.QueryString); viewModel.Query.ClosingDateFrom = DateTime.Today; viewModel.Query.JobsSet = viewModel.JobsSet; if (Request.QueryString["page"]?.ToUpperInvariant() != "ALL") { viewModel.Query.PageSize = viewModel.Paging.PageSize; viewModel.Query.CurrentPage = viewModel.Paging.CurrentPage; } viewModel.Metadata.Title = viewModel.Query.ToString(); var jobsProvider = new JobsDataFromApi( new Uri(ConfigurationManager.AppSettings["JobsApiBaseUrl"]), viewModel.JobsSet, viewModel.JobAdvertPage?.Url, new HttpClientProvider(), new MemoryJobCacheStrategy(MemoryCache.Default, Request.QueryString["ForceCacheRefresh"] == "1") ); var jobs = await jobsProvider.ReadJobs(viewModel.Query); viewModel.Jobs = jobs.Jobs; viewModel.Paging.TotalResults = jobs.TotalJobs; if (Request.QueryString["page"]?.ToUpperInvariant() == "ALL") { viewModel.Paging.PageSize = viewModel.Paging.TotalResults; } if (!String.IsNullOrEmpty(viewModel.Metadata.RssFeedUrl)) { var queryString = HttpUtility.ParseQueryString(Request.Url.Query); queryString.Remove("page"); if (queryString.HasKeys()) { viewModel.Metadata.RssFeedUrl = viewModel.Metadata.RssFeedUrl + "?" + queryString; } } } // Jobs close at midnight, so don't cache beyond then var untilMidnightTonight = DateTime.Today.ToUkDateTime().AddDays(1) - DateTime.Now.ToUkDateTime(); new HttpCachingService().SetHttpCacheHeadersFromUmbracoContent(model.Content, UmbracoContext.Current.InPreviewMode, Response.Cache, new IExpiryDateSource[] { expiryDate, new ExpiryDateFromPropertyValue(model.Content, "latestUnpublishDate_Latest") }, (int)untilMidnightTonight.TotalSeconds); return(CurrentTemplate(viewModel)); }
/// <summary> /// The default action to render the front-end view /// </summary> /// <param name="model"/> /// <returns/> public override ActionResult Index(RenderModel model) { if (model == null) { throw new ArgumentNullException(nameof(model)); } var viewModel = new SearchResultsViewModelFromUmbraco(model.Content).BuildModel(); // Add common properties to the model var modelBuilder = new BaseViewModelBuilder(); modelBuilder.PopulateBaseViewModel(viewModel, model.Content, new ContentExperimentSettingsService(), UmbracoContext.Current.InPreviewMode); modelBuilder.PopulateBaseViewModelWithInheritedContent(viewModel, new UmbracoLatestService(model.Content), new UmbracoSocialMediaService(model.Content), null, new UmbracoWebChatSettingsService(model.Content, new UrlListReader()), null); if (String.IsNullOrEmpty(Request.QueryString["altTemplate"])) { viewModel.Query = new JobSearchQueryFactory().CreateFromQueryString(Request.QueryString); viewModel.Query.ClosingDateFrom = DateTime.Today; var jobsProvider = new JobsDataFromExamine(ExamineManager.Instance.SearchProviderCollection[viewModel.ExamineSearcher], new QueryBuilder(new LuceneTokenisedQueryBuilder(), new KeywordsTokeniser(), new LuceneStopWordsRemover(), new WildcardSuffixFilter()), viewModel.JobAdvertPage != null ? new RelativeJobUrlGenerator(viewModel.JobAdvertPage.Url) : null); var jobs = Task.Run(async() => await jobsProvider.ReadJobs(viewModel.Query)).Result; if (String.IsNullOrWhiteSpace(Request.QueryString["page"])) { viewModel.Jobs = jobs.ToPagedList(1, 10); } else if (Request.QueryString["page"].ToUpperInvariant() == "ALL") { viewModel.Jobs = jobs.ToPagedList(1, 10000); } else { int page; Int32.TryParse(Request.QueryString["page"], out page); if (page < 1) { page = 1; } viewModel.Jobs = jobs.ToPagedList(page, 10); } if (!String.IsNullOrEmpty(viewModel.Metadata.RssFeedUrl)) { var queryString = HttpUtility.ParseQueryString(Request.Url.Query); queryString.Remove("page"); if (queryString.HasKeys()) { viewModel.Metadata.RssFeedUrl = viewModel.Metadata.RssFeedUrl + "?" + queryString; } } var lookupsProvider = new JobsLookupValuesFromExamine(ExamineManager.Instance.SearchProviderCollection[viewModel.ExamineLookupValuesSearcher]); viewModel.JobTypeLookupValues = Task.Run(async() => await lookupsProvider.ReadJobTypes()).Result; viewModel.OrganisationLookupValues = Task.Run(async() => await lookupsProvider.ReadOrganisations()).Result; viewModel.SalaryRangeLookupValues = Task.Run(async() => await lookupsProvider.ReadSalaryRanges()).Result; viewModel.WorkPatternLookupValues = Task.Run(async() => await lookupsProvider.ReadWorkPatterns()).Result; viewModel.LocationLookupValues = Task.Run(async() => await lookupsProvider.ReadLocations()).Result; } // Jobs close at midnight, so don't cache beyond then var untilMidnightTonight = DateTime.Today.ToUkDateTime().AddDays(1) - DateTime.Now.ToUkDateTime(); new HttpCachingService().SetHttpCacheHeadersFromUmbracoContent(model.Content, UmbracoContext.Current.InPreviewMode, Response.Cache, new List <string>() { "latestUnpublishDate_Latest" }, (int)untilMidnightTonight.TotalSeconds); return(CurrentTemplate(viewModel)); }