public async Task <ViewModels.PagingResult> GetMatchsByTag(int currentPage, params int[] tagIds) { var result = new ViewModels.PagingResult(); var matches = await _dbContext.Matchs .Where( x => !x.DeletedAt.HasValue && x.TagAssignments.Any(t => tagIds.Contains(t.TagId))) .Include(x => x.ImageServer) .OrderByDescending(x => x.MatchDate) .ThenByDescending(x => x.CreatedAt) .Page(currentPage, _siteSetttings.PageSize) .Select(x => x.ToViewModel()).ToListAsync(); var countMatch = await _dbContext.Matchs .CountAsync(x => !x.DeletedAt.HasValue && x.TagAssignments.Any(t => tagIds.Contains(t.TagId))); var totalPage = ((double)countMatch / _siteSetttings.PageSize) + 0.49; result.Matches = matches; result.TotalPage = (int)Math.Round(totalPage, 0, MidpointRounding.ToEven); result.CurrentPage = currentPage; return(result); }
public async Task <ViewModels.PagingResult> GetMatchsByCategory(int?categoryId, int currentPage) { var result = new ViewModels.PagingResult(); var matches = await _dbContext.Matchs .Where( x => !x.DeletedAt.HasValue && x.Category.Id == categoryId && !x.Category.DeletedAt.HasValue) .Include(x => x.ImageServer) .OrderByDescending(x => x.MatchDate) .ThenByDescending(x => x.CreatedAt) .Page(currentPage, _siteSetttings.PageSize) .Select(x => x.ToViewModel()).ToListAsync(); var countMatch = await _dbContext.Matchs .CountAsync(x => !x.DeletedAt.HasValue && x.Category.Id == categoryId && !x.Category.DeletedAt.HasValue); var totalPage = ((double)countMatch / _siteSetttings.PageSize) + 0.49; result.Matches = matches; result.TotalPage = (int)Math.Round(totalPage, 0, MidpointRounding.ToEven); result.CurrentPage = currentPage; return(result); }