Exemplo n.º 1
0
        private static void WorkOutOpenUntil(LocationViewModel model, DateTime ukNow, OpeningTimes opening)
        {
            var today = (ukNow.DayOfWeek.ToString().Substring(0, 2).ToUpperInvariant() == opening.Day.Substring(0, 2).ToUpperInvariant());

            var now   = ukNow.TimeOfDay;
            var open1 = (opening.OpensAtTime.HasValue && opening.ClosesAtTime.HasValue && now >= opening.OpensAtTime.Value.TimeOfDay && now <= opening.ClosesAtTime.Value.TimeOfDay);
            var open2 = (opening.OpensAgainAtTime.HasValue && opening.ClosesAgainAtTime.HasValue && now >= opening.OpensAgainAtTime.Value.TimeOfDay && now <= opening.ClosesAgainAtTime.Value.TimeOfDay);
            var open  = today && opening.Scheduled && (open1 || open2);


            if (open && open1)
            {
                model.OpenUntil = opening.ClosesAtTime;
            }
            if (open && open2)
            {
                model.OpenUntil = opening.ClosesAgainAtTime;
            }
        }
Exemplo n.º 2
0
        private static void WorkOutNextOpen(LocationViewModel model, OpeningTimes opening, DateTime ukNow)
        {
            if (opening.Scheduled && opening.OpensAtTime.HasValue && opening.OpensAtTime > ukNow && opening.OpensAtTime < model.NextOpen)
            {
                model.NextOpen = opening.OpensAtTime.Value;
            }
            if (opening.Scheduled && opening.OpensAgainAtTime.HasValue && opening.OpensAgainAtTime > ukNow && opening.OpensAgainAtTime < model.NextOpen)
            {
                model.NextOpen = opening.OpensAgainAtTime.Value;
            }

            // If it's open this day, and we've no better offer, it'll be open again this time next week
            if (opening.Scheduled && opening.OpensAtTime.HasValue)
            {
                var sameTimeNextWeek = opening.OpensAtTime.Value.AddDays(7);
                if (model.NextOpen > sameTimeNextWeek)
                {
                    model.NextOpen = sameTimeNextWeek;
                }
            }
        }
        protected override LocationViewModel UpdateLocationViewModel(IPublishedContent content, LocationViewModel model)
        {
            // Get the types of waste which have been selected for this recycling site
            var recycledTypes = content.GetPropertyValue <IEnumerable <string> >("wasteTypes_Content");

            if (recycledTypes != null)
            {
                ((List <string>)model.WasteTypesRecycled).AddRange(recycledTypes);
            }

            var acceptedTypes = content.GetPropertyValue <IEnumerable <string> >("acceptedWasteTypes_Content");

            if (acceptedTypes != null)
            {
                ((List <string>)model.WasteTypesAccepted).AddRange(acceptedTypes);
            }

            // Get the authority responsible for this site
            var preValueId = content.GetPropertyValue <int>("responsibleAuthority_Content");

            if (preValueId > 0)
            {
                model.ResponsibleAuthority = umbraco.library.GetPreValueAsString(preValueId);
            }

            return(model);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Maps the Umbraco content to the view model.
        /// </summary>
        /// <param name="content">The content.</param>
        /// <param name="expiryDate">The expiry date.</param>
        /// <param name="latestService">The latest service.</param>
        /// <param name="socialMediaService">The social media service.</param>
        /// <param name="eastSussex1SpaceService">The East Sussex One Space service.</param>
        /// <param name="webChatSettingsService">The web chat settings service.</param>
        /// <param name="relatedLinksService">The related links service.</param>
        /// <param name="contentExperimentSettingsService">The content experiment settings service.</param>
        /// <param name="escisService">The escis service.</param>
        /// <param name="ratingSettings">The rating settings.</param>
        /// <param name="mediaUrlTransformer">The media URL transformer.</param>
        /// <param name="skinService">The skin service.</param>
        /// <returns></returns>
        /// <exception cref="ArgumentNullException">content
        /// or
        /// latestService
        /// or
        /// socialMediaService
        /// or
        /// eastSussex1SpaceService
        /// or
        /// webChatSettingsService
        /// or
        /// relatedLinksService</exception>
        /// <exception cref="System.ArgumentNullException">content
        /// or
        /// latestService
        /// or
        /// socialMediaService
        /// or
        /// eastSussex1SpaceService
        /// or
        /// webChatSettingsService
        /// or
        /// relatedLinksService
        /// or
        /// contentExperimentSettingsService</exception>
        /// <remarks>
        /// Method is virtual so that document types which inherit from the 'Location' type can also inherit and extend the controller
        /// </remarks>
        protected virtual async Task <LocationViewModel> MapUmbracoContentToViewModel(IPublishedContent content, DateTime?expiryDate, latest.ILatestService latestService, ISocialMediaService socialMediaService, IEastSussex1SpaceService eastSussex1SpaceService, IWebChatSettingsService webChatSettingsService, IRelatedLinksService relatedLinksService, IContentExperimentSettingsService contentExperimentSettingsService, IEscisService escisService, IRatingSettingsProvider ratingSettings, IMediaUrlTransformer mediaUrlTransformer, ISkinToApplyService skinService)
        {
            if (content == null)
            {
                throw new ArgumentNullException("content");
            }
            if (latestService == null)
            {
                throw new ArgumentNullException("latestService");
            }
            if (socialMediaService == null)
            {
                throw new ArgumentNullException("socialMediaService");
            }
            if (eastSussex1SpaceService == null)
            {
                throw new ArgumentNullException("eastSussex1SpaceService");
            }
            if (webChatSettingsService == null)
            {
                throw new ArgumentNullException("webChatSettingsService");
            }
            if (relatedLinksService == null)
            {
                throw new ArgumentNullException("relatedLinksService");
            }
            if (contentExperimentSettingsService == null)
            {
                throw new ArgumentNullException("contentExperimentSettingsService");
            }
            if (ratingSettings == null)
            {
                throw new ArgumentNullException(nameof(ratingSettings));
            }
            if (skinService == null)
            {
                throw new ArgumentNullException(nameof(skinService));
            }

            var model = new LocationViewModel
            {
                Content             = new HtmlString(mediaUrlTransformer.ParseAndTransformMediaUrlsInHtml(content.GetPropertyValue <string>("content_Content"))),
                OpeningHoursDetails = new HtmlString(mediaUrlTransformer.ParseAndTransformMediaUrlsInHtml(content.GetPropertyValue <string>("openingHoursDetails_Content"))),
                Tab1Title           = content.GetPropertyValue <string>("tab1title_Content"),
                Tab1Content         = new HtmlString(mediaUrlTransformer.ParseAndTransformMediaUrlsInHtml(content.GetPropertyValue <string>("tab1content_Content"))),
                Tab2Title           = content.GetPropertyValue <string>("tab2title_Content"),
                Tab2Content         = new HtmlString(mediaUrlTransformer.ParseAndTransformMediaUrlsInHtml(content.GetPropertyValue <string>("tab2content_Content"))),
                Tab3Title           = content.GetPropertyValue <string>("tab3title_Content"),
                Tab3Content         = new HtmlString(mediaUrlTransformer.ParseAndTransformMediaUrlsInHtml(content.GetPropertyValue <string>("tab3content_Content"))),
                Location            = content.GetPropertyValue <AddressInfo>("location_Content"),
                Email1Label         = content.GetPropertyValue <string>("email1label_Content"),
                Email2Label         = content.GetPropertyValue <string>("email2label_Content"),
                Email1      = content.GetPropertyValue <string>("email1_Content"),
                Email2      = content.GetPropertyValue <string>("email2_Content"),
                Phone1Label = content.GetPropertyValue <string>("phone1label_Content"),
                Phone2Label = content.GetPropertyValue <string>("phone2label_Content"),
                Phone1      = content.GetPropertyValue <string>("phone1_Content"),
                Phone2      = content.GetPropertyValue <string>("phone2_Content"),
                Fax1Label   = content.GetPropertyValue <string>("fax1label_Content"),
                Fax2Label   = content.GetPropertyValue <string>("fax2label_Content"),
                Fax1        = content.GetPropertyValue <string>("fax1_Content"),
                Fax2        = content.GetPropertyValue <string>("fax2_Content")
            };

            var relatedLinksGroups = new RelatedLinksModelBuilder().OrganiseAsHeadingsAndSections(relatedLinksService.BuildRelatedLinksViewModelFromUmbracoContent(content, "relatedLinks_Content"));

            foreach (var linkGroup in relatedLinksGroups)
            {
                model.RelatedLinksGroups.Add(linkGroup);
            }

            // Opening times
            model.OpeningHours = DeserialiseOpeningHours(content);
            WorkOutRelativeOpeningTimes(model);
            WorkOutNextOpenRelativeTime(model);

            // Photo
            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, skinService);

            modelBuilder.PopulateBaseViewModelWithInheritedContent(model, latestService, socialMediaService, eastSussex1SpaceService, escisService, ratingSettings);

            return(model);
        }
 /// <summary>
 /// Provide a way for child classes to update the view model based on Umbraco content
 /// </summary>
 /// <param name="content"></param>
 /// <param name="viewModel"></param>
 /// <returns></returns>
 protected virtual LocationViewModel UpdateLocationViewModel(IPublishedContent content, LocationViewModel viewModel)
 {
     return(viewModel);
 }