public ActionResult Create(BookUp data) { try { // TODO: Add insert logic here if (ModelState.IsValid) { Book book = new Book(); book.Author = data.Author; book.Category = data.Category; book.Publish = data.Publish; book.Price = data.Price; book.OldLevel = data.OldLevel; book.Name = data.Name; book.UserID = Convert.ToInt32(Session["Uid"]); book.TotalNum = Convert.ToInt32(data.TotalNum); book.Categories = data.Categories; book.BookState="true"; Usedb.Book.Add(book); Usedb.SaveChanges(); int a = 0; return RedirectToAction("Index"); } else return View(data); } catch { return View(); } }
public ActionResult BookUpload(BookUp data) { if (ModelState.IsValid) { Book book = new Book(); book.Author = data.Author; book.Category = data.Category; book.Publish = data.Publish; book.Price = data.Price; book.OldLevel = data.OldLevel; book.Name = data.Name; book.UserID = Convert.ToInt32(Session["Uid"]); book.TotalNum = Convert.ToInt32(data.TotalNum); book.Categories = data.Categories; Usedb.Book.Add(book); Usedb.SaveChanges(); TempData["bookupload"] = "上传成功!"; } return View("BookUpload"); }
public ActionResult Edit(Book book) { if (ModelState.IsValid) { Usedb.Entry(book).State = EntityState.Modified; Usedb.SaveChanges(); return RedirectToAction("Index"); } return View(book); }