Exemple #1
0
        public GroupHomepage ToModel(ContentfulGroupHomepage entry)
        {
            var backgroundImage = ContentfulHelpers.EntryIsNotALink(entry.BackgroundImage.SystemProperties)
                                           ? entry.BackgroundImage.File.Url : string.Empty;


            var groups = entry.FeaturedGroups.Select(g => _groupFactory.ToModel(g));

            var groupCategory = _groupCategoryListFactory.ToModel(entry.FeaturedGroupsCategory);

            var groupSubCategory = _groupSubCategoryListFactory.ToModel(entry.FeaturedGroupsSubCategory);

            var featuredGroup = groups.Where(group => _dateComparer.DateNowIsNotBetweenHiddenRange(
                                                 group.DateHiddenFrom, group.DateHiddenTo)).ToList();

            var alerts = entry.Alerts.Select(_ => _alertFactory.ToModel(_));

            var bodyHeading = entry.BodyHeading;

            var body = entry.Body;

            var secondaryBodyHeading = entry.SecondaryBodyHeading;

            var secondaryBody = entry.SecondaryBody;

            var eventBanner = ContentfulHelpers.EntryIsNotALink(entry.EventBanner.Sys)
                ? _eventBannerFactory.ToModel(entry.EventBanner) : new NullEventBanner();

            return(new GroupHomepage(entry.Title, entry.Slug, entry.MetaDescription, backgroundImage, entry.FeaturedGroupsHeading, featuredGroup, groupCategory, groupSubCategory, alerts, bodyHeading, body, secondaryBodyHeading, secondaryBody, eventBanner));
        }
Exemple #2
0
        public async Task <HttpResponse> Get()
        {
            var builder = new QueryBuilder <ContentfulGroup>().ContentTypeIs("group").Include(1);
            var entries = await GetAllEntriesAsync(_client, builder);

            var contentfulGroups = entries as IEnumerable <ContentfulGroup> ?? entries.ToList();

            contentfulGroups =
                contentfulGroups.Where(
                    group => _dateComparer.DateNowIsNotBetweenHiddenRange(group.DateHiddenFrom, group.DateHiddenTo));

            var groupList = contentfulGroups.Select(g => _groupFactory.ToModel(g));

            return(entries == null || !groupList.Any()
                ? HttpResponse.Failure(HttpStatusCode.NotFound, "No Groups found")
                : HttpResponse.Successful(groupList.ToList()));
        }
        public Group ToModel(ContentfulGroup entry)
        {
            var imageUrl = entry.Image != null
                ? ContentfulHelpers.EntryIsNotALink(entry.Image.SystemProperties)
                    ? entry.Image.File.Url
                    : string.Empty
                : string.Empty;

            var categoriesReferences = entry.CategoriesReference != null
                ? entry.CategoriesReference.Where(o => o != null).Select(catogory => _contentfulGroupCategoryFactory.ToModel(catogory)).ToList()
                : new List <GroupCategory>();

            var subCategories = entry.SubCategories != null
                ? entry.SubCategories.Where(o => o != null).Select(category => _contentfulGroupSubCategoryFactory.ToModel(category)).ToList()
                : new List <GroupSubCategory>();

            var groupDocuments = entry.AdditionalDocuments.Where(document => ContentfulHelpers.EntryIsNotALink(document.SystemProperties)).Select(document => _documentFactory.ToModel(document)).ToList();

            var organisation = entry.Organisation != null?_contentfulOrganisationFactory.ToModel(entry.Organisation) : new Organisation();

            var status = "Published";

            if (!_dateComparer.DateNowIsNotBetweenHiddenRange(entry.DateHiddenFrom, entry.DateHiddenTo))
            {
                status = "Archived";
            }

            var administrators = entry.GroupAdministrators;

            var cost = entry.Cost != null && entry.Cost.Any() ? entry.Cost : new List <string>();

            var groupBranding = entry.GroupBranding != null?entry.GroupBranding.Where(o => o != null).Select(branding => _contentfulGroupBrandingFactory.ToModel(branding)).ToList() : new List <GroupBranding>();

            var alerts = entry.Alerts.Where(section => ContentfulHelpers.EntryIsNotALink(section.Sys) &&
                                            _dateComparer.DateNowIsWithinSunriseAndSunsetDates(section.SunriseDate, section.SunsetDate))
                         .Select(alert => _alertFactory.ToModel(alert));

            return(new Group(entry.Name, entry.Slug, entry.MetaDescription, entry.PhoneNumber, entry.Email, entry.Website,
                             entry.Twitter, entry.Facebook, entry.Address, entry.Description, imageUrl, ImageConverter.ConvertToThumbnail(imageUrl),
                             categoriesReferences, subCategories, new List <Crumb> {
                new Crumb("Stockport Local", string.Empty, "groups")
            }, entry.MapPosition, entry.Volunteering,
                             administrators, entry.DateHiddenFrom, entry.DateHiddenTo, status, cost, entry.CostText, entry.AbilityLevel, entry.VolunteeringText,
                             organisation, entry.Donations, entry.AccessibleTransportLink, groupBranding, entry.Tags, entry.AdditionalInformation, groupDocuments, entry.Sys.UpdatedAt, entry.SuitableFor, entry.AgeRange, entry.DonationsText, entry.DonationsUrl, alerts));
        }
Exemple #4
0
        public async Task <HttpResponse> GetEvent(string slug, DateTime?date)
        {
            var entries = await _cache.GetFromCacheOrDirectlyAsync("event-all", GetAllEvents, _eventsTimeout);

            var events = GetAllEventsAndTheirReccurrences(entries);

            var eventItem = events.Where(e => e.Slug == slug).FirstOrDefault();

            eventItem = GetEventFromItsOccurrences(date, eventItem);
            if (eventItem != null && !string.IsNullOrEmpty(eventItem.Group?.Slug) && !_dateComparer.DateNowIsNotBetweenHiddenRange(eventItem.Group.DateHiddenFrom, eventItem.Group.DateHiddenTo))
            {
                eventItem.Group = new Group(string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, new List <GroupCategory>(), new List <GroupSubCategory>(), new List <Crumb>(), new MapPosition(), false, null, null, null, "published", new List <string>()
                {
                    string.Empty
                }, string.Empty, string.Empty, string.Empty, null, false, string.Empty, new List <GroupBranding>(), new List <string>(), string.Empty, new List <Document>(), null, new List <string>(), new List <string>(), string.Empty, string.Empty, new List <Alert>());
            }

            return(eventItem == null
                ? HttpResponse.Failure(HttpStatusCode.NotFound, $"No event found for '{slug}'")
                : HttpResponse.Successful(eventItem));
        }
Exemple #5
0
        public Homepage ToModel(ContentfulHomepage entry)
        {
            var featuredTasksHeading = !string.IsNullOrEmpty(entry.FeaturedTasksHeading) ? entry.FeaturedTasksHeading : string.Empty;
            var featuredTasksSummary = !string.IsNullOrEmpty(entry.FeaturedTasksSummary) ? entry.FeaturedTasksSummary : string.Empty;
            var backgroundImage      = !string.IsNullOrEmpty(entry.BackgroundImage.File?.Url) ? entry.BackgroundImage.File.Url : string.Empty;
            var freeText             = !string.IsNullOrEmpty(entry.FreeText) ? entry.FreeText : string.Empty;

            var popularSearchTerms = ContentfulHelpers.ConvertToListOfStrings(entry.PopularSearchTerms);

            var featuredTasks =
                entry.FeaturedTasks.Where(subItem => ContentfulHelpers.EntryIsNotALink(subItem.Sys) &&
                                          _dateComparer.DateNowIsWithinSunriseAndSunsetDates(subItem.SunriseDate, subItem.SunsetDate))
                .Select(item => _subitemFactory.ToModel(item)).ToList();

            var featuredTopics =
                entry.FeaturedTopics.Where(subItem => ContentfulHelpers.EntryIsNotALink(subItem.Sys) &&
                                           _dateComparer.DateNowIsWithinSunriseAndSunsetDates(subItem.SunriseDate, subItem.SunsetDate))
                .Select(item => _subitemFactory.ToModel(item)).ToList();

            var alerts = entry.Alerts.Where(alert => ContentfulHelpers.EntryIsNotALink(alert.Sys) &&
                                            _dateComparer.DateNowIsWithinSunriseAndSunsetDates(alert.SunriseDate, alert.SunsetDate))
                         .Select(alert => _alertFactory.ToModel(alert)).ToList();

            var carouselContents =
                entry.CarouselContents.Where(subItem => ContentfulHelpers.EntryIsNotALink(subItem.Sys) &&
                                             _dateComparer.DateNowIsWithinSunriseAndSunsetDates(subItem.SunriseDate, subItem.SunsetDate))
                .Select(item => _carouselFactory.ToModel(item)).ToList();

            var campaignBanner = _carouselFactory.ToModel(entry.CampaignBanner);

            var featuredGroup = entry.FeaturedGroups.Where(group => ContentfulHelpers.EntryIsNotALink(group.Sys) &&
                                                           _dateComparer.DateNowIsNotBetweenHiddenRange(
                                                               group.DateHiddenFrom, group.DateHiddenTo))
                                .Select(group => _groupFactory.ToModel(group)).FirstOrDefault();

            return(new Homepage(popularSearchTerms, featuredTasksHeading, featuredTasksSummary, featuredTasks,
                                featuredTopics, alerts, carouselContents, backgroundImage, freeText, featuredGroup, entry.EventCategory, entry.MetaDescription, campaignBanner));
        }