private void LoadTestsForCandidate(QuizBookDbEntities1 _db)
        {
            //var ab = _db.T_Batch.Where(s => s.IsActive == true);
            //var abid = ab.Select(s => s.Id).ToList();

            var tenant   = long.Parse(SessionHelper.GetTenantID(Session));
            var scopes   = _db.T_CTestTracker.Where(s => s.Candidate.TenantId == tenant && s.InSession.Value == true && s.Finished.Value == false).ToList();
            var myScopes = new List <BatchScopeContent>();

            var quests = scopes.Where(x => x.T_Batch.EndDate != null && !(x.T_Batch.EndDate.Value < DateTime.Now)).OrderByDescending(s => s.BatchId).Select(a => new
            {
                ID               = a.BatchId,
                trackerId        = a.Id,
                CandidateName    = a.Candidate.FirstName + " " + a.Candidate.LastName,
                CandidateStaffId = a.Candidate.Username ?? "-",
                Test             = a.T_Batch.Name,
                Duration         = a.T_Batch.Duration.Value,
                Rem              = TimeSpan.FromSeconds(int.Parse(a.RemainingDuration)).ToString(@"hh\:mm\:ss"),
                st               = a.CurrentStartTime,
                la               = a.CurrentStartTime,
                Time             = a.T_Batch.StartDate.Value.ToString("dd/MM/yyyy hh:mm:ss tt"),
                ETime            = a.T_Batch.EndDate.Value.ToString("dd/MM/yyyy hh:mm:ss tt")
            }).Distinct().ToList();

            GridView1.DataSource = quests;
            GridView1.DataBind();
        }
        public void SwitchActivityAction(QuizBookDbEntities1 _db, HttpContext context, string id)
        {
            var opt = _db.T_Candidate.FirstOrDefault(s => s.Id == long.Parse(id));

            if (opt != null)
            {
                if (opt.IsActive != null && opt.IsActive.Value)
                {
                    opt.IsActive = false;
                }
                else
                {
                    opt.IsActive = true;
                }

                _db.SaveChanges();
                context.Response.ContentType = "text/plain";
                context.Response.Write("Successful");
            }
            else
            {
                context.Response.ContentType = "text/plain";
                context.Response.Write("Failed");
            }
        }
        public static string SwitchEssayActivity(string id)
        {
            QuizBookDbEntities1 _db = new QuizBookDbEntities1();

            try
            {
                var opt = _db.T_EssayQuestions.FirstOrDefault(s => s.Id == long.Parse(id));
                if (opt != null)
                {
                    if (opt.IsActive.Value)
                    {
                        opt.IsActive     = false;
                        opt.DateModified = DateTime.Now;
                    }
                    else
                    {
                        opt.IsActive     = true;
                        opt.DateModified = DateTime.Now;
                    }


                    _db.SaveChanges();
                    return("success");
                }
                return("failed");
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }
        }
        protected void tsname_TextChanged(object sender, EventArgs e)
        {
            var tsn = tsname.Text;

            using (QuizBookDbEntities1 _db = new QuizBookDbEntities1())
            {
                var tn = _db.Tenants.FirstOrDefault(s => tsn.Trim().Equals(s.TenantCode));
                if (tn != null)
                {
                    var roles = _db.Roles.AsEnumerable().Where(x => x.Active && x.TenantId.HasValue && x.TenantId == tn.Id);
                    if (roles.Count() > 0)
                    {
                        var rls = roles.OrderBy(s => s.Description).Select(a => new
                        {
                            Id   = a.Id,
                            Name = a.Description
                        }).ToList();

                        rls.Insert(0, new { Id = long.Parse("-1"), Name = "--Class--" });

                        RoleList.DataSource = rls;

                        RoleList.DataBind();
                        RoleList.Visible = true;
                    }
                }
            }
        }
Ejemplo n.º 5
0
        protected void lnkeditC_Click(object sender, EventArgs e)
        {
            LinkButton  lnkeditC = ((LinkButton)sender);
            var         p        = lnkeditC.Parent;
            HiddenField hdfIDC   = (HiddenField)p.FindControl("hdfIDC");
            var         idcr     = long.Parse(hdfIDC.Value);

            using (QuizBookDbEntities1 _db = new QuizBookDbEntities1())
            {
                var admin = _db.AdminUsers.FirstOrDefault(x => x.Id == idcr);
                if (admin != null)
                {
                    adminId.Value          = admin.Id.ToString();
                    firstname.Text         = admin.FirstName;
                    lname.Text             = admin.LastName;
                    dob.Text               = admin.DOB == null ? string.Empty : admin.DOB.Value.ToString("dd/MM/yyyy");
                    Address.Text           = admin.Address;
                    username.Text          = admin.Username;
                    email.Text             = admin.Email;
                    sex.SelectedValue      = admin.Sex;
                    RoleList.SelectedValue = admin.Role.HasValue ? admin.Role.Value.ToString() : "-1";
                    supervisor.Checked     = admin.Supervisor.HasValue ? admin.Supervisor.Value : false;
                    country.Attributes.Add("data-default-value", admin.Country);
                    state.Attributes.Add("data-default-value", admin.State);
                }
            }
        }
 protected void regBtn_Click(object sender, EventArgs e)
 {
     if (!string.IsNullOrEmpty(tnCode.Text))
     {
         if (tnCode.Text.Length == 6)
         {
             QuizBookDbEntities1 _db = new QuizBookDbEntities1();
             var tn = _db.Tenants.FirstOrDefault(s => s.TenantCode == tnCode.Text);
             if (tn != null)
             {
                 SessionHelper.SetTenantID(tn.Id.ToString(), Session);
                 SessionHelper.SetTenantName(tn.TenantName, Session);
                 SessionHelper.SetTenantImage(tn.Image, Session);
                 Response.Redirect("CandidateReg.aspx", false);
             }
             else
             {
                 lblAlert.Text = "There is no tenant registered as '" + tnCode.Text + "'. Kindly verify and re-enter tenant code above.";
             }
         }
         else
         {
             lblAlert.Text = "Tenant code should be 6 characters. You have " + tnCode.Text.Length + ". Kindly verify.";
         }
     }
     else
     {
         lblAlert.Text = "Kindly fill in your tenant code above";
     }
 }
        public static string ResetMth(string name)
        {
            string keySalt = "QuizBook";


            QuizBookDbEntities1 _db = new QuizBookDbEntities1();

            try
            {
                var pw     = Guid.NewGuid().ToString();
                var phrase = pw.Split('-')[0];

                var qg = _db.Candidates.AsEnumerable().FirstOrDefault(s => s.Username.Trim() == name.Trim() || s.Email.Trim() == name.Trim());
                //var qg = _db.T_QuestionType.FirstOrDefault(s => s.Id == long.Parse(id));
                if (qg != null)
                {
                    qg.LogInKey               = ErecruitHelper.getHash(phrase.Trim(), keySalt.Trim());
                    qg.ModifiedBy             = qg.Username;
                    qg.DefaultLoginKeyChanged = false;
                    qg.DateModified           = DateTime.Now;
                    _db.SaveChanges();
                    ErecruitHelper.sendPwReser(qg, " ", phrase);
                    return("success");
                }
                else
                {
                    return("notexist");
                }
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }
        }
Ejemplo n.º 8
0
        public static string DisableRole(string id)
        {
            var tenantId            = long.Parse(SessionHelper.GetTenantID(HttpContext.Current.Session));
            var userId              = SessionHelper.FetchUserId(HttpContext.Current.Session);
            QuizBookDbEntities1 _db = new QuizBookDbEntities1();

            try
            {
                var rId = long.Parse(id);
                //var user = _db.AdminUsers.FirstOrDefault(x => x.Id == userId);
                var qg = _db.Roles.FirstOrDefault(s => s.TenantId == tenantId && s.Id == rId);
                if (qg != null)
                {
                    qg.Active       = false;
                    qg.ModifiedBy   = userId.ToString();
                    qg.DateModified = DateTime.Now;
                    _db.SaveChanges();
                    HttpContext.Current.Session["NewSelRole"] = null;
                    return("success");
                }
                else
                {
                    return("exist");
                }
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }
        }
Ejemplo n.º 9
0
        public static string SwitchCandidateActivity(string id)
        {
            QuizBookDbEntities1 _db = new QuizBookDbEntities1();

            try
            {
                var opt = _db.Candidates.Where(s => s.Id == long.Parse(id)).FirstOrDefault();
                if (opt != null)
                {
                    if (opt.Status == ErecruitHelper.CStatus.Active.ToString())
                    {
                        opt.Status = ErecruitHelper.CStatus.Inactive.ToString();
                    }
                    else
                    {
                        opt.Status = ErecruitHelper.CStatus.Active.ToString();
                    }

                    _db.SaveChanges();
                    return("success");
                }
                return("failed");
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }
        }
        public static string NewQuestionGroup(string id, string name)
        {
            var tenantId            = long.Parse(SessionHelper.GetTenantID(HttpContext.Current.Session));
            QuizBookDbEntities1 _db = new QuizBookDbEntities1();

            try
            {
                var qg = _db.T_QuestionType.FirstOrDefault(s => s.TenantId == tenantId && s.Name.ToLower().Trim() == id.ToLower().Trim());
                if (qg == null)
                {
                    _db.T_QuestionType.Add(new T_QuestionType
                    {
                        TenantId    = tenantId,
                        Name        = id.Trim().ToUpper(),
                        Description = id.Trim().ToUpper(),
                        Status      = true,
                        AddedBy     = name,
                        DateAdded   = DateTime.Now
                    });
                    _db.SaveChanges();
                    return("success");
                }
                else
                {
                    return("exist");
                }
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }
        }
        public static string DeleteQuestionGroup(string id, string name)
        {
            var tenantId            = long.Parse(SessionHelper.GetTenantID(HttpContext.Current.Session));
            QuizBookDbEntities1 _db = new QuizBookDbEntities1();

            try
            {
                var qg = _db.T_QuestionType.FirstOrDefault(s => s.Id == long.Parse(id));
                if (qg != null)
                {
                    var qs = _db.T_Question.Where(s => s.TypeId == qg.Id);
                    qg.Status = false;
                    foreach (var x in qs)
                    {
                        x.IsActive = false;
                    }
                    _db.SaveChanges();
                    return("success");
                }
                else
                {
                    return("notexist");
                }
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }
        }
Ejemplo n.º 12
0
        protected void Button1_Click(object sender, EventArgs e)
        {
            using (QuizBookDbEntities1 _db = new QuizBookDbEntities1())
            {
                var stid = staffId.Text;
                var tent = long.Parse(SessionHelper.GetTenantID(Session));
                var cand = _db.Candidates.FirstOrDefault(s => s.Username == stid.Trim() && s.TenantId == tent);
                if (cand != null)
                {
                    var actTest = _db.T_CTestTracker.AsEnumerable().Where(s => s.CandidateId == cand.Id && s.Finished == true).OrderByDescending(x => x.CurrentStartTime).Select(x => new
                    {
                        Name         = x.T_Batch.Name,
                        Candidate    = x.CandidateId,
                        Batch        = x.BatchId,
                        TimeFinished = ErecruitHelper.GetDateStringFromDate(x.CurrentStartTime.Value)
                    });

                    CandidateTestList.DataSource = actTest.ToList();
                    CandidateTestList.DataBind();
                    DAlert.Visible = false;
                    DMain.Visible  = true;
                }
                else
                {
                    var actTest = new List <object>();
                    CandidateTestList.DataSource = actTest.ToList();
                    CandidateTestList.DataBind();

                    //alert.InnerText = "This Candidate does not exist on the portal.";
                    DAlert.Visible = false;
                    DMain.Visible  = true;
                }
            }
        }
Ejemplo n.º 13
0
        protected void loginBtn_Click(object sender, EventArgs e)
        {
            var usName = username.Text;
            var psWord = password.Text;

            using (QuizBookDbEntities1 _db = new QuizBookDbEntities1())
            {
                var user = _db.AdminUsers.FirstOrDefault(s => s.Username == usName);
                if (user != null)
                {
                    string key = user.LogInKey;
                    if (!string.IsNullOrEmpty(key) && !string.IsNullOrWhiteSpace(key))
                    {
                        byte[] pw       = ErecruitHelper.getByte(psWord, keySalt);
                        byte[] pwFromDB = Convert.FromBase64String(key);
                        if (ErecruitHelper.CompareByteArrays(pw, pwFromDB))
                        {
                            if (user.Status.Trim() == ErecruitHelper.CStatus.Active.ToString())
                            {
                                SessionHelper.SetEmail(user.Email, Session);
                                SessionHelper.SetUserId((int)user.Id, Session);
                                SessionHelper.SetUserName(user.Username, Session);
                                if (user.TenantId == null)
                                {
                                    SessionHelper.NullifyTenantID(Session);
                                }
                                else
                                {
                                    SessionHelper.SetTenantID(user.TenantId.Value.ToString(), Session);
                                    SessionHelper.SetTenantName(user.Tenant.TenantName.ToString(), Session);
                                }
                                SessionHelper.SetLocation(user.Location, Session);
                                SessionHelper.SetFirstName(user.FirstName, Session);
                                SessionHelper.SetLastName(user.LastName, Session);
                                var permissions = ErecruitHelper.GetAdminPermissions(_db, user);
                                SessionHelper.SetUserPermissions(permissions, System.Web.HttpContext.Current.Session);
                                //var adminObj = _db.Roles.FirstOrDefault(s => s.Description == "Admin");
                                var adminObj = _db.Roles.Select(s => s.Id).ToArray();
                                MB.FileBrowser.MagicSession.Current.FileBrowserAccessMode = IZ.WebFileManager.AccessMode.Write;
                                if (user.Role.HasValue && adminObj.Contains(user.Role.Value))
                                {
                                    Response.Redirect("index.aspx", false);
                                }
                                else
                                {
                                    Response.Redirect("TestLanding.aspx");
                                }
                            }
                            else
                            {
                                lblAlert.Text = string.Format("Your status is {0}. Kindly contact the Administartor", user.Status);
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 14
0
        protected void loginBtn_Click(object sender, EventArgs e)
        {
            var usName = username.Text;
            var psWord = password.Text;
            QuizBookDbEntities1 _db = new QuizBookDbEntities1();
            var user = _db.Candidates.FirstOrDefault(s => s.Username == usName);

            if (user != null)
            {
                string key = user.LogInKey;
                if (!string.IsNullOrEmpty(key) && !string.IsNullOrWhiteSpace(key))
                {
                    byte[] pw       = ErecruitHelper.getByte(psWord, keySalt);
                    byte[] pwFromDB = Convert.FromBase64String(key);
                    if (ErecruitHelper.CompareByteArrays(pw, pwFromDB))
                    {
                        if (user.Status.Trim() == ErecruitHelper.CStatus.Active.ToString())
                        {
                            SessionHelper.SetEmail(user.Email, Session);
                            SessionHelper.SetUserId((int)user.Id, Session);
                            SessionHelper.SetUserName(user.Username, Session);
                            if (user.TenantId == null)
                            {
                                SessionHelper.NullifyTenantID(Session);
                            }
                            else
                            {
                                SessionHelper.SetTenantID(user.TenantId.Value.ToString(), Session);
                            }
                            SessionHelper.SetLocation(user.Location, Session);
                            SessionHelper.SetFirstName(user.FirstName, Session);
                            SessionHelper.SetLastName(user.LastName, Session);
                            var permissions = ErecruitHelper.GetuserPermissions(_db, user);
                            SessionHelper.SetUserPermissions(permissions, System.Web.HttpContext.Current.Session);
                            Response.Redirect("TestLanding.aspx");
                        }
                        else
                        {
                            lblAlert.Text = string.Format("Your status is {0}. Kindly contact the Administartor", user.Status);
                        }
                    }
                    else
                    {
                        lblAlert.Text = string.Format("Your password seems incorrect. Kindly check.");
                    }
                }

                else
                {
                    lblAlert.Text = string.Format("No password set.");
                }
            }
            else
            {
                lblAlert.Text = string.Format("Cannot find user in the System.");
            }
        }
        //protected void preambleLists_SelectedIndexChanged(object sender, EventArgs e)
        //{
        //    try{
        //    var selectedQtype = long.Parse(DropDownList1.SelectedValue);
        //    var t = _db.T_QuestionTypes.FirstOrDefault(s => s.Id == selectedQtype);
        //    var QType = _db.T_Question.Select(s => s.PreambleId).Distinct();
        //    var Qt = _db.T_QuestionTypes.FirstOrDefault(s => s.Id == selectedQtype);
        //    var QTypeCount = QType.Count();
        //    var QTC = QTypeCount++;
        //    var selectedpreamble = long.Parse(preambleLists.SelectedValue);
        //    if (selectedpreamble == 0)
        //    {
        //        PreambleName.Text = Qt.Name + " " + QTC;
        //        preambleText.Text = "";
        //        PreamblePreview.Text = "";

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

        //        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();

        //    }
        //    else if (selectedpreamble != -1 && selectedpreamble != 0)
        //    {
        //        var id = QPid.Value;
        //        //var Id = long.Parse(id);
        //        //var cur = _db.T_Question.Where(s => s.Id == Id).FirstOrDefault();
        //        //var Qt = _db.T_QuestionTypes.FirstOrDefault(s => s.Id == cur.TypeId);
        //        if (!(string.IsNullOrEmpty(id)))
        //        {
        //            var preamble = _db.T_QuestionPreamble.FirstOrDefault(s => s.Id == selectedpreamble);


        //            PreamblePreview.Text ="";
        //            PreambleNamePreview.Text = "";
        //            preview.Visible = false;
        //            QPid.Value = preamble.Id.ToString();
        //            PreambleName.Text = preamble.Name;
        //            preambleText.Text = preamble.Body;

        //            preambleNameRow.Visible = true;
        //            preambleRow.Visible = true;
        //        }
        //        else
        //        {
        //            var preamble = _db.T_QuestionPreamble.FirstOrDefault(s => s.Id == selectedpreamble);

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

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

        //            PreambleNamePreview.Text = preamble.Name;
        //            PreamblePreview.Text = preamble.Body;
        //            preview.Visible = true;
        //        }

        //        var quests = _db.T_Question.Where(x => x.PreambleId == selectedpreamble).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();



        //    }
        //    else
        //    {
        //        PreambleName.Text = "";
        //        preambleText.Text = "";
        //        PreamblePreview.Text = "";
        //        PreambleNamePreview.Text = "";

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



        //    }
        //    }
        //    catch (Exception ex)
        //    {
        //        ErecruitHelper.SetErrorData(ex, Session);
        //        Response.Redirect("ErrorPage.aspx", false);
        //    }
        //}
        protected void lnkeditQ_Click(object sender, EventArgs e)
        {
            try
            {
                using (QuizBookDbEntities1 _db = new QuizBookDbEntities1()){
                    LinkButton  lnkedit = ((LinkButton)sender);
                    var         p       = lnkedit.Parent;
                    HiddenField hdfID   = (HiddenField)p.FindControl("hdfIDQ");
                    var         idcr    = long.Parse(hdfID.Value);
                    if (!(idcr == null))
                    {
                        var opt = _db.T_Question.FirstOrDefault(s => s.Id == (idcr));
                        if (opt != null)
                        {
                            if (opt.IsActive.Value)
                            {
                                opt.IsActive     = false;
                                opt.DateModified = DateTime.Now;
                            }
                            else
                            {
                                opt.IsActive     = true;
                                opt.DateModified = DateTime.Now;
                            }


                            _db.SaveChanges();
                            var selectedQtype = long.Parse(DropDownList1.SelectedValue);
                            var quests        = _db.ActiveQuestions_vw.AsEnumerable().Where(x => x.TypeId == selectedQtype && x.TenantId == long.Parse(SessionHelper.GetTenantID(Session))).Select(a => new QuestionModel
                            {
                                ID           = a.Id,
                                Detail       = a.Details,
                                Type         = a.Type,
                                Preamble     = a.Preamble,
                                Section      = a.Section,
                                OptionType   = a.OptionType,
                                OptionsCount = a.OptionsCount.ToString(),
                                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)
        {
            try
            {
                // string currentPageFileName = new FileInfo(this.Request.Url.AbsolutePath).Name;
                var PermMgr = new PermissionManager(Session);

                if (PermMgr.IsAdmin || PermMgr.CanManageTestBatches)
                {
                    //from.Text = ErecruitHelper.GetDateStringFromDateX(DateTime.Now);
                    //to.Text = ErecruitHelper.GetDateStringFromDateX(DateTime.Now);
                    if (!IsPostBack)
                    {
                        //var l = Enum.GetValues(typeof(ErecruitHelper.BatchGroupsR)).Cast<ErecruitHelper.BatchGroupsR>().ToList();
                        //var bg = l.Select(a => new
                        //{
                        //    Id = a.ToString(),
                        //    Name = a.ToString()

                        //}).Distinct().OrderBy(s => s.Name).ToList();
                        //bgrp.DataSource = bg;
                        // bgrp.DataBind();
                        var tn    = long.Parse(SessionHelper.GetTenantID(Session));
                        var cands = new List <object> {
                            new { ID = "ALL", Name = "ALL" }
                        };
                        using (QuizBookDbEntities1 _db = new QuizBookDbEntities1())
                        {
                            var batches = _db.T_Batch.Where(x => x.TenantId == tn && x.IsActive.Value).Select(x => new
                            {
                                ID   = x.Id,
                                Name = x.Name
                            }).OrderByDescending(x => x.ID);
                            GroupContentList.DataSource = batches.ToList();
                            GroupContentList.DataBind();
                        }
                    }
                }
                else
                {
                    Response.Redirect("NoPermission.aspx", false);
                }
            }
            catch (Exception ex)
            {
                ErecruitHelper.SetErrorData(ex, Session);
                Response.Redirect("ErrorPage.aspx", false);
            }
        }
Ejemplo n.º 17
0
        public static string PassCheck(string op, string xx)
        {
            string keySalt = "QuizBook";


            QuizBookDbEntities1 _db = new QuizBookDbEntities1();

            try
            {
                var usName = SessionHelper.FetchUserName(HttpContext.Current.Session);
                var psWord = op;

                string key = "";
                if (xx == "index")
                {
                    var qg = _db.AdminUsers.AsEnumerable().FirstOrDefault(s => s.Username.Trim() == usName.Trim());
                    key = qg == null?"":qg.LogInKey;
                }
                else
                {
                    var qg = _db.Candidates.AsEnumerable().FirstOrDefault(s => s.Username.Trim() == usName.Trim());
                    key = qg == null ? "" : qg.LogInKey;
                }


                if (!string.IsNullOrEmpty(key) && !string.IsNullOrWhiteSpace(key))
                {
                    byte[] pw       = ErecruitHelper.getByte(psWord, keySalt);
                    byte[] pwFromDB = Convert.FromBase64String(key);
                    if (ErecruitHelper.CompareByteArrays(pw, pwFromDB))
                    {
                        return("success");
                    }
                    else
                    {
                        return("failed");
                    }
                }
                else
                {
                    return("failed");
                }
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            var permissions = ErecruitHelper.GetUserPermissions(Page.Session);
            var sid         = SessionHelper.FetchStaffId(Page.Session);

            using (QuizBookDbEntities1 _db = new QuizBookDbEntities1())
            {
                var user = _db.T_Candidate.FirstOrDefault(s => s.Code.Trim() == sid.Trim());



                LoadTestsForCandidate(_db);

                //  testPanel.Visible = true;
            }
        }
Ejemplo n.º 19
0
        protected void lnkeditD_Click(object sender, EventArgs e)
        {
            LinkButton  lnkeditD = ((LinkButton)sender);
            var         p        = lnkeditD.Parent;
            HiddenField hdfIDD   = (HiddenField)p.FindControl("hdfIDD");
            var         idcr     = long.Parse(hdfIDD.Value);
            var         userId   = SessionHelper.FetchUserId(Session);

            using (QuizBookDbEntities1 _db = new QuizBookDbEntities1())
            {
                var admin = _db.AdminUsers.FirstOrDefault(x => x.Id == idcr);
                admin.Status       = string.IsNullOrEmpty(admin.Status)?"Inactive":admin.Status.Trim() == "Active"?"Inactive": "Active";
                admin.DateModified = DateTime.Now;
                _db.SaveChanges();
            }
            Response.Redirect("Admins.aspx", false);
        }
Ejemplo n.º 20
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                using (QuizBookDbEntities1 _db = new QuizBookDbEntities1())
                {
                    var tenantID = long.Parse(SessionHelper.GetTenantID(Session));
                    var roles    = _db.Roles.AsEnumerable().Where(x => x.Active && x.TenantId.HasValue && x.TenantId == tenantID).ToList();

                    var rls = roles.OrderBy(s => s.Description).Select(a => new
                    {
                        Id   = a.Id,
                        Name = a.Description
                    }).ToList();

                    rls.Insert(0, new { Id = long.Parse("-1"), Name = "--Select Role--" });

                    rl.DataSource = rls;

                    rl.DataBind();

                    roleModel obj    = new roleModel();
                    var       rs     = new List <roleModel>();
                    var       rCount = 0;
                    foreach (var a in roles)
                    {
                        obj              = new roleModel();
                        obj.ID           = a.Id;
                        obj.Role         = a.Description;
                        obj.CreatedBy    = string.IsNullOrEmpty(a.CreatedBy) ? "" : a.CreatedBy;
                        obj.DateCreated  = a.DateCreated.HasValue ? a.DateCreated.Value.ToString("dd-MM-yyyy") : "";
                        obj.ModifiedBy   = string.IsNullOrEmpty(a.ModifiedBy) ? "" : a.ModifiedBy;
                        obj.DateModified = a.DateModified.HasValue ? a.DateModified.Value.ToString("dd-MM-yyyy") : "";
                        rs.Add(obj);
                        rCount++;
                    }


                    TotalRecCount.Text = rCount + " Role(s)";

                    RoleList.DataSource = rs;
                    RoleList.DataBind();
                }
            }
        }
        public static string deleteQuestOption(string id)
        {
            QuizBookDbEntities1 _db = new QuizBookDbEntities1();

            try
            {
                var optId = long.Parse(id);
                var opt   = _db.T_Option.FirstOrDefault(s => s.Id == optId);
                if (opt != null)
                {
                    _db.T_Option.Remove(opt);
                    _db.SaveChanges();
                    return("success");
                }
                return("failed");
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }
        }
        protected void lnkeditCa_Click(object sender, EventArgs e)
        {
            LinkButton  lnkedit = ((LinkButton)sender);
            var         p       = lnkedit.Parent;
            HiddenField hdfID   = (HiddenField)p.FindControl("hdfIDCa");
            var         idcr    = long.Parse(hdfID.Value);

            using (QuizBookDbEntities1 _db = new QuizBookDbEntities1())
            {
                var tracker = _db.T_CTestTracker.FirstOrDefault(s => s.Id == idcr);
                if (tracker != null)
                {
                    tracker.LastQIndex       = 0;
                    tracker.CurrentStartTime = DateTime.Now;
                    tracker.InSession        = false;
                    tracker.Finished         = true;
                    _db.SaveChanges();
                }
            }
            Response.Redirect("ActiveCandidates.aspx", false);
        }
        public void ProcessRequest(HttpContext context)
        {
            // Those parameters are sent by the plugin
            QuizBookDbEntities1 _db = new QuizBookDbEntities1();
            var action = context.Request["action"];
            var qtS    = context.Request["qtypeSort"];
            var alink  = context.Request["z"];
            //var alink = context.Session["thelink"]!=null?context.Session["thelink"].ToString():"";
            var iDisplayLength = context.Request["iDisplayLength"];
            var iDisplayStart  = context.Request["iDisplayStart"];
            var iSortCol       = context.Request["iSortCol_0"];
            var iSortDir       = context.Request["sSortDir_0"];
            var iSearch        = context.Request["sSearch"];
            var isEcho         = context.Request["sEcho"];


            switch (action)
            {
            case "SwitchActivity":
                var id = context.Request["id"];
                SwitchActivityAction(_db, context, id);
                break;

            case "CandidateList":
                CandidatesGridDataLoad(_db, context, iSearch, iSortCol, iSortDir, iDisplayStart, iDisplayLength, isEcho);
                break;

            case "QuestList":
                QuestionGridDataLoad(_db, context, iSearch, iSortCol, iSortDir, iDisplayStart, iDisplayLength, isEcho, qtS);
                break;

            case "QuestOptList":
                OptionGridDataLoad(_db, context, iSearch, iSortCol, iSortDir, iDisplayStart, iDisplayLength, isEcho, alink);
                break;

            case "QuestTypeList":
                QtypeGridDataLoad(_db, context, iSearch, iSortCol, iSortDir, iDisplayStart, iDisplayLength, isEcho);
                break;
            }
        }
        public void QuestionGridDataLoad(QuizBookDbEntities1 _db, HttpContext context, string iSearch, string iSortCol2, string iSortDir, string iDisplayStart2, string iDisplayLength2, string isEcho, string qtS)
        {
            var iDisplayLength = int.Parse(iDisplayLength2);
            var iDisplayStart  = int.Parse(iDisplayStart2);
            var iSortCol       = int.Parse(iSortCol2);

            var quests = new List <QuestionModel>();

            if (qtS == "null")
            {
                quests = _db.T_Question.OrderByDescending(x => x.DateAdded).Select(a => new QuestionModel
                {
                    ID           = a.Id,
                    Detail       = string.IsNullOrEmpty(a.Details) ? "Empty" : "<div class='box'>" + a.Details.Trim() + "</div>",
                    Type         = ErecruitHelper.getTypeName(_db, a.TypeId),
                    OptionType   = ErecruitHelper.getOptionTypeName(_db, a.OptionType),
                    OptionsCount = ErecruitHelper.getOptionNumLink(_db, a.Id, a.Id),
                    IsActive     = a.IsActive.Value ? "Yes" : "No",
                    Edit         = "<a href='QuestionsList.aspx?z=" + a.Id + "' >Edit</a>",
                    D            = a.IsActive.Value ? "<a href='#' >Deactivate</a>" : "<a href='#' >Activate</a>"
                }).ToList();
            }
            else
            {
                quests = _db.T_Question.Where(s => s.TypeId == long.Parse(qtS)).OrderByDescending(x => x.DateAdded).Select(a => new QuestionModel
                {
                    ID           = a.Id,
                    Detail       = string.IsNullOrEmpty(a.Details) ? "Empty" : "<div class='box'>" + a.Details.Trim() + "</div>",
                    Type         = ErecruitHelper.getTypeName(_db, a.TypeId),
                    OptionType   = ErecruitHelper.getOptionTypeName(_db, a.OptionType),
                    OptionsCount = ErecruitHelper.getOptionNumLink(_db, a.Id, a.Id),
                    IsActive     = a.IsActive.Value ? "Yes" : "No",
                    Edit         = "<a href='QuestionsList.aspx?z=" + a.Id + "' >Edit</a>",
                    D            = a.IsActive.Value ? "<a href='#' >Deactivate</a>" : "<a href='#' >Activate</a>"
                }).Distinct().ToList();
            }
            //Searching
            IEnumerable <QuestionModel> f;

            if (!string.IsNullOrEmpty(iSearch))
            {
                f = quests
                    .Where(c => c.ID.ToString().ToLower().Contains(iSearch.ToLower())
                           ||
                           c.Detail.ToLower().Contains(iSearch.ToLower())
                           ||
                           c.Type.ToLower().Contains(iSearch.ToLower())
                           ||
                           c.OptionType.ToLower().Contains(iSearch.ToLower())
                           ||
                           c.OptionsCount.ToLower().Contains(iSearch.ToLower())
                           ||
                           c.IsActive.ToLower().Contains(iSearch.ToLower())
                           ||
                           c.Edit.ToLower().Contains(iSearch.ToLower())
                           ||
                           c.D.ToLower().Contains(iSearch.ToLower())


                           );
            }
            else
            {
                f = quests;
            }
            // Sorting
            var its = f;

            var sortCIndex = Convert.ToInt32(iSortCol);
            // Func<BDCCustomerGridModel, string> orderingFunction = (c => c.id.ToString());

            Func <QuestionModel, string> orderingFunct = (c => sortCIndex == 0 ? c.ID.ToString() :
                                                          sortCIndex == 1 ? c.Detail :
                                                          sortCIndex == 2 ? c.Type :
                                                          sortCIndex == 3 ? c.OptionType :
                                                          sortCIndex == 4 ? c.OptionsCount :
                                                          sortCIndex == 5 ? c.IsActive :
                                                          sortCIndex == 6 ? c.Edit :
                                                          sortCIndex == 7 ? c.D : ""
                                                          );

            //? sortColumnIndex == 2 ? c.Title :c.StartDate
            var sortDirect = iSortDir;

            // asc or desc
            f = sortDirect == "asc" ? f.OrderBy(orderingFunct) : f.OrderByDescending(orderingFunct);


            //Paging
            var displ = f
                        .Skip(iDisplayStart)
                        .Take(iDisplayLength);

            //Table Construction
            var thelst = from s in displ
                         select new[] { s.ID.ToString(), s.Detail, s.Type, s.OptionType, s.IsActive, s.OptionsCount, s.Edit, s.D };


            var r = new
            {
                sEcho                = isEcho,
                iTotalRecords        = quests.Count(),
                iTotalDisplayRecords = thelst.Count(),
                aaData               = thelst.ToList()
            };

            var srlizer = new JavaScriptSerializer();
            var jsonObj = srlizer.Serialize(r);

            context.Response.ContentType = "application/json";
            context.Response.Write(jsonObj);
        }
Ejemplo n.º 25
0
        public static string ChangePass(string op, string xx)
        {
            string keySalt = "QuizBook";


            QuizBookDbEntities1 _db = new QuizBookDbEntities1();

            try
            {
                var usName = SessionHelper.FetchUserName(HttpContext.Current.Session);
                var psWord = op;

                string key = "";
                if (xx == "index")
                {
                    var qg = _db.AdminUsers.AsEnumerable().FirstOrDefault(s => s.Username.Trim() == usName.Trim());
                    if (qg == null)
                    {
                        return("failed");
                    }
                    else
                    {
                        qg.LogInKey = ErecruitHelper.getHash(psWord.Trim(), keySalt.Trim());
                        qg.DefaultLoginKeyChanged = true;
                        qg.DateModified           = DateTime.Now;
                        _db.SaveChanges();
                        return("success");
                    }
                }
                else
                {
                    var qg = _db.Candidates.AsEnumerable().FirstOrDefault(s => s.Username.Trim() == usName.Trim());
                    if (qg == null)
                    {
                        return("failed");
                    }
                    else
                    {
                        qg.LogInKey     = ErecruitHelper.getHash(psWord.Trim(), keySalt.Trim());
                        qg.ModifiedBy   = qg.Username;
                        qg.DateModified = DateTime.Now;
                        _db.SaveChanges();
                        return("success");
                    }
                }


                //if (!string.IsNullOrEmpty(key) && !string.IsNullOrWhiteSpace(key))
                //{
                //    byte[] pw = ErecruitHelper.getByte(psWord, keySalt);
                //    byte[] pwFromDB = Convert.FromBase64String(key);

                //if (ErecruitHelper.CompareByteArrays(pw, pwFromDB))
                //{
                //    return "success";
                //}
                //else
                //{
                //    return "failed";
                //}
                //}
                //else
                //{
                //    return "failed";
                //}
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }
        }
Ejemplo n.º 26
0
        protected void regBtn_Click(object sender, EventArgs e)
        {
            // QuizBookDbEntities1 _db = new QuizBookDbEntities1();
            var page = Page.IsValid;

            if (page)
            {
                var fn       = firstname.Text;
                var ln       = lname.Text;
                var address  = Address.Text;
                var emailvar = email.Text;
                var sx       = sex.SelectedItem.Value;
                var dateOb   = dob.Text;
                var un       = username.Text;
                var pw       = password.Text;
                var cpw      = cPass.Text;
                if (pw.Trim() == cpw.Trim())
                {
                    HttpPostedFile file = tLogo.PostedFile;

                    if (file != null && file.ContentLength > 0)
                    {
                        string fname  = Path.GetFileName(file.FileName);
                        string ext    = System.IO.Path.GetExtension(file.FileName);
                        string fileID = Guid.NewGuid().ToString();
                        string path   = "";
                        if (shortName.Text.Length >= 6)
                        {
                            var tenant = new Tenant
                            {
                                TenantName   = name.Text,
                                TenantCode   = string.IsNullOrEmpty(shortName.Text) ? name.Text.Substring(0, 6) : shortName.Text,
                                Address      = Address.Text,
                                State        = Request[state.UniqueID].ToString(),
                                Country      = Request[country.UniqueID].ToString(),
                                TenantStatus = true,
                                DateCreated  = DateTime.Now,
                                CreatedBy    = "QuizBook",
                                TenantLimit  = 0,
                                Image        = Path.Combine("~/TenantLogo/", fileID + ext)
                            };


                            using (QuizBookDbEntities1 _db = new QuizBookDbEntities1())
                            {
                                _db.Tenants.Add(tenant);
                                _db.SaveChanges();
                                var rl = _db.Roles.FirstOrDefault(s => s.Description == "Admin");

                                _db.AdminUsers.Add(new AdminUser
                                {
                                    FirstName              = fn,
                                    LastName               = ln,
                                    Username               = un,
                                    Sex                    = sx,
                                    DOB                    = ErecruitHelper.GetCurrentDateFromDateString(dateOb),
                                    Address                = Address.Text,
                                    State                  = Request[state.UniqueID].ToString(),
                                    Country                = Request[country.UniqueID].ToString(),
                                    Location               = Request[Location.UniqueID].ToString(),
                                    TenantId               = tenant.Id,
                                    Email                  = emailvar,
                                    Role                   = rl.Id,
                                    Status                 = ErecruitHelper.CStatus.Active.ToString(),
                                    DateCreated            = DateTime.Now,
                                    CreatedBy              = "QuizBook",
                                    Captcha                = Page.IsValid,
                                    DefaultLoginKeyChanged = true,
                                    LogInKey               = ErecruitHelper.getHash(pw, keySalt),
                                    IpAddress              = ErecruitHelper.GetIP(HttpContext.Current)
                                });
                                _db.SaveChanges();
                            }



                            // var all =  new List<string[]>();
                            if (Directory.Exists(Server.MapPath("~/TenantLogo/")))
                            {
                                path = Server.MapPath(Path.Combine("~/TenantLogo/", fileID + ext));
                                // PPath = Path.Combine("~/Passports/", cand.Code + ext);
                                file.SaveAs(path);
                            }
                            else
                            {
                                Directory.CreateDirectory(Server.MapPath("~/TenantLogo/"));
                                path = Server.MapPath(Path.Combine("~/TenantLogo/", fileID + ext));
                                // PPath = Path.Combine("~/Passports/", cand.Code + ext);
                                file.SaveAs(path);
                            }
                            var data = File.ReadAllBytes(path);
                            SessionHelper.SetInfoValue("Your Profile has been successfully saved. Kindly <a href='Welcome.aspx'>click here</a> to proceed.", Session);
                            Response.Redirect("Info.aspx", false);
                        }
                        else
                        {
                            lblAlert.Text = "Short Name should be at least 6 characters";
                        }
                    }
                }
                else
                {
                    lblAlert.Text = "Administrator's Password did not match";
                }
            }
            else
            {
                lblAlert.Text = "Kindly fill the recaptcha";
            }
        }
        protected void regBtn_Click(object sender, EventArgs e)
        {
            try
            {
                var page = Page.IsValid;
                var tsn  = tsname.Text;
                var fn   = fname.Text;
                var ln   = lname.Text;
                //var address = Address.Text;
                var emailvar = email.Text;
                var sx       = sex.SelectedItem.Value;
                //var dateOb = dob.Text;
                var un = username.Text;
                //var pw = password.Text;
                //var cpw = cPass.Text;
                //var ste = Request[state.UniqueID].ToString();
                //var ctry = Request[country.UniqueID].ToString();

                var pw  = Request["userPw"].ToString();
                var cpw = Request["userPw2"].ToString();

                var lctn = Request[Location.UniqueID].ToString();
                var role = RoleList.Visible ? RoleList.SelectedValue : null;


                using (QuizBookDbEntities1 _db = new QuizBookDbEntities1())
                {
                    var tn = _db.Tenants.FirstOrDefault(s => tsn.Trim().Equals(s.TenantCode));
                    if (tn != null)
                    {
                        if (pw.Trim() == cpw.Trim())
                        {
                            long?n  = null;
                            var  rl = _db.Roles.FirstOrDefault(s => s.Description == "Candidate");

                            _db.Candidates.Add(new QuizBook.Candidate
                            {
                                FirstName = fn,
                                LastName  = ln,
                                Username  = un,
                                Sex       = sx,
                                //DOB = ErecruitHelper.GetCurrentDateFromDateString(dateOb),
                                //Address = Address.Text,
                                //State = Request[state.UniqueID].ToString(),
                                //Country = Request[country.UniqueID].ToString(),
                                Location               = Request[Location.UniqueID].ToString(),
                                Email                  = emailvar,
                                TenantId               = tn.Id,
                                Role                   = rl.Id,
                                Status                 = ErecruitHelper.CStatus.Active.ToString(),
                                DateCreated            = DateTime.Now,
                                CreatedBy              = "QuizBook",
                                Captcha                = Page.IsValid,
                                Class                  = role == null?n:long.Parse(role),
                                DefaultLoginKeyChanged = true,
                                LogInKey               = ErecruitHelper.getHash(pw, keySalt),
                                IpAddress              = ErecruitHelper.GetIP(HttpContext.Current)
                            });
                            _db.SaveChanges();
                            Session["InfoValue"] = "Your Profile has been successfully saved. Kindly <a href='CandLogin.aspx'>click here</a> to proceed.";
                            Response.Redirect("Info.aspx", false);
                        }
                        else
                        {
                            lblAlert.Text = "Registration Failed. Your passwords did not match";
                        }
                    }
                    else
                    {
                        lblAlert.Text = "Registration Failed. Kindly ensure you have the correct Tenant Code.";
                    }
                }
            }
            catch (Exception ex)
            {
                SessionHelper.SetExMessage(ex.Message, Session);
                SessionHelper.SetExStacktrace(ex.StackTrace, Session);
                Response.Redirect("ExceptionPage.aspx", false);
            }
        }
        public void CandidatesGridDataLoad(QuizBookDbEntities1 _db, HttpContext context, string iSearch, string iSortCol1, string iSortDir, string iDisplayStart1, string iDisplayLength1, string isEcho)
        {
            var iDisplayLength = int.Parse(iDisplayLength1);
            var iDisplayStart  = int.Parse(iDisplayStart1);
            var iSortCol       = int.Parse(iSortCol1);

            var data = _db.Candidates.Select(a => new CandidateGridModel
            {
                ID             = a.Id,
                TenantId       = a.TenantId ?? 0,
                Username       = a.Username,
                FirstName      = a.FirstName,
                LastName       = a.LastName,
                Sex            = a.Sex,
                DOB            = a.DOB == null ? "-" : a.DOB.Value.ToString("dd-MM-yyyy"),
                Status         = a.Status ?? "-",
                Email          = a.Email,
                D              = a.Status == ErecruitHelper.CStatus.Active.ToString() ? "Deactivate" : "Activate",
                DateRegistered = a.DateCreated == null ? "-" : a.DateCreated.Value.ToString("dd-MM-yyyy")
            }).ToList();
            //Searching
            IEnumerable <CandidateGridModel> filtered;

            if (!string.IsNullOrEmpty(iSearch))
            {
                filtered = data
                           .Where(c =>
                                  c.Username.ToLower().Contains(iSearch.ToLower())
                                  ||
                                  c.FirstName.ToLower().Contains(iSearch.ToLower())
                                  ||

                                  c.LastName.ToLower().Contains(iSearch.ToLower())
                                  ||

                                  c.D.ToLower().Contains(iSearch.ToLower())


                                  );
            }
            else
            {
                filtered = data;
            }


            // Sorting
            var items = filtered;

            var sortColumnIndex = Convert.ToInt32(iSortCol);
            // Func<BDCCustomerGridModel, string> orderingFunction = (c => c.id.ToString());

            Func <CandidateGridModel, string> orderingFunction = (c => sortColumnIndex == 0 ? c.Username :
                                                                  sortColumnIndex == 1 ? c.FirstName :
                                                                  sortColumnIndex == 2 ? c.LastName :

                                                                  sortColumnIndex == 8 ? c.D : ""
                                                                  );

            //? sortColumnIndex == 2 ? c.Title :c.StartDate
            var sortDirection = iSortDir;

            // asc or desc
            filtered = sortDirection == "asc" ? filtered.OrderBy(orderingFunction) : filtered.OrderByDescending(orderingFunction);
            //Paging
            var displayed = filtered
                            .Skip(iDisplayStart)
                            .Take(iDisplayLength);

            //Table Construction
            var thelist = from s in displayed
                          select new[] { s.Username, s.FirstName, s.LastName, s.D, s.DateRegistered.ToString() };
            var result = new
            {
                sEcho                = isEcho,
                iTotalRecords        = data.Count(),
                iTotalDisplayRecords = thelist.Count(),
                aaData               = thelist.ToList()
            };

            var serializer = new JavaScriptSerializer();
            var json       = serializer.Serialize(result);

            context.Response.ContentType = "application/json";
            context.Response.Write(json);
        }
        public void QtypeGridDataLoad(QuizBookDbEntities1 _db, HttpContext context, string iSearch, string iSortCol3, string iSortDir, string iDisplayStart3, string iDisplayLength3, string isEcho)
        {
            var iDisplayLength = int.Parse(iDisplayLength3);
            var iDisplayStart  = int.Parse(iDisplayStart3);
            var iSortCol       = int.Parse(iSortCol3);

            //var options = _db.T_QuestionTypes.Select(a => new QuestionTypeModel
            //{
            //    Id = a.Id.ToString(),
            //    Name = string.IsNullOrEmpty(a.Name) ? "Empty" : a.Name.Trim(),
            //    Status = a.Status.Value ? "Yes" : "No",
            //    Action = a.Status.Value ? "<a href='#'>Activate</a>" : "<a href='#'>Deactivate</a>"

            //}).ToList();

            var options = _db.T_QuestionType.Select(a => new QuestionTypeModel
            {
                Id     = "-",
                Name   = "3",
                Status = "No",
                Action = "YES"
            }).ToList();


            //Searching
            IEnumerable <QuestionTypeModel> fopt;

            if (!string.IsNullOrEmpty(iSearch))
            {
                fopt = options
                       .Where(c => c.Id.ToLower().Contains(iSearch.ToLower())
                              ||
                              c.Name.ToLower().Contains(iSearch.ToLower())
                              ||
                              c.Status.ToLower().Contains(iSearch.ToLower())
                              ||
                              c.Action.ToLower().Contains(iSearch.ToLower())
                              );
            }
            else
            {
                fopt = options;
            }
            // Sorting
            var itOpt = fopt;

            var sortOptIndex = Convert.ToInt32(iSortCol);


            Func <QuestionTypeModel, string> orderingOptFunct = (c => sortOptIndex == 0 ? c.Id.ToString() :
                                                                 sortOptIndex == 1 ? c.Name :

                                                                 sortOptIndex == 5 ? c.Status :
                                                                 sortOptIndex == 7 ? c.Action: ""
                                                                 );

            //? sortColumnIndex == 2 ? c.Title :c.StartDate
            var sortOptDirect = iSortDir;

            // asc or desc
            fopt = sortOptDirect == "asc" ? fopt.OrderBy(orderingOptFunct) : fopt.OrderByDescending(orderingOptFunct);


            //Paging
            var displOpt = fopt
                           .Skip(iDisplayStart)
                           .Take(iDisplayLength);

            //Table Construction
            var thelstOpt = from s in displOpt
                            select new[] { s.Id.ToString(), s.Name, s.Status, s.Action };


            var rOpt = new
            {
                sEcho                = isEcho,
                iTotalRecords        = options.Count(),
                iTotalDisplayRecords = thelstOpt.Count(),
                aaData               = thelstOpt.ToList()
            };

            var srlizerOpt = new JavaScriptSerializer();
            var jsonObjOpt = srlizerOpt.Serialize(rOpt);

            context.Response.ContentType = "application/json";
            context.Response.Write(jsonObjOpt);
        }
        public void OptionGridDataLoad(QuizBookDbEntities1 _db, HttpContext context, string iSearch, string iSortCol3, string iSortDir, string iDisplayStart3, string iDisplayLength3, string isEcho, string alink)
        {
            var iDisplayLength = int.Parse(iDisplayLength3);
            var iDisplayStart  = int.Parse(iDisplayStart3);
            var iSortCol       = int.Parse(iSortCol3);

            var options = _db.T_Option.AsEnumerable().Where(s => s.Q_Id == long.Parse(alink)).Select(a => new QuestionOptionModel
            {
                ID     = a.Id.ToString(),
                Detail = string.IsNullOrEmpty(a.Details) ? "Empty" : a.Details.Trim(),
                Answer = (a.Answer.Value.ToString()),
                E      = "<a href='QuestionOptions.aspx?z=" + a.Id + "' >Edit</a>",
                D      = "<a href='#'>Delete</a>"
            }).ToList();


            //Searching
            IEnumerable <QuestionOptionModel> fopt;

            if (!string.IsNullOrEmpty(iSearch))
            {
                fopt = options
                       .Where(c => c.ID.ToLower().Contains(iSearch.ToLower())
                              ||
                              c.Detail.ToLower().Contains(iSearch.ToLower())
                              ||
                              c.Answer.ToLower().Contains(iSearch.ToLower())
                              ||
                              c.E.ToLower().Contains(iSearch.ToLower())
                              ||
                              c.D.ToLower().Contains(iSearch.ToLower())
                              );
            }
            else
            {
                fopt = options;
            }
            // Sorting
            var itOpt = fopt;

            var sortOptIndex = Convert.ToInt32(iSortCol);


            Func <QuestionOptionModel, string> orderingOptFunct = (c => sortOptIndex == 0 ? c.ID.ToString() :
                                                                   sortOptIndex == 1 ? c.Detail :

                                                                   sortOptIndex == 5 ? c.Answer :
                                                                   sortOptIndex == 6 ? c.E :
                                                                   sortOptIndex == 7 ? c.D : ""
                                                                   );

            //? sortColumnIndex == 2 ? c.Title :c.StartDate
            var sortOptDirect = iSortDir;

            // asc or desc
            fopt = sortOptDirect == "asc" ? fopt.OrderBy(orderingOptFunct) : fopt.OrderByDescending(orderingOptFunct);


            //Paging
            var displOpt = fopt
                           .Skip(iDisplayStart)
                           .Take(iDisplayLength);

            //Table Construction
            var thelstOpt = from s in displOpt
                            select new[] { s.ID.ToString(), s.Detail, s.Answer, s.E, s.D };


            var rOpt = new
            {
                sEcho                = isEcho,
                iTotalRecords        = options.Count(),
                iTotalDisplayRecords = thelstOpt.Count(),
                aaData               = thelstOpt.ToList()
            };

            var srlizerOpt = new JavaScriptSerializer();
            var jsonObjOpt = srlizerOpt.Serialize(rOpt);

            context.Response.ContentType = "application/json";
            context.Response.Write(jsonObjOpt);
        }