public async Task <ApplicationUserResponse> UpdateAsync([FromBody] ApplicationUserAddRequest request)
        {
            if (request.password != null && !await _userValidators.ValidatePasswordAsync(request.user, request.password))
            {
                return(GetResponse(false, _userValidators.InvalidPasswordMessage));
            }

            var user = await _applicationUsersRepository.GetByIdAsync(request.user.Id);

            if (user.UserName != request.user.UserName && !await _userValidators.ValidateUserName(request.user.UserName))
            {
                return(GetResponse(false, _userValidators.InvalidUserNameMessage));
            }

            var result = await _applicationUsersRepository.UpdateAsync(request.user);



            if (!result)
            {
                return(GetResponse(false));
            }

            if (request.password != null)
            {
                var passwordChangeResult = await _applicationUsersRepository.ChangePassword(user, request.password);

                if (!passwordChangeResult)
                {
                    return(GetResponse(false));
                }
            }

            return(GetResponse(true));
        }
Exemplo n.º 2
0
        public async Task <TenantResponse> UpdateAsync([FromBody] TenantRequest request)
        {
            if (request.password != null && !await _UserValidators.ValidatePasswordAsync(new ApplicationUser(), request.password))
            {
                return(GetResponse(false, _UserValidators.InvalidPasswordMessage));
            }

            var tenant       = request.tenant;
            var actualTenant = await _TenantsRepository.GetAsync(tenant.TenantId);

            if (actualTenant.AssociatedUsername != tenant.AssociatedUsername && !await _UserValidators.ValidateUserName(request.tenant.AssociatedUsername))
            {
                return(GetResponse(false, _UserValidators.InvalidUserNameMessage));
            }

            var associatedUser = await _ApplicationUsersRepository.GetByUserNameAsync(actualTenant.AssociatedUsername);

            if (tenant.AssociatedUsername != actualTenant.AssociatedUsername)
            {
                associatedUser.UserName = tenant.AssociatedUsername;
                await _ApplicationUsersRepository.UpdateAsync(associatedUser);
            }

            if (request.password != null)
            {
                await _ApplicationUsersRepository.ChangePassword(associatedUser, request.password);
            }

            var result = await _TenantsRepository.UpdateAsync(tenant);

            return(GetResponse(result));
        }