Esempio n. 1
0
        private IQueryable <Role> CreateQuery(SearchRolesQuery query)
        {
            var dbQuery = _dbContext
                          .Roles
                          .AsNoTracking()
                          .AsQueryable();

            if (!string.IsNullOrEmpty(query.UserAreaCode))
            {
                dbQuery = dbQuery
                          .Where(r => r.UserAreaCode == query.UserAreaCode);
            }

            if (query.ExcludeAnonymous)
            {
                dbQuery = dbQuery
                          .Where(r => r.RoleCode != AnonymousRole.AnonymousRoleCode);
            }

            if (!string.IsNullOrEmpty(query.Text))
            {
                var text = query.Text.Trim();
                dbQuery = dbQuery.Where(r => r.Title.Contains(text))
                          .OrderByDescending(r => r.Title.StartsWith(text))
                          .ThenByDescending(r => r.Title);
            }
            else
            {
                dbQuery = dbQuery
                          .OrderBy(r => r.UserArea.Name)
                          .ThenBy(r => r.Title);
            }

            return(dbQuery);
        }
Esempio n. 2
0
        public IActionResult Get([FromServices] IUnitOfWork unitOfWork,
                                 [FromServices] IQueryHandlerDispatcher queryHandlerDispatcher,
                                 string criteria = "", int page = 1, int pageSize = 10)
        {
            var query = new SearchRolesQuery("corrid", criteria, page, pageSize, "", true);

            var dto = queryHandlerDispatcher.Handle <SearchRolesQuery, PaginatedSearchedRoleDto>(query);

            return(Ok(dto));
        }
Esempio n. 3
0
        public async Task <PagedQueryResult <RoleMicroSummary> > ExecuteAsync(SearchRolesQuery query, IExecutionContext executionContext)
        {
            var dbPagedResult = await CreateQuery(query).ToPagedResultAsync(query);

            var mappedResults = dbPagedResult
                                .Items
                                .Select(_roleMicroSummaryMapper.Map);

            return(dbPagedResult.ChangeType(mappedResults));
        }
Esempio n. 4
0
        public async Task <IActionResult> Get([FromQuery] SearchRolesQuery query)
        {
            if (query == null)
            {
                query = new SearchRolesQuery();
            }

            var results = await _queryExecutor.ExecuteAsync(query);

            return(_apiResponseHelper.SimpleQueryResponse(this, results));
        }
        private Expression <Func <Role, bool> > BuildExpresion(SearchRolesQuery request)
        {
            var normalizedName = request.Name?.ToLowerInvariant();
            Expression <Func <Role, bool> > whereExpresion = r => r.IsEnabled;

            if (!string.IsNullOrWhiteSpace(normalizedName))
            {
                whereExpresion.And(r => r.Name.Contains(normalizedName));
            }
            return(whereExpresion);
        }
        public async Task <IEnumerable <RoleVM> > Handle(SearchRolesQuery request, CancellationToken cancellationToken)
        {
            var normalizedName = request.Name?.ToLowerInvariant();
            Expression <Func <Role, bool> > whereExpresion = BuildExpresion(request);
            var result = await _context.Roles.AsNoTracking()
                         .Where(whereExpresion)
                         .ToMap(request.PageSize, request.Page)
                         .ToListAsync(cancellationToken);

            return(result);
        }
Esempio n. 7
0
        public async Task <JsonResult> Get([FromQuery] SearchRolesQuery query)
        {
            if (query == null)
            {
                query = new SearchRolesQuery();
            }
            ApiPagingHelper.SetDefaultBounds(query);

            var results = await _queryExecutor.ExecuteAsync(query);

            return(_apiResponseHelper.SimpleQueryResponse(results));
        }
Esempio n. 8
0
 public IEnumerable <IPermissionApplication> GetPermissions(SearchRolesQuery command)
 {
     yield return(new RoleReadPermission());
 }
 public IDomainRepositoryQueryContext <PagedQueryResult <RoleMicroSummary> > AsMicroSummaries(SearchRolesQuery query)
 {
     return(DomainRepositoryQueryContextFactory.Create(query, ExtendableContentRepository));
 }
Esempio n. 10
0
 public async Task <ActionResult <SearchRolesQueryResult> > Search([FromQuery] SearchRolesQuery query, CancellationToken cancellationToken)
 {
     return(await Mediator.Send(query, cancellationToken));
 }