예제 #1
0
        public async Task <BasePageList <ShortcutResult> > GetAsync(ShortcutFilter filter)
        {
            var inactivedStatus = ShortcutStatus.Inactived.GetCode();
            var search          = filter.Keyword != null?filter.Keyword.ToLower() : "";

            var shortcutQuery = _shortcutRepository.Get(x => filter.CanGetInactived || x.StatusId != inactivedStatus);

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

            var query = shortcutQuery.Select(x => new ShortcutResult
            {
                Description = x.Description,
                Id          = x.Id,
                Name        = x.Name,
                Icon        = x.Icon,
                TypeId      = x.TypeId,
                Url         = x.Url,
                Order       = x.Order,
                StatusId    = x.StatusId,
                CreatedDate = x.CreatedDate,
                CreatedById = x.CreatedById,
                UpdatedDate = x.UpdatedDate,
                UpdatedById = x.UpdatedById
            });

            if (filter.StatusId.HasValue)
            {
                query = query.Where(x => x.StatusId == filter.StatusId);
            }

            if (filter.TypeId.HasValue && filter.TypeId != 0)
            {
                query = query.Where(x => x.TypeId == filter.TypeId);
            }

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

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

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

            return(result);
        }
예제 #2
0
 public async Task <BasePageList <ShortcutResult> > GetAsync(ShortcutFilter filter)
 {
     return(await _shortcutRepository.GetAsync(filter));
 }