ASP.NET Core 2 and Angular 5
上QQ阅读APP看书,第一时间看更新

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.