예제 #1
0
    /// <summary>
    /// Handles the UniGrid's OnAction event.
    /// </summary>
    /// <param name="actionName">Name of item (button) that throws event</param>
    /// <param name="actionArgument">ID (value of Primary key) of corresponding data row</param>
    protected void uniGrid_OnAction(string actionName, object actionArgument)
    {
        switch (actionName.ToLower())
        {
        case "edit":
            URLHelper.Redirect("Newsletter_Frameset.aspx?newsletterid=" + Convert.ToString(actionArgument));
            break;

        case "delete":
            if (!CMSContext.CurrentUser.IsAuthorizedPerResource("cms.newsletter", "configure"))
            {
                RedirectToCMSDeskAccessDenied("cms.newsletter", "configure");
            }
            // delete Newsletter object from database
            NewsletterProvider.DeleteNewsletter(ValidationHelper.GetInteger(actionArgument, 0));
            break;

        case "clone":
            if (!CMSContext.CurrentUser.IsAuthorizedPerResource("cms.newsletter", "configure"))
            {
                RedirectToCMSDeskAccessDenied("cms.newsletter", "configure");
            }

            Newsletter oldnl = NewsletterProvider.GetNewsletter(ValidationHelper.GetInteger(actionArgument, 0));
            if (oldnl != null)
            {
                // Create new newsletter
                Newsletter nl = oldnl.Clone(true);

                // Find unique newsletter code name
                string newsletterDisplayName = nl.NewsletterDisplayName;
                string newsletterName        = nl.NewsletterName;

                while (NewsletterProvider.GetNewsletter(newsletterName, nl.NewsletterSiteID) != null)
                {
                    newsletterName        = Increment(newsletterName, "_", "");
                    newsletterDisplayName = Increment(newsletterDisplayName, "(", ")");
                }

                nl.NewsletterName        = newsletterName;
                nl.NewsletterDisplayName = newsletterDisplayName;

                if (NewsletterProvider.LicenseVersionCheck(CMSContext.CurrentSite.DomainName, FeatureEnum.Newsletters, VersionActionEnum.Insert))
                {
                    // Clone scheduled task
                    if (oldnl.NewsletterDynamicScheduledTaskID > 0)
                    {
                        TaskInfo oldti = TaskInfoProvider.GetTaskInfo(oldnl.NewsletterDynamicScheduledTaskID);
                        if (oldti != null)
                        {
                            // Create new task
                            TaskInfo ti = oldti.Clone(true);

                            ti.TaskDisplayName = GetString("DynamicNewsletter.TaskName") + nl.NewsletterDisplayName;

                            // Save the task
                            TaskInfoProvider.SetTaskInfo(ti);

                            nl.NewsletterDynamicScheduledTaskID = ti.TaskID;
                        }
                    }

                    NewsletterProvider.SetNewsletter(nl);
                }
                else
                {
                    lblError.Visible = true;
                    lblError.Text    = GetString("licenseversioncheck.newsletterclone");
                }
            }
            break;
        }
    }