public async Task<ActionResult> DisableUser(string userName)
        {

   
            List<string> users;
            List<string> enabledUsers;
            List<string> disabledUsers;
            using (var context = new ApplicationDbContext())
            {

                var userStore = new UserStore<ApplicationUser>(context);
                var userManager = new UserManager<ApplicationUser>(userStore);

                var selectedUser = userManager.FindByName(userName);

                if (selectedUser == null)
                    throw new Exception("User not found!");

                if (!selectedUser.UserName.Equals("[email protected]"))
                {


                    if (!selectedUser.LockoutEnabled)
                    {
                        userManager.SetLockoutEnabled(selectedUser.Id, true);
                        DateTime lockoutDate = DateTime.Now.AddYears(50);
                        await userManager.SetLockoutEndDateAsync(selectedUser.Id, lockoutDate);
                        context.SaveChanges();
                        userManager.Update(selectedUser);
                        ViewBag.ResultMessage = "Disabled successfully !";

                    }
                }
                else
                {
                    ViewBag.ResultMessage = "Cannot disable Admin";
                }

                users = (from u in userManager.Users select u.UserName).ToList();
                disabledUsers = new List<string>(users);
                enabledUsers = new List<string>(users);
                foreach (var user in users)
                {
                    if (!userManager.FindByName(user).LockoutEnabled)
                    {
                        disabledUsers.Remove(user);
                    }
                    else
                    {
                        enabledUsers.Remove(user);
                    }
                }
            }

            ViewBag.EnabledUsers = new SelectList(enabledUsers);
            ViewBag.DisabledUsers = new SelectList(disabledUsers);
            return View();
        }
        public void LockoutEnabled()
        {
            using (UserStore<IdentityUser> store = new UserStore<IdentityUser>())
            {
                using (UserManager<IdentityUser> manager = new UserManager<IdentityUser>(store))
                {
                    manager.UserTokenProvider = new EmailTokenProvider<IdentityUser>();

                    var user = User;

                    var taskLockoutSet = manager.SetLockoutEnabledAsync(user.Id, true);
                    taskLockoutSet.Wait();
                    Assert.IsTrue(taskLockoutSet.Result.Succeeded, string.Concat(taskLockoutSet.Result.Errors));

                    DateTimeOffset offSet = new DateTimeOffset(DateTime.UtcNow.AddMinutes(3));
                    var taskDateSet = manager.SetLockoutEndDateAsync(user.Id, offSet);
                    taskDateSet.Wait();
                    Assert.IsTrue(taskDateSet.Result.Succeeded, string.Concat(taskDateSet.Result.Errors));

                    var taskEnabledGet = manager.GetLockoutEnabledAsync(user.Id);
                    taskEnabledGet.Wait();
                    Assert.IsTrue(taskEnabledGet.Result, "Lockout not true");

                    var taskDateGet = manager.GetLockoutEndDateAsync(user.Id);
                    taskDateGet.Wait();
                    Assert.AreEqual(offSet,taskDateGet.Result, "Lockout date incorrect");

                    DateTime tmpDate = DateTime.UtcNow.AddDays(1);
                    user.LockoutEndDateUtc = tmpDate;
                    var taskGet = store.GetLockoutEndDateAsync(user);
                    taskGet.Wait();
                    Assert.AreEqual<DateTimeOffset>(new DateTimeOffset(tmpDate), taskGet.Result, "LockoutEndDate not set");

                    user.LockoutEndDateUtc = null;
                    var taskGet2 = store.GetLockoutEndDateAsync(user);
                    taskGet2.Wait();
                    Assert.AreEqual<DateTimeOffset>(new DateTimeOffset(), taskGet2.Result, "LockoutEndDate not set");

                    var minOffSet = DateTimeOffset.MinValue;
                    var taskSet2 = store.SetLockoutEndDateAsync(user, minOffSet);
                    taskSet2.Wait();
                    Assert.IsNull(user.LockoutEndDateUtc, "LockoutEndDate not null");

                    try
                    {
                        store.GetLockoutEnabledAsync(null);
                    }
                    catch (ArgumentException) { }

                    try
                    {
                        store.GetLockoutEndDateAsync(null);
                    }
                    catch (ArgumentException) { }

                    try
                    {
                        store.SetLockoutEndDateAsync(null, offSet);
                    }
                    catch (ArgumentException) { }

                    try
                    {
                        store.SetLockoutEnabledAsync(null, false);
                    }
                    catch (ArgumentException) { }
                }
            }
        }
 public async Task<JsonResult> BanUser(ManageUserViewModel model)
 {
     var context = new PhotoContestDbContext();
     var store = new UserStore<User>(context);
     var manager = new UserManager<User>(store);
     await manager.SetLockoutEnabledAsync(model.Id, true);
     await manager.SetLockoutEndDateAsync(model.Id, DateTime.Now.AddDays(14));
     return this.Json(
         string.Format("Successfully locked user {0}", model.UserName),
         JsonRequestBehavior.AllowGet);
 }