Advertisement
Stan0033

Untitled

Jul 21st, 2022
841
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.17 KB | None | 0 0
  1. //problem 7
  2.         public static string GetBooksReleasedBefore(BookShopContext context, string date) {
  3.             StringBuilder output = new StringBuilder();
  4.             //Return the title, edition type and price of all books that are released before a given date. The date will be a string in format dd-MM-yyyy.
  5.           //  DateTime customDate = new DateTime();
  6.            // customDate = customDate.AddYears(int.Parse(date.Split('-')[2]));
  7.          //   customDate = customDate.AddMonths(int.Parse(date.Split('-')[1]));
  8.           //  customDate = customDate.AddDays(int.Parse(date.Split('-')[0]));
  9.          
  10.             string[] bookTitles = context
  11.                 .Books
  12.                
  13.                 .Where(book => book.ReleaseDate < DateTime.Parse(date))
  14.                 .OrderByDescending(book => book.ReleaseDate)
  15.                  .Select(book => $"{book.Title} - {book.EditionType} - ${book.Price:f2}")
  16.                  
  17.                 .ToArray();
  18.  
  19.              
  20.  
  21.             foreach (string title in bookTitles)
  22.             {
  23.                 output.AppendLine(title);
  24.             }
  25.             return output.ToString().TrimEnd();
  26.        
  27.        
  28.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement