示例#1
0
        void ContentService_Published(Umbraco.Core.Publishing.IPublishingStrategy sender, Umbraco.Core.Events.PublishEventArgs<Umbraco.Core.Models.IContent> e)
        {
            var fs = new ForumService(ApplicationContext.Current.DatabaseContext);
            foreach (var ent in e.PublishedEntities.Where(x => x.ContentType.Alias == "Forum"))
            {
                Forum f = fs.GetById(ent.Id);

                if (f == null)
                {
                    f = new Forum();
                    f.Id = ent.Id;
                    f.ParentId = ent.ParentId;
                    f.SortOrder = ent.SortOrder;
                    f.TotalTopics = 0;
                    f.TotalComments = 0;
                    f.LatestPostDate = DateTime.Now;
                    f.LatestAuthor = 0;
                    f.LatestComment = 0;
                    f.LatestTopic = 0;
                    fs.Save(f);
                }
            }
        }
示例#2
0
        protected void modifyForum(object sender, CommandEventArgs e)
        {
            int pId = 0;
            if (!string.IsNullOrEmpty(Request.QueryString["id"]) && int.TryParse(Request.QueryString["id"], out pId) && umbraco.library.IsLoggedOn()) {

                Member m = Member.GetCurrentMember();
                Document d = new Document(pId);
                Document fnode = null;

                if (e.CommandName == "edit") {
                    int fId = int.Parse(e.CommandArgument.ToString());
                    fnode = new Document(fId);

                } else if(e.CommandName == "create") {

                    fnode = Document.MakeNew(tb_name.Text, DocumentType.GetByAlias("Forum"), new umbraco.BusinessLogic.User(0), d.Id);

                } else if(e.CommandName == "delete"){

                    int fId = int.Parse(e.CommandArgument.ToString());

                    if (Document.IsDocument(fId))
                    {
                        fnode = new Document(fId);
                    }

                    if (fnode != null)
                    {
                        if ((int)d.getProperty("owner").Value == m.Id && fnode.ParentId == d.Id)
                        {
                            fnode.delete();

                            //if still not dead it's because it's in the trashcan and should be deleted once more.
                            if (fnode.ParentId == -20)
                                fnode.delete();

                        }

                        if (fnode.ParentId == -20)
                            fnode.delete();

                        fnode = null;

                    }
                    var f = _forumService.GetById(fnode.Id);
                    if (f != null)
                        _forumService.Delete(f);

                }

                if (fnode != null && (int)d.getProperty("owner").Value == m.Id && fnode.ParentId == d.Id) {
                    fnode.Text = tb_name.Text;
                    fnode.getProperty("forumDescription").Value = tb_desc.Text;
                    fnode.getProperty("forumAllowNewTopics").Value = true;
                    fnode.Publish(new umbraco.BusinessLogic.User(0));
                    fnode.Save();
                    umbraco.library.UpdateDocumentCache(fnode.Id);

                    Forum f = _forumService.GetById(fnode.Id);

                    if (f == null)
                    {
                        f = new Forum();
                        f.Id = fnode.Id;
                        f.ParentId = fnode.ParentId;
                        f.SortOrder = 0;
                        f.TotalTopics = 0;
                        f.TotalComments = 0;
                        f.LatestPostDate = DateTime.Now;
                        _forumService.Save(f);
                    }
                }

                Response.Redirect(Node.GetCurrent().NiceUrl + "?id=" + pId.ToString());

            }
        }