private static Expression <Func <Appointment, bool> > Filter(AppointmentsFilter filter) { var expressionsList = new List <Expression <Func <Appointment, bool> > >(); if (filter.StatusId != null) { Expression <Func <Appointment, bool> > statusFilter = a => a.StatusId == filter.StatusId; expressionsList.Add(statusFilter); } if (filter.ServiceId != null) { Expression <Func <Appointment, bool> > serviceFilter = a => a.ServiceId == filter.ServiceId; expressionsList.Add(serviceFilter); } if (filter.DoctorId != null) { Expression <Func <Appointment, bool> > doctorFilter = a => a.DoctorId == filter.DoctorId; expressionsList.Add(doctorFilter); } if (filter.AnimalId != null) { Expression <Func <Appointment, bool> > animalFilter = a => a.AnimalId == filter.AnimalId; expressionsList.Add(animalFilter); } if (filter.ClientId != null) { Expression <Func <Appointment, bool> > clientFilter = a => a.Animal.ClientId == filter.ClientId; expressionsList.Add(clientFilter); } Expression <Func <Appointment, bool> > expression = appointment => true; foreach (var exp in expressionsList) { expression = expression.AndAlso(exp); } return(expression); }
public async Task <ICollection <Appointment> > GetAllAppointmentsAsync( AppointmentsFilter filter = null, PaginationFilter pagination = null) { if (pagination != null && filter != null) { return(await _repositoryWrapper.AppointmentRepository.GetAsync(Filter(filter), Include(), OrderBy(pagination), pagination.PageNumber, pagination.PageSize)); } if (filter != null) { return(await _repositoryWrapper.AppointmentRepository.GetAsync(Filter(filter), Include())); } if (pagination != null) { return(await _repositoryWrapper.AppointmentRepository.GetAsync(include : Include(), orderBy : OrderBy(pagination), pageNumber : pagination.PageNumber, pageSize : pagination.PageSize)); } return(await _repositoryWrapper.AppointmentRepository.GetAsync(include : Include())); }
public async Task <int> GetTotalCount(AppointmentsFilter filter = null) { return(await _repositoryWrapper.AppointmentRepository.CountAsync(Filter(filter))); }