Advertisement
Iv555

Untitled

Jul 10th, 2022
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.51 KB | None | 0 0
  1. public static string GetBooksByCategory(BookShopContext context, string input)
  2.         {
  3.             string[] categories = input.ToLower().Split(" ", StringSplitOptions.RemoveEmptyEntries);
  4.  
  5.             List<string> books = context.Books
  6.                 .Where(x => x.BookCategories.Any(x => categories.Contains(x.Category.Name.ToLower())))
  7.                 .Select(x => x.Title)
  8.                 .OrderBy(x => x)
  9.                 .ToList();
  10.  
  11.             return string.Join(Environment.NewLine, books);
  12.  
  13.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement