public async Task<IActionResult> PutSurveyTaker([FromRoute] int id, [FromBody] SurveyTaker surveyTaker) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != surveyTaker.Id) { return BadRequest(); } _context.Entry(surveyTaker).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!SurveyTakerExists(id)) { return NotFound(); } else { throw; } } return NoContent(); }
public ActionResult PostAnswers([FromBody] SurveyAnswerRequest req) { SurveyTaker taker = new SurveyTaker(); taker.Uid = Guid.NewGuid().ToString(); taker.Turk = req.Turk; taker.SurveyUid = req.SurveyUid; var answerList = req.AnswerList; _context.SurveyTaker.Add(taker); for (int i = 0; i < answerList.Length; i++) { if (answerList[i] != null) { SurveyAnswer answer = new SurveyAnswer(); answer.Uid = Guid.NewGuid().ToString(); answer.SurveyTakerUid = taker.Uid; answer.SurveyUid = req.SurveyUid; answer.Answer = answerList[i]; answer.DateCompleted = DateTime.Now; answer.Qid = i; _context.SurveyAnswer.Add(answer); } } _context.SaveChanges(); return Ok(new { message = "Success!" }); }
public async Task<IActionResult> PostSurveyTaker([FromBody] SurveyTaker surveyTaker) { if (!ModelState.IsValid) { return BadRequest(ModelState); } _context.SurveyTaker.Add(surveyTaker); await _context.SaveChangesAsync(); return CreatedAtAction("GetSurveyTaker", new { id = surveyTaker.Id }, surveyTaker); }