/// <inheritdoc />
        public async Task <TaskGetDto> AddAsync(TaskPostDto taskDto)
        {
            var task = _mapper.Map <Task>(taskDto);

            _taskRepository.Add(task);
            await _taskRepository.SaveChangesAsync();

            return(_mapper.Map <TaskGetDto>(task));
        }
        public async Task <Models.Task> AddAsync(TaskPostDto entity)
        {
            TaskPostDtoValidator validator = new TaskPostDtoValidator();
            ValidationResult     results   = validator.Validate(entity);

            if (!results.IsValid)
            {
                throw new ValidationException("TaskPostDTO", string.Join(". ", results.Errors));
            }

            return(await _repository.AddAsync(mapper.Map <Models.Task>(entity)));
        }
        public async Task <ActionResult <TaskGetDto> > PostAsync([FromBody] TaskPostDto taskDto)
        {
            var insertedTask = await _taskService.AddAsync(taskDto);

            return(Ok(insertedTask));
        }
Exemple #4
0
        public async Task <IActionResult> AddNewTask([FromBody] TaskPostDto taskPostDto)
        {
            var taskResp = await taskService.AddAsync(taskPostDto);

            return(CreatedAtAction("GetTaskById", new { id = taskResp.ID }, mapper.Map <TaskResponseDto>(taskResp)));
        }