async Task GetCastByIdWithMovieAsync() { try { Console.Write("Enter Id => "); int id = Convert.ToInt32(Console.ReadLine()); IEnumerable <Cast> casts = await castService.GetCastByIdWithMovieAsync(id); if (casts != null) { var result = casts.GroupBy(c => c.Id).Select(group => { var groupedCast = group.First(); groupedCast.Movies = group.Select(p => p.Movies.Single()).ToList(); groupedCast.Characters = group.Select(p => p.Characters.Single()).ToList(); return(groupedCast); }); bool any = false; foreach (var cast in result) { any = true; Console.WriteLine("Cast: " + cast.Name + "\n"); Console.WriteLine("Related Movies and Characters: "); if (cast.Movies.Count == cast.Characters.Count) { int length = cast.Movies.Count; for (int i = 0; i < length; i++) { Console.WriteLine(cast.Movies[i].Title + " \t\t\t " + cast.Characters[i]); } } Console.WriteLine(); } if (!any) { Console.WriteLine("No data."); } } else { Console.WriteLine("Some error occurs."); } } catch (FormatException fe) { Console.WriteLine("Only numbers are allowed"); } catch (OverflowException oe) { Console.WriteLine("value must be in between 1 to " + int.MaxValue); } catch (Exception ex) { Console.WriteLine("some error has been occured. Contact the admin department"); } }