Пример #1
0
        public async Task UpdateAsync(MofidyUserCommingFromClientDto userParam)
        {
            var user = _context.Users.Find(userParam.Id);

            if (user == null)
            {
                throw new AppException("User not found");
            }

            if (userParam.UserName != user.UserName)
            {
                // username has changed so check if the new username is already taken
                if (_context.Users.Any(x => x.UserName == userParam.UserName))
                {
                    throw new AppException("El usuario " + userParam.UserName + " ya existe en la db.");
                }
            }

            // update user properties
            user.Dni         = userParam.Dni;
            user.UserName    = userParam.UserName;
            user.Email       = userParam.UserName;
            user.PhoneNumber = userParam.PhoneNumber;

            //actualizo los roles del usuario
            foreach (var role in userParam.RolesUser)
            {
                await UpdateUserRoleWhenModify(user.Id, role.Id, role.RolBelongUser);
            }


            // update password if it was entered
            if (!string.IsNullOrWhiteSpace(userParam.Password))
            {
                user.PasswordHash = _userManager.PasswordHasher.HashPassword(user, userParam.Password);
            }

            _context.Users.Update(user);
            _context.SaveChanges();
        }
Пример #2
0
        public async Task <IActionResult> Update([FromBody] MofidyUserCommingFromClientDto userDto)
        {
            await _userService.UpdateAsync(userDto);

            return(Ok());
        }