public async Task <IEnumerable <TodoItemSummaryViewmodel> > GetItemsAsync(int todoListId, TodoItemsQuery query) { var itemsQuery = _dbContext .TodoItems .Include(x => x.ResponsibleParty) .Where(x => x.TodoListId == todoListId && (!query.HideDone || !x.IsDone)); itemsQuery = SortItems(); var items = itemsQuery .ToList() .Select(TodoItemSummaryViewmodelFactory.Create) .ToList(); await FillGravatarInfoAsync(items); return(items); IQueryable <TodoItem> SortItems() { if (query.OrderBy == ItemsOrderOption.ByImportance) { itemsQuery = itemsQuery.OrderBy(x => x.Importance); } if (query.OrderBy == ItemsOrderOption.ByRank) { itemsQuery = itemsQuery.OrderByDescending(x => x.Rank); } return(itemsQuery); } }
public async Task <IEnumerable <TodoItemSummaryViewmodel> > GetItems(int id, [FromQuery] TodoItemsQuery query) => await _todoItemService.GetItemsAsync(id, query);