public ActionResult Add(FormCollection form) { sbartoszak_bookwormsEntities ent = new sbartoszak_bookwormsEntities(); ViewBag.BookGenres = ent.Genres.OrderBy(g => g.Name).ToSelectListItem(1, g => g.IdGenre, g => g.Name, g => g.Name, g => g.IdGenre.ToString()); Book book = new Book(); if (TryUpdateModel(book)) { book.AddDate = DateTime.Now; ent.Books.AddObject(book); ent.SaveChanges(); } return RedirectToAction("Index"); }
/// <summary> /// Create a new Book object. /// </summary> /// <param name="idBook">Initial value of the IdBook property.</param> /// <param name="title">Initial value of the Title property.</param> /// <param name="author">Initial value of the Author property.</param> /// <param name="idGenre">Initial value of the IdGenre property.</param> /// <param name="addDate">Initial value of the AddDate property.</param> public static Book CreateBook(global::System.Int32 idBook, global::System.String title, global::System.String author, global::System.Int32 idGenre, global::System.DateTime addDate) { Book book = new Book(); book.IdBook = idBook; book.Title = title; book.Author = author; book.IdGenre = idGenre; book.AddDate = addDate; return book; }
/// <summary> /// Deprecated Method for adding a new object to the Books EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToBooks(Book book) { base.AddObject("Books", book); }