コード例 #1
0
        public void ValidateEditViewModel(EditUserRequestDto model)
        {
            if (string.IsNullOrEmpty(model.Id))
            {
                throw new BadRequestException(
                          $"Edit user error: Id cannot be null!");
            }

            if (string.IsNullOrEmpty(model.Email))
            {
                throw new BadRequestException(
                          $"Edit user error: Email cannot be null!");
            }

            if (string.IsNullOrEmpty(model.UserName))
            {
                throw new BadRequestException(
                          $"Edit user error: UserName cannot be null!");
            }

            if (string.IsNullOrEmpty(model.RoleId))
            {
                throw new BadRequestException(
                          "Edit user error: You must provide role id!");
            }
        }
コード例 #2
0
ファイル: UserService.cs プロジェクト: gmackiewicz/Allergo
        public async Task EditUserAsync(EditUserRequestDto requestDto)
        {
            _userValidationService.ValidateEditViewModel(requestDto);

            var user = await _userManager.FindByIdAsync(requestDto.Id);

            user.Email    = requestDto.Email;
            user.UserName = requestDto.UserName;

            await _userManager.UpdateAsync(user);

            await SetRoleForUserAsync(user, requestDto.RoleId);
        }