public ActionResult Create(MovieGenresDirectorsRatingsFormats mgdrf) { try { if (mgdrf.File != null) { mgdrf.Movie.ImagePath = mgdrf.File.FileName; string target = Path.Combine(Server.MapPath("~/images"), Path.GetFileName(mgdrf.File.FileName)); if (!System.IO.File.Exists(target)) { mgdrf.File.SaveAs(target); ViewBag.Message = "File Uploaded Successfully"; } else { ViewBag.Message = "File did not upload"; } } // TODO: Add insert logic here MovieManager.Insert(mgdrf.Movie); mgdrf.GenreIds.ToList().ForEach(a => MovieGenresDirectorsRatingsFormatsManager.Add(mgdrf.Movie.Id, a)); return(RedirectToAction("Index")); } catch (Exception ex) { ViewBag.Message = ex.Message; return(View(mgdrf)); } }
public ActionResult Edit(int id, MovieGenresDirectorsRatingsFormats mgdrf) { try { if (mgdrf.File != null) { mgdrf.Movie.ImagePath = mgdrf.File.FileName; string target = Path.Combine(Server.MapPath("~/images"), Path.GetFileName(mgdrf.File.FileName)); if (!System.IO.File.Exists(target)) { mgdrf.File.SaveAs(target); ViewBag.Message = "File Uploaded Successfully"; } else { ViewBag.Message = "File did not upload"; } } //deal with genres IEnumerable <int> oldGenres = new List <int>(); if (Session["genreids"] != null) { oldGenres = (IEnumerable <int>)Session["genreids"]; } IEnumerable <int> newGenres = new List <int>(); if (mgdrf.GenreIds != null) { newGenres = mgdrf.GenreIds; } //deletes IEnumerable <int> deletes = oldGenres.Except(newGenres); //adds IEnumerable <int> adds = newGenres.Except(oldGenres); deletes.ToList().ForEach(d => MovieGenresDirectorsRatingsFormatsManager.Delete(id, d)); adds.ToList().ForEach(a => MovieGenresDirectorsRatingsFormatsManager.Add(id, a)); // TODO: Add update logic here MovieManager.Update(mgdrf.Movie); return(RedirectToAction("Index")); } catch (Exception ex) { ViewBag.Message = ex.Message; return(View()); } }