示例#1
0
文件: TestPost.cs 项目: aisk/Molex
 public void testInsertPost()
 {
     Post post=new Post()
     {
         Title="Hello World!",
         PostDate=DateTime.Now,
         Content="<p>Hello World!</p>" +
             "<p>表格在很多iPhone应用程序中都是必需的UI元素。虽然对于应用程序开发而言,这并非是一项新发明,鉴于设备尺寸等方面的限制,表格在iPhone中的功能是非常固定的。</p>" +
             "<p>苹果在其SDK中,直接内置了很多风格来让你定制表格。不过,在你最初创建表格的时候,它看起来非常简单。在没有进行任何定制的时候,你可以为表格选择两种基本风格,默认风格和分组风格。</p>",
         AuthorId=1,
         AuthorName="sa",
     };
     PostFarm.InsertPost(post);
 }
示例#2
0
文件: PostFarm.cs 项目: aisk/Molex
        public static bool InsertPost(Post post)
        {
            using (var mongo=Mongo.Create(@"mongodb://localhost/test"))
            {
                var postCollection = mongo.GetCollection<Post> ();

                postCollection.Insert(post);
                return true;
            }
        }
示例#3
0
        public ActionResult Post()
        {
            if (Session["Id"]==null || Session["Id"].ToString()=="")
            {
                return Redirect("/");
            }

            if (Request.Form["Title"]!=null||Request.Form["Content"]!=null)
            {
                if (Request.Form["Title"]!=""||Request.Form["Content"]!="")
                {
                    //string content=Request.Form["Content"].ToString().Replace("<","&lt;").Replace(">","&gt;")
                    //	.Replace("\r\n","<br />").Replace("\n","<br />");
                    string content = Request.Form["Content"].ToString();
                    Post post=new Post()
                    {
                        Title=Request.Form["Title"].ToString(),
                        Content=content,
                        PostDate=DateTime.Now,
                        AuthorId=(int)Session["Id"],
                        AuthorName=Session["Name"].ToString(),
                        StatisticsView=0,
                    };
                    try
                    {
                        PostFarm.InsertPost(post);
                        return Redirect("/blog/"+post.Id+"/");
                    }
                    catch (Exception e)
                    {
                        ViewData["Message"]=e.Message;

                    }
                }
            }
            return View ();
        }