예제 #1
0
        public async Task <ApiResult <PagedResult <ProjectViewModel> > > GetProjectPaging(GetProjectPagingRequest request)
        {
            var query = from p in _context.Projects
                        select new { p };

            if (!string.IsNullOrEmpty(request.Keyword))
            {
                query = query.Where(x => x.p.ProjectName.Contains(request.Keyword));
            }

            //Paging
            int totalRow = await query.CountAsync();

            var data = await query.Skip((request.PageIndex - 1) *request.PageSize)
                       .Take(request.PageSize)
                       .Select(x => new ProjectViewModel()
            {
                ProjectID        = x.p.ProjectID,
                ProjectName      = x.p.ProjectName,
                Description      = x.p.Description,
                Skateholder      = x.p.Skateholder,
                DateBegin        = x.p.DateBegin.ToString("dd/MM/yyyy"),
                DateEstimatedEnd = x.p.DateEstimatedEnd.ToString("dd/MM/yyyy"),
                Status           = x.p.Status
            }).ToListAsync();

            //Select and projection
            var pagedResult = new PagedResult <ProjectViewModel>()
            {
                TotalRecords = totalRow,
                PageIndex    = request.PageIndex,
                PageSize     = request.PageSize,
                Items        = data
            };

            return(new ApiSuccessResult <PagedResult <ProjectViewModel> >(pagedResult));
        }
예제 #2
0
        public async Task <IActionResult> GetProjectPaging([FromQuery] GetProjectPagingRequest request)
        {
            var project = await _projectService.GetProjectPaging(request);

            return(Ok(project));
        }