public bool SaveAccount() { try { var p = new Patron(); DateTime _d; var DOB = rptr.Items[0].FindControl("DOB") as TextBox; if (DOB != null && !string.IsNullOrEmpty(DOB.Text)) { if (DateTime.TryParse(DOB.Text, out _d)) { p.DOB = _d; } } p.Age = FormatHelper.SafeToInt(((TextBox)(rptr.Items[0]).FindControl("Age")).Text); p.ProgID = FormatHelper.SafeToInt(((DropDownList)(rptr.Items[0]).FindControl("ProgID")).SelectedValue); p.Username = ((TextBox)(rptr.Items[0]).FindControl("Username")).Text; p.NewPassword = ((TextBox)(rptr.Items[0]).FindControl("Password")).Text; var famAcct = (DropDownList)rptr.Items[0].FindControl("FamilyAccount"); p.IsMasterAccount = (famAcct.SelectedValue == "Yes" && MasterPID.Text.Length == 0); p.SchoolGrade = ((TextBox)(rptr.Items[0]).FindControl("SchoolGrade")).Text; p.FirstName = ((TextBox)(rptr.Items[0]).FindControl("FirstName")).Text; p.MiddleName = ((TextBox)(rptr.Items[0]).FindControl("MiddleName")).Text; p.LastName = ((TextBox)(rptr.Items[0]).FindControl("LastName")).Text; p.Gender = ((DropDownList)(rptr.Items[0]).FindControl("Gender")).SelectedValue; p.EmailAddress = ((TextBox)(rptr.Items[0]).FindControl("EmailAddress")).Text; p.PhoneNumber = ((TextBox)(rptr.Items[0]).FindControl("PhoneNumber")).Text; p.PhoneNumber = FormatHelper.FormatPhoneNumber(p.PhoneNumber); p.StreetAddress1 = ((TextBox)(rptr.Items[0]).FindControl("StreetAddress1")).Text; p.StreetAddress2 = ((TextBox)(rptr.Items[0]).FindControl("StreetAddress2")).Text; p.City = ((TextBox)(rptr.Items[0]).FindControl("City")).Text; p.State = ((TextBox)(rptr.Items[0]).FindControl("State")).Text; p.ZipCode = ((TextBox)(rptr.Items[0]).FindControl("ZipCode")).Text; p.ZipCode = FormatHelper.FormatZipCode(p.ZipCode); p.Country = ((TextBox)(rptr.Items[0]).FindControl("Country")).Text; p.County = ((TextBox)(rptr.Items[0]).FindControl("County")).Text; p.ParentGuardianFirstName = ((TextBox)(rptr.Items[0]).FindControl("ParentGuardianFirstName")).Text; p.ParentGuardianLastName = ((TextBox)(rptr.Items[0]).FindControl("ParentGuardianLastName")).Text; p.ParentGuardianMiddleName = ((TextBox)(rptr.Items[0]).FindControl("ParentGuardianMiddleName")).Text; p.LibraryCard = ((TextBox)(rptr.Items[0]).FindControl("LibraryCard")).Text; p.PrimaryLibrary = FormatHelper.SafeToInt(((DropDownList)(rptr.Items[0]).FindControl("PrimaryLibrary")).SelectedValue); p.SchoolName = ((DropDownList)(rptr.Items[0]).FindControl("SchoolName")).SelectedValue; p.SchoolType = FormatHelper.SafeToInt(((DropDownList)(rptr.Items[0]).FindControl("SchoolType")).SelectedValue); var lc = LibraryCrosswalk.FetchObjectByLibraryID(p.PrimaryLibrary); if (lc != null) { p.District = lc.DistrictID == 0 ? ((DropDownList)(rptr.Items[0]).FindControl("District")).SelectedValue : lc.DistrictID.ToString(); } else { p.District = ((DropDownList)(rptr.Items[0]).FindControl("District")).SelectedValue; } var sc = SchoolCrosswalk.FetchObjectBySchoolID(p.SchoolName.SafeToInt()); if (sc != null) { p.SDistrict = sc.DistrictID == 0 ? ((DropDownList)(rptr.Items[0]).FindControl("SDistrict")).SelectedValue.SafeToInt() : sc.DistrictID; p.SchoolType = sc.SchTypeID == 0 ? FormatHelper.SafeToInt(((DropDownList)(rptr.Items[0]).FindControl("SchoolType")).SelectedValue) : sc.SchTypeID; } else { p.SDistrict = ((DropDownList)(rptr.Items[0]).FindControl("SDistrict")).SelectedValue.SafeToInt(); } p.Teacher = ((TextBox)(rptr.Items[0]).FindControl("Teacher")).Text; p.GroupTeamName = ((TextBox)(rptr.Items[0]).FindControl("GroupTeamName")).Text; p.LiteracyLevel1 = FormatHelper.SafeToInt(((TextBox)(rptr.Items[0]).FindControl("LiteracyLevel1")).Text); p.LiteracyLevel2 = FormatHelper.SafeToInt(((TextBox)(rptr.Items[0]).FindControl("LiteracyLevel2")).Text); p.ParentPermFlag = ((CheckBox)(rptr.Items[0]).FindControl("ParentPermFlag")).Checked; p.Over18Flag = int.Parse(RegistrationAge.Text) >= 18; p.ShareFlag = ((CheckBox)(rptr.Items[0]).FindControl("ShareFlag")).Checked; p.TermsOfUseflag = ((CheckBox)(rptr.Items[0]).FindControl("TermsOfUseflag")).Checked; var cr = this.CustomFields; p.Custom1 = string.IsNullOrEmpty(cr.DDValues1) ? ((TextBox)(rptr.Items[0]).FindControl("Custom1")).Text : ((DropDownList)(rptr.Items[0]).FindControl("Custom1DD")).SelectedValue; p.Custom2 = string.IsNullOrEmpty(cr.DDValues2) ? ((TextBox)(rptr.Items[0]).FindControl("Custom2")).Text : ((DropDownList)(rptr.Items[0]).FindControl("Custom2DD")).SelectedValue; p.Custom3 = string.IsNullOrEmpty(cr.DDValues3) ? ((TextBox)(rptr.Items[0]).FindControl("Custom3")).Text : ((DropDownList)(rptr.Items[0]).FindControl("Custom3DD")).SelectedValue; p.Custom4 = string.IsNullOrEmpty(cr.DDValues4) ? ((TextBox)(rptr.Items[0]).FindControl("Custom4")).Text : ((DropDownList)(rptr.Items[0]).FindControl("Custom4DD")).SelectedValue; p.Custom5 = string.IsNullOrEmpty(cr.DDValues5) ? ((TextBox)(rptr.Items[0]).FindControl("Custom5")).Text : ((DropDownList)(rptr.Items[0]).FindControl("Custom5DD")).SelectedValue; p.AvatarID = FormatHelper.SafeToInt(((System.Web.UI.HtmlControls.HtmlInputText)rptr.Items[0].FindControl("AvatarID")).Value); var registeringMasterAccount = true; if (!RegisteringFamily.Text.Equals("0")) { registeringMasterAccount = false; p.MasterAcctPID = int.Parse(MasterPID.Text); } if (p.IsValid(BusinessRulesValidationMode.INSERT)) { p.Insert(); var prog = Programs.FetchObject(p.ProgID); var earnedBadgesList = new List <Badge>(); if (prog.RegistrationBadgeID != 0) { AwardPoints.AwardBadgeToPatron(prog.RegistrationBadgeID, p, ref earnedBadgesList); } AwardPoints.AwardBadgeToPatronViaMatchingAwards(p, ref earnedBadgesList); var earnedBadges = string.Join("|", earnedBadgesList.Select(b => b.BID).Distinct()); if (p.IsMasterAccount && earnedBadges.Length > 0) { // if family account and is master, and has badges, rememebr to show them new SessionTools(Session).EarnedBadges(earnedBadges); } if (!p.IsMasterAccount && p.MasterAcctPID == 0 && earnedBadges.Length > 0) { // if not family master or not family at all and badges, rememebr to show ... new SessionTools(Session).EarnedBadges(earnedBadges); } if (p.IsMasterAccount) { parentGuardianFirst.Text = p.FirstName; parentGuardianMiddle.Text = p.MiddleName; parentGuardianLast.Text = p.LastName; } if (registeringMasterAccount) { MasterPID.Text = p.PID.ToString(); new SessionTools(Session).EstablishPatron(p); } } else { StringBuilder message = new StringBuilder("<strong>"); message.AppendFormat(SRPResources.ApplicationError1, "<ul>"); foreach (BusinessRulesValidationMessage m in p.ErrorCodes) { message.AppendFormat("<li>{0}</li>", m.ErrorMessage); } message.Append("</ul></strong>"); Session[SessionKey.PatronMessage] = message.ToString(); Session[SessionKey.PatronMessageLevel] = PatronMessageLevels.Warning; Session[SessionKey.PatronMessageGlyphicon] = "exclamation-sign"; return(false); } } catch (Exception ex) { this.Log().Error(string.Format("A problem occurred during registration: {0}", ex.Message)); Session[SessionKey.PatronMessage] = string.Format("<strong>{0}</strong>", ex.Message); Session[SessionKey.PatronMessageLevel] = PatronMessageLevels.Warning; Session[SessionKey.PatronMessageGlyphicon] = "exclamation-sign"; return(false); } return(true); }
public bool SaveAccount() { try { //var patron = (Patron)Session["Patron"]; Patron patron = null; if ((int)Session["MasterAcctPID"] == 0) { // we are the parent patron = (Patron)Session["Patron"]; } else { patron = Patron.FetchObject((int)Session["MasterAcctPID"]); } var p = new Patron(); DateTime _d; var DOB = rptr.Items[0].FindControl("DOB") as TextBox; if (DOB != null && !string.IsNullOrEmpty(DOB.Text)) { if (DateTime.TryParse(DOB.Text, out _d)) { p.DOB = _d; } } p.Age = FormatHelper.SafeToInt(((TextBox)rptr.Items[0].FindControl("Age")).Text); p.ProgID = FormatHelper.SafeToInt(((DropDownList)rptr.Items[0].FindControl("ProgID")).SelectedValue); p.Username = ((TextBox)rptr.Items[0].FindControl("Username")).Text; p.NewPassword = ((TextBox)rptr.Items[0].FindControl("Password")).Text; p.IsMasterAccount = false; p.MasterAcctPID = patron.PID; p.SchoolGrade = ((TextBox)rptr.Items[0].FindControl("SchoolGrade")).Text; p.FirstName = ((TextBox)rptr.Items[0].FindControl("FirstName")).Text; p.MiddleName = ((TextBox)rptr.Items[0].FindControl("MiddleName")).Text; p.LastName = ((TextBox)rptr.Items[0].FindControl("LastName")).Text; p.Gender = ((DropDownList)rptr.Items[0].FindControl("Gender")).SelectedValue; p.EmailAddress = ((TextBox)rptr.Items[0].FindControl("EmailAddress")).Text; p.PhoneNumber = ((TextBox)rptr.Items[0].FindControl("PhoneNumber")).Text; p.PhoneNumber = FormatHelper.FormatPhoneNumber(p.PhoneNumber); p.StreetAddress1 = ((TextBox)rptr.Items[0].FindControl("StreetAddress1")).Text; p.StreetAddress2 = ((TextBox)rptr.Items[0].FindControl("StreetAddress2")).Text; p.City = ((TextBox)rptr.Items[0].FindControl("City")).Text; p.State = ((TextBox)rptr.Items[0].FindControl("State")).Text; p.ZipCode = ((TextBox)rptr.Items[0].FindControl("ZipCode")).Text; p.ZipCode = FormatHelper.FormatZipCode(p.ZipCode); p.Country = ((TextBox)rptr.Items[0].FindControl("Country")).Text; p.County = ((TextBox)rptr.Items[0].FindControl("County")).Text; p.ParentGuardianFirstName = ((TextBox)rptr.Items[0].FindControl("ParentGuardianFirstName")).Text; p.ParentGuardianLastName = ((TextBox)rptr.Items[0].FindControl("ParentGuardianLastName")).Text; p.ParentGuardianMiddleName = ((TextBox)rptr.Items[0].FindControl("ParentGuardianMiddleName")).Text; p.LibraryCard = ((TextBox)rptr.Items[0].FindControl("LibraryCard")).Text; //p.District = ((DropDownList)rptr.Items[0].FindControl("District")).SelectedValue; //p.SDistrict = ((DropDownList)rptr.Items[0].FindControl("SDistrict")).SelectedValue.SafeToInt(); p.PrimaryLibrary = FormatHelper.SafeToInt(((DropDownList)rptr.Items[0].FindControl("PrimaryLibrary")).SelectedValue); p.SchoolName = ((DropDownList)rptr.Items[0].FindControl("SchoolName")).SelectedValue; p.SchoolType = FormatHelper.SafeToInt(((DropDownList)rptr.Items[0].FindControl("SchoolType")).SelectedValue); var lc = LibraryCrosswalk.FetchObjectByLibraryID(p.PrimaryLibrary); if (lc != null) { p.District = lc.DistrictID == 0 ? ((DropDownList)rptr.Items[0].FindControl("District")).SelectedValue : lc.DistrictID.ToString(); } else { p.District = ((DropDownList)rptr.Items[0].FindControl("District")).SelectedValue; } var sc = SchoolCrosswalk.FetchObjectBySchoolID(p.SchoolName.SafeToInt()); if (sc != null) { p.SDistrict = sc.DistrictID == 0 ? ((DropDownList)rptr.Items[0].FindControl("SDistrict")).SelectedValue.SafeToInt() : sc.DistrictID; p.SchoolType = sc.SchTypeID == 0 ? FormatHelper.SafeToInt(((DropDownList)rptr.Items[0].FindControl("SchoolType")).SelectedValue) : sc.SchTypeID; } else { p.SDistrict = ((DropDownList)rptr.Items[0].FindControl("SDistrict")).SelectedValue.SafeToInt(); } p.Teacher = ((TextBox)rptr.Items[0].FindControl("Teacher")).Text; p.GroupTeamName = ((TextBox)rptr.Items[0].FindControl("GroupTeamName")).Text; p.LiteracyLevel1 = FormatHelper.SafeToInt(((TextBox)rptr.Items[0].FindControl("LiteracyLevel1")).Text); p.LiteracyLevel2 = FormatHelper.SafeToInt(((TextBox)rptr.Items[0].FindControl("LiteracyLevel2")).Text); p.ParentPermFlag = true; p.Over18Flag = p.Age >= 18; p.ShareFlag = ((CheckBox)rptr.Items[0].FindControl("ShareFlag")).Checked; p.TermsOfUseflag = true; p.Custom1 = string.IsNullOrEmpty(this.CustomFields.DDValues1) ? ((TextBox)rptr.Items[0].FindControl("Custom1")).Text : ((DropDownList)rptr.Items[0].FindControl("Custom1DD")).SelectedValue; p.Custom2 = string.IsNullOrEmpty(this.CustomFields.DDValues2) ? ((TextBox)rptr.Items[0].FindControl("Custom2")).Text : ((DropDownList)rptr.Items[0].FindControl("Custom2DD")).SelectedValue; p.Custom3 = string.IsNullOrEmpty(this.CustomFields.DDValues3) ? ((TextBox)rptr.Items[0].FindControl("Custom3")).Text : ((DropDownList)rptr.Items[0].FindControl("Custom3DD")).SelectedValue; p.Custom4 = string.IsNullOrEmpty(this.CustomFields.DDValues4) ? ((TextBox)rptr.Items[0].FindControl("Custom4")).Text : ((DropDownList)rptr.Items[0].FindControl("Custom4DD")).SelectedValue; p.Custom5 = string.IsNullOrEmpty(this.CustomFields.DDValues5) ? ((TextBox)rptr.Items[0].FindControl("Custom5")).Text : ((DropDownList)rptr.Items[0].FindControl("Custom5DD")).SelectedValue; p.AvatarID = FormatHelper.SafeToInt(((System.Web.UI.HtmlControls.HtmlInputText)rptr.Items[0].FindControl("AvatarID")).Value); if (p.IsValid(BusinessRulesValidationMode.INSERT)) { p.Insert(); var prog = Programs.FetchObject(p.ProgID); var list = new List <Badge>(); if (prog.RegistrationBadgeID != 0) { AwardPoints.AwardBadgeToPatron(prog.RegistrationBadgeID, p, ref list); } AwardPoints.AwardBadgeToPatronViaMatchingAwards(p, ref list); patron.IsMasterAccount = true; patron.Update(); // update patron session for things like MasterAcctPID and IsMasterAccount new SessionTools(Session).EstablishPatron(patron); new SessionTools(Session).AlertPatron("Your family member has been added!", glyphicon: "check"); } else { StringBuilder message = new StringBuilder("<strong>"); message.AppendFormat(SRPResources.ApplicationError1, "<ul>"); foreach (BusinessRulesValidationMessage m in p.ErrorCodes) { message.AppendFormat("<li>{0}</li>", m.ErrorMessage); } message.Append("</ul></strong>"); new SessionTools(Session).AlertPatron(message.ToString(), PatronMessageLevels.Warning, "exclamation-sign"); return(false); } } catch (Exception ex) { this.Log().Error(string.Format("An exception was thrown adding a family member: {0}", ex.Message)); new SessionTools(Session).AlertPatron(string.Format("<strong>{0}</strong>", ex.Message), PatronMessageLevels.Warning, "exclamation-sign"); return(false); } return(true); }
public void EndTest() { // update SurveyResults and set is complete // score if scorable; var p = (Patron)Session["Patron"]; var sr = SurveyResults.FetchObject(int.Parse(SRID.Text)); sr.EndDate = DateTime.Now; sr.IsComplete = true; sr.IsScorable = Survey.IsScorable(sr.SID); if (sr.IsScorable) { sr.Score = SurveyResults.PerformScoring(sr.SRID); if ((decimal)Survey.MaxScore(sr.SID) != 0) { sr.ScorePct = (decimal)sr.Score * 100 / (decimal)Survey.MaxScore(sr.SID); } else { sr.ScorePct = 0; } if (sr.Source == Survey.Source(1)) { p.Score1 = sr.Score; p.Score1Pct = sr.ScorePct; p.Score1Date = sr.EndDate; p.Update(); Session["Patron"] = p; } if (sr.Source == Survey.Source(2)) { p.Score2 = sr.Score; p.Score2Pct = sr.ScorePct; p.Score2Date = sr.EndDate; p.Update(); Session["Patron"] = p; } } sr.Update(); var earnedBadgesList = new List <Badge>(); var s = DAL.Survey.FetchObject(sr.SID); if (s.BadgeId != 0) { AwardPoints.AwardBadgeToPatron(s.BadgeId, p, ref earnedBadgesList); } AwardPoints.AwardBadgeToPatronViaMatchingAwards(p, ref earnedBadgesList); var earnedBadges = string.Join("|", earnedBadgesList.Select(b => b.BID).Distinct()); new SessionTools(Session).EarnedBadges(earnedBadges); var SurveyEndPage = "~"; if (Session["Page"] != null && Session["Page"].ToString() == "1") { SurveyEndPage = "Thanks.aspx"; } Session.Remove("SRID"); Session.Remove("SID"); Session.Remove("QNum"); Session.Remove("SSrc"); Session.Remove("SSrcID"); Session.Remove("PreTestMandatory"); Session.Remove("Page"); if (Session["TestReturnPage"] != null && !string.IsNullOrEmpty(Session["TestReturnPage"].ToString())) { var gotoStr = Session["TestReturnPage"].ToString(); Session.Remove("TestReturnPage"); if (string.IsNullOrEmpty(gotoStr)) { Response.Redirect("~"); } else { Response.Redirect(string.Format("~/{0}", gotoStr)); } } else { Response.Redirect(SurveyEndPage); } }