Base solution for your next web application
Starts in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

Can't create a new user with no Tenant system. #561


User avatar
0
mrvithan created

I try to create a new user with no Tenant in an AppService using this code :

//Create user
        var user = new User
        {
            Name            = input.Name.Trim(),
            Surname         = input.Name.Trim(),
            EmailAddress    = input.Email.Trim(),
            IsActive        = true,
            TenantId        = 1
        };


        user.UserName   = input.Code;
        user.Password   = new PasswordHasher().HashPassword(input.Password);
        user.Roles      = new List<UserRole>();
        foreach (var agentRole in _roleManager.Roles.Where(r => r.Name == StaticRoleNames.Host.Agent).ToList())
        {
            user.Roles.Add(new UserRole { RoleId = agentRole.Id });
        }

        _userManager.Create(user);

I also setup a new role called 'Agent' with Tenant = 1. There is no error but the user has not been created.

Any suggestion ?


2 Answer(s)
  • User Avatar
    0
    mrvithan created

    Ok i found the error. The email is duplicated...!!! But it should throw an exception..

  • User Avatar
    0
    hikalkan created
    Support Team

    UserManager.Create returns an IdentityResult. Have you checked it?