Exemplo n.º 1
0
        public async Task OnGetAsync(
            [FromQuery] int page = 1,
            [FromQuery] string?q = null,
            [FromQuery] EClubSortingOptions sort = EClubSortingOptions.CreationDateDescending
            )
        {
            Query  = q;
            SortBy = sort;

            var query = _context.Clubs.AsQueryable();

            if (!string.IsNullOrEmpty(q))
            {
                query = query.Where(c => EF.Functions.Like(c.Name.ToUpper(), $"%{q.Trim().ToUpper()}%"));
            }

            Clubs = await(sort switch
            {
                EClubSortingOptions.NameAscending => query.OrderBy(c => c.Name),
                EClubSortingOptions.NameDescending => query.OrderByDescending(c => c.Name),
                EClubSortingOptions.MembersAscending => query.OrderBy(c => c.ClubMembers.Count),
                EClubSortingOptions.MembersDescending => query.OrderByDescending(c => c.ClubMembers.Count),
                EClubSortingOptions.StoriesAscending => query.OrderBy(c => c.Folders.Sum(f => f.StoriesCount)),
                EClubSortingOptions.StoriesDescending => query.OrderByDescending(c => c.Folders.Sum(f => f.StoriesCount)),
                EClubSortingOptions.ThreadsAscending => query.OrderBy(c => c.Threads.Count),
                EClubSortingOptions.ThreadsDescending => query.OrderByDescending(c => c.Threads.Count),
                EClubSortingOptions.CreationDateAscending => query.OrderBy(c => c.CreationDate),
                EClubSortingOptions.CreationDateDescending => query.OrderByDescending(c => c.CreationDate),
                _ => query.OrderByDescending(c => c.CreationDate)
            })
Exemplo n.º 2
0
        public async Task <List <ClubCard> > SearchAndSortPaginatedClubCards(
            int page,
            int perPage,
            string query             = null,
            EClubSortingOptions sort = EClubSortingOptions.CreationDateDescending
            )
        {
            var q = _context.Clubs.AsQueryable();

            if (!string.IsNullOrEmpty(query))
            {
                q = q.Where(c => EF.Functions.Like(c.Name.ToUpper(), $"%{query.Trim().ToUpper()}%"));
            }

            return(await q
                   .SortByEnum(sort)
                   .Paginate(page, perPage)
                   .ProjectTo <ClubCard>(_mapper.ConfigurationProvider)
                   .AsNoTracking()
                   .ToListAsync());
        }
Exemplo n.º 3
0
        public async Task OnGetAsync(
            [FromQuery] int page = 1,
            [FromQuery] string?q = null,
            [FromQuery] EClubSortingOptions sort = EClubSortingOptions.CreationDateDescending
            )
        {
            Query  = q;
            SortBy = sort;

            Clubs = await _clubRepo.SearchAndSortPaginatedClubCards(page, _config.ClubsPerPage, q, sort);

            var count = string.IsNullOrEmpty(q)
                ? await _clubRepo.CountClubs()
                : await _clubRepo.CountSearchedClubs(q);

            // Prepare pagination
            Pagination = new Pagination
            {
                PerPage     = _config.ClubsPerPage,
                ItemCount   = count,
                CurrentPage = page
            };
        }