public async Task <IActionResult> PostQuestion([FromBody] guessinggame.Models.Question question) { var quiz = _context.Quiz.SingleOrDefault(q => q.ID == question.QuizId); if (quiz == null) { return(NotFound()); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _context.Questions.Add(question); try { await _context.SaveChangesAsync(); } catch (DbUpdateException) { if (QuestionExists(question.ID)) { return(new StatusCodeResult(StatusCodes.Status409Conflict)); } else { throw; } } return(Ok(question)); //return CreatedAtAction("GetQuestion", new { id = question.ID }, question); }
public async Task <IActionResult> PutQuestion(int id, [FromBody] guessinggame.Models.Question question) //public async Task<IActionResult> PutQuestion([FromRoute] int id, [FromBody] guessinggame.Models.Question question) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != question.ID) { return(BadRequest()); } _context.Entry(question).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!QuestionExists(id)) { return(NotFound()); } else { throw; } } return(Ok(question)); }