public async Task <IActionResult> GetSessions([FromBody] SessionFinderModel finder) { try { Session[] sessions = await _sessionService.GetSessions(finder, userId); var sessionModels = _mapper.Map <SessionModel[]>(sessions); return(Ok(sessionModels)); } catch (AppException ex) { return(BadRequest(new { message = ex.Message })); } }
public async Task <Session[]> GetSessions(SessionFinderModel finder, Guid userId) { if (finder.End - finder.Start < TimeSpan.FromDays(32)) { return(await _context.SessionSlots .Where(x => x.Start > finder.Start) .Where(x => x.End < finder.End) .Where(x => (x.Attendees.Count < x.MaxAttendees) || finder.GetBooked || x.Attendees.Any(a => a.AttendeeId == userId)) .Where(x => (x.Subjects & finder.Subjects) > 0) .Where(x => x.HostId.ToBase64() == finder.HostId || finder.HostId == null) .Where(x => x.Grade == finder.Grade) .Include(x => x.Host) .Include(x => x.Attendees) .ThenInclude(x => x.Attendee) .ToArrayAsync()); } else { throw new AppException("Requested timespan too large."); } }