示例#1
0
    /// <summary>
    /// Creates page template scope. Called when the "Create scope" button is pressed.
    /// </summary>
    private bool CreatePageTemplateScope()
    {
        // Get template object
        PageTemplateInfo template = PageTemplateInfoProvider.GetPageTemplateInfo("MyNewTemplate");

        // If template exists
        if (template != null)
        {
            // Page template isn't from all pages
            template.PageTemplateForAllPages = false;

            // Create new template scope
            PageTemplateScopeInfo newScope = new PageTemplateScopeInfo();

            // Set some properties
            newScope.PageTemplateScopeTemplateID = template.PageTemplateId;
            newScope.PageTemplateScopeSiteID     = CMSContext.CurrentSiteID;
            newScope.PageTemplateScopePath       = "/";
            newScope.PageTemplateScopeLevels     = "/{0}/{1}";

            // Save scope to database
            PageTemplateScopeInfoProvider.SetPageTemplateScopeInfo(newScope);

            // Update page template
            PageTemplateInfoProvider.SetPageTemplateInfo(template);

            return(true);
        }

        return(false);
    }
示例#2
0
    /// <summary>
    /// Button OK click event.
    /// </summary>
    /// <param name="sender">Sender</param>
    /// <param name="e">Arguments</param>
    protected void btnOk_Click(object sender, EventArgs e)
    {
        // Validation
        string path = ValidationHelper.GetString(pathElem.Value, "");

        if (string.IsNullOrEmpty(path))
        {
            lblError.Visible        = true;
            lblError.ResourceString = "template.scopes.emptypath";
            return;
        }

        // Get scope if needed
        if (scopeID > 0)
        {
            if (ptsi == null)
            {
                ptsi = PageTemplateScopeInfoProvider.GetPageTemplateScopeInfo(scopeID);
            }
        }

        // Create info if needed
        if (ptsi == null)
        {
            ptsi = new PageTemplateScopeInfo();
        }

        // Update database

        // Class
        int classID = ValidationHelper.GetInteger(classElem.Value, 0);

        // No class selected or selected '(all)'
        if (classID <= 0)
        {
            ptsi.SetValue("PageTemplateScopeClassID", null);
        }
        else
        {
            ptsi.PageTemplateScopeClassID = classID;
        }

        // Culture
        int cultureID = ValidationHelper.GetInteger(cultureElem.Value, 0);

        if (cultureID == 0)
        {
            ptsi.SetValue("PageTemplateScopeCultureID", null);
        }
        else
        {
            ptsi.PageTemplateScopeCultureID = cultureID;
        }

        // Levels
        string levels = ValidationHelper.GetString(levelElem.Value, "");

        if (string.IsNullOrEmpty(levels))
        {
            ptsi.SetValue("PageTemplateScopeLevels", null);
        }
        else
        {
            ptsi.PageTemplateScopeLevels = levels;
        }

        // Other columns
        ptsi.PageTemplateScopePath       = ValidationHelper.GetString(pathElem.Value, "");
        ptsi.PageTemplateScopeTemplateID = templateID;

        if (ptsi.PageTemplateScopeID == 0)
        {
            // Site
            if (siteID != 0)
            {
                ptsi.PageTemplateScopeSiteID = siteID;
            }
        }

        // Insert or update
        PageTemplateScopeInfoProvider.SetPageTemplateScopeInfo(ptsi);

        // Redirect
        string url = URLHelper.CurrentURL;

        url = URLHelper.UpdateParameterInUrl(url, "scopeid", ptsi.PageTemplateScopeID.ToString());
        url = URLHelper.AddParameterToUrl(url, "saved", "1");
        URLHelper.Redirect(ResolveUrl(url));
    }