public ActionResult Create(MovieAdd newItem) { if (ModelState.IsValid) { var addedItem = man.AddMovie(newItem); if (addedItem == null) { return View("Error"); } else { return RedirectToAction("Index"); } } else { return View("Error"); } }
public Movie AddMovie(MovieAdd newItem) { Movie movie = Mapper.Map<Movie>(newItem); movie.Director = dc.Directors.Find(newItem.DirectorId); try { foreach (var item in newItem.GenreId.ToList()) { movie.Genres.Add(dc.Genres.Find(item)); } } catch (System.ArgumentNullException) { } dc.Movies.Add(movie); dc.Directors.Find(newItem.DirectorId).Movies.Add(movie); try { foreach (var item in newItem.GenreId.ToList()) { dc.Genres.Find(item).Movies.Add(movie); } } catch (System.ArgumentNullException) { } dc.SaveChanges(); return movie; }