public async Task <IActionResult> PostUpvoteQuestion([FromBody] UpvoteQuestion upvoteQuestion) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _context.UpvoteQuestion.Add(upvoteQuestion); try { await _context.SaveChangesAsync(); } catch (DbUpdateException) { if (UpvoteQuestionExists(upvoteQuestion.QuestionId)) { return(new StatusCodeResult(StatusCodes.Status409Conflict)); } else { throw; } } return(CreatedAtAction("GetUpvoteQuestion", new { id = upvoteQuestion.QuestionId }, upvoteQuestion)); }
public async Task <IActionResult> PutUpvoteQuestion([FromRoute] long id, [FromBody] UpvoteQuestion upvoteQuestion) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != upvoteQuestion.QuestionId) { return(BadRequest()); } _context.Entry(upvoteQuestion).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!UpvoteQuestionExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }