/// <summary> /// Deprecated Method for adding a new object to the Authors EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToAuthors(Author author) { base.AddObject("Authors", author); }
/// <summary> /// Create a new Author object. /// </summary> /// <param name="authorId">Initial value of the AuthorId property.</param> public static Author CreateAuthor(global::System.Int32 authorId) { Author author = new Author(); author.AuthorId = authorId; return author; }
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)); }