public static void insert2(db.Books entry) { dbEntities dc = new dbEntities(); dc.Books.Add(entry); dc.SaveChanges(); }
public ActionResult updateTwo(db.Books entry) { db.bll.books.updateTwo(entry); // 新增完成重定向回主页 return(RedirectToAction("Index")); }
// 更新方法三 public static void updateThree(db.Books entry) { db.dbEntities dc = new dbEntities(); db.lib.efHelp.entryUpdate(entry, dc); dc.SaveChanges(); }
// 删除方法 public static void delete(int bookid) { db.dbEntities dc = new dbEntities(); db.Books entry = dc.Books.SingleOrDefault(a => a.BookId == bookid); dc.Books.Remove(entry); dc.SaveChanges(); }
// 更新方法二 public static void updateTwo(db.Books entry) { db.dbEntities dc = new dbEntities(); // 1. 将entry附加到entry 2. 附加之后,将他的状态改成修改状态 dc.Entry <db.Books>(entry).State = System.Data.EntityState.Modified; dc.SaveChanges(); }
// 更新方法一 public static void updateOne(string AuthorName, string Title, Nullable <decimal> Price, int BookId) { db.dbEntities dc = new dbEntities(); db.Books entry = dc.Books.Single(a => a.BookId == BookId); entry.AuthorName = AuthorName; entry.Title = Title; entry.Price = Price; dc.SaveChanges(); }
public static void batchUpdatePrice(List <string> rowIDList, List <string> priceList, List <string> booktypeList, Dictionary <string, string> dicBookTag) { dbEntities dc = new dbEntities(); for (int i = 0; i < rowIDList.Count; i++) { int rowID = Convert.ToInt32(rowIDList[i]); db.Books entry = dc.Books.FirstOrDefault(b => b.BookId == rowID); entry.Price = Convert.ToDecimal(priceList[i]); entry.BookType = booktypeList[i]; entry.BookTag = dicBookTag[rowIDList[i]]; } dc.SaveChanges(); }
public ActionResult bookUpdate(db.Books entry) { if (Request["bookTag"] != null) { entry.BookTag = Request["bookTag"].ToString(); if (Request.Files.Count > 0 && Request.Files[0].FileName != "") { // 上传以后将文件存起来 string savePath = "/upload/" + DateTime.Now.ToString("yyyyMMddhhmmss") + Request.Files[0].FileName; Request.Files[0].SaveAs(Server.MapPath(savePath)); entry.BookCoverUrl = savePath; } } db.bll.books.updateThree(entry); return(RedirectToAction("bookIndex")); }
public ActionResult Order(int id) { db.Books entity = db.bll.books.getBooks(id); return(View(entity)); }
public ActionResult updateThree(int id) { db.Books entry = db.bll.books.getEntry(id); return(View(entry)); }
public ActionResult insertTwo() { db.Books entry = new db.Books(); return(View(entry)); }
public ActionResult Details(int id) { db.Books entry = db.bll.books.getEntry(id); return(View(entry)); }
public ActionResult bookInsert() { db.Books entry = new db.Books(); return(View(entry)); }