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 DeleteTaskAnswer(long answerId) { MultichoiceTaskAnswer answer = _db.MultichoiceTaskAnswers.Find(answerId); if (answer == null) { return(NotFound($"Answer with id={answerId} doesn't exist")); } answer.IsDeleted = true; _db.SaveChanges(); return(NoContent()); }
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()); }