public async Task <IActionResult> AddMovies([Bind("Id,Name,Duration,Synopsis,Director,TrailerUrl,PosterUrl,CheckBoxes, Actor1, Actor2, Actor3, Actor4")] MovieRes movie) { movie.AllGenreNames = await _moviesRepository.GetMovieGenres(); //movie.CheckBoxes = new CheckBoxModel[movie.AllGenreNames.Count]; //for (var i = 0; i < movie.AllGenreNames.Count; i++) //{ // movie.CheckBoxes[i] = new CheckBoxModel // { // Id = movie.AllGenreNames[i].Id, // IsSelected = false // }; //} if (ModelState.IsValid) { // for( var i = 0;i<movie.AllGenreNames.Count;i++) // { // if (movie.AllGenreNames[i].Id == movie.CheckBoxes[i].Id && movie.CheckBoxes[i].IsSelected) // { // movie.GenreNames.Add(movie.AllGenreNames[i].Name); // } // } await _moviesRepository.AddMovies(movie); return(RedirectToAction("HomeAdmin", "Administrator")); } return(View(movie)); }
public async Task <IActionResult> Details(MovieGetDetailsReq req) { MovieRes res = await _moviesRepository.GetDetailsAsync(req); res.Projections = res.Projections.OrderBy(p => p.ProjectionTime).ToList(); return(View(res)); }
public async Task <MovieRes> GetDetailsAsync(MovieGetDetailsReq req) { ProjectionGetDetailsByMovieIdReq projectionReq = new ProjectionGetDetailsByMovieIdReq { MovieId = req.Id }; IList <ProjectionRes> projections = await _projectionsRepository.GetProjectionsForMovieAsync(projectionReq); MovieRes res = await _dbContext.Movies .Where(m => m.Id == req.Id) .Select(m => new MovieRes { Id = m.Id, Name = m.Name, TrailerURL = m.TrailerUrl, PosterURL = m.PosterUrl, Duration = m.Duration, Synopsis = m.Synopsis, Director = m.Director, Projections = projections, GenreNames = m.GenreLinks .Select(mgl => mgl.MovieGenre.Name) .ToList(), ActorNames = m.ActorMovieLinks .Select(aml => aml.Actor.Name) .ToList() }).FirstOrDefaultAsync(); return(res); }
public async Task <IActionResult> DeleteMovies(int id) { if (id == null) { return(NotFound()); } MovieRes movie = await _moviesRepository.GetDetailsAsync(new MovieGetDetailsReq(id)); if (movie == null) { return(NotFound()); } return(View(movie)); }
public async Task <IActionResult> DeleteMovies1(int id) { if (id == null) { return(NotFound()); } //MovieRes movie = await _moviesRepository.GetDetailsAsync(new MovieGetDetailsReq(id)); //if (_moviesRepository.DeleteMovie(movie).IsCompleted) //{ // return RedirectToAction("HomeAdmin", "Administrator"); // } //return View(movie); MovieRes movie = await _moviesRepository.GetDetailsAsync(new MovieGetDetailsReq(id)); if (ModelState.IsValid) { await _moviesRepository.DeleteMovies(id); return(RedirectToAction("HomeAdmin", "Administrator")); } return(View(movie)); }
public async Task <Boolean> AddMovies(MovieRes res) { try { /* Actor actor1 = _dbContext.Actors.Where(a => a.Name == res.Actor1).FirstOrDefault(); * Actor actor2 = _dbContext.Actors.Where(a => a.Name == res.Actor2).FirstOrDefault(); * Actor actor3 = _dbContext.Actors.Where(a => a.Name == res.Actor3).FirstOrDefault(); * Actor actor4 = _dbContext.Actors.Where(a => a.Name == res.Actor4).FirstOrDefault(); * */ Movie movie = new Movie { Name = res.Name, Duration = res.Duration, Synopsis = res.Synopsis, Director = res.Director, TrailerUrl = res.TrailerURL, PosterUrl = res.PosterURL, }; _dbContext.Add(movie); await _dbContext.SaveChangesAsync(); /* * * int id = _dbContext.Movies.Where(m => m.Name == movie.Name).FirstOrDefault().Id; * * * if (GetActorByName(res.Actor1)!=null) * { * Actor actor1 = new Actor * { * Name = res.Actor1 * }; * _dbContext.Actors.Add(actor1); * ActorMovieLink aml1 = new ActorMovieLink * { * MovieId = id * }; * * } * if (GetActorByName(res.Actor2) != null) * { * Actor actor2 = new Actor * { * Name = res.Actor2 * }; * _dbContext.Actors.Add(actor2); * } * if (GetActorByName(res.Actor3) != null) * { * Actor actor3 = new Actor * { * Name = res.Actor3 * }; * _dbContext.Actors.Add(actor3); * } * if (GetActorByName(res.Actor4) != null) * { * Actor actor4 = new Actor * { * Name = res.Actor4 * }; * _dbContext.Actors.Add(actor4); * } * * * * * * * await _dbContext.SaveChangesAsync(); * * */ return(true); } catch { return(false); } }