public string Create(int userId, int examinationId) { try { //todo: change it to a transaction var ue = new UserExamination { UserId = userId, ExaminationId = examinationId, UserAnswers = new List<UserAnswer>() }; foreach (var id in _context.ExaminationQuestion.Where(w => w.Examination.ExaminationId == examinationId) .Select(s => s.Question.QuestionId)) { ue.UserAnswers.Add(new UserAnswer { QuestionId = id }); } _context.UserExaminations.Add(ue); _context.SaveChanges(); return string.Empty; } catch (Exception ex) { return ex.Message; } }
public string AnswerQuestion(UserExamination examination, int questionId, string answer) { try { _context.Database.ExecuteSqlCommand("UpdateAnswer @p0, @p1, @p2", examination.UserExaminationId, questionId, answer); return string.Empty; } catch (Exception ex) { return ex.Message; } }
public string ExaminationDone(UserExamination examination) { try { examination.Status = ExaminationStatus.Done; _context.Entry(examination).State = EntityState.Modified; _context.SaveChanges(); return string.Empty; } catch (Exception ex) { return ex.Message; } }