Exemplo n.º 1
0
 /// <summary>
 /// This function calculates score for individual question
 /// </summary>
 /// <param name="kQuestion"></param>
 /// <returns></returns>
 public double CalculateScoreForQuestion(KillerQuestion kQuestion)
 {
     var finalQuestionScore = 0.0f;
     if (kQuestion.Answers != null && kQuestion.Answers.Count > 0)
     {
         //single or multiple choice
         if (!kQuestion.SingleChoice)
         {
             //multiple choice
             var totalGainableScore = kQuestion.Answers.Sum(t => t.Score);
             foreach (var candidateAnswer in kQuestion.CandidateAnswers)
             {
                 var killerQuestionAnswer =
                     kQuestion.Answers.FirstOrDefault(k => k.AnswerId == candidateAnswer.AnswerId);
                 if (killerQuestionAnswer != null)
                 {
                     // this will manage the single and multiple choice answers
                     finalQuestionScore = (finalQuestionScore + killerQuestionAnswer.Score);
                 }
             }
             // Get the score from 100  eq:  (total scored /  totalGainableScore * 100)
             finalQuestionScore = finalQuestionScore / totalGainableScore * 100;
         }
         else
         {
             //single choice 
             if (kQuestion.CandidateAnswers != null && kQuestion.CandidateAnswers.Count > 0)
             {
                 //get the candidate answer 
                 var killerQuestionAnswer =
                     kQuestion.Answers.FirstOrDefault(
                         k => k.AnswerId == kQuestion.CandidateAnswers[0].AnswerId);
                 if (killerQuestionAnswer != null)
                 {
                     // this will manage the single and multiple choice answers
                     finalQuestionScore = killerQuestionAnswer.Score;
                 }
             }
         }
     }
     else
     {
         if (kQuestion.CandidateAnswers != null && kQuestion.CandidateAnswers.Count > 0)
         {
             // open questin with score
             var candidateAnswer = kQuestion.CandidateAnswers[0];
             if (candidateAnswer.AdditionalScore > 0)
             {
                 // sum up the score for the open question 
                 finalQuestionScore = candidateAnswer.AdditionalScore;
             }
         }
     }
     return Math.Round(finalQuestionScore, 2);
 }
Exemplo n.º 2
0
        /// <summary>
        /// This function add edit killer question
        /// </summary>
        /// <returns></returns>
        public int AddEditKillerQuestion(KillerQuestion kQuestion)
        {
            var context = new dbDataContext();
            if (kQuestion.Deleted && kQuestion.KillerQuestionId > 0)
            {
                DeleteKillerQuestion(kQuestion.KillerQuestionId);
                return -1;
            }

            // Create or retrieve the killer question
            var killerQuestion = context.tbl_KillerQuestions.FirstOrDefault(t => t.QuestionId == kQuestion.KillerQuestionId) ?? new tbl_KillerQuestion();
            // Assign killer question values
            killerQuestion.Question = kQuestion.Question;
            killerQuestion.JobId = kQuestion.JobId;
            killerQuestion.ExcludeFromScoring = kQuestion.ExcludeFromScoring;
            killerQuestion.SingleChoice = kQuestion.SingleChoice;
            killerQuestion.Published = true;
            try
            {
                // Add/Update killer question
                if (killerQuestion.QuestionId <= 0)
                {
                    killerQuestion.CreatedDate = DateTime.Now;
                    context.tbl_KillerQuestions.InsertOnSubmit(killerQuestion);
                }
                context.SubmitChanges();
            }
            catch (Exception e)
            {
                throw new Exception(e.ToString());
            }

            if (killerQuestion.QuestionId > 0)
            {
                kQuestion.KillerQuestionId = killerQuestion.QuestionId;
                //add answers
                foreach (var kAnswer in kQuestion.Answers)
                {
                    kAnswer.KillerQuestionId = kQuestion.KillerQuestionId;
                    kAnswer.AnswerId = AddEdtKillerQuestionAnswer(kAnswer);
                }

                //delete existing answers which have deleted from the save
                var answers = (from t in context.tbl_KillerQuestionAnswers
                               where !(kQuestion.Answers.Select(k => k.AnswerId)).Contains(t.AnswerId) && t.QuestionId == killerQuestion.QuestionId
                               select t);
                context.tbl_KillerQuestionAnswers.DeleteAllOnSubmit(answers);
                context.SubmitChanges();
            }
            else
            {
                return -1;
            }
            return kQuestion.KillerQuestionId;
        }