示例#1
0
        public async Task <ActionResult <TaskDto[]> > GetByListIdAsync([FromQuery] int taskListId, CancellationToken token)
        {
            if (taskListId <= 0)
            {
                return(BadRequest());
            }

            List <AppTask> tasks = await _taskService.GetByTaskListIdAsync(taskListId, token);

            if (tasks == null || !tasks.Any())
            {
                return(Ok(Array.Empty <AppTask>()));
            }

            TaskDto[] taskDtos = tasks.Select(task => _mapper.MapToDto(task)).ToArray();
            return(Ok(taskDtos));
        }
 public TaskListDto MapToDto(Data.Entities.TaskList taskList)
 {
     return(new TaskListDto
     {
         Id = taskList.Id,
         Name = taskList.Name,
         Tasks = taskList.Tasks != null
             ? taskList.Tasks.Select(task => _taskMapper.MapToDto(task)).ToArray()
             : Array.Empty <TaskDto>()
     });
 }