diff --git a/BulkyWeb/Areas/Admin/Controllers/UserController.cs b/BulkyWeb/Areas/Admin/Controllers/UserController.cs index dba3508..2e13e83 100644 --- a/BulkyWeb/Areas/Admin/Controllers/UserController.cs +++ b/BulkyWeb/Areas/Admin/Controllers/UserController.cs @@ -21,6 +21,29 @@ public IActionResult Index() return View(); } + [HttpPost] + public IActionResult LockUnlock([FromBody] string id) + { + var objFromDb = _db.ApplicationUsers.FirstOrDefault(u => u.Id == id); + if (objFromDb == null) + { + return Json(new { success = false, message = "Error while Locking/Unlocking" }); + } + + if (objFromDb.LockoutEnd != null && objFromDb.LockoutEnd > DateTime.Now) + { + // User is currently locked, we will unlock them + objFromDb.LockoutEnd = DateTime.Now; + } + else + { + objFromDb.LockoutEnd = DateTime.Now.AddYears(1000); + } + + _db.SaveChanges(); + return Json(new { success = true, message = "Operation Successful" }); + } + #region API CALLS [HttpGet] public IActionResult GetAll() diff --git a/BulkyWeb/Views/Shared/_Layout.cshtml b/BulkyWeb/Views/Shared/_Layout.cshtml index 9ed7e9a..5b4c373 100644 --- a/BulkyWeb/Views/Shared/_Layout.cshtml +++ b/BulkyWeb/Views/Shared/_Layout.cshtml @@ -33,9 +33,6 @@