Exemple #1
0
        public async Task <UserPatchDTO> PatchUser(string id, UserPatchDTO userPatchDTO)
        {
            if (userPatchDTO == null)
            {
                throw new ArgumentNullException(nameof(userPatchDTO));
            }

            try
            {
                User user = await _userManager.FindByIdAsync(id).ConfigureAwait(false);

                _ = await _userManager.ChangePasswordAsync(user, userPatchDTO.CurrentPassword, userPatchDTO.NewPassword).ConfigureAwait(false);
            }
            catch (DbUpdateConcurrencyException)
            {
                if (await UserExists(id).ConfigureAwait(false) == false)
                {
                    return(null);
                }
                else
                {
                    throw;
                }
            }

            return(userPatchDTO);
        }
        public void UpdateUserDisabled_WhenCalledWithNullID_ThrowsParameterException()
        {
            string id     = null;
            var    usrDTO = new UserPatchDTO {
                ID = id, Disabled = true
            };

            Assert.Throws <ParameterException>(() => _userService.UpdateUserDisabled(usrDTO));
        }
 public void UpdateUserDisabled(UserPatchDTO user)
 {
     if (user == null)
     {
         throw new ParameterException("Patch object cannot be null.");
     }
     if (user.ID == null || !Guid.TryParse(user.ID, out Guid res))
     {
         throw new ParameterException("User patch properties is in bad format.");
     }
     _userRepository.UpdateUserDisabledPropertyByUserId(user.ID, user.Disabled);
 }
        public async Task <ActionResult> Patch([FromRoute] string email, UserPatchDTO userPatch)
        {
            var storedUser = await _userRepositary.FindByEmail(email);

            if (storedUser == null)
            {
                return(NotFound());
            }

            if (!await UserCanAccessProfile(storedUser))
            {
                return(Forbid());
            }

            _mapper.Map(userPatch, storedUser);

            await _userRepositary.Update(storedUser);

            return(NoContent());
        }
Exemple #5
0
        public async Task <IActionResult> PatchUser(string id, UserPatchDTO userPatchDTO)
        {
            if (userPatchDTO == null)
            {
                throw new ArgumentNullException(nameof(userPatchDTO));
            }

            if (id != userPatchDTO.Id)
            {
                return(BadRequest());
            }

            var userResult = await _userRepository.PatchUser(id, userPatchDTO).ConfigureAwait(false);

            if (userResult == null)
            {
                return(NotFound());
            }

            return(NoContent());
        }
Exemple #6
0
        public async Task UpdateAsync(long id, UserPatchDTO userPatchDTO)
        {
            if (id != userPatchDTO.Id)
            {
                throw new ValidationException("Идентификаторы должны совпадать");
            }

            var user = await _userManager.FindByIdAsync(userPatchDTO.Id.ToString());

            if (user == null)
            {
                throw new NotFoundException("Пользователь не найден");
            }

            if (!await UserHasAccessToUser(await _userManager.GetUserAsync(User), user))
            {
                throw new ValidationException("Ошибка доступа");
            }

            user.FirstName = userPatchDTO.FirstName;
            user.LastName  = userPatchDTO.LastName;

            var result = await _userManager.SetEmailAsync(user, userPatchDTO.Email);

            if (!result.Succeeded)
            {
                throw new ValidationException("Данный эл.адрес уже занят");
            }

            result = await _userManager.SetUserNameAsync(user, userPatchDTO.Email);

            if (!result.Succeeded)
            {
                throw new ValidationException("Данный эл.адрес уже занят");
            }

            var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);

            await _userManager.ConfirmEmailAsync(user, code);
        }
Exemple #7
0
 public IActionResult UpdateUserDisabled(string id, [FromBody] UserPatchDTO user)
 {
     _userService.UpdateUserDisabled(user);
     return(Ok());
 }
        public void UpdateUserDisabled_WhenCalledWithNullObject_ThrowsParameterException()
        {
            UserPatchDTO usrDTO = null;

            Assert.Throws <ParameterException>(() => _userService.UpdateUserDisabled(usrDTO));
        }
Exemple #9
0
        public async Task <ActionResult> UpdateUser(long id, [FromBody] UserPatchDTO userPatchDTO)
        {
            await _bll.Identity.UpdateAsync(id, userPatchDTO);

            return(Ok());
        }