Exemplo n.º 1
0
        public async Task <IActionResult> UpdateAsync([FromRoute] Guid roleId, [FromBody] RoleRequestDto dto)
        {
            Role role;

            if (this.UserHasScope(RoleScopes.Admin))
            {
                role = await _updateRoleService.UpdateAsync(dto.ToRole(roleId));
            }
            else
            {
                role = await _updateRoleService.UpdateAsync(dto.ToRole(roleId), this.GetUserId());
            }

            var updated = RoleResponseDto.FromRole(role);

            return(Ok(updated));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> CreateAsync([FromBody] RoleRequestDto dto)
        {
            Role role;

            if (this.UserHasScope(RoleScopes.Admin))
            {
                role = await _addRoleService.AddAsync(dto.ToRole());
            }
            else
            {
                role = await _addRoleService.AddAsync(dto.ToRole(), this.GetUserId());
            }

            var created = RoleResponseDto.FromRole(role);

            return(Created($"{_siteSettings.ListenUri}/roles/{role.RoleId}", created));
        }