예제 #1
0
 /// <summary>
 /// Deprecated Method for adding a new object to the Blogs EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToBlogs(Blog blog)
 {
     base.AddObject("Blogs", blog);
 }
예제 #2
0
 /// <summary>
 /// Create a new Blog object.
 /// </summary>
 /// <param name="blogId">Initial value of the BlogId property.</param>
 /// <param name="authorId">Initial value of the AuthorId property.</param>
 public static Blog CreateBlog(global::System.Int32 blogId, global::System.Int32 authorId)
 {
     Blog blog = new Blog();
     blog.BlogId = blogId;
     blog.AuthorId = authorId;
     return blog;
 }
예제 #3
0
        public ActionResult CreateBlog(Models.BlogSummary summary)
        {
            //object blogIdResult = null;
            //using (SqlConnection connection = new SqlConnection(@"server=.\SQLEXPRESS; DataBase=TestDB; Integrated Security=SSPI"))
            //{
            //    var command = connection.CreateCommand();
            //    command.CommandText = "dbo.InsertBlog";
            //    command.CommandType = CommandType.StoredProcedure;
            //    command.Parameters.Add(new SqlParameter("@Title", summary.Title));
            //    command.Parameters.Add(new SqlParameter("@Description", summary.Title));
            //    command.Parameters.Add(new SqlParameter("@AuthorName", summary.AuthorName));
            //    command.Parameters.Add(new SqlParameter("@AuthorBio", summary.AuthorBio));
            //    command.Parameters.Add(new SqlParameter("@AuthorAge", summary.AuthorAge));
            //    command.Parameters.Add(new SqlParameter("@AuthorHometown", summary.AuthorHometown));
            //    connection.Open();
            //    blogIdResult = command.ExecuteScalar();
            //}
            //summary.BlogId = (int)(decimal)blogIdResult;

            var db = new ADO.TestDBEntities();

            ADO.Blog blog = new ADO.Blog { Title = summary.Title, Description = summary.Description };
            ADO.Author author = new ADO.Author { Name = summary.AuthorName, Bio = summary.AuthorBio, Hometown = summary.AuthorHometown, Age = summary.AuthorAge };
            db.AddToBlogs(blog);
            db.AddToAuthors(author);
            var result = db.SaveChanges();

            summary.BlogId = blog.BlogId;
            summary.AuthorId = author.AuthorId;

            return View(new Models.BlogSummary(summary));
        }