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));
        }
Beispiel #2
0
        /// <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));
        }
Beispiel #3
0
        /// <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));
        }