Exemplo n.º 1
0
        public ActionResult CheckForUniqueUser(string userName)
        {
            var user = _userService.GetUserByUserName(userName);
            var response = new JsonResponse {Exists = (user != null)};

            return Json(response, JsonRequestBehavior.AllowGet);
        }
Exemplo n.º 2
0
        public ActionResult ApproveDeny(string userName)
        {
            var response = new JsonResponse();

            var user = _userService.GetUserByUserName(userName);

            try
            {
                user.IsApproved = !user.IsApproved;
                _userService.UpdateUser(user);

                var approvedMsg = (user.IsApproved) ? "Approved" : "Denied";

                response.Success = true;
                response.Message = "User " + approvedMsg + " successfully!";
                response.Approved = user.IsApproved;
                response.ApprovedStatus = (user.IsApproved) ? "Approved" : "Not approved";
            }
            catch (Exception)
            {
                response.Success = false;
                response.Message = "User unlocked failed.";
            }

            return Json(response);
        }
Exemplo n.º 3
0
        public virtual ActionResult CreateRole(string roleName)
        {
            var response = new JsonResponse();

            if (string.IsNullOrEmpty(roleName))
            {
                response.Success = false;
                response.Message = "You must enter a role name.";
                response.CssClass = "red";

                return Json(response);
            }

            try
            {
                _roleServiceExtended.CreateRole(roleName);

                if (Request.IsAjaxRequest())
                {
                    response.Success = true;
                    response.Message = "Role created successfully!";
                    response.CssClass = "green";

                    return Json(response);
                }

                return RedirectToAction("Index");
            }
            catch (Exception ex)
            {
                if (Request.IsAjaxRequest())
                {
                    response.Success = false;
                    response.Message = ex.Message;
                    response.CssClass = "red";

                    return Json(response);
                }

                ModelState.AddModelError("", ex.Message);
            }

            return RedirectToAction("Index");
        }
Exemplo n.º 4
0
        public virtual ActionResult DeleteRole(string roleName)
        {
            var response = new JsonResponse();

            if (string.IsNullOrEmpty(roleName))
            {
                response.Success = false;
                response.Message = "You must select a Role Name to delete.";
                response.CssClass = "red";

                return Json(response);
            }

            _roleServiceExtended.DeleteRole(roleName);

            response.Success = true;
            response.Message = roleName + " was deleted successfully!";
            response.CssClass = "green";

            return Json(response);
        }
Exemplo n.º 5
0
        public ActionResult DeleteRoles(string roles, bool throwOnPopulatedRole)
        {
            var response = new JsonResponse();
            response.Messages = new List<ResponseItem>();

            if (string.IsNullOrEmpty(roles))
            {
                response.Success = false;
                response.Message = "You must select at least one role.";
                return Json(response);
            }

            var roleNames = roles.Split(',');
            var sb = new StringBuilder();

            var validRoleNames = roleNames.Where(role => !string.IsNullOrEmpty(role));
            foreach (var role in validRoleNames)
            {
                ResponseItem item;
                try
                {
                    _roleServiceExtended.DeleteRole(role, throwOnPopulatedRole);

                    item = new ResponseItem
                           {Success = true, Message = "Deleted this role successfully - " + role, CssClass = "green"};
                    response.Messages.Add(item);

                    //sb.AppendLine("Deleted this role successfully - " + role + "<br />");
                }
                catch (ProviderException ex)
                {
                    //sb.AppendLine(role + " - " + ex.Message + "<br />");

                    item = new ResponseItem {Success = false, Message = ex.Message, CssClass = "yellow"};
                    response.Messages.Add(item);
                }
            }

            response.Success = true;
            response.Message = sb.ToString();

            return Json(response);
        }
Exemplo n.º 6
0
        public ActionResult Unlock(string userName)
        {
            var response = new JsonResponse();

            var user = _userService.GetUserByUserName(userName);

            try
            {
                //user.UnlockUser();
                response.Success = true;
                response.Message = "User unlocked successfully!";
                response.Locked = false;
                response.LockedStatus = (response.Locked) ? "Locked" : "Unlocked";
            }
            catch (Exception)
            {
                response.Success = false;
                response.Message = "User unlocked failed.";
            }

            return Json(response);
        }
Exemplo n.º 7
0
        public ActionResult RevokeRolesForUser(string userName, string roles)
        {
            var response = new JsonResponse();

            if (string.IsNullOrEmpty(userName))
            {
                response.Success = false;
                response.Message = "The userName is missing.";
                return Json(response);
            }

            if (string.IsNullOrEmpty(roles))
            {
                response.Success = false;
                response.Message = "Roles is missing";
                return Json(response);
            }

            var roleNames = roles.Substring(0, roles.Length - 1).Split(',');

            if (roleNames.Length == 0)
            {
                response.Success = false;
                response.Message = "No roles are selected to be revoked.";
                return Json(response);
            }

            try
            {
                _roleServiceExtended.RemoveUsersFromRoles(new[] {userName}, roleNames);

                response.Success = true;
                response.Message = "The Role(s) has been REVOKED successfully for " + userName;
            }
            catch (Exception)
            {
                response.Success = false;
                response.Message = "There was a problem revoking roles for the user.";
            }

            return Json(response);
        }
Exemplo n.º 8
0
        public virtual ActionResult GrantRolesToUser(string userName, string roles)
        {
            var response = new JsonResponse();

            if (string.IsNullOrEmpty(userName))
            {
                response.Success = false;
                response.Message = "The userName is missing.";
                return Json(response);
            }

            var roleNames = roles.Substring(0, roles.Length - 1).Split(',');

            if (roleNames.Length == 0)
            {
                response.Success = false;
                response.Message = "No roles have been granted to the user.";
                return Json(response);
            }

            try
            {
                _roleServiceExtended.AddUsersToRoles(new[] {userName}, roleNames);

                response.Success = true;
                response.Message = "The Role(s) has been GRANTED successfully to " + userName;
            }
            catch (Exception)
            {
                response.Success = false;
                response.Message = "There was a problem adding the user to the roles.";
            }

            return Json(response);
        }