示例#1
0
        public ActionResult Index()
        {
            var blogPost = new BlogPost { Title = "My first blog post", Content = "Blog post content" };
            Data.BlogPosts.Add(blogPost);

            if (User.Identity.IsAuthenticated)
            {
                var user = Data.Users.All().FirstOrDefault(x => x.UserName == User.Identity.Name);
                Data.Comments.Add(new Comment { Author = user, BlogPost = blogPost, Content = "Spam!" });
            }

            Data.SaveChanges();

            return View();
        }
 /// <summary>
 /// Create a new BlogPost object.
 /// </summary>
 /// <param name="id">Initial value of the Id property.</param>
 /// <param name="postTitle">Initial value of the PostTitle property.</param>
 public static BlogPost CreateBlogPost(global::System.Int32 id, global::System.String postTitle)
 {
     BlogPost blogPost = new BlogPost();
     blogPost.Id = id;
     blogPost.PostTitle = postTitle;
     return blogPost;
 }
 /// <summary>
 /// Deprecated Method for adding a new object to the BlogPosts EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToBlogPosts(BlogPost blogPost)
 {
     base.AddObject("BlogPosts", blogPost);
 }