public async Task <ActionResult> RemoveBan(int id) { // get ban name for selected subverse var banToBeRemoved = await _db.SubverseBan.FindAsync(id); if (banToBeRemoved == null) { return(HybridError(ErrorViewModel.GetErrorViewModel(ErrorType.NotFound))); //return new HttpStatusCodeResult(HttpStatusCode.BadRequest); } else { var cmd = new SubverseBanCommand(banToBeRemoved.UserName, banToBeRemoved.Subverse, null, false).SetUserContext(User); var response = await cmd.Execute(); if (response.Success) { return(RedirectToAction("SubverseBans")); } else { ModelState.AddModelError(String.Empty, response.Message); ViewBag.SelectedSubverse = string.Empty; ViewBag.SubverseName = banToBeRemoved.Subverse; SetNavigationViewModel(banToBeRemoved.Subverse); return(View("~/Views/Subverses/Admin/RemoveBan.cshtml", banToBeRemoved)); } } }
public async Task <ActionResult> AddBan([Bind("Id,Subverse,UserName,Reason")] SubverseBan subverseBan) { if (!ModelState.IsValid) { return(View(subverseBan)); } //check perms if (!ModeratorPermission.HasPermission(User, subverseBan.Subverse, Domain.Models.ModeratorAction.Banning)) { return(RedirectToAction("Index", "Home")); } var cmd = new SubverseBanCommand(subverseBan.UserName, subverseBan.Subverse, subverseBan.Reason, true).SetUserContext(User); var result = await cmd.Execute(); if (result.Success) { return(RedirectToAction("SubverseBans")); } else { ModelState.AddModelError(string.Empty, result.Message); ViewBag.SubverseName = subverseBan.Subverse; ViewBag.SelectedSubverse = string.Empty; SetNavigationViewModel(subverseBan.Subverse); return(View("~/Views/Subverses/Admin/AddBan.cshtml", new SubverseBanViewModel { UserName = subverseBan.UserName, Reason = subverseBan.Reason })); } }