Exemplo n.º 1
0
        public async Task <IActionResult> LockUser(string UserName, DateTimeOffset?timeOut = null)
        {
            var user = await UserManagerAgent.FindByNameAsync(UserName).ConfigureAwait(false);

            if (!await UserManagerAgent.IsLockedOutAsync(user).ConfigureAwait(false))
            {
                var result = await UserManagerAgent.SetLockoutEnabledAsync(user, true).ConfigureAwait(false);

                if (result.Succeeded)
                {
                    if (timeOut.HasValue)
                    {
                        await UserManagerAgent.SetLockoutEndDateAsync(user, timeOut).ConfigureAwait(false);
                    }
                    else
                    {
                        await UserManagerAgent.SetLockoutEndDateAsync(user, DateTimeOffset.MaxValue).ConfigureAwait(false);
                    }
                }
            }

            return(RedirectToAction("Index", "Admin", new { id = "users" }));
        }