protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                var candId = SessionHelper.FetchCandidateId(Session);


                var tracker   = _db.T_CTestTracker.FirstOrDefault(s => s.CandidateId == long.Parse(candId));
                var cand      = _db.T_Candidate.FirstOrDefault(s => s.Code == tracker.CandidateCode);
                var b_id      = _db.T_BatchSet.Where(s => s.CandidateId == cand.Id).Select(x => x.BatchId);
                var candBatch = _db.T_Batch.FirstOrDefault(s => b_id.Contains(s.Id) && s.IsActive.Value);
                //string path = Path.Combine("~/Passports/", "no-pic-avatar.jpg");
                //Image1.ImageUrl = !(string.IsNullOrEmpty(cand.Passport)) ? cand.Passport : path;
                //string st = cand.Code + " - " + cand.FirstName + " " + cand.LastName;
                //CandName.Text = st;


                var cbSet = _db.T_BatchSet.FirstOrDefault(s => s.BatchId == candBatch.Id && s.CandidateId == cand.Id);

                if (cand != null && candBatch != null)
                {
                    var bs = _db.T_BatchSet.FirstOrDefault(s => s.BatchId == candBatch.Id && s.CandidateId == cand.Id);
                    ccode.InnerHtml       = cand.Code;
                    CGender.InnerHtml     = cand.Sex;
                    Surname.InnerHtml     = cand.LastName;
                    COthernames.InnerHtml = cand.FirstName + " " + cand.MiddleName + " " + cand.MaidenName;
                    CDob.InnerHtml        = ErecruitHelper.AppendZero(cand.DateOfBirth.Value.Day) + "/" + ErecruitHelper.AppendZero(cand.DateOfBirth.Value.Month) + "/" + cand.DateOfBirth.Value.Year;
                    cgrade.InnerHtml      = bs.TestScore + "%";
                }
            }
            catch (Exception ex)
            {
                ErecruitHelper.SetErrorData(ex, Session);
                Response.Redirect("ErrorPage.aspx", false);
            }
        }
示例#2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                string currentPageFileName = new FileInfo(this.Request.Url.AbsolutePath).Name;
                var    PermMgr             = new PermissionManager(Session);

                if (PermMgr.IsAdmin || PermMgr.CanWorkWithCandidates || PermMgr.CanApprove)
                {
                    if (!IsPostBack)
                    {
                        string code = Request["z"];

                        if (!string.IsNullOrEmpty(code))
                        {
                            var cand = _db.T_Candidate.FirstOrDefault(s => s.Id.ToString() == code);

                            if (cand != null)
                            {
                                candId.Value = cand.Id.ToString();
                                Label1.Text  = cand.Code;
                                Label2.Text  = cand.LastName;
                                Label3.Text  = cand.FirstName + " " + cand.MiddleName + " " + cand.MaidenName;
                                Label4.Text  = cand.Sex;
                                Label5.Text  = ErecruitHelper.AppendZero(cand.DateOfBirth.Value.Day) + "/" + ErecruitHelper.AppendZero(cand.DateOfBirth.Value.Month) + "/" + cand.DateOfBirth.Value.Year;
                                Label6.Text  = cand.Degree;
                                Label10.Text = cand.ClassOfDegree;
                                Label11.Text = cand.Course;
                                Label12.Text = cand.Referer;
                                Label13.Text = cand.Email;
                                Label14.Text = cand.ApprovalStatus;
                                Comment.Text = cand.Comment;
                                string path = Path.Combine("~/Passports/", "no-pic-avatar.jpg");
                                Image1.ImageUrl = !(string.IsNullOrEmpty(cand.Passport)) ? cand.Passport : path;
                                Image1.DataBind();

                                var b_id = _db.T_BatchSet.Where(s => s.CandidateId == cand.Id).Select(x => x.BatchId);

                                var candBatch = _db.T_Batch.FirstOrDefault(s => b_id.Contains(s.Id) && s.IsActive.Value);
                                if (candBatch != null)
                                {
                                    var cbSet = _db.T_BatchSet.FirstOrDefault(s => s.BatchId == candBatch.Id && s.CandidateId == cand.Id);
                                    if (cbSet != null)
                                    {
                                        Label7.Text = string.IsNullOrEmpty(cbSet.TestScore)?"Not Taken":cbSet.TestScore + "%";
                                        Label8.Text = cbSet.Essay == true ? "Taken" : "Not Taken";
                                        Label9.Text = cbSet.Psychometric == true ? "Taken" : "Not Taken";
                                    }
                                }
                            }
                            else
                            {
                                ErecruitHelper.SetErrorData(new NullReferenceException(), Session);
                                Response.Redirect("ErrorPage.aspx", false);
                            }
                        }
                        else
                        {
                            ErecruitHelper.SetErrorData(new NullReferenceException(), Session);
                            Response.Redirect("ErrorPage.aspx", false);
                        }
                    }
                }
                else
                {
                    Response.Redirect("NoPermission.aspx", false);
                }
            }
            catch (Exception ex)
            {
                ErecruitHelper.SetErrorData(ex, Session);
                Response.Redirect("ErrorPage.aspx", false);
            }
        }
        protected void check_Click(object sender, EventArgs e)
        {
            try
            {
                var code = Code.Text;
                if (!string.IsNullOrEmpty(code))
                {
                    var cand = _db.T_Candidate.FirstOrDefault(s => s.Code == code);

                    if (cand != null)
                    {
                        var b_id = _db.T_BatchSet.Where(s => s.CandidateId == cand.Id).Select(x => x.BatchId);

                        var candBatch = _db.T_Batch.FirstOrDefault(s => b_id.Contains(s.Id) && s.IsActive.Value);
                        if (candBatch != null)
                        {
                            var cbSet   = _db.T_BatchSet.FirstOrDefault(s => s.BatchId == candBatch.Id && s.CandidateId == cand.Id);
                            var tracker = _db.T_CTestTracker.FirstOrDefault(s => s.CandidateId == cand.Id && s.BatchId == candBatch.Id);
                            if (tracker != null)
                            {
                                if (cbSet.Finished == false && cbSet.IsLive == true)
                                {
                                    cbSet.IsLive = false;

                                    _db.SaveChanges();

                                    var      duration        = candBatch.Duration.ToString();
                                    string[] ds              = duration.Split(':');
                                    int      min             = 0;
                                    int      sec             = 0;
                                    int      hour            = 0;
                                    int      TestdurationSum = 0;
                                    if (ds.Length == 1)
                                    {
                                        min             = int.Parse(ds[0]);
                                        sec             = 0;
                                        hour            = 0;
                                        TestdurationSum = ((hour * 3600) + (min * 60) + sec);
                                    }
                                    else if (ds.Length == 2)
                                    {
                                        min             = int.Parse(ds[0]);
                                        sec             = int.Parse(ds[1]);
                                        hour            = 0;
                                        TestdurationSum = ((hour * 3600) + (min * 60) + sec);
                                    }
                                    else
                                    {
                                        min             = int.Parse(ds[1]);
                                        sec             = int.Parse(ds[2]);
                                        hour            = int.Parse(ds[0]);
                                        TestdurationSum = ((hour * 3600) + (min * 60) + sec);
                                    }

                                    var timeEnding = DateTime.Now;
                                    var ending     = timeEnding.AddSeconds(TestdurationSum);

                                    var st          = DateTime.Now;
                                    var initialTime = tracker.InitialStartTime == null
                          ? st
                          : tracker.InitialStartTime.Value;


                                    DateTime lastActiveTime = tracker.CurrentStartTime == null
                             ? initialTime
                             : tracker.CurrentStartTime.Value;

                                    //TimeSpan spent = (lastActiveTime - initialTime);

                                    //int hours = spent.Hours;
                                    //int mins = spent.Minutes;
                                    //int secs = spent.Seconds;
                                    if (initialTime != null)
                                    {
                                        var span = (lastActiveTime - initialTime);

                                        //var sumSpent = ((span.Hours * 3600) + (span.Minutes * 60) + span.Seconds);

                                        var spentTime = new TimeSpan(span.Hours, span.Minutes, span.Seconds);

                                        ending = ending.Subtract(spentTime);
                                    }

                                    TimeSpan remaining = (ending - timeEnding);

                                    //var timeString = String.Format("{0}:{1}:{2}", ErecruitHelper.AppendZero(remaining.Hours),
                                    //                               ErecruitHelper.AppendZero(remaining.Minutes),
                                    //                               ErecruitHelper.AppendZero(remaining.Seconds));
                                    resultLbl.Text = "Session for the Candidate: " + cand.Code + " has been reset.<br />Time Remaining: " + ErecruitHelper.AppendZero(remaining.Hours) + " hours, " + ErecruitHelper.AppendZero(remaining.Minutes) + " minutes and " + ErecruitHelper.AppendZero(remaining.Seconds) + " seconds";
                                    //int sumSpent = ((hours ) + (mins * 60) + secs);
                                    //string[] ds = duration.Split(',');
                                    //int min = 0;
                                    //int sec = 0;
                                    //if (ds.Length == 1)
                                    //{
                                    //    min = int.Parse(ds[0]);
                                    //    sec = 0;
                                    //    duration = min + "," + sec;
                                    //    resultLbl.Text = "Session for the Candidate: " + cand.Code + " has been reset.<br />Time Remaining: " + min + " minutes and " + sec + " seconds";
                                    //}
                                    //else
                                    //{
                                    //    min = int.Parse(ds[0]);
                                    //    sec = int.Parse(ds[1]);
                                    //    duration = min + "," + sec;
                                    //    resultLbl.Text = "Session for the Candidate: " + cand.Code + " has been reset.<br />Time Remaining: " + min + " minutes and " + sec + " seconds";
                                    //}



                                    //SessionHelper.SetCandidateCode(code, Session);
                                    //Response.Redirect("ActivateCandidateSession.aspx", false);
                                }
                                else if (cbSet.Finished == false && cbSet.IsLive == false)
                                {
                                    resultLbl.Text = "The candidate Session currently valid.";
                                }
                                else
                                {
                                    var rsltTxt = "The candidate must have finished the test.";



                                    resultLbl.Text = rsltTxt;
                                }
                            }
                            else
                            {
                                resultLbl.Text = "The candidate is yet to start the test.";
                            }
                        }
                        else
                        {
                            resultLbl.Text = "The candidate has not been assigned to a test batch.";
                        }
                    }
                    else
                    {
                        resultLbl.Text = "This is not a valid candidate code";
                    }
                }
            }
            catch (Exception ex)
            {
                ErecruitHelper.SetErrorData(ex, Session);
                Response.Redirect("ErrorPage.aspx", false);
            }
        }
示例#4
0
        protected void AudiTrailGrid_Sorting(object sender, GridViewSortEventArgs e)
        {
            try{
                var auditLogs = _db.AuditRecords.OrderByDescending(s => s.AuditDate).ToList();
                TotalRecCount.Text = auditLogs.Count() + " Log(s)";

                if ((string)Session["EXP"] == e.SortExpression && (string)Session["DIRECTION"] == SortDirection.Ascending.ToString())
                {
                    e.SortDirection = SortDirection.Descending;
                }
                else
                {
                    e.SortDirection = SortDirection.Ascending;
                }

                Session["EXP"]       = e.SortExpression;
                Session["DIRECTION"] = e.SortDirection.ToString();
                switch (e.SortExpression)
                {
                case "UserName":
                    if (e.SortDirection == SortDirection.Ascending)
                    {
                        auditLogs = auditLogs.OrderBy(s => s.UserName).ToList();

                        AudiTrailGrid.DataSource = auditLogs;
                        AudiTrailGrid.DataBind();
                    }
                    else
                    {
                        auditLogs = auditLogs.OrderByDescending(s => s.UserName).ToList();
                        AudiTrailGrid.DataSource = auditLogs;
                        AudiTrailGrid.DataBind();
                    }

                    break;

                case "Action":
                    if (e.SortDirection == SortDirection.Ascending)
                    {
                        auditLogs = auditLogs.OrderBy(s => s.Action).ToList();

                        AudiTrailGrid.DataSource = auditLogs;
                        AudiTrailGrid.DataBind();
                    }
                    else
                    {
                        auditLogs = auditLogs.OrderByDescending(s => s.Action).ToList();
                        AudiTrailGrid.DataSource = auditLogs;
                        AudiTrailGrid.DataBind();
                    }

                    break;

                case "TableName":
                    if (e.SortDirection == SortDirection.Ascending)
                    {
                        auditLogs = auditLogs.OrderBy(s => s.TableName).ToList();

                        AudiTrailGrid.DataSource = auditLogs;
                        AudiTrailGrid.DataBind();
                    }
                    else
                    {
                        auditLogs = auditLogs.OrderByDescending(s => s.TableName).ToList();
                        AudiTrailGrid.DataSource = auditLogs;
                        AudiTrailGrid.DataBind();
                    }

                    break;
                //case "MemberName":
                //    if (e.SortDirection == SortDirection.Ascending)
                //    {
                //        auditLogs = auditLogs.OrderBy(s => s.MemberName).ToList();

                //        AudiTrailGrid.DataSource = auditLogs;
                //        AudiTrailGrid.DataBind();
                //    }
                //    else
                //    {
                //        auditLogs = auditLogs.OrderByDescending(s => s.MemberName).ToList();
                //        AudiTrailGrid.DataSource = auditLogs;
                //        AudiTrailGrid.DataBind();
                //    }

                //    break;
                //case "OldValue":
                //    if (e.SortDirection == SortDirection.Ascending)
                //    {
                //        auditLogs = auditLogs.OrderBy(s => s.OldValue).ToList();

                //        AudiTrailGrid.DataSource = auditLogs;
                //        AudiTrailGrid.DataBind();
                //    }
                //    else
                //    {
                //        auditLogs = auditLogs.OrderByDescending(s => s.OldValue).ToList();
                //        AudiTrailGrid.DataSource = auditLogs;
                //        AudiTrailGrid.DataBind();
                //    }

                //    break;
                //case "NewValue":
                //    if (e.SortDirection == SortDirection.Ascending)
                //    {
                //        auditLogs = auditLogs.OrderBy(s => s.NewValue).ToList();

                //        AudiTrailGrid.DataSource = auditLogs;
                //        AudiTrailGrid.DataBind();
                //    }
                //    else
                //    {
                //        auditLogs = auditLogs.OrderByDescending(s => s.NewValue).ToList();
                //        AudiTrailGrid.DataSource = auditLogs;
                //        AudiTrailGrid.DataBind();
                //    }

                //    break;
                case "AuditDate":
                    if (e.SortDirection == SortDirection.Ascending)
                    {
                        auditLogs = auditLogs.OrderBy(s => s.AuditDate).ToList();

                        AudiTrailGrid.DataSource = auditLogs;
                        AudiTrailGrid.DataBind();
                    }
                    else
                    {
                        auditLogs = auditLogs.OrderByDescending(s => s.AuditDate).ToList();
                        AudiTrailGrid.DataSource = auditLogs;
                        AudiTrailGrid.DataBind();
                    }

                    break;
                }
            }
            catch (Exception ex)
            {
                ErecruitHelper.SetErrorData(ex, Session);
                Response.Redirect("ErrorPage.aspx", false);
            }
        }
        protected void C_TestStart_Click(object sender, EventArgs e)
        {
            try
            {
                var code = Code.Text;
                if (!string.IsNullOrEmpty(code))
                {
                    var cand = _db.T_Candidate.FirstOrDefault(s => s.Code == code);



                    if (cand.ApprovalStatus == QuizBook.Helpers.ErecruitHelper.ApprovalStatus.APPROVED.ToString())
                    {
                        if (cand != null)
                        {
                            SessionHelper.SetCandidateCode(cand.Code.ToString(CultureInfo.InvariantCulture), Session);
                            var b_id = _db.T_BatchSet.Where(s => s.CandidateId == cand.Id).Select(x => x.BatchId);

                            if (!b_id.Any())
                            {
                                Info.Text = "You have not been assigned to a batch.\n Please contact the Administrator.";
                                //Response.Redirect("CandidateLogin.aspx");
                            }
                            else
                            {
                                var candBatch = _db.T_Batch.FirstOrDefault(s => b_id.Contains(s.Id) && s.IsActive.Value);
                                if (candBatch != null)
                                {
                                    if (candBatch.StartDate <= DateTime.Now)
                                    {
                                        var bSets = _db.T_BatchSet.Where(s => s.BatchId == candBatch.Id).ToList();
                                        //int membersCount = bSets.Count();
                                        //int finishedMembersCount = bSets.Where(s => s.Finished.Value).Count();
                                        var cbSet = _db.T_BatchSet.FirstOrDefault(s => s.BatchId == candBatch.Id && s.CandidateId == cand.Id);
                                        if (cbSet != null && cbSet.Finished == true)
                                        {
                                            SessionHelper.SetCandidateId(cand.Id.ToString(CultureInfo.InvariantCulture), Session);

                                            if (cbSet.Essay == true)
                                            {
                                                if (cbSet.Psychometric == true)
                                                {
                                                    ErecruitHelper.CheckBatches(_db, candBatch);
                                                    Info.Text = "You have already finished this process";
                                                }
                                                else
                                                {
                                                    var exitingPsyc1 = _db.T_MultiintelligencQuizBookDb.FirstOrDefault(s => s.CandidateId == cand.Id);
                                                    if (exitingPsyc1 != null)
                                                    {
                                                        Response.Redirect("BackGroundQuestionaire.aspx", false);
                                                    }
                                                    else
                                                    {
                                                        Response.Redirect("MultiIntelligenceTest.aspx", false);
                                                    }
                                                }
                                            }
                                            else
                                            {
                                                //Info.Text = "You have not done the Essay part";
                                                Response.Redirect("CandidateTestResult.aspx", false);
                                            }

                                            //if (cbSet.Psychometric == false)
                                            //{
                                            //    Info.Text = "You have not done the Psychometric part";
                                            //}
                                            //else if (cbSet.Finished == true&& cbSet.Psychometric == true && cbSet.Essay == true)
                                            //{

                                            //}
                                            //if (cbSet.Essay == true)
                                            //{
                                            //}
                                            // Info.Text = "You Have Done this test.";
                                        }
                                        else
                                        {
                                            var batchSet = bSets.FirstOrDefault(s => s.CandidateId == cand.Id);

                                            if (batchSet.IsLive.Value)
                                            {
                                                Info.Text = "You Currently have a Session on.\n Please contact the Administrator.";
                                                // Response.Redirect("CandidateLogin.aspx");
                                            }
                                            else
                                            {
                                                if (candBatch != null)
                                                {
                                                    var tracker = _db.T_CTestTracker.FirstOrDefault(s => s.CandidateId == cand.Id && s.BatchId == candBatch.Id);
                                                    if (tracker != null)
                                                    {
                                                        //var duration = tracker.RemainingDuration.ToString();
                                                        //string[] ds = duration.Split(':');
                                                        //int hour = 0;
                                                        //int min = 0;
                                                        //int sec = 0;
                                                        //if (ds.Length == 1)
                                                        //{
                                                        //    min = int.Parse(ds[0]);
                                                        //    sec = 0;
                                                        //    hour = 0;
                                                        //    duration = hour+":"+min + ":" + sec;
                                                        //}
                                                        //else if (ds.Length == 2)
                                                        //{
                                                        //    min = int.Parse(ds[0]);
                                                        //    sec = int.Parse(ds[1]);
                                                        //    hour = 0;
                                                        //    duration = hour + ":" + min + ":" + sec;
                                                        //}
                                                        //else
                                                        //{
                                                        //    min = int.Parse(ds[1]);
                                                        //    sec = int.Parse(ds[2]);
                                                        //    hour = int.Parse(ds[0]);
                                                        //    duration = hour + ":" + min + ":" + sec;
                                                        //}
                                                        var st          = DateTime.Now;
                                                        var initialTime = tracker.InitialStartTime == null
                                                  ? st
                                                  : tracker.InitialStartTime.Value;


                                                        DateTime lastActiveTime = tracker.CurrentStartTime == null
                                                     ? initialTime
                                                     : tracker.CurrentStartTime.Value;

                                                        TimeSpan spent = (lastActiveTime - initialTime);

                                                        int hours    = spent.Hours;
                                                        int mins     = spent.Minutes;
                                                        int secs     = spent.Seconds;
                                                        int sumSpent = ((hours * 3600) + (mins * 60) + secs);

                                                        var      TestDuration    = tracker.TestDuration.ToString();
                                                        string[] ds              = TestDuration.Split(':');
                                                        int      hour            = 0;
                                                        int      min             = 0;
                                                        int      sec             = 0;
                                                        int      TestdurationSum = 0;
                                                        if (ds.Length == 1)
                                                        {
                                                            min             = int.Parse(ds[0]);
                                                            sec             = 0;
                                                            hour            = 0;
                                                            TestdurationSum = ((hour * 3600) + (min * 60) + sec);
                                                        }
                                                        else if (ds.Length == 2)
                                                        {
                                                            min             = int.Parse(ds[0]);
                                                            sec             = int.Parse(ds[1]);
                                                            hour            = 0;
                                                            TestdurationSum = ((hour * 3600) + (min * 60) + sec);
                                                        }
                                                        else
                                                        {
                                                            min             = int.Parse(ds[1]);
                                                            sec             = int.Parse(ds[2]);
                                                            hour            = int.Parse(ds[0]);
                                                            TestdurationSum = ((hour * 3600) + (min * 60) + sec);
                                                        }


                                                        if (sumSpent >= TestdurationSum)
                                                        {
                                                            Response.Redirect("CandidateTestResult.aspx?z=elapsed", false);
                                                        }
                                                        else
                                                        {
                                                            //var endtime = st.AddSeconds(TestdurationSum - sumSpent);

                                                            //tracker.CurrentStartTime = st;
                                                            //tracker.EndTime = endtime;

                                                            batchSet.IsLive     = true;
                                                            candBatch.SessionOn = true;
                                                            _db.SaveChanges();


                                                            tracker = _db.T_CTestTracker.FirstOrDefault(s => s.CandidateId == cand.Id && s.BatchId == candBatch.Id);
                                                            var remaining = tracker.RemainingDuration;
                                                            var d         = tracker.TestDuration;
                                                            if (d != "00:00:00" && remaining != "00:00:00")
                                                            {
                                                                var existingQCount = _db.T_CandidateTemp.Count(s => s.CandidateId == cand.Id && s.BatchId == candBatch.Id);

                                                                if (existingQCount < 1)
                                                                {
                                                                    List <long?> Q         = _db.T_BatchQuestions.Where(s => s.BatchId == candBatch.Id).Select(x => x.QuestionId).ToList();
                                                                    var          questions = _db.T_Question.Where(s => Q.Contains(s.Id)).ToList();
                                                                    var          typ       = questions.Select(s => s.PreambleId).Distinct().OrderBy(s => s).ToList();
                                                                    //Randomize the questions
                                                                    // Q.Shuffle();
                                                                    int count = 0;
                                                                    foreach (var t in typ)
                                                                    {
                                                                        var qs = questions.Where(s => s.PreambleId == t).ToList();
                                                                        //Randomize the questions
                                                                        RandomHelper.Shuffle(qs);
                                                                        RandomHelper.Shuffle(qs);
                                                                        foreach (var q in qs)
                                                                        {
                                                                            _db.T_CandidateTemp.Add(new T_CandidateTemp
                                                                            {
                                                                                CandidateId = cand.Id,
                                                                                BatchId     = candBatch.Id,
                                                                                PreambleId  = q.PreambleId,
                                                                                Q_Id        = q.Id,
                                                                                Q_Index     = (count + 1),
                                                                                Answered    = false
                                                                            });
                                                                            count++;
                                                                        }
                                                                        _db.SaveChanges();
                                                                    }
                                                                }
                                                                //List<T_Question> questions = _db.T_Question.Where(s => Q.Contains(s.Id) && s.IsActive.Value).ToList();



                                                                SessionHelper.SetCandidateId(cand.Id.ToString(CultureInfo.InvariantCulture), Session);
                                                                Response.Redirect("CandidateTestPage.aspx", false);
                                                            }
                                                        }
                                                    }
                                                    else
                                                    {
                                                        var st       = DateTime.Now;
                                                        var duration = candBatch.Duration.ToString();
                                                        //string[] ds = duration.Split(':');
                                                        //int min = 0;
                                                        //int sec = 0;
                                                        //int hour = 0;
                                                        //int TestdurationSum = 0;
                                                        //if (ds.Length == 1)
                                                        //{
                                                        //    min = int.Parse(ds[0]);
                                                        //    sec = 0;
                                                        //    hour = 0;
                                                        //    TestdurationSum = ((hour * 3600) + (min * 60) + sec);
                                                        //}
                                                        //else if (ds.Length == 2)
                                                        //{
                                                        //    min = int.Parse(ds[0]);
                                                        //    sec = int.Parse(ds[1]);
                                                        //    hour = 0;
                                                        //    TestdurationSum = ((hour * 3600) + (min * 60) + sec);
                                                        //}
                                                        //else
                                                        //{
                                                        //    min = int.Parse(ds[1]);
                                                        //    sec = int.Parse(ds[2]);
                                                        //    hour = int.Parse(ds[0]);
                                                        //    TestdurationSum = ((hour * 3600) + (min * 60) + sec);
                                                        //}


                                                        //var endtime = st.AddSeconds(TestdurationSum);


                                                        _db.T_CTestTracker.Add(new T_CTestTracker
                                                        {
                                                            CandidateId   = cand.Id,
                                                            BatchId       = candBatch.Id,
                                                            CandidateCode = cand.Code,
                                                            // InitialStartTime = st,
                                                            // CurrentStartTime = st,
                                                            TestDuration      = ErecruitHelper.AppendZero(0) + ":" + ErecruitHelper.AppendZero(int.Parse(duration)) + ":" + ErecruitHelper.AppendZero(0),
                                                            RemainingDuration = duration,
                                                            //EndTime = endtime
                                                        }
                                                                               );

                                                        //var batchSets = _db.T_BatchSet.Where(s => s.BatchId == candBatch.Id).ToList();


                                                        // var batchSet = bSets.Where(s => s.CandidateId == cand.Id).FirstOrDefault();


                                                        batchSet.IsLive      = true;
                                                        batchSet.TimeStarted = DateTime.Now;
                                                        candBatch.SessionOn  = true;
                                                        _db.SaveChanges();

                                                        tracker = _db.T_CTestTracker.FirstOrDefault(s => s.CandidateId == cand.Id && s.BatchId == candBatch.Id);
                                                        var remaining = tracker.RemainingDuration;
                                                        var d         = tracker.TestDuration;
                                                        if (d != "0:0:0" && remaining != "0:0:0")
                                                        {
                                                            var existingQCount = _db.T_CandidateTemp.Count(s => s.CandidateId == cand.Id && s.BatchId == candBatch.Id);

                                                            if (existingQCount < 1)
                                                            {
                                                                List <long?> Q         = _db.T_BatchQuestions.Where(s => s.BatchId == candBatch.Id).Select(x => x.QuestionId).ToList();
                                                                var          questions = _db.T_Question.Where(s => Q.Contains(s.Id)).ToList();
                                                                var          typ       = questions.Select(s => s.PreambleId).Distinct().OrderBy(s => s).ToList();
                                                                //Randomize the questions
                                                                // Q.Shuffle();
                                                                int count = 0;
                                                                foreach (var t in typ)
                                                                {
                                                                    var qs = questions.Where(s => s.PreambleId == t).ToList();
                                                                    //Randomize the questions
                                                                    RandomHelper.Shuffle(qs);
                                                                    RandomHelper.Shuffle(qs);
                                                                    foreach (var q in qs)
                                                                    {
                                                                        _db.T_CandidateTemp.Add(new T_CandidateTemp
                                                                        {
                                                                            CandidateId = cand.Id,
                                                                            BatchId     = candBatch.Id,
                                                                            PreambleId  = q.PreambleId,
                                                                            Q_Id        = q.Id,
                                                                            Q_Index     = (count + 1),
                                                                            Answered    = false
                                                                        });
                                                                        count++;
                                                                    }
                                                                    _db.SaveChanges();
                                                                }
                                                            }
                                                            //List<T_Question> questions = _db.T_Question.Where(s => Q.Contains(s.Id) && s.IsActive.Value).ToList();



                                                            SessionHelper.SetCandidateId(cand.Id.ToString(CultureInfo.InvariantCulture), Session);
                                                            Response.Redirect("CandidateTestPage.aspx", false);
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                    else
                                    {
                                        Info.Text = "It is not yet time to take this test.\n Please contact the Administrator.";
                                    }
                                }
                                else
                                {
                                    Info.Text = "You are not assigned to any active batch.\n Please contact the Administrator.";
                                }
                            }
                        }
                        else
                        {
                            Info.Text = "This is not a valid candidate ID.\n Please contact the Administrator.";
                            // Response.Redirect("CandidateLogin.aspx");
                        }
                    }
                    else
                    {
                        Info.Text = "You have not been approved.\n Please contact the Administrator.";
                    }
                }
            }
            catch (Exception ex)
            {
                ErecruitHelper.SetErrorData(ex, Session);
                Response.Redirect("ErrorPage.aspx", false);
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                string currentPageFileName = new FileInfo(this.Request.Url.AbsolutePath).Name;
                var    PermMgr             = new PermissionManager(Session);

                if (PermMgr.IsAdmin || PermMgr.CanManageTestResults)
                {
                    var code = SessionHelper.FetchCandidateCode(Session);
                    var bid  = Session["Batchid"].ToString();
                    if (!string.IsNullOrEmpty(code))
                    {
                        var cand = _db.T_Candidate.FirstOrDefault(s => s.Code == code);

                        if (cand != null)
                        {
                            //var tracker = _db.T_CTestTracker.FirstOrDefault(s => s.CandidateId == cand.Id);

                            //var b_id = _db.T_BatchSet.Where(s => s.CandidateId == cand.Id).Select(x => x.BatchId);

                            var candBatch = _db.T_Batch.FirstOrDefault(s => s.Id == long.Parse(bid));
                            if (candBatch != null)
                            {
                                if (cand != null && candBatch != null)
                                {
                                    var bs = _db.T_BatchSet.FirstOrDefault(s => s.BatchId == candBatch.Id && s.CandidateId == cand.Id);
                                    ccode.InnerHtml       = cand.Code;
                                    CGender.InnerHtml     = cand.Sex;
                                    Surname.InnerHtml     = cand.LastName;
                                    COthernames.InnerHtml = cand.FirstName + " " + cand.MiddleName + " " + cand.MaidenName;
                                    CDob.InnerHtml        = ErecruitHelper.AppendZero(cand.DateOfBirth.Value.Day) + "/" + ErecruitHelper.AppendZero(cand.DateOfBirth.Value.Month) + "/" + cand.DateOfBirth.Value.Year;
                                    cgrade.InnerHtml      = bs.TestScore + "%";
                                }

                                var cbSet = _db.T_BatchSet.FirstOrDefault(s => s.BatchId == candBatch.Id && s.CandidateId == cand.Id);
                                if (cbSet.Finished == true)
                                {
                                    GetTextBoxes(this);

                                    if (TextBoxes.Count > 0)
                                    {
                                        var psychTestResult = _db.T_MultiintelligencQuizBookDb.FirstOrDefault(s => s.CandidateId == cand.Id && s.BatchId == candBatch.Id);
                                        var intel           = TextBoxes.FirstOrDefault(s => s.CssClass == "intel");
                                        var analysis        = TextBoxes.Where(s => s.CssClass == "analysis").OrderBy(x => x.ID).ToList();
                                        var summation       = TextBoxes.Where(s => s.CssClass == "summation").OrderBy(x => x.ID).ToList();
                                        var D1 = TextBoxes.Where(s => s.CssClass == "D1").OrderBy(x => x.ID).ToList();
                                        var D2 = TextBoxes.Where(s => s.CssClass == "D2").OrderBy(x => x.ID).ToList();
                                        var D3 = TextBoxes.Where(s => s.CssClass == "D3").OrderBy(x => x.ID).ToList();
                                        var D4 = TextBoxes.Where(s => s.CssClass == "D4").OrderBy(x => x.ID).ToList();
                                        var D5 = TextBoxes.Where(s => s.CssClass == "D5").OrderBy(x => x.ID).ToList();
                                        var D6 = TextBoxes.Where(s => s.CssClass == "D6").OrderBy(x => x.ID).ToList();
                                        var D7 = TextBoxes.Where(s => s.CssClass == "D7").OrderBy(x => x.ID).ToList();

                                        intel.Text = psychTestResult.Intelligence;

                                        //D1
                                        var d1 = psychTestResult.Options1.Split(',');
                                        for (var s = 0; s < d1.Length; s++)
                                        {
                                            if (s < D1.Count)
                                            {
                                                D1[s].Text = d1[s];
                                            }
                                        }

                                        //D2
                                        var d2 = psychTestResult.Options2.Split(',');
                                        for (var s = 0; s < d1.Length; s++)
                                        {
                                            if (s < D2.Count)
                                            {
                                                D2[s].Text = d2[s];
                                            }
                                        }

                                        //D3
                                        var d3 = psychTestResult.Options3.Split(',');
                                        for (var s = 0; s < d3.Length; s++)
                                        {
                                            if (s < D3.Count)
                                            {
                                                D3[s].Text = d3[s];
                                            }
                                        }

                                        //D4
                                        var d4 = psychTestResult.Options4.Split(',');
                                        for (var s = 0; s < d4.Length; s++)
                                        {
                                            if (s < D4.Count)
                                            {
                                                D4[s].Text = d4[s];
                                            }
                                        }
                                        //D5
                                        var d5 = psychTestResult.Options5.Split(',');
                                        for (var s = 0; s < d5.Length; s++)
                                        {
                                            if (s < D5.Count)
                                            {
                                                D5[s].Text = d5[s];
                                            }
                                        }
                                        //D6
                                        var d6 = psychTestResult.Options6.Split(',');
                                        for (var s = 0; s < d6.Length; s++)
                                        {
                                            if (s < D6.Count)
                                            {
                                                D6[s].Text = d6[s];
                                            }
                                        }
                                        //D7
                                        var d7 = psychTestResult.Options7.Split(',');
                                        for (var s = 0; s < d7.Length; s++)
                                        {
                                            if (s < D7.Count)
                                            {
                                                D7[s].Text = d7[s];
                                            }
                                        }

                                        //summation
                                        var dsummation = psychTestResult.Summations.Split(',');
                                        for (var s = 0; s < dsummation.Length; s++)
                                        {
                                            if (s < summation.Count)
                                            {
                                                summation[s].Text = dsummation[s];
                                            }
                                        }
                                        //analysis
                                        var danalysis = psychTestResult.Summations.Split(',');
                                        for (var s = 0; s < danalysis.Length; s++)
                                        {
                                            if (s < analysis.Count)
                                            {
                                                analysis[s].Text = danalysis[s];
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                else
                {
                    Response.Redirect("NoPermission.aspx", false);
                }
            }
            catch (Exception ex)
            {
                ErecruitHelper.SetErrorData(ex, Session);
                Response.Redirect("ErrorPage.aspx", false);
            }
        }
示例#7
0
        protected void SearchAuditTrail_Click(object sender, EventArgs e)
        {
            try{
                var user   = username.Text;
                var action = Action.Text;
                var c      = cond.Value;
                var table  = tablename.Text;
                // var col = column.Text;
                var dateLogged = AuditDate.Text;

                IQueryable <AuditRecord> logs;

                if (!string.IsNullOrEmpty(user))
                {
                    logs = _db.AuditRecords.Where(s => (s.UserName.Contains(user)));
                }
                else
                {
                    logs = _db.AuditRecords.AsQueryable();
                }

                if (!string.IsNullOrEmpty(table))
                {
                    logs = logs.Where(s => s.TableName.Contains(table)).AsQueryable();
                }
                if (!string.IsNullOrEmpty(action))
                {
                    logs = logs.Where(s => s.Action.Contains(action)).AsQueryable();
                }
                //if (!string.IsNullOrEmpty(col) )
                //{
                //    logs = logs.Where(s => s.MemberName.Contains(col)).AsQueryable();
                //}
                if (!string.IsNullOrEmpty(dateLogged))
                {
                    var logdate = ErecruitHelper.GetCurrentDateFromDateStringWithHM(dateLogged);
                    if ((logdate) != null)
                    {
                        if (c == "=")
                        {
                            logs = logs.Where(s => s.AuditDate == (logdate)).AsQueryable();
                        }
                        else if (c == "<")
                        {
                            logs = logs.Where(s => s.AuditDate < (logdate)).AsQueryable();
                        }
                        else if (c == ">")
                        {
                            logs = logs.Where(s => s.AuditDate > (logdate)).AsQueryable();
                        }
                    }
                }
                TotalRecCount.Text       = logs.Count() + " Log(s)";
                AudiTrailGrid.DataSource = logs;
                AudiTrailGrid.DataBind();
            }
            catch (Exception ex)
            {
                ErecruitHelper.SetErrorData(ex, Session);
                Response.Redirect("ErrorPage.aspx", false);
            }
        }
        protected void check_Click(object sender, EventArgs e)
        {
            var code = Code.Text;

            var cand = _db.T_Candidate.FirstOrDefault(s => s.Code == code);

            if (!(cand == null))
            {
                var b_set = _db.T_BackGroundQuestAnswers.Where(s => s.CandidateId == cand.Id).ToList();
                int count = b_set.Count();
                if (count > 1)
                {
                    var quests = b_set.Select(a => new PrevBatchGridModel
                    {
                        ID        = a.Id,
                        BatchName = ErecruitHelper.getBatchName((long)a.BatchId),
                        Code      = ErecruitHelper.getCandidateCode((long)a.CandidateId) + "," + a.BatchId,
                        DateTaken = ErecruitHelper.GetDateStringFromDate((DateTime)a.Dateadded)
                    }).Distinct().ToList();
                    batchHistory.DataSource = quests;
                    batchHistory.DataBind();
                    batchHistoryPanel.Visible = true;

                    SessionHelper.NullCandidateCode(Session);
                    Session["Batchid"] = null;
                }
                else if (count == 1)
                {
                    batchHistoryPanel.Visible = false;
                    SessionHelper.SetCandidateCode(code, Session);
                    Session["Batchid"] = b_set[0].BatchId;
                    Response.Redirect("BackgroundView.aspx", false);
                }
                else
                {
                    resultLbl.Text            = "No History";
                    batchHistoryPanel.Visible = false;
                }
            }
            else
            {
                resultLbl.Text            = "This is not a valid candidate code";
                batchHistoryPanel.Visible = false;
            }
            //if (!string.IsNullOrEmpty(code))
            //{
            //    var cand = _db.T_Candidate.FirstOrDefault(s => s.Code == code);

            //    if (cand != null)
            //    {

            //        var b_id = _db.T_BatchSet.Where(s => s.CandidateId == cand.Id).Select(x => x.BatchId);

            //        var candBatch = _db.T_Batch.FirstOrDefault(s => b_id.Contains(s.Id) && s.IsActive.Value);
            //        if (candBatch != null)
            //        {


            //            var cbSet = _db.T_BatchSet.FirstOrDefault(s => s.BatchId == candBatch.Id && s.CandidateId == cand.Id);
            //            var c_off = _db.T_Settings.FirstOrDefault(s => s.SettingsName == ErecruitHelper.Settings.CUT_OFF_MARK.ToString()).SettingsValue;
            //            if (cbSet != null && cbSet.Finished == true)
            //            {
            //                if (double.Parse(cbSet.TestScore) > double.Parse(c_off))
            //                {
            //                    SessionHelper.SetCandidateCode(code, Session);
            //                    Response.Redirect("BackgroundView.aspx", false);
            //                }
            //                else
            //                {
            //                    resultLbl.Text = "The candidate did not pass the test.";
            //                }
            //            }
            //            else
            //            {
            //                var rsltTxt = "The candidate has not concluded the test.";



            //                resultLbl.Text = rsltTxt;
            //            }

            //        }
            //        else
            //        {
            //            resultLbl.Text = "The candidate has not been assigned to a test batch.";

            //        }

            //    }
            //    else
            //    {
            //        resultLbl.Text = "This is not a valid candidate code";
            //    }
            //}
        }
        protected void saveRole_Click(object sender, EventArgs e)
        {
            var tenantID = long.Parse(SessionHelper.GetTenantID(Session));
            var userId   = SessionHelper.FetchUserId(Session);
            var fn       = firstname.Text;
            var ln       = lname.Text;
            var role     = RoleList.SelectedValue;
            var emailvar = email.Text;
            var sx       = sex.SelectedItem.Value;
            var dateOb   = dob.Text;
            var un       = username.Text;
            var address  = Address.Text;
            var super    = supervisor.Checked;
            var adId     = adminId.Value;

            //var cpw = cPass.Text;

            if (string.IsNullOrEmpty(role) || role == "-1")
            {
                messageBox.Text = "Kindly Select a Role.";
            }
            else
            {
                using (QuizBookDbEntities1 _db = new QuizBookDbEntities1())
                {
                    var pw     = Guid.NewGuid().ToString();
                    var phrase = pw.Split('-')[0];

                    if (string.IsNullOrEmpty(adId))
                    {
                        var newAdmin = new AdminUser
                        {
                            FirstName              = fn,
                            LastName               = ln,
                            Username               = un,
                            Sex                    = sx,
                            DOB                    = ErecruitHelper.GetCurrentDateFromDateString(dateOb),
                            Address                = address,
                            State                  = Request[state.UniqueID].ToString(),
                            Country                = Request[country.UniqueID].ToString(),
                            Location               = Request[Location.UniqueID].ToString(),
                            TenantId               = tenantID,
                            Email                  = emailvar,
                            Supervisor             = super,
                            Role                   = long.Parse(role),
                            Status                 = ErecruitHelper.CStatus.Active.ToString(),
                            DateCreated            = DateTime.Now,
                            CreatedBy              = userId.ToString(),
                            Captcha                = Page.IsValid,
                            DefaultLoginKeyChanged = true,
                            LogInKey               = ErecruitHelper.getHash(phrase.Trim(), keySalt.Trim()),
                            IpAddress              = ErecruitHelper.GetIP(HttpContext.Current)
                        };
                        _db.AdminUsers.Add(newAdmin);
                        _db.SaveChanges();
                        ErecruitHelper.sendProfile(newAdmin, "", phrase);
                    }
                    else
                    {
                        long idcr  = long.Parse(adId);
                        var  admin = _db.AdminUsers.FirstOrDefault(x => x.Id == idcr);
                        if (admin != null)
                        {
                            admin.FirstName    = fn;
                            admin.LastName     = ln;
                            admin.Username     = un;
                            admin.Sex          = sx;
                            admin.DOB          = ErecruitHelper.GetCurrentDateFromDateString(dateOb);
                            admin.Address      = address;
                            admin.State        = Request[state.UniqueID].ToString();
                            admin.Country      = Request[country.UniqueID].ToString();
                            admin.Location     = Request[Location.UniqueID].ToString();
                            admin.TenantId     = tenantID;
                            admin.Email        = emailvar;
                            admin.Supervisor   = super;
                            admin.Role         = long.Parse(role);
                            admin.DateModified = DateTime.Now;
                            admin.Status       = ErecruitHelper.CStatus.Active.ToString();
                            admin.IpAddress    = ErecruitHelper.GetIP(HttpContext.Current);
                            _db.SaveChanges();
                            messageBox.Text = "Changes Saved";
                        }
                    }

                    Response.Redirect("Admins.aspx", false);
                }
            }
        }
        protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
        {
            try{
                var selectedQtype = long.Parse(DropDownList1.SelectedValue);
                var t             = _db.T_QuestionType.FirstOrDefault(s => s.Id == selectedQtype);

                var tenantId = long.Parse(SessionHelper.GetTenantID(Session));
                //if (selectedQtype == 1 || selectedQtype == 3 || selectedQtype == 4)
                //{
                //    //PreambleName.Text = "";
                //    //preambleNameRow.Visible = true;
                //    //PreambleName.Text = "";
                //    //preambleNameRow.Visible = true;

                //    PreambleName.Text = "";
                //    preambleText.Text = "";
                //    PreamblePreview.Text = "";
                //    PreambleNamePreview.Text = "";

                //    preview.Visible = false;
                //    preambleNameRow.Visible = false;
                //    preambleRow.Visible = false;

                //    //Populates the preambles DropDownList
                //    var p = _db.T_Question.Where(s => s.TypeId == selectedQtype).Select(s => s.PreambleId).Distinct();
                //    var preamblesList = _db.T_QuestionPreamble.Where(s => p.Contains(s.Id));
                //    var preamb = preamblesList.Select(a => new
                //    {
                //        Id = a.Id,
                //        Name = a.Name
                //    }).Distinct().ToList();
                //    preamb.Insert(0, new
                //    {
                //        Id = long.Parse("-1"),
                //        Name = "Select..."
                //    });
                //    preamb.Insert(1, new
                //    {
                //        Id = long.Parse("0"),
                //        Name = "New Question Preamble"
                //    });
                //    preambleLists.DataSource = preamb;
                //    preambleLists.DataBind();

                //    preambles.Visible = true;
                //}
                //else
                //{
                // preambles.Visible = false;

                //preambleLists.SelectedIndex = 0;

                PreambleName.Text        = "";
                preambleText.Text        = "";
                PreamblePreview.Text     = "";
                PreambleNamePreview.Text = "";

                preview.Visible         = false;
                preambleNameRow.Visible = false;
                preambleRow.Visible     = false;

                //  }
                //Populates the Question Type DropDownList
                var typ = _db.T_QuestionType.Where(x => x.TenantId == tenantId && x.Status == true).Select(a => new
                {
                    Id   = a.Id,
                    Name = a.Name
                }).OrderBy(s => s.Name).ToList();
                DropDownList1.SelectedValue = selectedQtype.ToString();
                DropDownList1.DataSource    = typ;
                DropDownList1.DataBind();

                //var quests = _db.T_Question.Where(x => x.TypeId == selectedQtype).OrderBy(x =>x.DateAdded).Select(a => new QuestionModel
                //{
                //    ID = a.Id,
                //    Detail = string.IsNullOrEmpty(a.Details) ? "Empty" : a.Details.Trim(),
                //    Type = ErecruitHelper.getTypeName(_db, a.TypeId),
                //    Preamble = ErecruitHelper.GetPreambleName(_db, a.PreambleId),
                //    OptionType = ErecruitHelper.getOptionTypeName(_db, a.OptionType),
                //    OptionsCount = ErecruitHelper.getOptionNum(_db, a.Id).ToString(),
                //    IsActive = a.IsActive.Value ? "Yes" : "No",
                //    // D = "<a id='" + a.Id.ToString() + "'  onclick='deleteQuest(this)' href='#' >Delete</a>"
                //    D = a.IsActive.Value ? "Deactivate" : "Activate"

                //}).Distinct().ToList();
                //  QuestionIndex.Text = quests.Count + " "+t.Name+" Question(s)";
                // GridView1.DataSource = quests;
                // GridView1.DataBind();

                var quests = _db.ActiveQuestions_vw.Where(x => x.TypeId == selectedQtype && x.TenantId == tenantId).OrderBy(x => x.Id).Select(a => new
                {
                    ID           = a.Id,
                    Detail       = a.Details,
                    Type         = a.Type,
                    Preamble     = a.Preamble,
                    Section      = a.Section,
                    OptionType   = a.OptionType,
                    OptionsCount = a.OptionsCount,
                    IsActive     = a.IsActive,
                    // D = "<a id='" + a.Id.ToString() + "'  onclick='deleteQuest(this)' href='#' >Delete</a>"
                    D = a.D
                }).ToList();
                QuestionIndex.Text   = quests.Count + " Question(s)";
                GridView1.DataSource = quests;
                GridView1.DataBind();
            }
            catch (Exception ex)
            {
                ErecruitHelper.SetErrorData(ex, Session);
                Response.Redirect("ErrorPage.aspx", false);
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            string currentPageFileName = new FileInfo(this.Request.Url.AbsolutePath).Name;
            var    PermMgr             = new PermissionManager(Session);

            if (PermMgr.IsAdmin || PermMgr.CanManageTestResults)
            {
                var c = SessionHelper.FetchCandidateCode(Session);
                if (!string.IsNullOrEmpty(c))
                {
                    var cand = _db.T_Candidate.FirstOrDefault(s => s.Code == c);
                    if (!(cand == null))
                    {
                        var b_id = _db.T_BatchSet.Where(s => s.CandidateId == cand.Id).Select(x => x.BatchId).ToList();

                        if (b_id.Count() != 0)
                        {
                            var bs        = new T_BatchSet();
                            var candBatch = new T_Batch();

                            if (Session["BatchSetId"] != null)
                            {
                                bs        = _db.T_BatchSet.FirstOrDefault(s => s.Id == long.Parse(Session["BatchSetId"].ToString()));
                                candBatch = _db.T_Batch.FirstOrDefault(s => s.Id == bs.BatchId);
                                var b_set  = _db.T_BatchSet.Where(s => s.CandidateId == cand.Id).ToList();
                                var quests = b_set.Select(a => new PrevBatchGridModel
                                {
                                    ID        = a.Id,
                                    BatchName = ErecruitHelper.getBatchName((long)a.BatchId),
                                    Code      = a.Finished == true ? ErecruitHelper.getCandidateCode((long)a.CandidateId) + "," + a.Id : ErecruitHelper.getCandidateCode((long)a.CandidateId),
                                    DateTaken = a.Finished == true ? a.TimeStarted.ToString() : "Not Finished."
                                }).Distinct().ToList();
                                batchHistory.DataSource = quests;
                                batchHistory.DataBind();
                                batchHistoryPanel.Visible = true;
                            }
                            else
                            {
                                bs        = _db.T_BatchSet.FirstOrDefault(s => s.CandidateId == cand.Id);
                                candBatch = _db.T_Batch.FirstOrDefault(s => s.Id == bs.BatchId);
                            }

                            if (bs.Finished == true)
                            {
                                int    totalQuestions = _db.T_BatchQuestions.Count(s => s.BatchId == candBatch.Id);
                                int    correct        = _db.T_CandidateAnswers.Count(s => s.CandidateId == cand.Id && s.BatchId == candBatch.Id && s.Correct == true);
                                double percentage     = (double)correct / totalQuestions;
                                percentage = Math.Round((percentage * 100), 2);

                                var rsltTxt = "Candidate Name: " + cand.FirstName + " " + cand.LastName + "<br /><br />Got " + correct + " question(s)  out of " + totalQuestions + " questions.<br /><br />Percentage Score: " + percentage + " %";

                                name.Text = rsltTxt;
                                CID.Value = cand.Code;
                                BID.Value = candBatch.Id.ToString();
                                BindScoreGrid(cand.Id, candBatch);
                            }
                            else
                            {
                                var rsltTxt = "The candidate has not concluded the test.";

                                name.Text = rsltTxt;
                                batchHistoryPanel.Visible = false;
                                ScoreListPanel.Visible    = false;
                            }
                        }
                        else
                        {
                            resultLbl.Text            = "The candidate has not been assigned to a test batch.";
                            batchHistoryPanel.Visible = false;
                            ScoreListPanel.Visible    = false;
                        }
                    }
                    else
                    {
                        resultLbl.Text            = "This is not a valid candidate code";
                        batchHistoryPanel.Visible = false;
                        ScoreListPanel.Visible    = false;
                    }
                }
            }
            else
            {
                batchHistoryPanel.Visible = false;
                ScoreListPanel.Visible    = false;
                Response.Redirect("NoPermission.aspx", false);
            }
        }
        protected void check_Click(object sender, EventArgs e)
        {
            var code = Code.Text;

            var cand = _db.T_Candidate.FirstOrDefault(s => s.Code == code);

            if (!(cand == null))
            {
                var b_set = _db.T_BatchSet.Where(s => s.CandidateId == cand.Id).ToList();
                int count = b_set.Count();
                if (count > 1)
                {
                    var quests = b_set.Select(a => new PrevBatchGridModel
                    {
                        ID        = a.Id,
                        BatchName = ErecruitHelper.getBatchName((long)a.BatchId),
                        Code      = a.Finished == true ? ErecruitHelper.getCandidateCode((long)a.CandidateId) + "," + a.Id : ErecruitHelper.getCandidateCode((long)a.CandidateId),
                        DateTaken = a.Finished == true ? ErecruitHelper.GetDateStringFromDate((DateTime)a.TimeStarted) : "Not Finished."
                    }).Distinct().ToList();
                    batchHistory.DataSource = quests;
                    batchHistory.DataBind();
                    batchHistoryPanel.Visible = true;
                    ScoreListPanel.Visible    = false;
                    SessionHelper.NullCandidateCode(Session);
                    Session["BatchSetId"] = null;
                }
                else if (count == 1)
                {
                    batchHistoryPanel.Visible = false;
                    SessionHelper.SetCandidateCode(code, Session);
                    Session["BatchSetId"] = null;
                    Response.Redirect("ViewTestScore.aspx", false);
                }
                else
                {
                    resultLbl.Text            = String.Empty;
                    batchHistoryPanel.Visible = false;
                }
            }
            else
            {
                resultLbl.Text            = "This is not a valid candidate code";
                batchHistoryPanel.Visible = 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);
                }
            }
        }
 protected void submit_Click(object sender, EventArgs e)
 {
     try
     {
         //var selectedGroup = bgrp.SelectedValue;
         var GroupItem = GroupContentList.SelectedValue;
         // Session["Grp"] = string.IsNullOrEmpty(selectedGroup) ? "ALL" : selectedGroup.Trim();
         Session["GrpList"] = string.IsNullOrEmpty(GroupItem) ? "ALL" : GroupItem.Trim();
         //ErecruitHelper.GetCurrentDateFromDateStringWithHM(Stdate);
         Session["dateFrom"] = string.IsNullOrEmpty(from.Text)?DateTime.Now.Date:ErecruitHelper.GetCurrentDateFromDateStringWithHM(from.Text);
         Session["dateTo"]   = string.IsNullOrEmpty(to.Text) ? DateTime.Now.Date : ErecruitHelper.GetCurrentDateFromDateStringWithHM(to.Text);
         Session["From"]     = string.IsNullOrEmpty(from.Text) ? true : false;
         Session["To"]       = string.IsNullOrEmpty(to.Text) ? true : false;
         Response.Redirect("BatchReport.aspx", false);
         // Response.Redirect("~/Reports/ResultView.aspx", false);
     }
     catch (Exception ex)
     {
         ErecruitHelper.SetErrorData(ex, Session);
         Response.Redirect("ErrorPage.aspx", false);
     }
 }