예제 #1
0
        /// <summary>
        /// Create user-role relationship.
        /// </summary>
        /// <param name="userId">User to add to role</param>
        /// <param name="roleId">Role to assign</param>
        /// <returns>ID of added user-role relationship</returns>
        public long?AddUserToRole(long userId, long roleId)
        {
            if ((userId > 0) && (roleId > 0))
            {
                try
                {
                    var userRole = new UserRoleBinding {
                        UserId = userId, RoleId = roleId
                    };

                    // Send REST request
                    var response = Provider.MakeRequest(BaseUrl + "/rest/cms.userrole", HttpVerb.Post, null, userRole.ToString());
                    var id       = Convert.ToInt64(RestHelper.GetAttributeFromReponse(response, userRole.IdTagName));

                    LogMessage("User " + userId + " has been added to role " + roleId + ".");

                    if (OnSuccess != null)
                    {
                        OnSuccess();
                    }

                    return(id);
                }
                catch (Exception ex)
                {
                    LogError("Adding user " + userId + " to role " + roleId + " failed.", ex);
                }
            }

            return(null);
        }
예제 #2
0
        /// <summary>
        /// Create user-role relationship.
        /// </summary>
        /// <param name="userId">User to add to role</param>
        /// <param name="roleId">Role to assign</param>
        /// <returns>ID of added user-role relationship</returns>
        public long? AddUserToRole(long userId, long roleId)
        {
            if ((userId > 0) && (roleId > 0))
            {
                try
                {
                    var userRole = new UserRoleBinding { UserId = userId, RoleId = roleId };

                    // Send REST request
                    var response = Provider.MakeRequest(BaseUrl + "/rest/cms.userrole", HttpVerb.Post, null, userRole.ToString());
                    var id = Convert.ToInt64(RestHelper.GetAttributeFromReponse(response, userRole.IdTagName));

                    LogMessage("User " + userId + " has been added to role " + roleId + ".");

                    if (OnSuccess != null)
                    {
                        OnSuccess();
                    }

                    return id;

                }
                catch (Exception ex)
                {
                    LogError("Adding user " + userId + " to role " + roleId + " failed.", ex);
                }
            }

            return null;
        }