Exemple #1
0
        public async Task <IReadOnlyList <TodoDto> > Handle(ListAllTodosQuery request, CancellationToken cancellationToken)
        {
            var currentAccount = await accountProvider.GetCurrentAsync(cancellationToken);

            var todos = await customDbContext.Todos
                        .AsNoTracking()
                        .Where(todo => todo.OwnerId == currentAccount.Id)
                        .Where(todo => !todo.Archived)
                        .OrderBy(t => t.Completed ? 1 : 0)
                        .ThenByDescending(t => EF.Property <int>(t.Priority, "priority"))
                        .Skip(request.Offset)
                        .Take(request.Limit)
                        .Select(todo => new TodoDto(todo.Id.ToGuid(), todo.Name, todo.Priority.ToInt32(), todo.Completed, todo.GroupId))
                        .ToListAsync(cancellationToken);

            return(todos.AsReadOnly());
        }
Exemple #2
0
        public async Task <ActionResult <IEnumerable <TodoDto> > > GetAsListAsync(int limit, int offset, bool listAll, Guid?groupId)
        {
            IRequest <IReadOnlyList <TodoDto> > query;

            if (groupId.HasValue)
            {
                query = new ListTodosByGroupQuery(groupId.Value, limit, offset);
            }
            else if (listAll)
            {
                query = new ListAllTodosQuery(limit, offset);
            }
            else
            {
                query = new ListTodosWithoutGroupQuery(limit, offset);
            }

            var todos = await requestSender.Send(query);

            return(Ok(todos));
        }