Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.54 KB | None | 0 0
  1.         public static string GetTotalProfitByCategory(BookShopContext db)
  2.         {
  3.             var books = db.Categories
  4.                 .Select(x => new
  5.                 {
  6.                     name = x.Name,
  7.                     profit = x.CategoryBooks.Sum(a => a.Book.Price * a.Book.Copies)
  8.                 })
  9.                 .OrderByDescending(x => x.profit)
  10.                 .ThenBy(x => x.name)
  11.                 .ToList();
  12.  
  13.             return string.Join(Environment.NewLine, books.Select(x => $"{x.name} ${x.profit:f2}"));
  14.  
  15.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement