public async Task <ActionResult <Page <MeetingListItem> > > GetMeetings( CancellationToken cancellationToken, [FromQuery] DateListBinding binding) { var address = User.GetAddress(); House house = await _houseRepository.GetByAddress(address, cancellationToken); if (house == null) { return(NotFound(address)); } var query = _context.Meetings .AsNoTracking() .Include(o => o.House) .Where(o => o.House.Id == house.Id) .Select(o => new MeetingListItem { Id = o.Id, Title = o.Title, MeetingDate = o.MeetingDate, Description = o.Description }); if (binding.StartDate != null) { query = query.Where(o => o.MeetingDate >= binding.StartDate); } if (binding.EndDate != null) { query = query.Where(o => o.MeetingDate <= binding.EndDate); } var items = await query .Skip(binding.Offset) .Take(binding.Limit) .ToListAsync(); return(new Page <MeetingListItem> { Limit = binding.Limit, Offset = binding.Offset, Total = await query.CountAsync(), Items = items }); }
public async Task <ActionResult <Page <NewsPostView> > > GetVotingsPerson( CancellationToken cancellationToken, [FromQuery] DateListBinding binding ) { var house = await _houseRepository.GetByAddress(User.GetAddress(), cancellationToken); if (house == null) { return(NotFound($"House not found")); } var query = _context.News .AsNoTracking() .Include(o => o.House) .Where(o => o.House.Id == house.Id) .Where(o => binding.StartDate == null ? true : o.CreateDate >= binding.StartDate) .Where(o => binding.EndDate == null ? true : o.CreateDate <= binding.EndDate) .Select(o => new NewsPostView { Id = o.Id, Title = o.Title, Description = o.Description, CreateDate = o.CreateDate, Image = o.Image }); var items = await query .Skip(binding.Offset) .Take(binding.Limit) .ToListAsync(); return(new Page <NewsPostView> { Limit = binding.Limit, Offset = binding.Offset, Total = await query.CountAsync(), Items = items }); }