Пример #1
0
        /// <summary>
        /// UpdateAssessmentScore - This method is called to recalculate the section score after a checkbox is clicked.  The method is
        /// called from the Assessment controller as it is responding to the Ajax call to update the checkbox
        /// </summary>
        /// <param name="sessionAssessment">Assessment object passed from the controller</param>
        /// <param name="questionID">Integer - ID of question checked on the screen</param>
        /// <param name="questionValue">boolean - new value of checkbox that was checked on the screen</param>
        /// <returns></returns>
        internal Assessment UpdateAssessmentScore(Assessment sessionAssessment, int questionID, bool questionValue)
        {
            // Select the question object from the Assessment
            var question = from o in sessionAssessment.CategoryDatas
                           from p in o.SectionDatas
                           from q in p.GroupDatas
                           from r in q.QuestionDatas
                           where r.QuestionID == questionID
                           select r;

            // Update the Answer value with the new value from the screen
            question.Single().Answer = questionValue;

            // Recompute the Section scores
            sessionAssessment.CalculateScore();

            return(sessionAssessment);
        }
Пример #2
0
        /// <summary>
        /// UpdateAssessmentData updates the assessment question data with the changes made by the user.  It is called from the Update action
        /// method in the AssessmentController when an assessment is saved.
        /// </summary>
        /// <param name="assessmentToUpdate">int? - AssessmentID of assessment being updated</param>
        /// <param name="assessmentResponse">string[] of QuestionIDs which are generated in the Update view for the AssessmentController</param>
        /// <param name="updateIdentity">int - Identity of user making updates to the assessment</param>
        internal void UpdateAssessmentData(int?assessmentID, string[] assessmentResponse, int updateIdentity)
        {
            var        responseHS         = new HashSet <string>();
            Assessment assessmentToUpdate = new Assessment();

            if (assessmentID != null)
            {
                assessmentToUpdate = DAL.GetAssessment(assessmentID.Value);

                if (assessmentResponse != null)
                {
                    responseHS = new HashSet <string>(assessmentResponse);
                }
                // Spin through all the questions and update Answer with any changes
                foreach (var o in assessmentToUpdate.CategoryDatas)
                {
                    foreach (var p in o.SectionDatas)
                    {
                        foreach (var q in p.GroupDatas)
                        {
                            foreach (var r in q.QuestionDatas)
                            {
                                if (responseHS.Contains(r.QuestionID.ToString()))
                                {
                                    r.Answer = true;
                                }
                                else
                                {
                                    r.Answer = false;
                                }
                            }
                        }
                    }
                }

                assessmentToUpdate.CalculateScore();                        // Calculate the score of the updated Assessment
                assessmentToUpdate.LastUpdated  = DateTime.Now;             // Added to update the lastupdate time
                assessmentToUpdate.LastUpdateBy = updateIdentity;
                assessmentToUpdate.Finalized    = false;
                DAL.SaveContextChanges();
            }
        }