20 Recipes for Programming MVC 3 by Jamie Munro
Author:Jamie Munro [Jamie Munro]
Language: eng
Format: epub
Tags: COMPUTERS / Programming / Microsoft Programming
ISBN: 9781449309855
Publisher: O'Reilly Media
Published: 2011-09-28T16:00:00+00:00
The Edit function is updated to first call the DeleteFile function, then call the UploadFile function.
The DeleteConfirmed function is updated to call the DeleteFile function before deleting the book from the database.
using System; using System.Collections.Generic; using System.Data; using System.Data.Entity; using System.Linq; using System.Linq.Dynamic; using System.Web; using System.Web.Mvc; using MvcApplication4.Models; using MvcApplication4.Utils; using PagedList; namespace MvcApplication4.Controllers { public class BooksController : Controller { private BookDBContext db = new BookDBContext(); ... // // GET: /Books/Create public ActionResult Create() { return View(); } // // POST: /Books/Create [HttpPost] public ActionResult Create(Book book, HttpPostedFileBase file) { if (ModelState.IsValid) { // Upload our file book.Thumbnail = FileUpload.UploadFile(file); db.Books.Add(book); db.SaveChanges(); return RedirectToAction("Index"); } return View(book); } // // GET: /Books/Edit/5 public ActionResult Edit(int id) { Book book = db.Books.Find(id); return View(book); } // // POST: /Books/Edit/5 [HttpPost] public ActionResult Edit(Book book, HttpPostedFileBase file) { if (ModelState.IsValid) { // Delete old file FileUpload.DeleteFile(book.Thumbnail); // Upload our file book.Thumbnail = FileUpload.UploadFile(file); db.Entry(book).State = EntityState.Modified; db.SaveChanges(); return RedirectToAction("Index"); } return View(book); } // // GET: /Books/Delete/5 public ActionResult Delete(int id) { Book book = db.Books.Find(id); return View(book); } // // POST: /Books/Delete/5 [HttpPost, ActionName("Delete")] public ActionResult DeleteConfirmed(int id) { Book book = db.Books.Find(id); // Delete old file FileUpload.DeleteFile(book.Thumbnail); db.Books.Remove(book); db.SaveChanges(); return RedirectToAction("Index"); } ... } }
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Deep Learning with Python by François Chollet(16063)
The Mikado Method by Ola Ellnestam Daniel Brolund(13341)
Hello! Python by Anthony Briggs(13148)
OCA Java SE 8 Programmer I Certification Guide by Mala Gupta(12314)
Dependency Injection in .NET by Mark Seemann(12172)
Algorithms of the Intelligent Web by Haralambos Marmanis;Dmitry Babenko(10929)
The Well-Grounded Java Developer by Benjamin J. Evans Martijn Verburg(10772)
A Developer's Guide to Building Resilient Cloud Applications with Azure by Hamida Rebai Trabelsi(10540)
Grails in Action by Glen Smith Peter Ledbrook(10237)
Secrets of the JavaScript Ninja by John Resig Bear Bibeault(10163)
Sass and Compass in Action by Wynn Netherland Nathan Weizenbaum Chris Eppstein Brandon Mathis(9536)
Hit Refresh by Satya Nadella(9040)
Kotlin in Action by Dmitry Jemerov(8890)
Test-Driven iOS Development with Swift 4 by Dominik Hauser(8674)
The Kubernetes Operator Framework Book by Michael Dame(8488)
Exploring Deepfakes by Bryan Lyon and Matt Tora(8308)
Robo-Advisor with Python by Aki Ranin(8261)
Practical Computer Architecture with Python and ARM by Alan Clements(8234)
Implementing Enterprise Observability for Success by Manisha Agrawal and Karun Krishnannair(8203)