public async Task <IActionResult> Put(int id, [FromBody] Quiz quiz) { try { Quiz existing = await QuizRepo.GetQuizById(id); if (existing is null) { return(NotFound()); } quiz.QuizId = id; var success = await QuizRepo.EditQuiz(quiz); if (!success) { return(BadRequest("invalid request")); } } catch (ArgumentException ex) { return(BadRequest(ex.Message)); } return(NoContent()); }
public async Task <ActionResult <Quiz> > GetQuizById(int id) { if (await QuizRepo.GetQuizById(id) is Quiz quiz) { return(quiz); } return(NotFound()); }
public async Task <IActionResult> Post([FromBody] Quiz quiz) { try { var id = await QuizRepo.CreateQuiz(quiz); Quiz model = await QuizRepo.GetQuizById(id); return(CreatedAtRoute("Get", new { Id = id }, model)); } catch (ArgumentException ex) { return(BadRequest(ex.Message)); } }