From 4be6ec03ef62df77f933b1d48cc46390334de88d Mon Sep 17 00:00:00 2001 From: Dmitry Ignatiev Date: Wed, 15 Nov 2023 17:53:49 +0300 Subject: [PATCH] Order todo list by creation time --- .../todo_app/TodoApi/Controllers/TodoController.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/module2/08_docker_containerization_advanced/todo_app/TodoApi/Controllers/TodoController.cs b/module2/08_docker_containerization_advanced/todo_app/TodoApi/Controllers/TodoController.cs index 8a4bd13..f47189e 100644 --- a/module2/08_docker_containerization_advanced/todo_app/TodoApi/Controllers/TodoController.cs +++ b/module2/08_docker_containerization_advanced/todo_app/TodoApi/Controllers/TodoController.cs @@ -50,6 +50,8 @@ namespace TodoApi.Controllers q = q.Take(Math.Min(t, MaxResultCount)); } + q = q.OrderBy(e => e.CreatedAt); + var result = new { Items = await q.ToArrayAsync(), @@ -72,12 +74,12 @@ namespace TodoApi.Controllers await _db.SaveChangesAsync(); return Ok(todo); } - + [HttpPost("toggle")] public async Task Toggle(ToggleModel vm) { var now = DateTimeOffset.UtcNow; - + await _db.Todos.Where(e => vm.Ids.Contains(e.Id)) .ExecuteUpdateAsync(setters => setters