public async Task <IdentityResult> AddToRoleAsync(string userName, string role)
        {
            using (IServiceScope scope = this._provider.CreateScope())
            {
                DM.ApplicationUser user = await this.GetUserByNameAsync(scope, userName);

                return(await scope.ServiceProvider.GetRequiredService <UserManager <DM.ApplicationUser> >().AddToRoleAsync(user, role));
            }
        }
        public async Task <SignInResult> PasswordSignInAsync(string userName, string password, bool isPersistent = default(bool), bool lockoutOnFailure = default(bool))
        {
            using (IServiceScope scope = this._provider.CreateScope())
            {
                DM.ApplicationUser user = await this.GetUserByNameAsync(scope, userName);

                return(await scope.ServiceProvider.GetRequiredService <SignInManager <DM.ApplicationUser> >().PasswordSignInAsync(user, password, isPersistent: false, lockoutOnFailure: true));
            }
        }
 public async Task <IdentityResult> CreateAsync(dynamic user)
 {
     using (IServiceScope scope = this._provider.CreateScope())
     {
         DM.ApplicationUser applicationUser = new DM.ApplicationUser()
         {
             FirstName = user.FirstName,
             LastName  = user.LastName,
             Email     = user.Email,
             UserName  = user.UserName
         };
         return(await scope.ServiceProvider.GetRequiredService <UserManager <DM.ApplicationUser> >().CreateAsync(applicationUser, user.Password));
     }
 }
        private async Task <bool> SetEmailConfirmationAsync(Guid id, bool isConfirm)
        {
            bool isSucceeded = default(bool);

            using (IServiceScope scope = this._provider.CreateScope())
            {
                DM.ApplicationUser user = await this.GetUserByIdAsync(scope, id);

                if (user != null)
                {
                    user.EmailConfirmed = isConfirm;

                    UserManager <DM.ApplicationUser> userManager = scope.ServiceProvider.GetRequiredService <UserManager <DM.ApplicationUser> >();

                    string token = await userManager.GenerateEmailConfirmationTokenAsync(user); /*without token  EmailConfirmed can't be updated */

                    IdentityResult result = await userManager.UpdateAsync(user);                /* await userManager.ConfirmEmailAsync(user, token); */

                    isSucceeded = result.Succeeded;
                }
            }

            return(isSucceeded);
        }