public async Task <IActionResult> Index(UserStatusFilterModel filter)
        {
            var filterRequest = new UserStatusFilter()
            {
                Page     = filter.Page,
                PageSize = _pagerOptions.PageSize,
                Keyword  = filter.Search
            };

            var statusPageList = await _userStatusService.GetAsync(filterRequest);

            var statuses = statusPageList.Collections.Select(x => new UserStatusModel()
            {
                Id          = x.Id,
                Name        = x.Name,
                Description = x.Description
            });

            var statusPage = new PageListModel <UserStatusModel>(statuses)
            {
                Filter      = filter,
                TotalPage   = statusPageList.TotalPage,
                TotalResult = statusPageList.TotalResult
            };

            if (_httpHelper.IsAjaxRequest(Request))
            {
                return(PartialView("_UserStatusTable", statusPage));
            }

            return(View(statusPage));
        }
예제 #2
0
        public async Task <BasePageList <UserStatusResult> > GetAsync(UserStatusFilter filter)
        {
            var search = filter.Keyword != null?filter.Keyword.ToLower() : "";

            var query = _statusRepository.Table
                        .Select(x => new UserStatusResult()
            {
                Id          = x.Id,
                Name        = x.Name,
                Description = x.Description
            });

            if (!string.IsNullOrEmpty(search))
            {
                query = query.Where(x => x.Name.ToLower().Contains(search) || x.Description.ToLower().Contains(search));
            }

            var filteredNumber = query.Select(x => x.Id).Count();

            var statuses = await query.OrderBy(x => x.Id)
                           .Skip(filter.PageSize * (filter.Page - 1))
                           .Take(filter.PageSize)
                           .ToListAsync();

            var result = new BasePageList <UserStatusResult>(statuses)
            {
                TotalResult = filteredNumber,
                TotalPage   = (int)Math.Ceiling((double)filteredNumber / filter.PageSize)
            };

            return(result);
        }
예제 #3
0
 public async Task <BasePageList <UserStatusResult> > GetAsync(UserStatusFilter filter)
 {
     return(await _statusRepository.GetAsync(filter));
 }