public async Task UpdateAsync(Guid Id, UpdateUser command) { Core.Domain.User existUser = await _userRepository.GetAsync(Id); if (existUser == null) { throw new Exception($"Exception with id: '{Id}' does not exists"); } if (existUser.Password != command.OldPassword.Hash()) { throw new Exception("Exception password: The old password is incorrect"); } Core.Domain.User user = await _userRepository.GetAsync(command.Email); if (user != null && user != existUser) { throw new Exception($"Exception with e-mail: '{command.Email}' already exists"); } user = await _userRepository.GetByPhoneAsync(command.PhoneNumber); if (user != null && user != existUser) { throw new Exception($"Exception with this phone number: '{command.PhoneNumber}' already exists"); } if (command.FirstName != null) { existUser.SetFirstName(command.FirstName); } if (command.LastName != null) { existUser.SetLastName(command.LastName); } if (command.PhoneNumber != null) { existUser.SetPhoneNumber(command.PhoneNumber); } if (command.Email != null) { existUser.SetEmail(command.Email); } if (command.Password != null) { existUser.SetPassword(command.Password.Hash()); } await _userRepository.UpdateAsync(existUser); }