protected void OnBtnSaveClicked(object sender, EventArgs e) { CandidateTelephoneRepository repo = new CandidateTelephoneRepository(); CandidateTelephone saveItem = GetCadidateTelephone(); if (string.IsNullOrEmpty(Request.QueryString["TelePhoneId"])) { if (!string.IsNullOrEmpty(Request.QueryString["candidateID"])) { //Insert new record repo.Insert(saveItem); } else { //save to session List<CandidateTelephone> list = SessionManager.NewCandidateTelephoneList; saveItem.TelePhoneId = 0 - list.Count - 2; list.Add(saveItem); SessionManager.NewCandidateTelephoneList = list; } } else { int telephoneID = int.Parse(Request.QueryString["TelePhoneId"]); if (telephoneID > 0)//existed in database { //Update the record. saveItem.TelePhoneId = telephoneID; repo.Update(saveItem); } else //get from session data { List<CandidateTelephone> list = SessionManager.NewCandidateTelephoneList; CandidateTelephone existedItem = list.Find(delegate(CandidateTelephone t) { return t.TelePhoneId == telephoneID; }); if (existedItem != null) { int index = list.IndexOf(existedItem); list.Remove(existedItem); saveItem.TelePhoneId = existedItem.TelePhoneId; list.Insert(index, saveItem); SessionManager.NewCandidateTelephoneList = list; } } } string script = "<script type=\"text/javascript\">"; script += " OnBtnSaveClientClicked();"; script += " </script>"; if (!ClientScript.IsClientScriptBlockRegistered("redirectUser")) ClientScript.RegisterStartupScript(this.GetType(), "redirectUser", script); //this.Page.ClientScript.RegisterStartupScript(this.GetType(), this.Page.ClientID, script); }
/// <summary> /// save the candidate telephone in case adding a new candidate /// </summary> private void SaveContactTelephone(Candidate candidate) { if (SessionManager.NewCandidateTelephoneList != null && SessionManager.NewCandidateTelephoneList.Count > 0) { foreach (CandidateTelephone phone in SessionManager.NewCandidateTelephoneList) { CandidateTelephoneRepository phoneRepo = new CandidateTelephoneRepository(); phone.CandidateID = candidate.CandidateId; phoneRepo.Insert(phone); } } }