// GET: Delete public ActionResult Index(int id = 0) { if (id == 0 || id < 0) { return(RedirectToAction("Index", "List")); } try { using (var db = new MyMovieListDBEntities()) { Movie search = db.Movies.Where(p => p.Id == id).FirstOrDefault(); db.Movies.Remove(search); db.SaveChanges(); } TempData["Result"] = "Successfully removed the movie"; return(RedirectToAction("Index", "List")); } catch { TempData["Error"] = "Error during removing"; return(RedirectToAction("Index", "List")); } }
// GET: Home public ActionResult Index() { try { using (MyMovieListDBEntities db = new MyMovieListDBEntities()) { var last = (from d in db.Movies orderby d.LastUpdate descending, d.Id descending select d).Take(3).ToList(); return(View(last)); } } catch (Exception e) { return(Content("Exception found during connecting: <br>" + e)); } }
// GET: Edit public ActionResult Index(int id = 0) { if (id == 0) { return(RedirectToAction("Index", "List")); } using (var db = new MyMovieListDBEntities()) { var edit = db.Movies.Where(p => p.Id == id); Movie item = edit.FirstOrDefault(); ViewBag.TitleError = TempData["TitleError"]; return(View(item)); } }
// GET: List public ActionResult Index() { try { using (MyMovieListDBEntities db = new MyMovieListDBEntities()) { var movies = (from d in db.Movies orderby d.Title select d).ToList(); ViewBag.Result = TempData["Result"]; ViewBag.Error = TempData["Error"]; return(View(movies)); } } catch (Exception e) { return(Content("Exception found during connecting: <br>" + e)); } }
public ActionResult Index(Movie model, HttpPostedFileBase imageFile) { try { if (!ModelState.IsValid) { TempData["TitleError"] = "The title is required and can not exceed 100 characters"; return(RedirectToAction("Index", model)); } else { using (var db = new MyMovieListDBEntities()) { Movie test = new Movie(); test = (from c in db.Movies where c.Id == model.Id select c).FirstOrDefault(); test.Title = model.Title; if (imageFile != null) { test.Poster = null; test.Poster = new byte[imageFile.ContentLength]; imageFile.InputStream.Read(test.Poster, 0, imageFile.ContentLength); } test.ReleaseDate = model.ReleaseDate; test.YourSeanceDate = model.YourSeanceDate; test.Score = model.Score; test.LastUpdate = DateTime.Now; test.UpdateType = "Modified"; db.SaveChanges(); TempData["Result"] = "Successfully edited the movie"; return(RedirectToAction("Index", "List")); } } } catch { ViewBag.Error = "SOME PROBLEM. PLEASE TRY AGAIN. "; return(View(model.Id)); } }
public ActionResult Index(Movie model, HttpPostedFileBase imageFile) { try { if (!ModelState.IsValid) { ViewBag.TitleError = "The title is required and can not exceed 100 characters"; return(View("Index", model)); } else { using (var db = new MyMovieListDBEntities()) { model.LastUpdate = DateTime.Now; model.UpdateType = "Add"; if (imageFile != null) { model.Poster = new byte[imageFile.ContentLength]; imageFile.InputStream.Read(model.Poster, 0, imageFile.ContentLength); } db.Movies.Add(model); db.SaveChanges(); TempData["Result"] = "Successfully added the movie"; return(RedirectToAction("Index", "List")); } } } catch { ViewBag.Error = "SOME PROBLEM. PLEASE TRY AGAIN. "; return(View(model)); } }