public ActionResult <TaskReadDto> PostTask(TaskCreateDto taskCreateDto)
        {
            _logger.LogInformation("Consultando a lista de tarefas de Id: {id}", taskCreateDto.TaskListId);
            TaskList taskList = _taskListsRepo.GetTaskListById(taskCreateDto.TaskListId);

            if (taskList == null)
            {
                _logger.LogWarning("A lista de tarefas de Id: {id} não existe", taskCreateDto.TaskListId);
                return(NotFound());
            }

            _logger.LogInformation("Mapeando a tarefa a ser cadastrada para a model");
            Models.Task task = _mapper.Map <Models.Task>(taskCreateDto);

            _logger.LogInformation("Cadastrando a tarefa no banco de dados");
            _tasksRepo.PostTask(task);
            _tasksRepo.SaveChanges();

            if (taskCreateDto.Tags != null && taskCreateDto.Tags.Count > 0)
            {
                Tag     tag;
                TaskTag taskTag = new TaskTag()
                {
                    TaskId = task.Id
                };

                _logger.LogInformation("Cadastrando as tags da tarefa e fazendo os relacionamentos no banco de dados");
                foreach (TagCreateDto tagCreateDto in taskCreateDto.Tags)
                {
                    tag = _mapper.Map <Tag>(tagCreateDto);
                    _tagsRepo.PostTag(tag);
                    _tagsRepo.SaveChanges();

                    taskTag.TagId = tag.Id;
                    _taskTagsRepo.PostTaskTag(taskTag);
                    _taskTagsRepo.SaveChanges();
                }
            }

            _logger.LogInformation("Montando objeto de retorno");
            Models.Task taskCreated = _tasksRepo.GetTaskById(task.Id);
            TaskReadDto taskReadDto = _mapper.Map <TaskReadDto>(taskCreated);

            if (taskCreated.TaskTags != null && taskCreated.TaskTags.Count > 0)
            {
                List <Tag> tags = taskCreated.TaskTags.Select(tt => tt.Tag).ToList();
                taskReadDto.Tags = _mapper.Map <List <TagReadDto> >(tags);
            }

            return(CreatedAtAction("GetTaskById", new { id = taskReadDto.Id }, taskReadDto));
        }
        public ActionResult <TaskReadDto> GetTaskById(long id)
        {
            _logger.LogInformation("Consultando a tarefa de Id: {id}", id);
            Models.Task task = _tasksRepo.GetTaskById(id);

            if (task == null)
            {
                _logger.LogWarning("A tarefa de Id: {id} não existe", id);
                return(NotFound());
            }

            _logger.LogInformation("Mapeando a tarefa de Id: {id} para a classe de DTO", id);
            TaskReadDto taskReadDto = _mapper.Map <TaskReadDto>(task);

            if (task.TaskTags != null && task.TaskTags.Count > 0)
            {
                _logger.LogInformation("Mapeando as tags da tarefa de Id: {id} para a classe de DTO", id);
                List <Tag> tags = task.TaskTags.Select(tt => tt.Tag).ToList();
                taskReadDto.Tags = _mapper.Map <List <TagReadDto> >(tags);
            }

            return(Ok(taskReadDto));
        }