public IActionResult Add(AddMovieBindingModel model) { if (!this.ModelState.IsValid) { return(this.View()); } var director = this.context .Directors .FirstOrDefault(d => d.Name == model.Director); if (director == null) { director = new Director() { Name = model.Director }; this.context.Directors.Add(director); this.context.SaveChanges(); } var movie = new Movie() { DirectorId = director.Id, CoverImg = model.CoverImg, Title = model.Title, Description = model.Description }; this.context.Movies.Add(movie); this.context.SaveChanges(); return(this.RedirectToAction("Details", new { id = movie.Id })); }
public IActionResult Add(AddMovieBindingModel model) { if (ModelState.IsValid) { var movie = new Movie(); movie.Title = model.Title; var director = _context.Directors.FirstOrDefault(a => a.Name == model.Director); if (director is null) { director = new Director { Name = model.Director }; this._context.Directors.Add(director); this._context.SaveChanges(); } movie.DirectorId = director.Id; movie.PosterImageUrl = model.PosterImageUrl; movie.Description = model.Description; this._context.Movies.Add(movie); this._context.SaveChanges(); return(RedirectToAction("Details", new { id = movie.Id })); } return(this.View()); }
public IActionResult Add(AddMovieBindingModel model) { if (!this.ModelState.IsValid) { return(this.View()); } Director director = this.db.Directors.FirstOrDefault(a => a.Name == model.Director); if (director == null) { director = new Director() { Name = model.Director }; this.db.Add(director); this.db.SaveChanges(); } var movie = new Movie() { DirectorId = director.Id, CoverImg = model.CoverImg, Title = model.Title, ShortDescription = model.ShortDescription }; this.db.Add(movie); this.db.SaveChanges(); return(this.RedirectToPage("/Index")); }
public bool Add(AddMovieBindingModel model) { var movie = Mapper.Map <Movie>(model); this.context.Movies.Add(movie); this.context.SaveChanges(); return(true); }
public IActionResult Add(AddMovieBindingModel model) { if (!ModelState.IsValid) { return(this.View()); } var movie = this.movieService.Add(model); return(RedirectToAction("All", "Movies")); }
public IActionResult Add(AddMovieBindingModel model) { if (!ModelState.IsValid) { return(this.View()); } using (this.Context) { var director = this.Context .Directors .FirstOrDefault(x => x.Name == model.Director); if (director == default(Director)) { director = new Director() { Name = model.Director }; this.Context.Directors.Add(director); this.Context.SaveChanges(); } Movie movie = new Movie() { Title = model.Title, Description = model.Description, PosterImage = model.PosterImage, DirectorId = director.Id }; this.Context.Movies.Add(movie); this.Context.SaveChanges(); return(RedirectToAction("Details", new { id = movie.Id })); } }