Example #1
0
        public Task <FilterResultModel <RoleViewModel> > Handle(GetRoleListViewQuery request, CancellationToken cancellationToken)
        {
            var sortBy        = request.SortBy.Trim() != "" ? request.SortBy : "Name";
            var sortDirection = (request.SortDirection.ToUpper() == "DESCENDING") ? true : false;

            FilterResultModel <RoleViewModel> result = new FilterResultModel <RoleViewModel> ();
            var role = _database.Roles
                       .Select(RoleViewModel.ClaimLessProjection)
                       .Select(DynamicQueryHelper.GenerateSelectedColumns <RoleViewModel> (request.SelectedColumns))
                       .AsQueryable();

            if (request.Filter.Count() > 0)
            {
                role = role
                       .Where(DynamicQueryHelper
                              .BuildWhere <RoleViewModel> (request.Filter)).AsQueryable();
            }

            result.Count = role.Count();

            var PageSize   = (request.PageSize == 0) ? result.Count : request.PageSize;
            var PageNumber = (request.PageSize == 0) ? 1 : request.PageNumber;

            result.Items = role.OrderBy(sortBy, sortDirection)
                           .Skip(PageNumber - 1)
                           .Take(PageSize)
                           .ToList();

            return(Task.FromResult <FilterResultModel <RoleViewModel> > (result));
        }
Example #2
0
 public async Task <IEnumerable <RoleViewModel> > Handle(GetRoleListViewQuery request, CancellationToken cancellationToken)
 {
     return(await _roleManager.Roles
            .Select(RoleViewModel.Projection)
            .ToListAsync());
 }
Example #3
0
        public async Task <ActionResult <IEnumerable <RoleViewModel> > > GetAllUserRoles([FromQuery] GetRoleListViewQuery query)
        {
            var roles = await _Mediator.Send(query);

            return(StatusCode(200, roles));
        }