Ejemplo n.º 1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                try
                {
                    var candId  = Session["CandId"].ToString();
                    var batchId = Session["BatchId"].ToString();
                    var tenant  = SessionHelper.GetTenantID(Session);
                    using (QuizBookDbEntities1 _db = new QuizBookDbEntities1())
                    {
                        if (string.IsNullOrEmpty(tenant))
                        {
                            ErecruitHelper.SetErrorData(new NullReferenceException("There must be a valid Organisation"), Session);
                            Response.Redirect("ErrorPage.aspx", false);
                        }
                        else
                        {
                            if (string.IsNullOrEmpty(candId))
                            {
                                ErecruitHelper.SetErrorData(new NullReferenceException("There must be a valid candidate"), Session);
                                Response.Redirect("ErrorPage.aspx", false);
                            }
                            else
                            {
                                if (string.IsNullOrEmpty(batchId))
                                {
                                    ErecruitHelper.SetErrorData(new NullReferenceException("There must be a valid Batch"), Session);
                                    Response.Redirect("ErrorPage.aspx", false);
                                }
                                else
                                {
                                    var cid = long.Parse(candId);
                                    var bid = long.Parse(batchId);
                                    var tid = long.Parse(tenant);

                                    var repM   = _db.TestResultReports.FirstOrDefault(s => s.candId == cid && s.batchId == bid && s.tenantId == tid);
                                    var repSum = _db.TestReportSummaries.FirstOrDefault(x => x.ReportId == repM.Id);
                                    var repAns = _db.TestReportAnswers.Where(x => x.ReportId == repM.Id).ToList();



                                    logoCt.Src = GetUrl("book.png");

                                    //var result = _db.IndividualTestResult_sp(bid, cid, tid).ToList();
                                    //var cand = result.FirstOrDefault();

                                    candidateId.Text   = repM.candidateId.ToUpper();
                                    candidateName.Text = repM.candidateName.ToUpper();
                                    batchName.Text     = repM.batchName.ToUpper();
                                    tenantName.Text    = repM.tenantName.ToUpper();
                                    tstDate.Text       = repM.tstDate;


                                    var forList = repAns.Select(x => new
                                    {
                                        sn            = x.sn,
                                        question      = x.question,
                                        Mark          = x.Mark,
                                        Score         = x.Score,
                                        chosenAnswer  = x.chosenAnswer,
                                        correctAnswer = x.correctAnswer,
                                        Status        = x.correct == "Correct" ? "<span style='color:#008000;'>Right</span>":x.correct == "Partial"? "<span style='color:#ffb400;'>Partial</span>": " <span style='color:#f00;'>Wrong</span>",
                                    }).ToList();



                                    //var forList = result.Select((s, i) => new
                                    //{
                                    //    sn = (i + 1).ToString(),
                                    //    Question = s.QuestionDetails,
                                    //    Answer = string.IsNullOrEmpty(s.ChosenAnswerDetails) ? "Unanswered" : s.ChosenAnswerDetails,
                                    //    CorrectAnswer = s.CorrectAnswer,
                                    //    Status = s.Correct.HasValue ? s.Correct.Value ? "<b style='color:green;'>Right</b>" : "<b style='color:red;'>Wrong</b>" : "<b style='color:red;'>Wrong</b>"
                                    //}).ToList();

                                    ResultList.DataSource = forList;
                                    ResultList.DataBind();

                                    var summary = new ResultModel
                                    {
                                        Correct           = repSum.Correct.Value,
                                        Partial           = repSum.Partial.Value,
                                        Wrong             = repSum.Wrong.Value,
                                        Unanswered        = repSum.Unanswered.Value,
                                        CorrectPercent    = repSum.CorrectPercent.Value,
                                        PartialPercent    = repSum.PartialPercent.Value,
                                        WrongPercent      = repSum.WrongPercent.Value,
                                        UnansweredPercent = repSum.UnansweredPercent.Value,
                                        CorrectCount      = repSum.CorrectCount.Value,
                                        PartialCount      = repSum.PartialCount.Value,
                                        WrongCount        = repSum.WrongCount.Value,
                                        UnansweredCount   = repSum.UnansweredCount.Value,
                                        questionCount     = repSum.questionCount.HasValue ? repSum.questionCount.Value:0,
                                        questionTotalMark = repSum.questionTotalMark.HasValue? repSum.questionTotalMark.Value:0,
                                        testDate          = repSum.testDate.Value
                                    };

                                    var totalQustionMark = forList.Sum(x => x.Mark);

                                    Correct.Text           = repM.Correct.ToString();
                                    Wrong.Text             = repM.Wrong.ToString();
                                    Partial.Text           = repM.Partial.ToString();
                                    Unanswered.Text        = repM.Unanswered.ToString();
                                    percentage.Text        = repM.percentage.ToString();
                                    result_correct.Text    = summary.Correct.ToString();
                                    result_partial.Text    = summary.Partial.ToString();
                                    result_wrong.Text      = summary.Wrong.ToString();
                                    result_unanswered.Text = summary.Unanswered.ToString();
                                    sumation_result.Text   = (summary.Correct + summary.Partial).ToString() + " out of " + totalQustionMark;
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    WSProfile filter = new WSProfile(System.Reflection.Assembly.GetExecutingAssembly().FullName.Split(',')[0], Path.GetFileName(Request.Url.AbsolutePath) + "-" + System.Reflection.MethodBase.GetCurrentMethod().Name, ApplicationType.WebApplication);
                    filter.LogError(ex);
                    //ErecruitHelper.SetErrorData(ex, Session);
                    //Response.Redirect("ErrorPage.aspx", false);
                }
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                try
                {
                    var tenant = SessionHelper.GetTenantID(Session);
                    using (QuizBookDbEntities1 _db = new QuizBookDbEntities1())
                    {
                        if (string.IsNullOrEmpty(tenant))
                        {
                            ErecruitHelper.SetErrorData(new NullReferenceException("There must be a valid Organisation"), Session);
                            Response.Redirect("ErrorPage.aspx", false);
                        }
                        else
                        {
                            var      selectedBatch = Session["GrpList"] == null?0: long.Parse(Session["GrpList"].ToString());
                            DateTime?fromDate      = DateTime.Now;
                            if ((bool)Session["From"])
                            {
                                fromDate = null;
                            }
                            else
                            {
                                fromDate = (DateTime)Session["dateFrom"];
                            }
                            DateTime?toDate = DateTime.Now;
                            if ((bool)Session["To"])
                            {
                                toDate = null;
                            }
                            else
                            {
                                toDate = (DateTime)Session["dateTo"];
                            }
                            //var toDate = (bool)Session["To"] ? null : (DateTime)Session["dateTo"];
                            //logoCtrl.ImageUrl = HostingEnvironment.MapPath("~/Images/book.png");
                            //logoCtrl.ImageUrl = GetUrl("book.png");
                            logoCt.Src = GetUrl("book.png");
                            //Session["imageURL"] = GetUrl("Images/book.png");

                            var details     = new ERecruitReportFactory().BatchReport(selectedBatch, fromDate, toDate, long.Parse(tenant)).ToList();
                            var oneInstance = details.FirstOrDefault();
                            var count       = details.Count();
                            candCount.Text        = count.ToString();
                            batchName.Text        = oneInstance == null? "":oneInstance.BatchName;
                            ppassed.Text          = count > 0?((details.Count(x => x.Passed == 1) / count) * 100) + " %":"0 %";
                            pfailed.Text          = count > 0 ? ((details.Count(x => x.Failed == 1) / count) * 100) + " %" : "0 %";
                            ResultList.DataSource = details;
                            ResultList.DataBind();
                        }
                    }
                }
                catch (Exception ex)
                {
                    WSProfile filter = new WSProfile(System.Reflection.Assembly.GetExecutingAssembly().FullName.Split(',')[0], Path.GetFileName(Request.Url.AbsolutePath) + "-" + System.Reflection.MethodBase.GetCurrentMethod().Name, ApplicationType.WebApplication);
                    filter.LogError(ex);
                    //ErecruitHelper.SetErrorData(ex, Session);
                    //Response.Redirect("ErrorPage.aspx", false);
                }
            }
        }