public ActionResult <MultichoiceTaskAnswerDto> AddTaskAnswer([FromBody] AddTaskAnswerCommand cmd) { StpTask task = _db.Tasks.Find(cmd.TaskId); if (task == null) { return(NotFound($"Answer with id={cmd.TaskId} doesn't exist")); } MultichoiceTaskAnswer answer = new MultichoiceTaskAnswer() { Name = cmd.Name, IsCorrect = cmd.IsCorrect, TaskId = cmd.TaskId }; _db.MultichoiceTaskAnswers.Add(answer); _db.SaveChanges(); var res = new MultichoiceTaskAnswerDto() { Id = answer.Id, Name = answer.Name, IsCorrect = answer.IsCorrect }; return(CreatedAtAction(nameof(AddTaskAnswer), res)); }
public IActionResult UpdateTaskAnswer([FromBody] MultichoiceTaskAnswerDto answerDto) { MultichoiceTaskAnswer answer = _db.MultichoiceTaskAnswers.Find(answerDto.Id); if (answer == null) { return(NotFound($"Answer with id={answerDto.Id} doesn't exist")); } answer.IsCorrect = answerDto.IsCorrect; answer.Name = answerDto.Name; _db.SaveChanges(); return(Ok()); }