Advertisement
dimitrix85

Untitled

Apr 7th, 2019
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.57 KB | None | 0 0
  1. ublic static string ExportTopMovies(CinemaContext context, int rating)
  2.         {
  3.             //var test = context.Movies.First().Projections.Select(p => p.Tickets);
  4.  
  5.             var movies = context.Movies
  6.                 .Where(m => m.Rating >= rating && m.Projections.SelectMany(p => p.Tickets).Any())
  7.                 .OrderByDescending(m => m.Rating)
  8.                 .ThenByDescending(m => m.Projections.SelectMany(p => p.Tickets).Sum(t => t.Price))
  9.                 .Take(10)
  10.                 .Select(m => new
  11.                 {
  12.                     MovieName = m.Title,
  13.                     Rating = m.Rating.ToString("F2"),
  14.                     TotalIncomes = m.Projections.SelectMany(p => p.Tickets).Sum(t => t.Price).ToString("F2"),
  15.                     Customers = m.Projections
  16.                         .SelectMany(p => p.Tickets)
  17.                         .Select(t => t.Customer)
  18.                         .Select(t => new
  19.                                 {
  20.                                     FirstName = t.FirstName,
  21.                                     LastName = t.LastName,
  22.                                     Balance = t.Balance.ToString("F2")
  23.                                 })
  24.                         .OrderByDescending(x => x.Balance)
  25.                         .ThenBy(x => x.FirstName)
  26.                         .ThenBy(x => x.LastName)
  27.                         .ToArray()
  28.                 })            
  29.                 .ToArray();
  30.  
  31.             var result = JsonConvert.SerializeObject(movies, Newtonsoft.Json.Formatting.Indented);
  32.  
  33.             return result;
  34.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement