public async Task <IActionResult> MovieInfo(string movieId) { var client = _clientFactory.CreateClient(); var request = new HttpRequestMessage(HttpMethod.Get, $"{MovieAPIRoot}getmovie/{movieId}"); request.Headers.Add("Accept", "application/json"); request.Headers.Add("User-Agent", "DotNetflix.Web"); var response = await client.SendAsync(request); if (response.IsSuccessStatusCode) { using var responseStream = await response.Content.ReadAsStreamAsync(); var movie = await JsonSerializer.DeserializeAsync <Movie>(responseStream, new JsonSerializerOptions() { PropertyNameCaseInsensitive = true }); var vm = new MovieInfoViewModel() { Movie = movie }; return(View(vm)); } return(View()); }
public async Task <IActionResult> Index(string id) { try { var cmdbMovie = cmdbrepo.GetMovieCMDb(id); var omdbMovie = omdbrepo.GetMovieByID(id); List <Task> tasks = new List <Task>() { cmdbMovie, omdbMovie }; await Task.WhenAll(tasks); MovieInfoViewModel viewModel = new MovieInfoViewModel(cmdbMovie.Result, omdbMovie.Result); return(View(viewModel)); } //Ifall något går fel så skickas användaren till Error vyn. catch (Exception) { return(RedirectToAction("Index", "Error")); } }
public async Task <IActionResult> Index(string id) { var json = await movieServices.GetByIDAsync(id); MovieFull movieFull = JsonConvert.DeserializeObject <MovieFull>(json); var commentsForMovie = _moviedb.Comments.Where(comment => comment.MovieImdbApi == id); List <AppUser> users = new List <AppUser>(); foreach (var comment in commentsForMovie) { var user = await _userManager.FindByIdAsync(comment.UserId); users.Add(user); } MovieInfoViewModel viewModel = new MovieInfoViewModel { Movie = movieFull, comments = commentsForMovie, userEmails = users }; return(View(viewModel)); }
public MovieInfo(MovieShort movieIntro) : this() { BindingContext = new MovieInfoViewModel(movieIntro, new PageService()); }