Ejemplo n.º 1
0
        /// <summary>
        /// Saves information about student's results on specific question
        /// </summary>
        /// <param name="questionId">Question id</param>
        /// <param name="isCorrect">Answer is correct</param>
        public static void AddAttempt(int questionId, bool isCorrect)
        {
            var db = new Entities();

            var question = db.Questions.FirstOrDefault(x => x.ID == questionId);

            if (question == null) throw new Exception("Вопрос не найден");

            question.TotalAttempts++;
            if (isCorrect) question.RightAttempts++;

            db.ObjectStateManager.ChangeObjectState(question, EntityState.Modified);
            db.SaveChanges();
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Add test result to database
 /// </summary>
 /// <param name="result">Result instance</param>
 public static void Add(Result result)
 {
     var db = new Entities();
     db.Results.AddObject(result);
     db.SaveChanges();
 }