public async Task <ActionResult> SelectedItems(Moives items) { try { // List<MoviesItem> movielist = new List<MoviesItem>(); var rating = 0.0; var runtimemovie = 0; if (items != null && items.SelectedMovies != null) { foreach (var item in items.SelectedMovies) { var movieItem = await searchMovies.MoviiesByID(item); try { if (!movieItem.imdbRating.ToLower().Contains("n/a")) { rating += Convert.ToDouble(movieItem.imdbRating); } if (movieItem.Runtime.ToLower().Contains("min")) { runtimemovie += Convert.ToInt32(movieItem.Runtime.ToLower().Replace("min", "")); } } catch (System.Exception) { ViewBag.Error = "Something Wrong..Please Try Later"; } ViewBag.totalTime = runtimemovie; ViewBag.AvgRating = Math.Round(rating / items.SelectedMovies.Count, 2); ViewBag.Search = true; } } else { ViewBag.Error = "Select Aleast One Item From List"; } return(View("index", iMovieList)); } catch (System.Exception) { ViewBag.Error = "Something Wrong..Please Try Later"; // return HttpNotFound(); return(View("index", iMovieList)); } }
public async Task <Moives> GetMoviesAsync(string title, string type, string year) { try { using (var httpClient = new System.Net.Http.HttpClient()) { Moives movies = new Moives(); var url = AplicationData.Url; if (title != null) { url = $"{url}&s={title}"; } if (type.Trim() != string.Empty) { url = $"{url}&type={type}"; } if (year != null) { url = $"{url}&y={year}"; } using (System.Net.Http.HttpResponseMessage response = await httpClient.GetAsync(url)) { if (response.IsSuccessStatusCode) { string json = await response.Content.ReadAsStringAsync(); movies = JsonConvert.DeserializeObject <Moives>(json); } } return(movies); } } catch (Exception) { throw; } }