public ActionResult Edit(EconomicsBook book) { using (Group001BookstoreEntities dbContext = new Group001BookstoreEntities()) { if (this.Request.Files != null && this.Request.Files.Count > 0 && this.Request.Files[0].ContentLength > 0 && this.Request.Files[0].ContentLength < 1024 * 1024) { book.CoverImagePath = this.Request.Files[0].FileName; } dbContext.EconomicsBooks.Attach(book); dbContext.Entry(book).State = System.Data.Entity.EntityState.Modified; dbContext.SaveChanges(); } return(RedirectToAction("BookList")); }
public ActionResult Edit(ChildrenBook ChildrenBook) { using (Group001BookstoreEntities dbContext = new Group001BookstoreEntities()) { if (this.Request.Files != null && this.Request.Files.Count > 0 && this.Request.Files[0].ContentLength > 0 && this.Request.Files[0].ContentLength < 1024 * 100) { string fileName = Path.GetFileName(this.Request.Files[0].FileName); string filePathOfWebsite = "~/Images/ChildrenBookCover/" + fileName; ChildrenBook.CoverImagePath = filePathOfWebsite; this.Request.Files[0].SaveAs(this.Server.MapPath(filePathOfWebsite));//无法添加图片,路径名不对。 } dbContext.ChildrenBooks.Attach(ChildrenBook); dbContext.Entry(ChildrenBook).State = System.Data.Entity.EntityState.Modified; dbContext.SaveChanges(); } return(RedirectToAction("Show")); }
public ActionResult Detail(CSBook book) { using (Group001BookstoreEntities dbContext = new Group001BookstoreEntities()) { if (this.Request.Files != null && this.Request.Files.Count > 0 && this.Request.Files[0].ContentLength > 0 && this.Request.Files[0].ContentLength < 1024 * 1024) { string fileName = Path.GetFileName(this.Request.Files[0].FileName); string pathOfWebsite = "~/Images/CSBookCovers/" + fileName; book.CoverImagePath = pathOfWebsite; this.Request.Files[0].SaveAs(this.Server.MapPath(pathOfWebsite)); } dbContext.CSBooks.Attach(book); dbContext.Entry(book).State = System.Data.Entity.EntityState.Modified; dbContext.SaveChanges(); } return(RedirectToAction("Show")); }
public ActionResult UserRevise(User user) { if (user.FirstName != null && user.LastName != null && user.DateofBirth != 0 && this.ModelState.IsValid) { using (Group001BookstoreEntities dbContext = new Group001BookstoreEntities()) { dbContext.Users.Attach(user); dbContext.Entry(user).State = System.Data.Entity.EntityState.Modified; dbContext.SaveChanges(); } return(View("UserInfo", user)); } else { return(View("Error")); } }
public ActionResult Edit(NovelBook novel) { using (Group001BookstoreEntities dbContext = new Group001BookstoreEntities()) { if (this.Request.Files != null && this.Request.Files.Count > 0 && this.Request.Files[0].ContentLength > 0 && this.Request.Files[0].ContentLength < 1024 * 100) { string fileName = Path.GetFileName(this.Request.Files[0].FileName); string filePathOfWebsite = "~/Images/NovelCovers/" + fileName; novel.CoverImagePath = filePathOfWebsite; this.Request.Files[0].SaveAs(this.Server.MapPath(filePathOfWebsite)); } dbContext.NovelBooks.Attach(novel); dbContext.Entry(novel).State = System.Data.Entity.EntityState.Modified; dbContext.SaveChanges(); } return(RedirectToAction("Show", new { pageNumber = 1 })); }