// GET: Actors/Details/5 public ActionResult Details(int id) { Actor actor = _actorRepository.GetActorById(id); if (actor == null) { return(HttpNotFound()); } return(View(actor)); }
//Detail public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ActorModel ActorModel = _ActorRep.GetActorById(id); if (ActorModel == null) { return(HttpNotFound()); } return(View(ActorModel)); }
public ActionResult Create([Bind(Include = "Name,Year,Plot,Image,ProducerId,ActorIDs,TmdbId")] CreateMovieViewModel model) { if (ModelState.IsValid) { Movie movie = new Movie { Id = new int(), Name = model.Name, Year = model.Year, Plot = model.Plot, Image = model.Image, TmdbId = model.TmdbId }; var producerId = int.Parse(model.ProducerId); //Producer producer = db.Producers.Find(ProducerId); Producer producer = _producerRepository.GetProducerById(producerId); movie.Producer = producer; if (model.ActorIDs != null) { foreach (var id in model.ActorIDs) { var actorId = int.Parse(id); var actor = _actorRepository.GetActorById(actorId); try { movie.Actors.Add(actor); } catch (Exception ex) { return(View("Error", new HandleErrorInfo(ex, "Movies", "Index"))); } } } try { _movieRepository.InsertMovie(movie); _movieRepository.Save(); } catch (Exception ex) { return(View("Error", new HandleErrorInfo(ex, "Movies", "Index"))); } //return RedirectToAction("Details", new { id=movie.ID}); TempData["Name"] = movie.Name; TempData["Method"] = "Create"; TempData["Exists"] = "true"; return(RedirectToAction("Index")); } ModelState.AddModelError("", "Something Failed."); return(View(model)); }
public IActionResult Get(int id) { try { var actor = actorRepository.GetActorById(id); return(Ok(actor)); } catch (Exception e) { throw e; } }
public Actor GetActorById(int id) { var result = _actorRepository.GetActorById(id); return(result); }
public Actor GetActorById(int id) { return(repo.GetActorById(id)); }
/// <summary> /// Responsible for persisting movie information after fetching information from TMDB endpoint. /// </summary> /// <param name="movieId">The Imdb movie id for the movie needs to be persisted.</param> public void PersistMoive(string movieId) { IContainer continer = IocContainerSingleton.Instance.Container; IMovieRepository movieRepository = continer.Resolve <IMovieRepository>(); if (movieRepository.CheckMovieExist(movieId)) { return; } IActorRepository actorRepository = continer.Resolve <IActorRepository>(); IDirectorRepository directorRepository = continer.Resolve <IDirectorRepository>(); IUnitOfWork unitOfWork = continer.Resolve <IUnitOfWork>(); TmdbMovieInformatonDto movieFromApi = movieInfoFetchService.GetMovieAsync(movieId); TmdbMovieCastInfoDto movieCastFromApi = movieInfoFetchService.GetMovieCreditsAsync(movieId); Movie movie = mapper.GetMapper().Map <Movie>(movieFromApi); movieRepository.PersistMovie(movie); foreach (var castedActor in movieCastFromApi.Cast.Take(8)) { Actor actor = null; if (!actorRepository.CheckExistById(castedActor.Id)) { actor = mapper.GetMapper().Map <Actor>(castedActor); actor.Movies.Add(movie); actorRepository.PersistActor(actor); } else { actor = actorRepository.GetActorById(castedActor.Id); actor.Movies.Add(movie); } movie.Actors.Add(actor); } List <TmdbCrewDto> directorInfoFromApi = movieCastFromApi.Crew .Where(crew => crew.Job == "Director").ToList(); foreach (TmdbCrewDto directorDtoFromApi in directorInfoFromApi) { Director director = null; if (!directorRepository.CheckExistById(directorDtoFromApi.Id)) { director = mapper.GetMapper().Map <Director>(directorDtoFromApi); director.Movies.Add(movie); directorRepository.PersistDirector(director); } else { director = directorRepository.GetDirectorById(directorDtoFromApi.Id); director.Movies.Add(movie); } movie.Directors.Add(director); } unitOfWork.Complete(); }