コード例 #1
0
        /// <summary>
        /// Modify existing role.
        /// </summary>
        /// <param name="role">Role to modify</param>
        public long?ModifyRole(Role role)
        {
            if (role != null)
            {
                try
                {
                    if (!RoleExists(role.Id))
                    {
                        LogMessage("Role " + role.CodeName + " was not modified because it doesn't exists.");
                    }
                    else
                    {
                        // Send REST request
                        var response = Provider.MakeRequest(BaseUrl + "/rest/cms.role/" + role.Id, HttpVerb.Put,
                                                            null, role.ToString());

                        var newId = Convert.ToInt64(RestHelper.GetAttributeFromReponse(response, role.IdTagName));

                        LogMessage("Role " + role.CodeName + " has been modified.");

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

                        return(newId);
                    }
                }
                catch (Exception ex)
                {
                    LogError("Modifying role " + role.CodeName + " failed.", ex);
                }
            }

            return(null);
        }
コード例 #2
0
        /// <summary>
        /// Add role to CMS.
        /// </summary>
        /// <param name="role">Role to add</param>
        /// <returns>ID of added role</returns>
        public long?AddRole(Role role)
        {
            if (role != null)
            {
                try
                {
                    if (RoleExists(role.Id))
                    {
                        LogMessage("Role " + role.CodeName + " was not added because it already exists.");
                    }
                    else
                    {
                        // Send REST request
                        var response = Provider.MakeRequest(BaseUrl + "/rest/cms.role", HttpVerb.Post, null,
                                                            role.ToString());

                        var id = Convert.ToInt64(RestHelper.GetAttributeFromReponse(response, role.IdTagName));

                        LogMessage("Role " + role.CodeName + " has been added.");

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

                        return(id);
                    }
                }
                catch (Exception ex)
                {
                    LogError("Adding role " + role.CodeName + " failed.", ex);
                }
            }

            return(null);
        }
コード例 #3
0
ファイル: RestSender.cs プロジェクト: Kentico/ADImportService
        /// <summary>
        /// Add role to CMS.
        /// </summary>
        /// <param name="role">Role to add</param>
        /// <returns>ID of added role</returns>
        public long? AddRole(Role role)
        {
            if (role != null)
            {
                try
                {
                    if (RoleExists(role.Id))
                    {
                        LogMessage("Role " + role.CodeName + " was not added because it already exists.");
                    }
                    else
                    {
                        // Send REST request
                        var response = Provider.MakeRequest(BaseUrl + "/rest/cms.role", HttpVerb.Post, null,
                            role.ToString());

                        var id = Convert.ToInt64(RestHelper.GetAttributeFromReponse(response, role.IdTagName));

                        LogMessage("Role " + role.CodeName + " has been added.");

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

                        return id;
                    }

                }
                catch (Exception ex)
                {
                    LogError("Adding role " + role.CodeName + " failed.", ex);
                }

            }

            return null;
        }
コード例 #4
0
ファイル: RestSender.cs プロジェクト: Kentico/ADImportService
        /// <summary>
        /// Modify existing role.
        /// </summary>
        /// <param name="role">Role to modify</param>
        public long? ModifyRole(Role role)
        {
            if (role != null)
            {
                try
                {
                    if (!RoleExists(role.Id))
                    {
                        LogMessage("Role " + role.CodeName + " was not modified because it doesn't exists.");
                    }
                    else
                    {
                        // Send REST request
                        var response = Provider.MakeRequest(BaseUrl + "/rest/cms.role/" + role.Id, HttpVerb.Put,
                            null, role.ToString());

                        var newId = Convert.ToInt64(RestHelper.GetAttributeFromReponse(response, role.IdTagName));

                        LogMessage("Role " + role.CodeName + " has been modified.");

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

                        return newId;
                    }
                }
                catch (Exception ex)
                {
                    LogError("Modifying role " + role.CodeName + " failed.", ex);
                }
            }

            return null;
        }