public IHttpActionResult PutQuestionResponse(int id, QuestionResponse questionResponse) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != questionResponse.Id) { return BadRequest(); } db.Entry(questionResponse).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!QuestionResponseExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }
public IHttpActionResult PostQuestionResponse(QuestionResponse questionResponse) { if (!ModelState.IsValid) { return BadRequest(ModelState); } Thread.Sleep(1000); questionResponse.MentorId = this.User.Identity.GetUserId(); var surveyQuestion = db.SurveyQuestions.Where(x => x.Id == questionResponse.QuestionId).FirstOrDefault(); questionResponse.SurveyQuestion = surveyQuestion; db.QuestionResponses.Add(questionResponse); db.SaveChanges(); return CreatedAtRoute("DefaultApi", new { id = questionResponse.Id }, questionResponse); }