Advertisement
Stan0033

Untitled

Jul 20th, 2022 (edited)
851
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.97 KB | None | 0 0
  1. // problem 6  
  2. public static string GetBooksByCategory(BookShopContext context, string input)
  3.         {
  4.             //Return in a single string the titles of books by a given list of categories.
  5.             //Order by title alphabetically.
  6.             string[] categories = input.Split(' ');
  7.             StringBuilder output = new StringBuilder();
  8.            
  9.             string[] bookTitles = context
  10.                 .Books
  11.                
  12.                  .Where(book => book.BookCategories. ) // the category of the book contains all of the categories listed ??
  13.                                                        // relationship of Books with BooksCategories and Categories
  14.                 .Select(book => book.Title)
  15.                 .OrderBy(book => book)
  16.                 .ToArray();
  17.                 foreach(string title in bookTitles)
  18.             {
  19.                 output.AppendLine(title);
  20.             }
  21.  
  22.             return output.ToString().TrimEnd();
  23.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement