// GET: Default
        public async Task <ActionResult> Index(string postcode)
        {
            // Ensure there's one version of this URL so that the data is consistent in Google Analytics
            if (Path.GetFileName(Request.RawUrl).ToUpperInvariant() == "DEFAULT.ASPX")
            {
                return(new RedirectResult(Url.Content("~/"), true));
            }

            var model           = new LibrariesViewModel();
            var templateRequest = new EastSussexGovUKTemplateRequest(Request);

            try
            {
                model.WebChat = await templateRequest.RequestWebChatSettingsAsync();
            }
            catch (Exception ex)
            {
                // Catch and report exceptions - don't throw them and cause the page to fail
                ex.ToExceptionless().Submit();
            }
            try
            {
                model.TemplateHtml = await templateRequest.RequestTemplateHtmlAsync();
            }
            catch (Exception ex)
            {
                // Catch and report exceptions - don't throw them and cause the page to fail
                ex.ToExceptionless().Submit();
            }

            return(View(model));
        }
        /// <summary>
        /// Displays the list of closures as HTML
        /// </summary>
        /// <param name="date">The date.</param>
        /// <returns></returns>
        public async Task <ActionResult> Index(string date)
        {
            var model = new SchoolClosuresViewModel()
            {
                ShowPlannedClosures = false, ShowEmergencyClosures = true
            };

            // This page displays closures for a specific day. By default, that's today, but can be set to a different day.
            model.TargetDay = TargetDayForClosures(date, DateTime.Now.ToUkDateTime());

            model.Metadata.Title = BuildPageTitle(model);

            // If the date is in the past, the closures won't be listed any more so we want to return a
            // response that'll tell search engines not to list this page
            if (model.TargetDay < DateTime.Today)
            {
                new HttpStatus().Gone();
            }

            IServiceClosureData closureData = await LoadClosureData();

            if (closureData != null && closureData.EmergencyClosureExists(model.TargetDay.Value))
            {
                // Get all schools from the XML and add them to the list.
                // List has the TargetDate set which filters the data
                var allServices = closureData.Services();
                foreach (var service in allServices)
                {
                    service.Url = PrepareAbsoluteUrl(SchoolUrl.FormatSchoolUrl(service.Code).ToString());
                    model.Services.Add(service);
                }
            }

            // Support the website template
            var templateRequest = new EastSussexGovUKTemplateRequest(Request);

            try
            {
                model.WebChat = await templateRequest.RequestWebChatSettingsAsync();
            }
            catch (Exception ex)
            {
                // Failure to get webchat settings should be reported, but should not cause the page to fail
                ex.ToExceptionless().Submit();
            }
            try
            {
                model.TemplateHtml = await templateRequest.RequestTemplateHtmlAsync();
            }
            catch (Exception ex)
            {
                // Failure to get the template should be reported, but should not cause the page to fail
                ex.ToExceptionless().Submit();
            }

            return(View(model));
        }
        // GET: Default
        public async Task <ActionResult> Index(string pc)
        {
            var model = new LibrariesViewModel();

            model.Postcode = pc;

            if (!String.IsNullOrEmpty(model.Postcode))
            {
                try
                {
                    await GetAndBindData(model, HttpContext.Cache);
                }
                catch (SoapException ex)
                {
                    if (!ex.Message.Contains("The postcode entered appears to be incorrect.") &&
                        !ex.Message.Contains("The postcode entered could not be found."))
                    {
                        ex.ToExceptionless().Submit();
                    }

                    var helper = new SoapExceptionWrapper(ex);
                    model.PostcodeLookupError = String.Format(CultureInfo.InvariantCulture, Properties.Resources.ErrorFromWebService, helper.Message, helper.Description);
                }
            }

            var templateRequest = new EastSussexGovUKTemplateRequest(Request);

            try
            {
                // Do this if you want your page to support web chat. It should, unless you have a reason not to.
                model.WebChat = await templateRequest.RequestWebChatSettingsAsync();
            }
            catch (Exception ex)
            {
                // Catch and report exceptions - don't throw them and cause the page to fail
                ex.ToExceptionless().Submit();
            }
            try
            {
                // Do this to load the template controls.
                model.TemplateHtml = await templateRequest.RequestTemplateHtmlAsync();
            }
            catch (Exception ex)
            {
                // Catch and report exceptions - don't throw them and cause the page to fail
                ex.ToExceptionless().Submit();
            }

            return(View(model));
        }
        // GET: Sets a cookie based on a querystring parameter, which has the effect of changing the sitewide text size
        public async Task <ActionResult> Change()
        {
            var model = new TextSizeViewModel
            {
                Metadata =
                {
                    Title      = "Text size changed",
                    IsInSearch = false,
                    DateIssued = new DateTimeOffset(new DateTime(2010, 4, 19))
                }
            };

            if (Request.QueryString["textsize"] != null && Request.QueryString["textsize"].Length == 1)
            {
                HttpCookie textSize = new HttpCookie("textsize", Request.QueryString["textsize"]);
                textSize.Expires = DateTime.Now.AddMonths(1);
                if (Request.Url.Host.IndexOf("eastsussex.gov.uk", StringComparison.Ordinal) > -1)
                {
                    textSize.Domain = ".eastsussex.gov.uk";
                }
                Response.Cookies.Add(textSize);
            }

            // Add a cache-busting parameter so that the user isn't returned to an HTTP-cached version of the page which has the old text size
            if (Request.UrlReferrer != null && Request.UrlReferrer.AbsolutePath != Request.Url.AbsolutePath)
            {
                var referrerQuery = HttpUtility.ParseQueryString(Request.UrlReferrer.Query);
                referrerQuery.Remove("nocache");
                referrerQuery.Add("nocache", Guid.NewGuid().ToString());
                var redirectTo = new Uri(Request.UrlReferrer.Scheme + "://" + Request.UrlReferrer.Authority + Request.UrlReferrer.AbsolutePath + "?" + referrerQuery);
                new HttpStatus().SeeOther(redirectTo);
            }

            var templateRequest = new EastSussexGovUKTemplateRequest(Request);

            try
            {
                // Do this to load the template controls.
                model.TemplateHtml = await templateRequest.RequestTemplateHtmlAsync().ConfigureAwait(false);
            }
            catch (Exception ex)
            {
                // Catch and report exceptions - don't throw them and cause the page to fail
                ex.ToExceptionless().Submit();
            }

            return(View(model));
        }
Пример #5
0
        public async Task EastSussexGovUKTemplateRequest_calls_IWebChatSettingsService()
        {
            var httpContextAccessor = new Mock <IHttpContextAccessor>();

            httpContextAccessor.Setup(x => x.HttpContext).Returns(CreateHttpContext());
            var webChat = new Mock <IWebChatSettingsService>();

            webChat.Setup(x => x.ReadWebChatSettings()).Returns(Task.FromResult(new WebChatSettings()));
            var templateRequest = new EastSussexGovUKTemplateRequest(
                httpContextAccessor.Object,
                new Mock <IViewSelector>().Object,
                new Mock <IHtmlControlProvider>().Object,
                new Mock <IBreadcrumbProvider>().Object,
                new Mock <ILibraryCatalogueContext>().Object,
                new Mock <ITextSize>().Object,
                webChat.Object
                );

            await templateRequest.RequestWebChatSettingsAsync();

            webChat.Verify(x => x.ReadWebChatSettings());
        }
Пример #6
0
        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));
        }
Пример #7
0
        public async Task EastSussexGovUKTemplateRequest_requests_control(string controlId, EsccWebsiteView view)
        {
            var httpContextAccessor = new Mock <IHttpContextAccessor>();

            httpContextAccessor.Setup(x => x.HttpContext).Returns(CreateHttpContext());
            var viewSelector = new Mock <IViewSelector>();

            viewSelector.Setup(x => x.CurrentViewIs(It.IsAny <string>())).Returns(view);
            var htmlProvider       = new Mock <IHtmlControlProvider>();
            var breadcrumbProvider = new Mock <IBreadcrumbProvider>();
            var templateRequest    = new EastSussexGovUKTemplateRequest(
                httpContextAccessor.Object,
                viewSelector.Object,
                htmlProvider.Object,
                breadcrumbProvider.Object,
                null,
                null,
                null
                );

            await templateRequest.RequestTemplateHtmlAsync();

            htmlProvider.Verify(x => x.FetchHtmlForControl(It.IsAny <string>(), It.IsAny <Uri>(), controlId, breadcrumbProvider.Object, It.IsAny <int>(), It.IsAny <bool>()));
        }
Пример #8
0
        // GET: Search
        public async Task <ActionResult> Index()
        {
            var redirect = RedirectOldUrls();

            if (redirect != null)
            {
                return(redirect);
            }

            var model = new SearchResultsViewModel();

            model.SearchTerm = Request.QueryString["q"];
            model.SearchTermWithinResults = Request.QueryString["refine"];
            model.Metadata.Title          = "Search results";
            model.Metadata.DateCreated    = new DateTimeOffset(new DateTime(2012, 3, 16));
            model.Metadata.IsInSearch     = false;

            // If there's a search query
            if (!String.IsNullOrEmpty(model.SearchTerm))
            {
                // Redisplay search term
                if (!String.IsNullOrEmpty(model.SearchTermWithinResults))
                {
                    model.Metadata.Title = "Search results for '" + HttpUtility.HtmlEncode(model.SearchTermWithinResults) + "' within '" + HttpUtility.HtmlEncode(model.SearchTerm) + "'";
                }
                else
                {
                    model.Metadata.Title = "Search results for '" + HttpUtility.HtmlEncode(model.SearchTerm) + "'";
                }

                // Search Google with standard options
                var service    = new GoogleCustomSearch(ConfigurationManager.AppSettings["GoogleSearchApiKey"], ConfigurationManager.AppSettings["GoogleSearchEngineId"], new ConfigurationProxyProvider());
                var cacheHours = new TimeSpan(Int32.Parse(ConfigurationManager.AppSettings["CacheHours"], CultureInfo.CurrentCulture), 0, 0);
                service.CacheStrategy = new FileCacheStrategy(Server.MapPath(ConfigurationManager.AppSettings["CacheFilePath"]), cacheHours);
                var query = new GoogleQuery(model.SearchTerm);
                if (!String.IsNullOrEmpty(model.SearchTermWithinResults))
                {
                    query.QueryWithinResultsTerms = model.SearchTermWithinResults;
                }
                query.PageSize = model.Paging.PageSize;
                query.Page     = model.Paging.CurrentPage;

                if ((model.Paging.PageSize * model.Paging.CurrentPage) <= model.Paging.MaximumResultsAvailable)
                {
                    var response = await service.SearchAsync(query);

                    model.Paging.TotalResults = response.TotalResults;
                    model.Results             = response.Results();
                    model.SpellingSuggestions = response.SpellingSuggestions();
                    model.ResultsAvailable    = true;
                }
                else
                {
                    model.ResultsAvailable = false;
                }
            }
            else
            {
                model.ResultsAvailable = true;
            }
            new HttpCacheHeaders().CacheUntil(Response.Cache, DateTime.Now.AddDays(1));

            var templateRequest = new EastSussexGovUKTemplateRequest(Request);

            try
            {
                model.WebChat = await templateRequest.RequestWebChatSettingsAsync();
            }
            catch (Exception ex)
            {
                // Catch and report exceptions - don't throw them and cause the page to fail
                ex.ToExceptionless().Submit();
            }
            try
            {
                model.TemplateHtml = await templateRequest.RequestTemplateHtmlAsync();
            }
            catch (Exception ex)
            {
                // Catch and report exceptions - don't throw them and cause the page to fail
                ex.ToExceptionless().Submit();
            }

            return(View(model));
        }