Exemplo n.º 1
0
        public async Task GetAllRoles_Test()
        {
            int roleCount = 50;

            for (int i = 0; i < roleCount; i++)
            {
                var createRoleDto = new CreateRoleDto()
                {
                    Name               = $"Role{i,2}",
                    DisplayName        = $"Test role{i,2}",
                    Description        = $"Role{i,2} for test",
                    GrantedPermissions = new List <string>()
                    {
                        PermissionNames.Pages_Roles, PermissionNames.Pages_Users
                    }
                };
                var roleDto = await _roleAppService.CreateAsync(createRoleDto);
            }

            PagedRoleResultRequestDto pagedRoleDto = new PagedRoleResultRequestDto()
            {
                Keyword        = string.Empty,
                SkipCount      = 17,
                MaxResultCount = 8
            };

            var roles = await _roleAppService.GetAllAsync(pagedRoleDto);

            roles.Items.Count.ShouldBe(8);
            roles.Items[0].Name.ShouldBe("Role16");
        }
Exemplo n.º 2
0
        /// <summary>
        /// List all roles
        /// </summary>
        /// <param name="scopeId">Scope id to filter</param>
        /// <param name="cancellationToken">A System.Threading.CancellationToken to observe while waiting for the task to complete</param>
        private async Task <IActionResult> RunGetAllAsync(Guid?scopeId, CancellationToken cancellationToken)
        {
            IEnumerable <RoleResponse> result =
                (await _roleAppService.GetAllAsync(cancellationToken))
                .Select(r => r.Map());

            if ((scopeId ?? Guid.Empty) != Guid.Empty)
            {
                result = result.Where(r => r.Scope.Id == scopeId);
            }

            result = result
                     .OrderBy(o => o.Scope.Name)
                     .ThenBy(o => o.Name)
                     .ToList();

            return(Ok(result));
        }
Exemplo n.º 3
0
        public async Task <ActionResult> Index()
        {
            var roles       = (await _roleAppService.GetAllAsync(new PagedAndSortedResultRequestDto())).Items;
            var permissions = (await _roleAppService.GetAllPermissions()).Items;
            var model       = new RoleListViewModel
            {
                Roles       = roles,
                Permissions = permissions
            };

            return(View(model));
        }
Exemplo n.º 4
0
        public async Task <ActionResult <IEnumerable <RoleViewModel> > > Get(int page = 0, int size = 20)
        {
            try
            {
                var list = await _appService.GetAllAsync(page, size);

                return(new JsonResult(list));
            }
            catch (Exception)
            {
                // TODO: log error
                return(BadRequest(new
                {
                    success = false,
                    errors = new string[] { "Could not get the roles" }
                }));
            }
        }