コード例 #1
0
 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;
     }
 }
コード例 #2
0
 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;
     }
 }
コード例 #3
0
 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;
     }
 }