Exemple #1
0
        public ActionResult ChangeUserAccess(string name)
        {
            if (name == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            var targetUser = _userManagerService.FindByName(name);

            if (targetUser == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.NotFound));
            }
            var isUserPerformingActionModerator = _userManagerService.IsInRole(User.Identity.GetUserId(), "Moderator");
            var isTargetUserModerator           = _userManagerService.IsInRole(targetUser.Id, "Moderator");

            if (!User.IsInRole("Administrator") && (!isUserPerformingActionModerator || isTargetUserModerator))
            {
                return(UserManagement());
            }
            if (targetUser.IsBanned)
            {
                _userManagerService.UnbanUser(targetUser.Id);
            }
            else
            {
                _userManagerService.BanUser(targetUser.Id);
            }
            return(UserManagement());
        }