public async Task <ActionResult> Store([FromBody] ExamViewModel model) { int id = model.Id; var existingEntity = await _examsService.GetByIdAsync(id); if (existingEntity == null) { return(NotFound()); } ValidateEditRequest(existingEntity); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var exam = model.MapEntity(_mapper, CurrentUserId); //先存檔 _examsService.SaveExam(existingEntity, exam); //對答案 bool withOptions = true; exam = _examsService.GetById(id, withOptions); exam.SetAnswers(); exam.Finish(); await _examsService.UpdateAsync(exam); return(Ok()); }
public async Task <ActionResult> Save(int id, [FromBody] ExamViewModel model) { var existingEntity = await _examsService.GetByIdAsync(id); if (existingEntity == null) { return(NotFound()); } var exam = model.MapEntity(_mapper, CurrentUserId); ValidateSaveRequest(exam); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _examsService.SaveExam(existingEntity, exam); return(Ok()); }