Esempio n. 1
0
        public async Task <IPagedResult <CategoryOfUsersDto> > CategoriesByExceptUserIdAsync(int exceptUserId, IPageInfo paging, string column, OrderDirection direction, string search)
        {
            var query = new CategoriesByExceptUserIdQuery(Dispatcher)
            {
                ExceptUserId      = exceptUserId,
                Paging            = paging,
                OrderByColumnName = column,
                OrderByDirection  = direction,
                Search            = search
            };

            return(await query.ExecuteAsync());
        }
        public override async Task <IPagedResult <CategoryOfUsersDto> > HandleAsync(CategoriesByExceptUserIdQuery query, CancellationToken token)
        {
            var exceptUserCategories = Entities.Where(p => p.CreatorId != query.ExceptUserId);

            var filteredCategories = exceptUserCategories;

            if (!string.IsNullOrEmpty(query.Search))
            {
                filteredCategories = filteredCategories.Where(p => p.Name.ToLower().Contains(query.Search.ToLower()) || p.Tooltip.ToLower().Contains(query.Search.ToLower()));
            }

            var categories = ProjectTo <CategoryOfUsersDto>(filteredCategories.OrderBy(query.OrderByColumnName, query.OrderByDirection))
                             .Skip(query.Paging.CalculateSkip())
                             .Take(query.Paging.PageSize);

            return(new PagedResult <CategoryOfUsersDto>(await categories.ToArrayAsync(token))
            {
                TotalCount = await exceptUserCategories.CountAsync(token),

                FilteredCount = await filteredCategories.CountAsync(token)
            });
        }