public async Task <HttpResponse> GetStartPage(string startPageSlug) { var builder = new QueryBuilder <ContentfulStartPage>() .ContentTypeIs("startPage") .FieldEquals("fields.slug", startPageSlug) .Include(3); var entries = await _client.GetEntries(builder); if (!entries.Any()) { return(HttpResponse.Failure(HttpStatusCode.NotFound, $"No start page found for '{startPageSlug}'")); } var startPageEntry = entries.FirstOrDefault(); var startPage = _contentfulFactory.ToModel(startPageEntry); if (!_dateComparer.DateNowIsWithinSunriseAndSunsetDates(startPage.SunriseDate, startPage.SunsetDate)) { startPage = new NullStartPage(); } return(startPage.GetType() == typeof(NullStartPage) ? HttpResponse.Failure(HttpStatusCode.NotFound, $"No start page found for '{startPageSlug}'") : HttpResponse.Successful(startPage)); }
public async Task <PrivacyNotice> GetPrivacyNotice(string slug) { var builder = new QueryBuilder <ContentfulPrivacyNotice>().ContentTypeIs("privacyNotice").FieldEquals("fields.slug", slug).Include(3); var entries = await _client.GetEntries(builder); var entry = entries.FirstOrDefault(); return(entry is not null?_contentfulFactory.ToModel(entry) : null); }
public async Task <HttpResponse> GetEventHomepage() { var builder = new QueryBuilder <ContentfulEventHomepage>().ContentTypeIs("eventHomepage").Include(1); var entries = await _client.GetEntries(builder); var entry = entries.ToList().First(); return(entry == null ? HttpResponse.Failure(HttpStatusCode.NotFound, "No event homepage found") : HttpResponse.Successful(await AddHomepageRowEvents(_contentfulEventHomepageFactory.ToModel(entry)))); }
public async Task <HttpResponse> GetProfile(string slug) { var builder = new QueryBuilder <ContentfulProfile>().ContentTypeIs("profile").FieldEquals("fields.slug", slug).Include(1); var entries = await _client.GetEntries(builder); var entry = entries.FirstOrDefault(); return(entry == null ? HttpResponse.Failure(HttpStatusCode.NotFound, $"No profile found for '{slug}'") : HttpResponse.Successful(_profileFactory.ToModel(entry))); }
public async Task <HttpResponse> Get() { var builder = new QueryBuilder <ContentfulShowcase>().ContentTypeIs("showcase").Include(3); var entries = await _client.GetEntries(builder); var showcases = entries.Select(e => _contentfulFactory.ToModel(e)); return(showcases.GetType() == typeof(NullHomepage) ? HttpResponse.Failure(HttpStatusCode.NotFound, "No Showcases found") : HttpResponse.Successful(showcases)); }
private async Task <ContentfulNewsRoom> GetNewsRoom() { var builder = new QueryBuilder <ContentfulNewsRoom>().ContentTypeIs("newsroom").Include(1); var entries = await _client.GetEntries(builder); return(entries.FirstOrDefault()); }
public async Task <HttpResponse> GetTopicByTopicSlug(string slug) { var builder = new QueryBuilder <ContentfulTopic>().ContentTypeIs("topic").FieldEquals("fields.slug", slug).Include(2); var entries = await _client.GetEntries(builder); var entry = entries.FirstOrDefault(); if (entry == null) { return(HttpResponse.Failure(HttpStatusCode.NotFound, $"No topic found for '{slug}'")); } var model = _topicFactory.ToModel(entry); return(HttpResponse.Successful(model)); }
public async Task <HttpResponse> Get() { var builder = new QueryBuilder <ContentfulHomepage>().ContentTypeIs("homepage").Include(2); var entries = await _client.GetEntries(builder); var entry = entries.FirstOrDefault(); return(entry == null ? HttpResponse.Failure(HttpStatusCode.NotFound, "No homepage found") : HttpResponse.Successful(_homepageFactory.ToModel(entry))); }
private async Task <BusinessIdToRedirects> GetRedirectForBusinessId(string businessId) { var config = _createConfig(businessId); _client = ClientManager.GetClient(config); var builder = new QueryBuilder <ContentfulRedirect>().ContentTypeIs(ContentType).Include(1); var entries = await _client.GetEntries(builder); return(!entries.Any() ? new NullBusinessIdToRedirects() : _contenfulFactory.ToModel(entries.FirstOrDefault())); }
public async Task <HttpResponse> Get() { var sections = new List <ContentfulSectionForSiteMap>(); var builder = new QueryBuilder <ContentfulArticleForSiteMap>().ContentTypeIs("article").Include(2).Limit(ContentfulQueryValues.LIMIT_MAX); var articles = await _client.GetEntries(builder); foreach (var article in articles.Where(e => e.Sections.Any())) { foreach (var section in article.Sections) { sections.Add(new ContentfulSectionForSiteMap { Slug = $"{article.Slug}/{section.Slug}", SunriseDate = section.SunriseDate, SunsetDate = section.SunsetDate }); } } return(sections.GetType() == typeof(NullHomepage) ? HttpResponse.Failure(HttpStatusCode.NotFound, "No Sections found") : HttpResponse.Successful(sections)); }
private async Task <ContentfulArticle> GetArticleEntry(string articleSlug) { var builder = new QueryBuilder <ContentfulArticle>() .ContentTypeIs("article") .FieldEquals("fields.slug", articleSlug) .Include(3); var entries = await _client.GetEntries(builder); var entry = entries.FirstOrDefault(); return(entry); }
public async Task <ContentfulGroup> GetContentfulGroup(string slug) { var builder = new QueryBuilder <ContentfulGroup>().ContentTypeIs("group").FieldEquals("fields.slug", slug).Include(1); var entries = await _client.GetEntries(builder); var entry = entries.FirstOrDefault(); return(entry); }
private async Task <List <EventCategory> > GetCategoriesDirect() { var builder = new QueryBuilder <ContentfulEventCategory>().ContentTypeIs("eventCategory"); var entries = await _client.GetEntries(builder); if (entries == null || !entries.Any()) { new List <EventCategory>(); } var eventCategories = entries.Select(eventCatogory => _contentfulFactory.ToModel(eventCatogory)).ToList(); return(!eventCategories.Any() ? null : eventCategories); }
public async Task <HttpResponse> GetGroupCategories() { var builder = new QueryBuilder <ContentfulGroupCategory>().ContentTypeIs("groupCategory"); var entries = await _client.GetEntries(builder); if (entries == null || !entries.Any()) { return(HttpResponse.Failure(HttpStatusCode.NotFound, "No group catogories found")); } var groupCategories = entries.Select(groupCatogory => _contentfulFactory.ToModel(groupCatogory)).ToList(); groupCategories = groupCategories.OrderBy(c => c.Name).ToList(); return(HttpResponse.Successful(groupCategories)); }
public async Task <HttpResponse> GetFooter() { var builder = new QueryBuilder <ContentfulFooter>().ContentTypeIs("footer").Include(1); var entries = await _client.GetEntries(builder); var entry = entries.FirstOrDefault(); var footer = _contentfulFactory.ToModel(entry); if (footer == null) { return(HttpResponse.Failure(HttpStatusCode.NotFound, "No footer found")); } return(HttpResponse.Successful(footer)); }
public async Task <HttpResponse> GetContactUsIds(string slug) { var builder = new QueryBuilder <ContentfulContactUsId>().ContentTypeIs("contactUsId").FieldEquals("fields.slug", slug).Include(1); var entries = await _client.GetEntries(builder); var entry = entries.FirstOrDefault(); if (entry == null) { return(HttpResponse.Failure(HttpStatusCode.NotFound, $"No contact us id found for '{slug}'")); } var contactUsId = _contentfulFactory.ToModel(entry); return(HttpResponse.Successful(contactUsId)); }
public async Task <HttpResponse> GetContactUsArea() { var builder = new QueryBuilder <ContentfulContactUsArea>().ContentTypeIs("contactUsArea").Include(3); var entries = await _client.GetEntries(builder); var entry = entries.FirstOrDefault(); var contactUsArea = _contentfulFactory.ToModel(entry); if (contactUsArea == null) { return(HttpResponse.Failure(HttpStatusCode.NotFound, "No contact us area found")); } return(HttpResponse.Successful(contactUsArea)); }
public async Task <HttpResponse> GetOrganisation(string slug) { var builder = new QueryBuilder <ContentfulOrganisation>().ContentTypeIs("organisation").FieldEquals("fields.slug", slug); var entries = await _client.GetEntries(builder); var entry = entries.FirstOrDefault(); if (entry == null) { return(HttpResponse.Failure(HttpStatusCode.NotFound, "No Organisation found")); } var organisation = _contentfulFactory.ToModel(entry); organisation.Groups = await _groupRepository.GetLinkedGroupsByOrganisation(slug); return(HttpResponse.Successful(organisation)); }
public async Task <ContentfulCollection <T> > GetAllEntriesAsync <T>(Contentful.Core.IContentfulClient _client, QueryBuilder <T> builder, ILogger logger = null) { var result = new ContentfulCollection <T>(); result.Items = new List <T>(); if (!BuilderHasProperty(builder, "limit")) { builder.Limit(ContentfulQueryValues.LIMIT_MAX); } builder.Skip(999); var builderString = builder.Build(); builderString = builderString.Replace("skip=999", "skip=xxx"); var totalItems = 0; var skip = 0; do { builderString = builderString.Replace("skip=xxx", $"skip={skip}"); var items = new ContentfulCollection <T>(); try { items = await _client.GetEntries <T>(builderString); } catch (Exception ex) { logger?.LogError(ex, $"Could not get Entries: {ex.Message}"); throw; } builderString = builderString.Replace($"skip={skip}", "skip=xxx"); totalItems = items.Total; result.Items = result.Items.Concat(items.Items); skip += ContentfulQueryValues.LIMIT_MAX; } while (result.Items.Count() < totalItems); return(result); }