public ActionResult Create(ActorViewModel actorVM) { if (ModelState.IsValid && actorVM != null) { Actor actor = new Actor { Name = actorVM.Name, Studio = actorVM.Studio, StudioAddress = actorVM.StudioAddress }; db.Actors.Add(actor); db.SaveChanges(); return Content(""); } return PartialView("_CreateActor", actorVM); }
public ActionResult Create(MovieViewModel movieVM) { if (ModelState.IsValid && movieVM != null) { var actorId = Convert.ToInt32(movieVM.LandingMaleRoleName); var actressId = Convert.ToInt32(movieVM.LandingFemaleRoleName); Actor leadingActress = new Actor(); Actor leadingActor = new Actor(); if (actorId > 0) { leadingActor = db.Actors.Find(actorId); if (leadingActor == null) { throw new ArgumentException("Actor does not exists!"); } } if (actressId > 0) { leadingActress = db.Actors.Find(actressId); if (leadingActress == null) { throw new ArgumentException("Actress does not exists!"); } } Movie movie = new Movie() { Title = movieVM.Title, Year = movieVM.Year, LandingFemaleRole = leadingActress, LandingMaleRole = leadingActor }; db.Movies.Add(movie); db.SaveChanges(); return Content(""); } return PartialView("_CreateMovie", movieVM); }