public async Task <ActionResult <TaskDto> > CreateAsync([FromBody][Required] TaskDto taskDto, CancellationToken token) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var task = _mapper.MapToEntity(taskDto); var created = await _taskService.AddTaskAsync(task, token); return(CreatedAtAction(nameof(GetByIdAsync), new { id = created.Id }, _mapper.MapToDto(created))); }
public Data.Entities.TaskList MapToEntity(TaskListDto dto, string userId) { return(new Data.Entities.TaskList { Id = dto.Id, Name = dto.Name, UserId = userId, Tasks = dto.Tasks != null ? dto.Tasks.Select(task => _taskMapper.MapToEntity(task)).ToArray() : null }); }