public IActionResult Ban(string id) { var currentUser = GetCurrentUser(); if (id == currentUser.Id) { return(Unauthorized()); } var user = this.userService.GetUserById(id); if (user == null) { return(NotFound()); } ViewData["Message"] = user.UserName; var model = new BanBindingModel() { Id = id, LockoutEnd = DateTime.Now.Date }; return(View(model)); }
public IActionResult Ban(BanBindingModel model) { if (!ModelState.IsValid) { return(View()); } var user = this.userService.GetUserById(model.Id); if (user == null) { return(NotFound()); } bool isBaned = this.userService.IsUserBanned(user, model.LockoutEnd); if (!isBaned) { this.TempData.Put("__Message", new MessageModel() { Type = MessageType.Warning, Message = WebConstants.UnsuccesfullBan }); } this.TempData.Put("__Message", new MessageModel() { Type = MessageType.Success, Message = WebConstants.SuccessfulBan }); return(RedirectToAction("/")); }
public async Task <IHttpActionResult> Ban(BanBindingModel banModel) { ApplicationUser user = await UserManager.FindByIdAsync(banModel.Id); if (user == null) { return(NotFound()); } DateTimeOffset FineBan = DateTimeOffset.Now; FineBan = FineBan.AddDays(banModel.BanDays); IdentityResult result = await UserManager.SetLockoutEnabledAsync(user.Id, true); result = await UserManager.SetLockoutEndDateAsync(user.Id, FineBan); if (!result.Succeeded) { return(GetErrorResult(result)); } return(Ok()); }