针对N2中非管理权限用户的数据保存

很有幸的,今天针对N2中非管理权限用户的数据保存方法有了些心得:

1.XML文件保存

很显然,通用的文件保存方式不论在Mvc框架下或者是Web框架下都能达到我们的目的。

2.N2 API

这里向大家介绍一些更为有效的方法,包括创建节点,更新节点,移动节点,复制节点和删除节点等等

创建节点:

public void CreateNews(ContentItem parent, string title, string intro, string text)

{
        News news = N2.Context.Definitions.CreateInstance<News>(parent);
        news.Title = title;
        news.Introduction = intro;
        news.Text = text;

        N2.Context.Persister.Save(news);
}

更新节点或者更新节点集合
public void UpdateNews(News news, string title, string intro, string text)
{
        news.Title = title;
        news.Introduction = intro;
        news.Text = text;

        N2.Context.Persister.Save(news);
}
public void UpdateSomeNews(int itemId)
{
        News news = N2.Context.Persister.Get<News>(itemId);

        news.Title = textBoxTitle.Text;
        news.Introduction = textBoxIntroduction.Text;
        news.Text = textBoxText.Text;

        N2.Context.Persister.Save(news);
}

移动节点:
public void MoveMe(ContentItem destination)
{
        TextPage current = N2.Context.CurrentPage;
        N2.Context.Persister.Move(current, destination);
}
复制节点:
public void CopyMe(ContentItem destination)
{
        TextPage current = N2.Context.CurrentPage;
        N2.Context.Persister.Copy(current, destination);
}
删除节点并移动到StartPage
public void CopyMe(ContentItem destination)
{
        TextPage current = N2.Context.CurrentPage;

        if (current != N2.Find.StartPage)
                N2.Context.Persister.Delete(current);

        Response.Redirect("/");
}
     
参考文章http://code.google.com/p/n2cms/wiki/CreatingUpdatingItems
原文地址:https://www.cnblogs.com/chenjunsheep/p/1687977.html