コード例 #1
0
        public async Task<ActionResult> Index(string username) 
        { 
            var user = await UserManager.FindByNameAsync(HttpUtility.UrlDecode(username));

            //var user = await  this.UserManager.FindByNameAsync(username);
            var viewModel = new UserViewModel
            {
                Username = user.UserName,
                Email = user.Email,
                Roles = user.Roles,
                LockedOut = user.LockoutEnabled,
                LockedOutEndDate = user.LockoutEndDate
            };

            return View(viewModel);
        }
コード例 #2
0
        public async Task<ActionResult> Index(UserViewModel userViewModel)
        {
            if (ModelState.IsValid)
            {
                var user = await UserManager.FindByNameAsync(HttpUtility.UrlDecode(userViewModel.Username));
                if (user != null)
                {
                    await UserManager.SetLockoutEnabledAsync(user.Id, userViewModel.LockedOut);

                    return RedirectToAction("List", "Users");
                }
                else
                { 
                    ModelState.AddModelError("", "User was not found.");
                }
            }
            return View(userViewModel);
        }