Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //problem 7
- public static string GetBooksReleasedBefore(BookShopContext context, string date) {
- StringBuilder output = new StringBuilder();
- //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.
- // DateTime customDate = new DateTime();
- // customDate = customDate.AddYears(int.Parse(date.Split('-')[2]));
- // customDate = customDate.AddMonths(int.Parse(date.Split('-')[1]));
- // customDate = customDate.AddDays(int.Parse(date.Split('-')[0]));
- string[] bookTitles = context
- .Books
- .Where(book => book.ReleaseDate < DateTime.Parse(date))
- .OrderByDescending(book => book.ReleaseDate)
- .Select(book => $"{book.Title} - {book.EditionType} - ${book.Price:f2}")
- .ToArray();
- foreach (string title in bookTitles)
- {
- output.AppendLine(title);
- }
- return output.ToString().TrimEnd();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement