Esempio n. 1
0
        /// <summary>
        /// Adds or removes a role for a user account.
        /// </summary>
        /// <param name="username">The user which roles should be modified.</param>
        /// <param name="rolename">The role which should be added or removed.</param>
        /// <param name="isInRole">The new role status for the user account. If false, the role will be deleted for the user account.</param>
        /// <returns></returns>
        public JsonResult AddRemoveRoleForUser(string username, string rolename, bool isInRole)
        {
            MyJsonResult result;

            try
            {
                _accountService.AddRemoveRoleForUser(username, rolename, isInRole);

                var action = isInRole ? "added" : "removed";
                var msg    = string.Format("The role {0} has been {1} for user {2}.", rolename, action, username);

                result = MyJsonResult.CreateSuccess(msg);
            }
            catch (ArgumentException ex)
            {
                result = MyJsonResult.CreateError("Could not remove role for user: " + ex.Message);
            }

            return(Json(result));
        }