Exemplo n.º 1
0
        public async Task <IActionResult> CreateAsync([FromBody] UserRequestDto createDto)
        {
            var user = await _addUserService.AddAsync(createDto.ToUser());

            var created = UserResponseDto.FromUser(user);

            return(Created($"{_siteSettings.ListenUri}/users/{user.UserId}", created));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> FindAsync([FromRoute] Guid userId)
        {
            User user;

            if (this.UserHasScope(UserScopes.Admin) || userId == this.GetUserId())
            {
                user = await _findUserService.FindAsync(userId);
            }
            else
            {
                throw new ForbiddenException();
            }

            var found = UserResponseDto.FromUser(user);

            return(Ok(found));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> UpdateAsync([FromRoute] Guid userId, [FromBody] UserRequestDto dto)
        {
            User user;

            if (this.UserHasScope(UserScopes.Admin) || userId == this.GetUserId())
            {
                user = await _updateUserService.UpdateAsync(dto.ToUser(userId));
            }
            else
            {
                throw new ForbiddenException();
            }

            var updated = UserResponseDto.FromUser(user);

            return(Ok(updated));
        }
Exemplo n.º 4
0
        public static UserResponseDto FromUser(User user, bool includeChildren)
        {
            var dto = new UserResponseDto
            {
                user_id       = user.UserId,
                username      = user.Username,
                created_date  = user.CreatedDateTime,
                modified_date = user.ModifiedDateTime
            };

            if (includeChildren)
            {
                dto.applications = user.Applications?.Select(a =>
                                                             ApplicationResponseDto.FromApplication(a, false)).ToList();
            }

            return(dto);
        }