protected void Button1_Click(object sender, EventArgs e) { try{ var Qtype = DropDownList1.SelectedValue; var opptype = DropDownList2.SelectedValue; var mark = markTxt.Text; var pOpt = percentOption.Checked; // var preambleid = preambleLists.SelectedValue; //var preambleName = PreambleName.Text; //var preamble = preambleText.Text; //T_QuestionsPreamble p = null; // if (!string.IsNullOrEmpty(preamble)) // { // p = new T_QuestionsPreamble // { // Name = preambleName, // Body = preamble, // AddedBy = SessionHelper.FetchEmail(Session), // DateAdded = DateTime.Now // }; // _db.T_QuestionPreamble.Add(p); // _db.SaveChanges(); // } if (!string.IsNullOrEmpty(TextBox1.Text)) { var email = SessionHelper.FetchEmail(Session); var opttype = long.Parse(opptype);//(long)ErecruitHelper.OptionType.Single; decimal altmark = 1; var qMark = string.IsNullOrEmpty(mark) ? 1 : decimal.TryParse(mark, out altmark)?altmark:1; var tyId = long.Parse(Qtype); var tenantId = long.Parse(SessionHelper.GetTenantID(HttpContext.Current.Session)); T_Question q = new T_Question { //PreambleId = p != null ? p.Id : string.IsNullOrEmpty(preambleid)||(long.Parse(preambleid) == -1) ? 0 :long.Parse(preambleid), TypeId = tyId, OptionType = opttype, Section = Section.Text, TenantId = tenantId, IsActive = true, Details = TextBox1.Text, Mark = qMark, OptionPercentageMark = pOpt, AddedBy = email, DateAdded = DateTime.Now }; _db.T_Question.Add(q); _db.SaveChanges(); } Response.Redirect("QuestionsList.aspx", false); } catch (Exception ex) { ErecruitHelper.SetErrorData(ex, Session); Response.Redirect("ErrorPage.aspx", false); } }
protected void Button1_Click(object sender, EventArgs e) { T_Question q = new T_Question { TypeId = long.Parse(DropDownList1.SelectedValue), OptionType = long.Parse(DropDownList2.SelectedValue), IsActive = true, Details = TextBox1.Text }; _db.T_Question.Add(q); _db.SaveChanges(); Response.Redirect("QuestionsList.aspx", false); }
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); } }
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 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); } }
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); } }
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); } }
protected void submit_Click(object sender, EventArgs e) { try { var staffid = SessionHelper.FetchStaffId(Page.Session); var c = _db.T_Candidate.FirstOrDefault(s => s.Code == staffid); if (c != null) { submit.Text = "Update"; var gr = grades.SelectedValue; var br = branches.SelectedValue; var div = divisions.SelectedValue; var sec = Sector.SelectedValue; var reg = Region.SelectedValue; } else { var lastname = SessionHelper.FetchLastName(Page.Session); var othername = SessionHelper.FetchFirstName(Page.Session); var email = SessionHelper.FetchEmail(Page.Session); var gr = grades.SelectedValue; var br = branches.SelectedValue; var div = divisions.SelectedValue; var sec = Sector.SelectedValue; var reg = Region.SelectedValue; _db.T_Candidate.Add( new T_Candidate { Code = staffid, StaffID = staffid, FirstName = othername, LastName = lastname, Email = email, Grade = gr, Branch = int.Parse(br), Division = div, Sector = sec, IsActive = true, ApprovalStatus = ErecruitHelper.ApprovalStatus.APPROVED.ToString(), Region = int.Parse(reg), RegisterBy = SessionHelper.FetchEmail(Page.Session), DateRegistered = DateTime.Now }); _db.SaveChanges(); Response.Redirect("TestLanding.aspx", false); } } catch (Exception ex) { ErecruitHelper.SetErrorData(ex, Session); Response.Redirect("Err.aspx", false); } }
protected void Button1_Click(object sender, EventArgs e) { try { var curQ_id = long.Parse(HiddenField1.Value); if (curQ_id != null) { var question = _db.T_Question.FirstOrDefault(s => s.Id == curQ_id); if (question != null) { T_Option q = new T_Option { Q_Id = curQ_id, Answer = CheckBox1.Checked, Details = TextBox1.Text, AddedBy = SessionHelper.FetchEmail(Session), DateAdded = DateTime.Now }; _db.T_Option.Add(q); var qTrueOption = _db.T_Option.FirstOrDefault(s => s.Q_Id == question.Id && s.Answer == true); var single = ErecruitHelper.OptionType.Single.ToString(); var opttype = _db.T_QOptionType.FirstOrDefault(s => s.Name == single); if (question.OptionType == opttype.Id) { if (q.Answer == true && qTrueOption != null) { q.AddedBy = SessionHelper.FetchEmail(Session); q.DateAdded = DateTime.Now; qTrueOption.Answer = false; qTrueOption.ModifiedBy = SessionHelper.FetchEmail(Session); qTrueOption.DateModified = DateTime.Now; _db.SaveChanges(); } else if (question.T_QOptionType.Name == "Multi") { q.AddedBy = SessionHelper.FetchEmail(Session); q.DateAdded = DateTime.Now; _db.SaveChanges(); } } else { _db.SaveChanges(); } } } Response.Redirect("QuestionOptions.aspx?z=" + curQ_id, false); } catch (Exception ex) { ErecruitHelper.SetErrorData(ex, Session); Response.Redirect("ErrorPage.aspx", false); } }
//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 lnkeditCS_Click(object sender, EventArgs e) { LinkButton lnkedit = ((LinkButton)sender); var p = lnkedit.Parent; HiddenField hdfID = (HiddenField)p.FindControl("hdfIDCS"); var idcr = long.Parse(hdfID.Value); if (!(idcr == null)) { var opt = _db.T_Candidate.Where(s => s.Id == idcr).FirstOrDefault(); if (opt.ApprovalStatus == ErecruitHelper.ApprovalStatus.APPROVED.ToString()) { if (opt != null) { if (opt.IsActive.Value) { opt.IsActive = false; } else { opt.IsActive = true; } _db.SaveChanges(); var quests = _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") }).Distinct().ToList(); TotalRecCount.Text = quests.Count() + " Candidate(s)"; CandidateList.DataSource = quests.OrderByDescending(x => x.ID).ToList(); CandidateList.DataBind(); } resultLbl.Text = ""; } else { resultLbl.Text = "The candidate has to be approved first"; } } }
protected void CutOff_Click(object sender, EventArgs e) { try{ var cid = coffId.Value; var newvalue = Coff.Text; if (!string.IsNullOrEmpty(cid)) { long id = long.Parse(cid); var coff = _db.T_Settings.FirstOrDefault(s => s.Id == id); if (coff != null) { coff.SettingsValue = newvalue; coff.ModifiedBy = SessionHelper.FetchEmail(Session); coff.DateModified = DateTime.Now; _db.SaveChanges(); } } }catch (Exception ex) { ErecruitHelper.SetErrorData(ex, Session); Response.Redirect("ErrorPage.aspx", false); } }
protected void ESave_Click(object sender, EventArgs e) { try{ var essay = EssayText.Text; if (!string.IsNullOrEmpty(essay)) { var duration = !string.IsNullOrEmpty(EssayDuration.Text) ? int.Parse(EssayDuration.Text) : 0; _db.T_EssayQuestions.Add(new T_EssayQuestions { Question = essay, Duration = duration, IsActive = Q_Active.Checked, DateAdded = DateTime.Now }); _db.SaveChanges(); } else { } Response.Redirect("EssayQuestions.aspx", false); } catch (Exception ex) { ErecruitHelper.SetErrorData(ex, Session); Response.Redirect("ErrorPage.aspx", false); } }
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); }
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); }
protected void Button1_Click(object sender, EventArgs e) { try { var id = candId.Value; var com = Comment.Text; if (!string.IsNullOrEmpty(id)) { var cand = _db.T_Candidate.FirstOrDefault(s => s.Id.ToString() == id); if (cand != null) { cand.Comment = string.IsNullOrEmpty(com) ? "" : com; _db.SaveChanges(); } } } catch (Exception ex) { ErecruitHelper.SetErrorData(ex, Session); Response.Redirect("Candidate.aspx", false); } }
protected void submit_Click(object sender, EventArgs e) { try { var id = cidHdn.Value; var gr = grades.SelectedValue; var br = branches.SelectedValue; var div = divisions.SelectedValue; var sec = Sector.SelectedValue; var reg = Region.SelectedValue; var candidate = _db.T_Candidate.FirstOrDefault(s => s.Id == long.Parse(id)); candidate.Grade = gr; candidate.Branch = int.Parse(br); candidate.Division = div; candidate.Sector = sec; candidate.Region = int.Parse(reg); _db.SaveChanges(); } 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); } }
protected void Button1_Click(object sender, EventArgs e) { try { var sb = Batches.SelectedValue; if (string.IsNullOrEmpty(sb)) { return; } var selectedBatch = long.Parse(Batches.SelectedValue); var selectedIndex = Batches.SelectedIndex; var batch = _db.T_Batch.FirstOrDefault(s => s.Id == selectedBatch); int[] selectedCandidates = ActiveCandidateList.GetSelectedIndices(); var contentIds = new List <int>(); var cids = selectedCandidates.Select(i => int.Parse(ActiveCandidateList.Items[i].Value)).ToList(); foreach (int x in cids) { if (x == 0) { } else { contentIds.Add(x); } } foreach (int x in contentIds) { var x1 = x; var hasActive = false; var prevBatchSet = _db.T_BatchSet.Where(s => s.CandidateId == x1).Select(s => s.BatchId); List <T_Batch> prevBatch = null; if (prevBatchSet.Any()) { prevBatch = _db.T_Batch.Where(s => prevBatchSet.Contains(s.Id)).ToList(); } if (prevBatch != null && prevBatch.Count > 0) { foreach (var batch1 in prevBatch) { if (batch1.IsActive == true) { hasActive = true; } } } if (hasActive) { //Session["Status"] = ""; } else { var existing = _db.T_BatchSet.FirstOrDefault(s => s.BatchId == batch.Id && s.CandidateId == x); if (existing == null) { if (batch != null) { _db.T_BatchSet.Add(new T_BatchSet { CandidateId = x, BatchId = batch.Id, Finished = false, IsLive = false }); } } } } _db.SaveChanges(); Session["ToBeSelected"] = selectedIndex; Response.Redirect("AddCandidateToBatch.aspx", false); } catch (Exception ex) { ErecruitHelper.SetErrorData(ex, Session); Response.Redirect("ErrorPage.aspx", false); } }
protected void BQsubmit_Click(object sender, EventArgs e) { try { var candId = SessionHelper.FetchCandidateId(Session); var id = long.Parse(candId); var cand = _db.T_Candidate.FirstOrDefault(s => s.Id == id); 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 Q1 = TextBox1.Text; var Q2 = TextBox2.Text; var Q3 = TextBox3.Text; var Q4a = Request.Form["r1"]; var Q4b = TextBox4.Text; var Q5a = TextBox5.Text; var Q5b = TextBox6.Text; var Q6a = TextBox7.Text; var Q6b = TextBox8.Text; var Q7a = TextBox9.Text; var Q7b = TextBox10.Text; var Q8a = TextBox11.Text; var Q8b = TextBox12.Text; var Q9a = TextBox13.Text; var Q9b = TextBox14.Text; var Q10a = TextBox15.Text; var Q10b = TextBox16.Text; var Q11 = TextBox17.Text; var Q12 = TextBox18.Text; var Q13 = TextBox19.Text; var Q14 = TextBox20.Text; var Q15a = TextBox21.Text; var Q15b = TextBox22.Text; var Q15c = TextBox23.Text; var Q16 = TextBox24.Text; var Q17a = Request.Form["r2"]; var Q17b = TextBox25.Text; var Q18a = Request.Form["r3"]; var Q18b = TextBox26.Text; var Q19 = TextBox27.Text; var Q20a = Request.Form["r4"]; var Q20b = TextBox28.Text; var Q21a = Request.Form["r5"]; var Q21b = TextBox29.Text; var Q22 = TextBox30.Text; var Q23a1 = TextBox31.Text; var Q23a2 = TextBox32.Text; var Q23a3 = TextBox33.Text; var Q23b1 = TextBox34.Text; var Q23b2 = TextBox35.Text; var Q23b3 = TextBox36.Text; var Q24a1 = TextBox37.Text; var Q24a2 = TextBox38.Text; var Q24b = TextBox39.Text; var Q25 = TextBox40.Text; var ack = Request.Form["r6"]; //validation var litmus = false; string[] elements = new string[] { TextBox1.Text, TextBox2.Text, TextBox3.Text, Request.Form["r1"], TextBox4.Text, TextBox5.Text, TextBox6.Text, TextBox7.Text, TextBox8.Text, TextBox9.Text, TextBox10.Text, TextBox11.Text, TextBox12.Text, TextBox13.Text, TextBox14.Text, TextBox15.Text, TextBox16.Text, TextBox17.Text, TextBox18.Text, TextBox19.Text, TextBox20.Text , TextBox21.Text, TextBox22.Text, TextBox23.Text, TextBox24.Text, Request.Form["r2"], TextBox25.Text, Request.Form["r3"], TextBox26.Text, TextBox27.Text, Request.Form["r4"] , TextBox28.Text, Request.Form["r5"], TextBox29.Text, TextBox30.Text, TextBox31.Text, TextBox32.Text, TextBox33.Text, TextBox34.Text, TextBox35.Text, TextBox36.Text, TextBox37.Text, TextBox38.Text, TextBox39.Text, TextBox40.Text, Request.Form["r6"] }; foreach (var i in elements) { if (string.IsNullOrEmpty(i)) { litmus = true; } else { litmus = false; } } if (litmus) { msgLabel.Text = "Please make sure you answer all the questions"; } else { _db.T_BackGroundQuestAnswers.Add(new T_BackGroundQuestAnswers { CandidateId = cand.Id, BatchId = candBatch.Id, Q1 = Q1, Q2 = Q2, Q3 = Q3, Q4a = Q4a, Q4b = Q4b, Q5a = Q5a, Q5b = Q5b, Q6a = Q6a, Q6b = Q6b, Q7a = Q7a, Q7b = Q7b, Q8a = Q8a, Q8b = Q8b, Q9a = Q9a, Q9b = Q9b, Q10a = Q10a, Q10b = Q10b, Q11 = Q11, Q12 = Q12, Q13 = Q13, Q14 = Q14, Q15a = Q15a, Q15b = Q15b, Q15c = Q15c, Q16 = Q16, Q17a = Q17a, Q17b = Q17b, Q18a = Q18a, Q18b = Q18b, Q19 = Q19, Q20a = Q20a, Q20b = Q20b, Q21a = Q21a, Q21b = Q21b, Q22 = Q22, Q23a1 = Q23a1, Q23a2 = Q23a2, Q23a3 = Q23a3, Q23b1 = Q23b1, Q23b2 = Q23b2, Q23b3 = Q23b3, Q24a1 = Q24a1, Q24a2 = Q24a2, Q24b = Q24b, Q25 = Q25, Acknowledgement = ack, Dateadded = DateTime.Now }); var cbSet = _db.T_BatchSet.FirstOrDefault(s => s.BatchId == candBatch.Id && s.CandidateId == cand.Id); cbSet.Psychometric = true; _db.SaveChanges(); Response.Redirect("FinalPage.aspx", false); } } } } catch (Exception ex) { ErecruitHelper.SetErrorData(ex, Session); Response.Redirect("ErrorPage.aspx", false); } }
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"; } }
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); } }
protected void lnkedit3_Click(object sender, EventArgs e) { LinkButton lnkedit = ((LinkButton)sender); var p = lnkedit.Parent; HiddenField hdfID = (HiddenField)p.FindControl("hdfID3"); var idcr = long.Parse(hdfID.Value); if (!(idcr == null)) { var batch = _db.T_Batch.FirstOrDefault(s => s.Id == idcr); var sid = SessionHelper.FetchUserName(Page.Session); var user = _db.Candidates.FirstOrDefault(s => s.Username.Trim() == sid.Trim()); if (batch.IsActive.Value) { Session["SelectedBatch"] = idcr; if (batch.StartDate <= DateTime.Now) { var tracker = _db.T_CTestTracker.FirstOrDefault(s => s.CandidateId == user.Id && s.BatchId == batch.Id); if (tracker != null) { SessionHelper.SetCandidateId(user.Id.ToString(CultureInfo.InvariantCulture), Session); Response.Redirect("_CandidateTestPage.aspx", false); } else { var st = DateTime.Now; var duration = batch.Duration.ToString(); _db.T_CTestTracker.Add(new T_CTestTracker { CandidateId = user.Id, BatchId = batch.Id, CandidateCode = user.Username, InSession = true, Finished = false, // InitialStartTime = st, // CurrentStartTime = st, TestDuration = ErecruitHelper.AppendZero(0) + ":" + ErecruitHelper.AppendZero(int.Parse(duration)) + ":" + ErecruitHelper.AppendZero(0), RemainingDuration = duration //EndTime = endtime }); batch.SessionOn = true; _db.SaveChanges(); tracker = _db.T_CTestTracker.FirstOrDefault(s => s.CandidateId == user.Id && s.BatchId == batch.Id); var remaining = tracker.RemainingDuration; var d = tracker.TestDuration; if (d != "0:0:0" && remaining != "0:0:0") { SessionHelper.SetCandidateId(user.Id.ToString(CultureInfo.InvariantCulture), Session); Response.Redirect("_CandidateTestPage.aspx", false); } } // Response.Redirect("_CandidateTestPage.aspx", false); } else { messageLbl.Visible = true; messagePanel.Visible = true; messageLbl.Text = "It is not yet time to take this Test :'" + batch.Name + "'\n Please contact the Administrator."; } } else { LoadTestsForCandidate(user); var info = "This test is no longer active."; messageLbl.Visible = true; messagePanel.Visible = true; messageLbl.Text = info; } } }
protected void Save_Click(object sender, EventArgs e) { try { var candId = SessionHelper.FetchCandidateId(Session); var id = long.Parse(candId); var cand = _db.T_Candidate.FirstOrDefault(s => s.Id == id); 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 ansCol1 = Request.Form["D1"]; var ansCol2 = Request.Form["D2"]; var ansCol3 = Request.Form["D3"]; var ansCol4 = Request.Form["D4"]; var ansCol5 = Request.Form["D5"]; var ansCol6 = Request.Form["D6"]; var ansCol7 = Request.Form["D7"]; var sums = Request.Form["Summation"]; var intel = intelligence.Value; if (string.IsNullOrEmpty(ansCol1) || string.IsNullOrEmpty(ansCol2) || string.IsNullOrEmpty(ansCol3) || string.IsNullOrEmpty(ansCol4) || string.IsNullOrEmpty(ansCol5) || string.IsNullOrEmpty(ansCol6) || string.IsNullOrEmpty(ansCol7) || string.IsNullOrEmpty(sums) || string.IsNullOrEmpty(intel)) { msgLabel.Text = "Please make sure you answer all the questions"; } else { _db.T_MultiintelligencQuizBookDb.Add(new T_MultiintelligencQuizBookDb { CandidateId = cand.Id, BatchId = candBatch.Id, Options1 = ansCol1, Options2 = ansCol2, Options3 = ansCol3, Options4 = ansCol4, Options5 = ansCol5, Options6 = ansCol6, Options7 = ansCol7, Summations = sums, Intelligence = intel, DateLogged = DateTime.Now }); _db.SaveChanges(); Response.Redirect("BackGroundQuestionaire.aspx", false); } } } } catch (Exception ex) { ErecruitHelper.SetErrorData(ex, Session); Response.Redirect("ErrorPage.aspx", false); } }
protected void Save_Click(object sender, EventArgs e) { try { // var all = new List<string[]>(); var tenantId = long.Parse(SessionHelper.GetTenantID(HttpContext.Current.Session)); string fId = FileID.Value; //long preaId = 0; if (!string.IsNullOrEmpty(fId)) { string ext = EXT.Value; //all = ErecruitHelper.GetLinesFromFile(fId, ext); var data = File.ReadAllBytes(fId); ImportFromExcel import = new ImportFromExcel(); if (ext == ".xls") { import.LoadXls(data); } else if (ext == ".xlsx") { import.LoadXlsx(data); } //first parameter it's the sheet number in the excel workbook //second paramter it's the number of rows to skip at the start(we have an header in the file) List <QuestionUploadModel> all = import.ExcelToList <QuestionUploadModel>(0, 1); if (all.Count() < 1) { resultLbl.Text = "Either you uploaded an empty file or you provided wrong file type. Only allowed file type is .csv, .xls or.xlsx!"; } else { resultLbl.Text = ""; var Qtype = DropDownList1.SelectedValue; var ex = 0; var obj = new List <object>(); foreach (var s in all) { ex += _db.SearchQuestion(s.Question.ToLower()).Where(x => x.TypeId == long.Parse(Qtype)).Count(); T_Question q = new T_Question { PreambleId = 0, TypeId = long.Parse(Qtype), OptionType = (long)ErecruitHelper.OptionType.Single, IsActive = true, Details = s.Question, TenantId = tenantId, Section = s.Section, AddedBy = SessionHelper.FetchEmail(Session), DateAdded = DateTime.Now }; _db.T_Question.Add(q); _db.SaveChanges(); var opts = new List <T_Option>(); if (!string.IsNullOrEmpty(s.A)) { opts.Add(new T_Option { Q_Id = q.Id, Details = s.A, Answer = s.Answer == ErecruitHelper.OptionIndex.A.ToString(), AddedBy = SessionHelper.FetchEmail(Session), DateAdded = DateTime.Now }); } if (!string.IsNullOrEmpty(s.B)) { opts.Add(new T_Option { Q_Id = q.Id, Details = s.B, Answer = s.Answer == ErecruitHelper.OptionIndex.B.ToString(), AddedBy = SessionHelper.FetchEmail(Session), DateAdded = DateTime.Now }); } if (!string.IsNullOrEmpty(s.C)) { opts.Add(new T_Option { Q_Id = q.Id, Details = s.C, Answer = s.Answer == ErecruitHelper.OptionIndex.C.ToString(), AddedBy = SessionHelper.FetchEmail(Session), DateAdded = DateTime.Now }); } if (!string.IsNullOrEmpty(s.D)) { opts.Add(new T_Option { Q_Id = q.Id, Details = s.D, Answer = s.Answer == ErecruitHelper.OptionIndex.D.ToString(), AddedBy = SessionHelper.FetchEmail(Session), DateAdded = DateTime.Now }); } if (!string.IsNullOrEmpty(s.E)) { opts.Add(new T_Option { Q_Id = q.Id, Details = s.E, Answer = s.Answer == ErecruitHelper.OptionIndex.E.ToString(), AddedBy = SessionHelper.FetchEmail(Session), DateAdded = DateTime.Now }); } // _db.T_Option.InsertAllOnSubmit(opts); ExtensionMethods.InsertAllOnSubmit(_db.T_Option, opts); _db.SaveChanges(); } if (ex > 0) { resultLbl.Text = "Some Question(s) already exist in the system therefore were skipped."; } else { resultLbl.Text = "Questions Uploaded"; } } } else { HttpPostedFile file = QuestionFile.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 = ""; // var all = new List<string[]>(); if (Directory.Exists(Server.MapPath("~/UploadedQuestions/"))) { path = Server.MapPath(Path.Combine("~/UploadedQuestions/", fileID + ext)); // PPath = Path.Combine("~/Passports/", cand.Code + ext); file.SaveAs(path); } else { Directory.CreateDirectory(Server.MapPath("~/UploadedQuestions/")); path = Server.MapPath(Path.Combine("~/UploadedQuestions/", fileID + ext)); // PPath = Path.Combine("~/Passports/", cand.Code + ext); file.SaveAs(path); } var data = File.ReadAllBytes(path); ImportFromExcel import = new ImportFromExcel(); if (ext == ".xls") { import.LoadXls(data); } else if (ext == ".xlsx") { import.LoadXlsx(data); } //first parameter it's the sheet number in the excel workbook //second paramter it's the number of rows to skip at the start(we have an header in the file) List <QuestionUploadModel> all = import.ExcelToList <QuestionUploadModel>(0, 1); if (all.Count() < 1) { resultLbl.Text = "Either you uploaded an empty file or you provided wrong file type. Only allowed file type is .csv, .xls or.xlsx!"; } else { resultLbl.Text = ""; var Qtype = DropDownList1.SelectedValue; var ex = 0; var obj = new List <object>(); foreach (var s in all) { ex += _db.SearchQuestion(s.Question.ToLower()).Where(x => x.TypeId == long.Parse(Qtype)).Count(); T_Question q = new T_Question { PreambleId = 0, TypeId = long.Parse(Qtype), OptionType = (long)ErecruitHelper.OptionType.Single, IsActive = true, Details = s.Question, Section = s.Section, TenantId = tenantId, AddedBy = SessionHelper.FetchEmail(Session), DateAdded = DateTime.Now }; _db.T_Question.Add(q); _db.SaveChanges(); var opts = new List <T_Option>(); if (!string.IsNullOrEmpty(s.A)) { opts.Add(new T_Option { Q_Id = q.Id, Details = s.A, Answer = s.Answer == ErecruitHelper.OptionIndex.A.ToString(), AddedBy = SessionHelper.FetchEmail(Session), DateAdded = DateTime.Now }); } if (!string.IsNullOrEmpty(s.B)) { opts.Add(new T_Option { Q_Id = q.Id, Details = s.B, Answer = s.Answer == ErecruitHelper.OptionIndex.B.ToString(), AddedBy = SessionHelper.FetchEmail(Session), DateAdded = DateTime.Now }); } if (!string.IsNullOrEmpty(s.C)) { opts.Add(new T_Option { Q_Id = q.Id, Details = s.C, Answer = s.Answer == ErecruitHelper.OptionIndex.C.ToString(), AddedBy = SessionHelper.FetchEmail(Session), DateAdded = DateTime.Now }); } if (!string.IsNullOrEmpty(s.D)) { opts.Add(new T_Option { Q_Id = q.Id, Details = s.D, Answer = s.Answer == ErecruitHelper.OptionIndex.D.ToString(), AddedBy = SessionHelper.FetchEmail(Session), DateAdded = DateTime.Now }); } if (!string.IsNullOrEmpty(s.E)) { opts.Add(new T_Option { Q_Id = q.Id, Details = s.E, Answer = s.Answer == ErecruitHelper.OptionIndex.E.ToString(), AddedBy = SessionHelper.FetchEmail(Session), DateAdded = DateTime.Now }); } ExtensionMethods.InsertAllOnSubmit(_db.T_Option, opts); //_db.T_Option.InsertAllOnSubmit(opts); _db.SaveChanges(); } if (ex > 0) { resultLbl.Text = "Some Question(s) already exist in the system therefore were skipped."; } else { resultLbl.Text = "Questions Uploaded"; } } } } } catch (Exception ex) { ErecruitHelper.SetErrorData(ex, Session); Response.Redirect("ErrorPage.aspx", false); } }
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); } }
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); } }