/// <summary>
    /// Handles delete action.
    /// </summary>
    /// <param name="eventArgument">Objecttype(item or itemcategory);objectid</param>
    public void RaisePostBackEvent(string eventArgument)
    {
        string[] values = eventArgument.Split(';');
        if (values.Length == 3)
        {
            int      id       = ValidationHelper.GetInteger(values[1], 0);
            int      parentId = ValidationHelper.GetInteger(values[2], 0);
            BaseInfo biParent = BaseAbstractInfoProvider.GetInfoById(categoryObjectType, parentId);

            if (biParent == null)
            {
                return;
            }

            String categoryPath = ValidationHelper.GetString(biParent.GetValue(categoryPathColumn), String.Empty);
            int    parentID     = ValidationHelper.GetInteger(biParent.GetValue(categoryParentColumn), 0);

            //Test permission
            if (!MembershipContext.AuthenticatedUser.IsAuthorizedPerResource(ResourceName, "Modify"))
            {
                String url = CMSPage.GetAccessDeniedUrl(UIHelper.ACCESSDENIED_PAGE, ResourceName, "modify", String.Empty, String.Empty);

                // Display access denied page in conent frame and select deleted item again
                String denyScript = @"$cmsj(document).ready(function(){ frames['paneContentTMain'].location = '" + ResolveUrl(url) + "';" + SelectAfterLoad(categoryPath + "/", id, values[0], parentId, false, false) + "});";

                ltlScript.Text += ScriptHelper.GetScript(denyScript);
                return;
            }

            string script = String.Empty;

            switch (values[0])
            {
            case "item":
                BaseInfo bi = BaseAbstractInfoProvider.GetInfoById(objectType, id);
                if (bi != null)
                {
                    bi.Delete();
                }

                break;

            case "category":
                try
                {
                    BaseInfo biCate = BaseAbstractInfoProvider.GetInfoById(categoryObjectType, id);
                    if (biCate != null)
                    {
                        biCate.Delete();
                    }
                }
                catch (Exception ex)
                {
                    // Make alert with exception message, most probable cause is deleting category with subcategories
                    script = String.Format("alert('{0}');\n", ex.Message);

                    // Current node stays selected
                    parentId = id;
                }
                break;
            }

            // After delete select first tab always
            tabIndexStr     = String.Empty;
            script          = SelectAfterLoad(categoryPath + "/", parentId, "category", parentID, true, true) + script;
            ltlScript.Text += ScriptHelper.GetScript(script);
        }
    }
Example #2
0
    /// <summary>
    /// Handles delete action.
    /// </summary>
    /// <param name="eventArgument">Objecttype(item or itemcategory);objectid</param>
    public void RaisePostBackEvent(string eventArgument)
    {
        string[] values = eventArgument.Split(';');
        if (values.Length == 3)
        {
            int      id       = ValidationHelper.GetInteger(values[1], 0);
            int      parentId = ValidationHelper.GetInteger(values[2], 0);
            BaseInfo biParent = ProviderHelper.GetInfoById(categoryObjectType, parentId);

            if (biParent == null)
            {
                return;
            }

            String categoryPath = ValidationHelper.GetString(biParent.GetValue(categoryPathColumn), String.Empty);
            int    parentID     = ValidationHelper.GetInteger(biParent.GetValue(categoryParentColumn), 0);

            //Test permission
            if (!MembershipContext.AuthenticatedUser.IsAuthorizedPerResource(ResourceName, "Modify"))
            {
                String url = CMSPage.GetAccessDeniedUrl(AdministrationUrlHelper.ADMIN_ACCESSDENIED_PAGE, ResourceName, "modify", String.Empty, String.Empty);

                // Display access denied page in conent frame and select deleted item again
                String denyScript = @"$cmsj(document).ready(function(){ frames['paneContentTMain'].location = '" + ResolveUrl(url) + "';" + SelectAfterLoad(categoryPath + "/", id, values[0], parentId, false, false) + "});";

                ScriptHelper.RegisterClientScriptBlock(Page, typeof(string), ClientID + "_AccessDenied", ScriptHelper.GetScript(denyScript));
                return;
            }

            switch (values[0])
            {
            case "item":
                BaseInfo bi = ProviderHelper.GetInfoById(objectType, id);
                if (bi != null)
                {
                    bi.Delete();
                }

                break;

            case "category":
                try
                {
                    BaseInfo biCate = ProviderHelper.GetInfoById(categoryObjectType, id);
                    if (biCate != null)
                    {
                        biCate.Delete();
                    }
                }
                catch (Exception ex)
                {
                    // Make alert with exception message, most probable cause is deleting category with subcategories
                    var script = $"alert('{ScriptHelper.GetString(ex.Message, false)}');\n";
                    script += SelectAfterLoad(categoryPath + "/", id, "category", parentID, true, true);

                    ScriptHelper.RegisterClientScriptBlock(Page, typeof(string), ClientID + "_AfterLoad", ScriptHelper.GetScript(script));
                    return;
                }
                break;
            }

            // After delete select first tab always
            tabIndexStr = String.Empty;
            var location = UIContextHelper.GetElementUrl(UIContext.UIElement, UIContext);
            location = URLHelper.RemoveParameterFromUrl(location, "objectid");
            location = URLHelper.UpdateParameterInUrl(location, "parentobjectid", parentId.ToString());

            URLHelper.Redirect(location);
        }
    }