public async Task <AppointmentListViewModel> GetPaginatedAppointments(GetPaginatedAppointments request, CancellationToken cancellationToken = default)
        {
            var entities = await _context.Appointments
                           .Where(x => (!request.UserIds.Any() || request.UserIds.Contains(x.UserId)) &&
                                  (!request.ServiceIds.Any() || request.ServiceIds.Contains(x.ServiceId)) &&
                                  (!request.BranchIds.Any() || request.BranchIds.Contains(x.BranchId)))
                           .Select(AppointmentViewModel.QueryableProjection)
                           .OrderBy(x => x.ArrivalDate)
                           .Skip((request.Page - 1) * request.Take)
                           .Take(request.Take)
                           .ToListAsync(cancellationToken);

            var totalNumberOfEntities = await _context.Appointments
                                        .CountAsync(x => (!request.UserIds.Any() || request.UserIds.Contains(x.UserId)) &&
                                                    (!request.ServiceIds.Any() || request.ServiceIds.Contains(x.ServiceId)) &&
                                                    (!request.BranchIds.Any() || request.BranchIds.Contains(x.BranchId)),
                                                    cancellationToken : cancellationToken);

            return(new AppointmentListViewModel
            {
                Appointments = entities,
                TotalNumberOfElements = totalNumberOfEntities
            });
        }
Ejemplo n.º 2
0
 public async Task <ActionResult> GetPaginatedAppointments([FromQuery] GetPaginatedAppointments request)
 {
     return(Ok(await _appointmentSchedulerService.GetPaginatedAppointments(request)));
 }