コード例 #1
0
        public void DeleteCategory(string categoryName)
        {
            if (String.IsNullOrEmpty(categoryName))
            {
                throw new ArgumentOutOfRangeException("categoryName");
            }

            Category category = GetCategory(categoryName);

            Post.DestroyDeletedPostCascadingForCategory(category.Id);
            Category.Destroy(Category.Columns.Id, category.Id);
            NavigationSettings settings = NavigationSettings.Get();

            DynamicNavigationItem item = settings.Items.Find(dni => dni.CategoryId == category.Id);

            if (item != null)
            {
                NavigationSettings.Remove(item.Id);
            }
            CategoryController.Reset();
        }
コード例 #2
0
        void CreateNavigationLink <TPlugin>() where TPlugin : GraffitiEvent, IPluginConfigurationProvider, new()
        {
            TPlugin  plugin   = PluginHelper.GetPluginWithCurrentSettings <TPlugin>();
            Category category = _categoryRepository.GetCategory(plugin.CategoryName);

            // Dynamic navigation items for categories are automatically created if the dynamic navigation items are empty.
            NavigationSettings settings = NavigationSettings.Get();

            if (settings.SafeItems().Exists(dni => dni.NavigationType == DynamicNavigationType.Category && dni.CategoryId == category.Id))
            {
                // The dynamic navigation item already exists.
                return;
            }

            DynamicNavigationItem item = new DynamicNavigationItem
            {
                NavigationType = DynamicNavigationType.Category,
                CategoryId     = category.Id,
                Id             = Guid.NewGuid()
            };

            NavigationSettings.Add(item);
        }
コード例 #3
0
    protected void lbDelete_Command(object sender, CommandEventArgs args)
    {
        int      id = Convert.ToInt32(args.CommandArgument);
        Category c  = new Category(id);

        if (c.HasChildren)
        {
            Message.Text = "You cannot delete this category because it has child categories.";
            Message.Type = StatusType.Error;
            return;
        }

        var postCounts = Post.GetPostCounts(id, null);

        if (postCounts != null && postCounts.Count > 0)
        {
            int totalPosts = 0;
            foreach (PostCount p in postCounts)
            {
                totalPosts += p.Count;
            }

            if (totalPosts == 1)
            {
                Message.Text  = "You cannot delete this category because it is in use by " + totalPosts + " post.";
                Message.Text += " <a href=\"" + ResolveUrl("~/graffiti-admin/posts/?category=") + id +
                                "\">Click here</a> to change this post to another category or delete it.";
                Message.Type = StatusType.Error;
            }
            else
            {
                Message.Text  = "You cannot delete this category because it is in use by " + totalPosts + " posts.";
                Message.Text += " <a href=\"" + ResolveUrl("~/graffiti-admin/posts/?category=") + id +
                                "\">Click here</a> to change these posts to another category or delete them.";
                Message.Type = StatusType.Error;
            }
            return;
        }

        try
        {
            // destroy any deleted posts in this category
            Post.DestroyDeletedPostCascadingForCategory(id);

            Category.Destroy(Category.Columns.Id, id);

            NavigationSettings    navSettings = NavigationSettings.Get();
            DynamicNavigationItem item        = navSettings.Items == null
                                                             ? null
                                                             : navSettings.Items.Find(
                delegate(DynamicNavigationItem itm) { return(itm.CategoryId == id); });

            if (item != null)
            {
                NavigationSettings.Remove(item.Id);
            }

            CategoryController.Reset();
            GetCategories();

            Message.Text = "The category " + c.Name + " was deleted.";
        }
        catch (Exception ex)
        {
            Message.Text = ex.Message;
            Message.Type = StatusType.Error;
        }
    }
コード例 #4
0
    protected void Page_Load(object sender, EventArgs e)
    {
        LiHyperLink.SetNameToCompare(Context, "presentation");

        NavigationSettings settings = NavigationSettings.Get();
        CategoryCollection cc       = new CategoryController().GetTopLevelCachedCategories();

        foreach (Category c in cc)
        {
            bool found = false;
            foreach (DynamicNavigationItem di in settings.SafeItems())
            {
                if (di.NavigationType == DynamicNavigationType.Category && di.CategoryId == c.Id)
                {
                    found = true;
                    break;
                }
            }

            if (!found)
            {
                the_Categories.Items.Add(new ListItem(c.Name, "Category-" + c.UniqueId));
            }
        }


        Query q = Post.CreateQuery();

        q.AndWhere(Post.Columns.CategoryId, CategoryController.UnCategorizedId);
        q.AndWhere(Post.Columns.IsDeleted, false);
        q.AndWhere(Post.Columns.Status, 1);

        PostCollection pc = new PostCollection();

        pc.LoadAndCloseReader(q.ExecuteReader());

        foreach (Post p in pc)
        {
            bool found = false;
            foreach (DynamicNavigationItem di in settings.SafeItems())
            {
                if (di.NavigationType == DynamicNavigationType.Post && di.PostId == p.Id)
                {
                    found = true;
                    break;
                }
            }

            if (!found)
            {
                the_Posts.Items.Add(new ListItem(p.Title, "Post-" + p.UniqueId));
            }
        }

        // 0 - Title, 1 - Type, 2 - LID
        string itemFormat =
            "<div style=\"border: solid 1px #999; padding: 4px;\"><strong>{0} ({1})</strong><div style=\"text-align:right;\"><a title=\"Delete Link\" href=\"javascript:void();\" onclick=\"remove_Link( &#39;{1}&#39;,&#39;{0}&#39;, &#39;{2}&#39;); return false;\">Delete</a></div></div>";

        foreach (DynamicNavigationItem dni in settings.SafeItems())
        {
            lbar.Items.Add(
                new OrderedListItem(string.Format(itemFormat, dni.Name, dni.NavigationType.ToString(), dni.Id),
                                    dni.Name, dni.NavigationType.ToString() + "-" + dni.Id.ToString()));
        }
    }