public TestProvider AddTestForums(ApiContext context) { var forum1 = new Forum.Models.Forum() { Id = Guid.NewGuid(), Title = "A title of a forum", Author = new SimpleUser() { Id = Guid.NewGuid(), Name = "Some forum author" } }; context.Forums.Add(forum1); context.SaveChanges(); return(_instance); }
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.Models.Forum f = _forumService.GetById(fnode.Id); if (f == null) { f = new Forum.Models.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()); } }
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.Models.Forum f = _forumService.GetById(fnode.Id); if (f == null) { f = new Forum.Models.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()); } }