public async Task <Announcement[]> GetAnnouncements(AnnouncementQuery query, int?limit = null) { FilterDefinition <Announcement> filter = Builders <Announcement> .Filter.Empty; if (query.FromTimestamp != null) { filter &= Builders <Announcement> .Filter.Gte(a => a.TimeStamp, query.FromTimestamp); } if (query.ToTimestamp != null) { filter &= Builders <Announcement> .Filter.Lte(a => a.TimeStamp, query.ToTimestamp); } if (query.Important != null) { filter &= Builders <Announcement> .Filter.Eq(a => a.Important, query.Important); } var find = _announcementCollection.Find(filter); if (limit != null) { find = find.Limit(limit); } List <Announcement> announcements = await find.ToListAsync(); return(announcements.ToArray()); }
public AnnouncementsTableDto GetAll(AnnouncementsTableFilterModelDto announcementsTableFilter) { AnnouncementQuery announcementQuery = _mapper.Map <AnnouncementQuery>(announcementsTableFilter); IPagedList <Announcement> announcements = _announcementService.GetAnnouncements(announcementQuery); List <AnnouncementsTableRowDto> announcementsTableRowDtos = _mapper.Map <IEnumerable <Announcement>, IEnumerable <AnnouncementsTableRowDto> >(announcements).ToList(); return(new AnnouncementsTableDto { AnnouncementsTableRows = announcementsTableRowDtos, TotalDisplayedRecords = announcements.TotalCount, TotalRecords = announcements.TotalCount }); }
public AnnouncementQueryTest() { TestEnvironment.Init(); query = new AnnouncementQuery(); }