Example #1
0
        private AssessmentResult ConvertAssessmentResultViewModelToDomain(AssessmentResultViewModel assessmentResultViewModel)
        {
            AssessmentResult assessmentResult = new AssessmentResult();

            assessmentResult.AssessmentPaperId = assessmentResultViewModel.AssessmentPaperId;
            assessmentResult.EmployeeId        = assessmentResultViewModel.EmployeeId;
            assessmentResult.AssessmentDate    = assessmentResultViewModel.AssessmentDate;
            assessmentResult.IsActive          = true;
            assessmentResult.CreatedOn         = DateTime.Now;
            assessmentResult.LastEditedOn      = DateTime.Now;
            return(assessmentResult);
        }
Example #2
0
        public ActionResult Result(AssessmentViewModel assessmentViewModel, FormCollection objf)//(int empId, AssessmentViewModel assessmentViewModel)
        {
            AssessmentResultViewModel assessmentResultViewModel = new AssessmentResultViewModel();

            //assessmentResultViewModel.AssessmentPaperId = assessmentViewModel.AssessmentPaper.AssessmentPaperId;
            assessmentResultViewModel.AssessmentPaperId = Convert.ToInt32(objf["AssessmentViewModel.AssessmentQuestions[1].AssessmentPaperId"]);
            assessmentResultViewModel.AssessmentPaperId = Convert.ToInt32(objf["HfldAssessmentPaperId"]);

            assessmentResultViewModel.AssessmentDate = DateTime.Now;
            assessmentResultViewModel.EmployeeId     = Convert.ToInt32(Session["EmpID"]);
            AssessmentResult assessmentResult = ConvertAssessmentResultViewModelToDomain(assessmentResultViewModel);
            DataTable        dtResultDetails;

            dtResultDetails = new DataTable("AssessmentResultDetails");
            dtResultDetails.Columns.Add("AssessmentResultId", typeof(int));
            dtResultDetails.Columns.Add("QuestionId", typeof(int));
            dtResultDetails.Columns.Add("SelectedAnswer", typeof(string));
            dtResultDetails.Columns.Add("AnswerScore", typeof(int));
            dtResultDetails.Columns.Add("isactive", typeof(bool));
            dtResultDetails.Columns.Add("CreatedBy", typeof(int));
            dtResultDetails.Columns.Add("CreatedOn", typeof(DateTime));
            dtResultDetails.Columns.Add("LastEditedBy", typeof(int));
            dtResultDetails.Columns.Add("LastEditedOn", typeof(DateTime));

            //AssessmentViewModel
            assessmentViewModel = GetAssessmentPaperById(assessmentResultViewModel.AssessmentPaperId);
            if (assessmentViewModel.AssessmentQuestions != null && assessmentViewModel.AssessmentQuestions.Count > 0)
            {
                foreach (var question in assessmentViewModel.AssessmentQuestions)
                {
                    string selectedAnswer = string.Empty;

                    if (question.IsMultiChoiceAnswer)
                    {
                        if (Convert.ToString(objf["Chk_AssessmentViewModel.AssessmentQuestions[" + question.QuestionId + "].Option1"]).Contains("true"))
                        {
                            selectedAnswer = selectedAnswer + " Option 1 ,";
                        }
                        if (Convert.ToString(objf["Chk_AssessmentViewModel.AssessmentQuestions[" + question.QuestionId + "].Option2"]).Contains("true"))
                        {
                            selectedAnswer = selectedAnswer + " Option 2 ,";
                        }

                        if (!string.IsNullOrEmpty(question.Option3Description))
                        {
                            if (Convert.ToString(objf["Chk_AssessmentViewModel.AssessmentQuestions[" + question.QuestionId + "].Option3"]).Contains("true"))
                            {
                                selectedAnswer = selectedAnswer + " Option 3 ,";
                            }
                        }

                        if (!string.IsNullOrEmpty(question.Option4Description))
                        {
                            if (Convert.ToString(objf["Chk_AssessmentViewModel.AssessmentQuestions[" + question.QuestionId + "].Option4"]).Contains("true"))
                            {
                                selectedAnswer = selectedAnswer + " Option 4 ,";
                            }
                        }

                        if (!string.IsNullOrEmpty(question.Option5Description))
                        {
                            if (Convert.ToString(objf["Chk_AssessmentViewModel.AssessmentQuestions[" + question.QuestionId + "].Option5"]).Contains("true"))
                            {
                                selectedAnswer = selectedAnswer + " Option 5 ,";
                            }
                        }
                        if (!string.IsNullOrEmpty(question.Option6Description))
                        {
                            if (Convert.ToString(objf["Chk_AssessmentViewModel.AssessmentQuestions[" + question.QuestionId + "].Option6"]).Contains("true"))
                            {
                                selectedAnswer = selectedAnswer + " Option 6 ,";
                            }
                        }
                    }
                    else
                    {
                        try
                        {
                            if (!string.IsNullOrEmpty(objf["Rbtn_AssessmentViewModel.AssessmentQuestions[" + question.QuestionId + "].Option"]))
                            {
                                selectedAnswer = objf["Rbtn_AssessmentViewModel.AssessmentQuestions[" + question.QuestionId + "].Option"];
                            }
                        }
                        catch (Exception)
                        { }
                    }

                    selectedAnswer = selectedAnswer.TrimEnd(',');
                    if (selectedAnswer != "")
                    {
                        question.SelectedAnswer = selectedAnswer;
                        int score = 0;
                        score = CalculateScore(assessmentViewModel.AssessmentPaper.AssessmentPaperId, question.QuestionId, selectedAnswer, assessmentViewModel);
                        dtResultDetails.Rows.Add(1, question.QuestionId, question.SelectedAnswer, score, true, 1, DateTime.Now, 1, DateTime.Now);
                    }
                }
            }
            string strResult = _IAssessmentService.SaveAssessmentResult(dtResultDetails, assessmentResult);

            string [] strSplited = strResult.Split(',');
            assessmentResultViewModel.TotalScore = Convert.ToInt32(strSplited[0]);
            assessmentResultViewModel.OutofScore = assessmentViewModel.AssessmentQuestions.Count;
            assessmentResultViewModel.Message    = Convert.ToString(strSplited[1]);
            return(View("Result", assessmentResultViewModel));
        }