ByTitle()

Go right after the Latest() method and add the following code:

/// <summary>
/// GET: api/quiz/ByTitle
/// Retrieves the {num} Quizzes sorted by Title (A to Z)
/// </summary>
/// <param name="num">the number of quizzes to retrieve</param>
/// <returns>{num} Quizzes sorted by Title</returns>
[HttpGet("ByTitle/{num:int?}")]
public IActionResult ByTitle(int num = 10)
{
var sampleQuizzes = ((JsonResult)Latest(num)).Value
as List<QuizViewModel>;

return new JsonResult(
sampleQuizzes.OrderBy(t => t.Title),
new JsonSerializerSettings()
{
Formatting = Formatting.Indented
});
}

As we can see, this internally calls the Latest() method itself--which actually just returns some sample quizzes created on-the-fly--and outputs them in alphabetical order.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.21.46.78