Ejemplo n.º 1
0
        /// <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"/>
        /// <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));
        }
        /// <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));
        }