public void Publish_WithValidId_MovesTheMovie() { var inputMovie = new MovieCreationBindingModel() { Title = "firsts", Genre = "action", Lenght = 122, Director = "Jon", Description = "dsgdsgdsgdsgdsgdsgdsgdsghthrthrtjdfdfhtrjtrj", ReleaseDate = DateTime.Parse("Jan 1, 2030") }; var controller = new UpcomingMoviesController(dbContext, mapper); controller.Create(inputMovie); dbContext.SaveChanges(); var movie = dbContext.UpcomingMovies.First(); controller.Publish(movie.Id); var movies = dbContext.Movies.ToList(); var upcomingMovies = dbContext.UpcomingMovies.ToList(); Assert.AreEqual(1, movies.Count); Assert.AreEqual(0, upcomingMovies.Count); }
public IActionResult Create(MovieCreationBindingModel model) { if (!ModelState.IsValid) { return(View()); } var director = this.context.Directors.FirstOrDefault(d => d.FullName == model.Director); if (director == null) { director = new Director() { FullName = model.Director, ImageUrl = model.DirectorImageUrl }; this.context.Directors.Add(director); this.context.SaveChanges(); } var movie = new Movie { Title = model.Title, Director = director, Genre = model.Genre, Lenght = model.Lenght, ReleaseDate = model.ReleaseDate, Actors = model.Actors, Description = model.Description, Reviews = new List <Review>(), ImageUrl = model.ImageUrl }; if (this.context.Movies.Any(m => m.Title == movie.Title)) { return(RedirectToAction("Create", "Movies", new { area = "admin" })); } this.context.Movies.Add(movie); context.SaveChanges(); return(RedirectToAction("Index", "Movies", new { area = "admin" })); }