コード例 #1
0
        public async Task <IActionResult> Index(string keyword, string status, int pageIndex = 1, int pageSize = 5)
        {
            var request = new GetProcessPlanPagingRequest()
            {
                Keyword   = keyword,
                Status    = status,
                PageIndex = pageIndex,
                PageSize  = pageSize
            };
            var data = await _processPlanApiClient.GetProcessPlanPaging(request);

            ViewBag.Keyword = keyword;

            return(View(data.ResultObj));
        }
コード例 #2
0
        public async Task <ApiResult <PagedResult <ProcessPlanVm> > > GetProcessPlanPaging(GetProcessPlanPagingRequest bundle)
        {
            IQueryable <ProcessPlan> query = _context.ProcessPlans;

            if (!string.IsNullOrEmpty(bundle.Status))
            {
                switch (bundle.Status)
                {
                case "true":
                    query = query.Where(c => c.Status == StatusProcessPlan.Processed);
                    break;

                case "false":
                    query = query.Where(c => c.Status == StatusProcessPlan.Cancel);
                    break;
                }
            }

            query = query.Where(c => c.Status != StatusProcessPlan.Processing);

            if (!string.IsNullOrEmpty(bundle.Keyword))
            {
                query = query.Where(c => c.Name.Contains(bundle.Keyword) || c.Code.Contains(bundle.Keyword));
            }

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

            query = query.OrderByDescending(c => c.Id);

            var query1 = query.Include(x => x.Creator);
            var query2 = query1.Include(l => l.Responsible);

            var data = await query2.Skip((bundle.PageIndex - 1) *bundle.PageSize)
                       .Take(bundle.PageSize)
                       .Select(i => new ProcessPlanVm()
            {
                Id     = i.Id,
                Code   = i.Code,
                Name   = i.Name,
                Status = i.Status == StatusProcessPlan.Processed ? "Đã hoàn thành" :
                         i.Status == StatusProcessPlan.Cancel ? "Đã hủy" : "Đang chế biến",
                CreatedDate     = i.CreatedDate.ToString("dd-MM-yyyy"),
                CodeCreator     = i.Creator.Code,
                CodeResponsible = i.Responsible.Code
            }).ToListAsync();

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

            return(new ApiSuccessResult <PagedResult <ProcessPlanVm> >(pagedResult));
        }
コード例 #3
0
        public async Task <ApiResult <PagedResult <ProcessPlanVm> > > GetProcessPlanPaging(GetProcessPlanPagingRequest bundle)
        {
            var url = $"/api/ProcessPlan/paging?pageIndex=" +
                      $"{bundle.PageIndex}&pageSize={bundle.PageSize}&keyword={bundle.Keyword}&status={bundle.Status}";
            var result = await GetListAsync <ProcessPlanVm>(url);

            return(result);
        }
コード例 #4
0
        public async Task <IActionResult> GetAllPaging([FromQuery] GetProcessPlanPagingRequest request)
        {
            var result = await _processPlanService.GetProcessPlanPaging(request);

            return(Ok(result));
        }