Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ublic static string ExportTopMovies(CinemaContext context, int rating)
- {
- //var test = context.Movies.First().Projections.Select(p => p.Tickets);
- var movies = context.Movies
- .Where(m => m.Rating >= rating && m.Projections.SelectMany(p => p.Tickets).Any())
- .OrderByDescending(m => m.Rating)
- .ThenByDescending(m => m.Projections.SelectMany(p => p.Tickets).Sum(t => t.Price))
- .Take(10)
- .Select(m => new
- {
- MovieName = m.Title,
- Rating = m.Rating.ToString("F2"),
- TotalIncomes = m.Projections.SelectMany(p => p.Tickets).Sum(t => t.Price).ToString("F2"),
- Customers = m.Projections
- .SelectMany(p => p.Tickets)
- .Select(t => t.Customer)
- .Select(t => new
- {
- FirstName = t.FirstName,
- LastName = t.LastName,
- Balance = t.Balance.ToString("F2")
- })
- .OrderByDescending(x => x.Balance)
- .ThenBy(x => x.FirstName)
- .ThenBy(x => x.LastName)
- .ToArray()
- })
- .ToArray();
- var result = JsonConvert.SerializeObject(movies, Newtonsoft.Json.Formatting.Indented);
- return result;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement