public ActionResult Ban(string subName, BanUserModel model) { if (string.IsNullOrEmpty(subName)) return Redirect(Url.Subs()); var sub = _subDao.GetSubByName(subName); if (sub == null) throw new HttpException(404, "sub not found"); if (!_permissionDao.CanUserManageSubAccess(_userContext.CurrentUser, sub.Id)) throw new HttpException(403, "not allowed to moderate bans"); var response = _commandBus.Send<BanUserFromSub, BanUserFromSubResponse>(new BanUserFromSub { UserName = model.UserName, BannedBy = _userContext.CurrentUser.Id, SubId = sub.Id, DateBanned = Common.CurrentTime(), ReasonPrivate = model.ReasonPrivate, ReasonPublic = model.ReasonPublic }); return CommonJsonResult(response.Error); }
public ActionResult Ban(string subName, BanUserModel model) { if (string.IsNullOrEmpty(subName)) return Redirect(Url.Subs()); var sub = _subDao.GetSubByName(subName); if (sub == null) throw new HttpException(404, "sub not found"); if (!_permissionDao.CanUserModerateSub(_userContext.CurrentUser.Id, sub.Id)) throw new HttpException(403, "not allowed to moderate bans"); try { var response = _commandBus.Send<BanUserFromSub, BanUserFromSubResponse>(new BanUserFromSub { UserName = model.UserName, BannedBy = _userContext.CurrentUser.Id, SubId = sub.Id, DateBanned = Common.CurrentTime(), BannedUntil = model.BannedUntil, ReasonPrivate = model.ReasonPrivate, ReasonPublic = model.ReasonPublic }); if (!string.IsNullOrEmpty(response.Error)) { return Json(new { success = false, error = response.Error }); } return Json(new { success = true, error = (string)null }); } catch (Exception ex) { // TODO: log error return Json(new { success = false, error = "An unexpected error has occured." }); } }