public async Task <List <string> > GetPaginationUris(IssueTableFilter filter)
        {
            if (filter == null)
            {
                filter = new IssueTableFilter();
            }

            var dict = new Dictionary <string, string>();
            var res  = new List <string>();

            dict.Add("Filter.PerPage", filter.PerPage.ToString());
            dict.Add("Filter.TypeId", filter.TypeId.ToString());
            dict.Add("Filter.StatusId", filter.StatusId.ToString());

            var query      = QueryString.Create(dict).Value;
            var issueCount = await _ctx.Issues.Where(i => i.ProjectId == ProjectId &&
                                                     (filter.TypeId == 0 || filter.TypeId == i.TypeId) &&
                                                     (filter.StatusId == 0 || filter.StatusId == i.StatusId))
                             .CountAsync();

            var totalPages = issueCount % filter.PerPage == 0 ? issueCount / filter.PerPage : issueCount / filter.PerPage + 1;

            var req = _httpCtxAccessor.HttpContext.Request;

            for (int i = 1; i <= totalPages; i++)
            {
                var uri = $"{req.Scheme}://{req.Host.ToUriComponent()}/IssuesTable{query}&CurrentPage={i}";
                res.Add(uri);
            }

            return(res);
        }
        public async Task <IssueTableViewModel> GetIssueTableViewModel(IssueTableFilter filter, int currentPage)
        {
            var issueTableVM = new IssueTableViewModel();

            ProjectId = (int)_httpCtxAccessor.HttpContext.Session.GetInt32("projectId");

            issueTableVM.Issues = await GetIssues(filter, currentPage);

            issueTableVM.Types = await GetTypeSelectItems();

            issueTableVM.Status = await GetStatusSelectItems();

            foreach (var t in issueTableVM.Types)
            {
                if (t.Id == filter.TypeId)
                {
                    issueTableVM.SelectedType = t;
                    break;
                }
            }

            foreach (var s in issueTableVM.Status)
            {
                if (s.Id == filter.StatusId)
                {
                    issueTableVM.SelectedStatus = s;
                    break;
                }
            }

            return(issueTableVM);
        }
예제 #3
0
        public async Task OnGetAsync(IssueTableFilter filter, int currentPage = 1)
        {
            IssueTable = await _issuesTableVMService.GetIssueTableViewModel(filter, currentPage);

            PageUris = await _issuesTableVMService.GetPaginationUris(filter);

            CurrentPage = currentPage;
        }
        public async Task <List <IssueTableItemViewModel> > GetIssues(IssueTableFilter filter, int currentPage)
        {
            var skip = (currentPage - 1) * filter.PerPage;

            return(await _ctx.Issues.Include(i => i.Type)
                   .Include(i => i.Status)
                   .Where(i => i.ProjectId == ProjectId &&
                          (filter.TypeId == 0 || filter.TypeId == i.TypeId) &&
                          (filter.StatusId == 0 || filter.StatusId == i.StatusId))
                   .Select(i => new IssueTableItemViewModel
            {
                Id = i.Id,
                Name = i.Name,
                Type = i.Type,
                Status = i.Status,
                DueDate = i.DueDate
            })
                   .Skip(skip)
                   .Take(filter.PerPage)
                   .ToListAsync());
        }