Ejemplo n.º 1
0
        public async Task <UserDTO> UpdateUser(UserUpdateDTO userDto)
        {
            var userToUpdate = await _userRepo.GetAsync(userDto.DodId);

            var currentUserDodId = GetCurrentUserId();

            if (userToUpdate == null)
            {
                throw new ArgumentException("User account does not exist");
            }

            var oldUser = new User(userToUpdate);

            _domainMapper.GetMapper <UserUpdateDTO, User>(userDto, userToUpdate).Map();
            if (currentUserDodId == userToUpdate.DodId)
            {
                _userDomainService.UpdateUser(userToUpdate, oldUser);
            }
            else
            {
                await _userDomainService.AdminUpdateUser(currentUserDodId, userToUpdate, oldUser);
            }

            await _userRepo.SaveAsync();

            return(_autoMapper.Map <UserDTO>(userToUpdate));
        }