/// <summary> /// Gets a paginated list of contacts. /// </summary> /// <param name="queryResource">Paginating, sorting and searching query parameters.</param> /// <returns>Paginated list of contacts.</returns> public PagedResponse <List <ContactResource> > ListAsync(QueryResource queryResource) { try { if (queryResource == null) { throw new ArgumentNullException(nameof(queryResource)); } var contacts = _contactRepository.DbSet(); if (!string.IsNullOrWhiteSpace(queryResource.SearchBy)) { contacts = contacts.Where( c => c.Name.ToLower().Contains(queryResource.SearchBy.Trim().ToLower())); } contacts = contacts.ApplyOrder(queryResource.SortOrder); var pagedResponse = PagedResponse <Contact> .ToPagedResponse( contacts, queryResource.PageNumber, queryResource.PageSize); return(_mapper.Map <PagedResponse <List <ContactResource> > >(pagedResponse)); } catch (Exception ex) { Console.WriteLine(ex.Message); return(new PagedResponse <List <ContactResource> >( ex.Message, queryResource.PageNumber, queryResource.PageSize)); } }
public async Task <PagedResponse <ItemResponseDto> > GetAllItems(FilterParams filterParams, PaginationParams paginationParams, bool withGroups = true) { IQueryable <Item> items = null; items = Repository.GetAllAsQueryable(); if (filterParams != null) { if (!string.IsNullOrEmpty(filterParams.Term)) { items = items.Where(i => i.Name.Contains(filterParams.Term, StringComparison.InvariantCultureIgnoreCase) || i.Description.Contains(filterParams.Term, StringComparison.InvariantCultureIgnoreCase)); } } if (withGroups) { items = items.Include(i => i.Group).OrderBy(i => i.Name); } else { items = items.OrderBy(i => i.Name); } PagedResponse <ItemResponseDto> pagedResponse = new PagedResponse <ItemResponseDto>(); pagedResponse = await pagedResponse.ToPagedResponse(items, paginationParams, this.Mapper.Map <IEnumerable <ItemResponseDto> >); return(pagedResponse); }
public async Task <PagedResponse <UserResponseDto> > GetAllUsers(FilterParams filterParams, PaginationParams paginationParams, bool withRoles = true) { IQueryable <User> users = null; users = Repository.GetAllAsQueryable().OrderBy(u => u.Login); if (filterParams != null) { if (!string.IsNullOrEmpty(filterParams.Term)) { users = users.Where(u => u.Login.Contains(filterParams.Term, StringComparison.InvariantCultureIgnoreCase) || u.Type.ToString().Contains(filterParams.Term, StringComparison.InvariantCultureIgnoreCase)); } } if (withRoles) { users = users.Include(e => e.UserRoles).ThenInclude(ur => ur.Role); } else { users = Repository.GetAllAsQueryable(); } PagedResponse <UserResponseDto> pagedResponse = new PagedResponse <UserResponseDto>(); pagedResponse = await pagedResponse.ToPagedResponse(users, paginationParams, this.Mapper.Map <IEnumerable <UserResponseDto> >); return(pagedResponse); }
/// <summary> /// Gets a paginated list of reservations. /// </summary> /// <param name="queryResource">Paginating, sorting and searching query parameters.</param> /// <returns>Paginated list of reservations.</returns> public PagedResponse <List <ReservationResource> > ListAsync(QueryResource queryResource) { try { if (queryResource == null) { throw new ArgumentNullException(nameof(queryResource)); } var reservations = _reservationRepository.DbSet() .Include(r => r.Contact) .Include(r => r.Place) .Select(r => r); if (!string.IsNullOrWhiteSpace(queryResource.SearchBy)) { reservations = reservations.Where(c => c.Contact.Name.ToLower().Contains(queryResource.SearchBy.Trim().ToLower()) || c.Place.Name.ToLower().Contains(queryResource.SearchBy.Trim().ToLower())); } reservations = reservations.ApplyOrderToReservation(queryResource.SortOrder); var pagedResponse = PagedResponse <Reservation> .ToPagedResponse( reservations, queryResource.PageNumber, queryResource.PageSize); return(_mapper.Map <PagedResponse <List <ReservationResource> > >(pagedResponse)); } catch (Exception ex) { Console.WriteLine(ex.Message); return(new PagedResponse <List <ReservationResource> >( ex.Message, queryResource.PageNumber, queryResource.PageSize)); } }
public ActionResult <PagedResponse <BookWithAuthorsDTO> > GetBooks([FromQuery] PaginationParams pagination) { IQueryable <Book> lstBookDTO = this.repository.GetBooksWithAuthorsAsQueryable(); PagedResponse <BookWithAuthorsDTO> pagedResponse = new PagedResponse <BookWithAuthorsDTO>(); pagedResponse.ToPagedResponse(lstBookDTO, pagination, this.mapper.Map <IEnumerable <BookWithAuthorsDTO> >); return(Ok(pagedResponse)); }
public async Task <PagedResponse <DonationResponseDto> > GetAllDonation(Expression <Func <Donation, bool> > predicate, PaginationParams paginationParams) { IQueryable <Donation> donation = DonationRepository.GetWhereAsQueryable(predicate).Include(d => d.CharitableEntity).Include(d => d.DonationItem).OrderByDescending(g => g.Date); PagedResponse <DonationResponseDto> pagedResponse = new PagedResponse <DonationResponseDto>(); pagedResponse = await pagedResponse.ToPagedResponse(donation, paginationParams, this.Mapper.Map <IEnumerable <DonationResponseDto> >); return(pagedResponse); }
public async Task <PagedResponse <DonationResponseDto> > GetAllDonation(PaginationParams paginationParams) { IQueryable <Donation> donation = DonationRepository.GetAllAsQueryable().OrderBy(g => g.Date); PagedResponse <DonationResponseDto> pagedResponse = new PagedResponse <DonationResponseDto>(); pagedResponse = await pagedResponse.ToPagedResponse(donation, paginationParams, this.Mapper.Map <IEnumerable <DonationResponseDto> >); return(pagedResponse); }
public async Task <PagedResponse <CharityInfoResponseDto> > GetAllCharitiesInfo(PaginationParams paginationParams) { IQueryable <CharitableInformation> charitableEntities = Repository.GetAllAsQueryable().OrderBy(g => g.Nickname); PagedResponse <CharityInfoResponseDto> pagedResponse = new PagedResponse <CharityInfoResponseDto>(); pagedResponse = await pagedResponse.ToPagedResponse(charitableEntities, paginationParams, this.Mapper.Map <IEnumerable <CharityInfoResponseDto> >); return(pagedResponse); }
public async Task <PagedResponse <DonorPFResponseDto> > GetAllDonorsPF(Expression <Func <DonorPF, bool> > predicate, PaginationParams paginationParams) { IQueryable <DonorPF> donorsPf = Repository.GetWhereAsQueryable(predicate).OrderBy(d => d.Name); PagedResponse <DonorPFResponseDto> pagedResponse = new PagedResponse <DonorPFResponseDto>(); pagedResponse = await pagedResponse.ToPagedResponse(donorsPf, paginationParams, this.Mapper.Map <IEnumerable <DonorPFResponseDto> >); return(pagedResponse); }
public async Task <PagedResponse <DonorPJResponseDto> > GetAllDonorsPJ(PaginationParams paginationParams) { IQueryable <DonorPJ> donorsPf = repository.GetAllAsQueryable(); PagedResponse <DonorPJResponseDto> pagedResponse = new PagedResponse <DonorPJResponseDto>(); pagedResponse = await pagedResponse.ToPagedResponse(donorsPf, paginationParams, this.mapper.Map <IEnumerable <DonorPJResponseDto> >); return(pagedResponse); }
public async Task <PagedResponse <GroupResponseDto> > GetAllGroups(FilterParams filterParams, PaginationParams paginationParams) { IQueryable <Group> groups = Repository.GetAllAsQueryable().OrderBy(g => g.Name); if (filterParams != null) { if (!string.IsNullOrEmpty(filterParams.Term)) { groups = groups.Where(g => g.Name.Contains(filterParams.Term, StringComparison.InvariantCultureIgnoreCase) || g.Description.Contains(filterParams.Term, StringComparison.InvariantCultureIgnoreCase)); } } PagedResponse <GroupResponseDto> pagedResponse = new PagedResponse <GroupResponseDto>(); pagedResponse = await pagedResponse.ToPagedResponse(groups, paginationParams, this.Mapper.Map <IEnumerable <GroupResponseDto> >); return(pagedResponse); }
public async Task <PagedResponse <CharityResponseDto> > GetAllCharities(Expression <Func <CharitableEntity, bool> > predicate, FilterCharityParams filterParams, PaginationParams paginationParams, bool withInformation = false) { IQueryable <CharitableEntity> charitableEntities = null; charitableEntities = Repository.GetWhereAsQueryable(predicate); if (filterParams != null) { if (!string.IsNullOrEmpty(filterParams.State)) { charitableEntities = charitableEntities.Where(c => c.Address.State.ToLower().Contains(filterParams.State.ToLower(), StringComparison.InvariantCultureIgnoreCase)); } if (!string.IsNullOrEmpty(filterParams.City)) { charitableEntities = charitableEntities.Where(c => c.Address.City.ToLower().Contains(filterParams.City.ToLower(), StringComparison.InvariantCultureIgnoreCase)); } if (!string.IsNullOrEmpty(filterParams.Term)) { charitableEntities = charitableEntities.Where(c => c.Name.ToLower().Contains(filterParams.Term.ToLower(), StringComparison.InvariantCultureIgnoreCase) || c.Cnpj.ToLower().Contains(filterParams.Term.ToLower(), StringComparison.InvariantCultureIgnoreCase) || c.CharitableInformation.Nickname.ToLower().Contains(filterParams.Term.ToLower(), StringComparison.InvariantCultureIgnoreCase)); } } charitableEntities = charitableEntities.OrderBy(g => g.Name); if (withInformation) { charitableEntities = charitableEntities.Include(p => p.CharitableInformation); } PagedResponse <CharityResponseDto> pagedResponse = new PagedResponse <CharityResponseDto>(); pagedResponse = await pagedResponse.ToPagedResponse(charitableEntities, paginationParams, this.Mapper.Map <IEnumerable <CharityResponseDto> >); return(pagedResponse); }