public async Task <List <AtoZ> > GetAtoZItemFromContentType(string contentType, string letter) { var atozList = new List <AtoZ>(); var builder = new QueryBuilder <ContentfulAtoZ>() .ContentTypeIs(contentType) .Include(0); var entries = await GetAllEntriesAsync(_client, builder, _logger); var entriesWithDisplayOn = entries != null?entries .Where(x => x.DisplayOnAZ == "True" && ((x.Title.ToLower().StartsWith(letter)) || (x.Name.ToLower().StartsWith(letter)) || (x.AlternativeTitles == null ? false : (x.AlternativeTitles.Any(alt => alt.ToLower().StartsWith(letter)))))) : null; if (entriesWithDisplayOn != null) { foreach (var item in entriesWithDisplayOn) { DateTime sunriseDate = DateComparer.DateFieldToDate(item.SunriseDate); DateTime sunsetDate = DateComparer.DateFieldToDate(item.SunsetDate); if (_dateComparer.DateNowIsWithinSunriseAndSunsetDates(sunriseDate, sunsetDate)) { AtoZ buildItem = _contentfulAtoZFactory.ToModel(item); var matchingItems = buildItem.SetTitleStartingWithLetter(letter); atozList.AddRange(matchingItems); } } } return(atozList); }
public void ShouldReturnADateTimeFromANormalDateTime() { var inputDate = new DateTime(2016, 01, 20); var date = DateComparer.DateFieldToDate(inputDate); date.Should().Be(inputDate); }
public void ShouldReturnADateTimeFromAOffsetDateTime() { var offsetDateTime = new DateTimeOffset(2016, 09, 21, 0, 0, 0, new TimeSpan(+1, 0, 0)); var date = DateComparer.DateFieldToDate(offsetDateTime); date.Should().Be(new DateTime(2016, 09, 20, 23, 0, 0)); }
public CarouselContent ToModel(ContentfulCarouselContent carousel) { var title = carousel.Title ?? string.Empty; var slug = carousel.Slug ?? string.Empty; var teaser = carousel.Teaser ?? string.Empty; var image = ContentfulHelpers.EntryIsNotALink(carousel.Image.SystemProperties) ? carousel.Image.File.Url : string.Empty; var url = carousel.Url ?? string.Empty; DateTime sunriseDate = DateComparer.DateFieldToDate(carousel.SunriseDate); DateTime sunsetDate = DateComparer.DateFieldToDate(carousel.SunsetDate); return(new CarouselContent(title, slug, teaser, image, sunriseDate, sunsetDate, url)); }
public void ShouldReturnMinimumDateTimePossibleFromAInvalidDateString() { var date = DateComparer.DateFieldToDate("not-valid"); date.Should().Be(DateTime.MinValue); }