public void AddToRecentlyViewed(Patron patron, string username) { if (patron == null || string.IsNullOrWhiteSpace(username)) throw new BusinessLogicException(string.Format("Error while trying to add patron {0} to {1}'s recently viewed patrons. Neither value can be null.", patron, username)); User user = _users.SingleOrDefault(i => i.Username.Equals(username, StringComparison.CurrentCultureIgnoreCase)); if (user == null) throw new BusinessLogicException(string.Format("Could not locate user with username {0} while trying to add patron {1} to their recently viewed patron list.", username, patron)); // If this invoice already has an entry, updated its ViewedOn value. // Otherwise, add a new entry. RecentlyViewedPatron needsUpdating = _recentlyViewedPatrons.SingleOrDefault(i => i.PatronId == patron.PatronId); if (needsUpdating != null) { RecentlyViewedPatron newEntry = new RecentlyViewedPatron { PatronId = patron.PatronId, UserId = user.UserId, ViewedOn = DateTime.Now }; // Delete the older entry and insert the new entry to replace it. _recentlyViewedPatrons.Attach(needsUpdating); _repository.Entry(needsUpdating).State = EntityState.Deleted; _recentlyViewedPatrons.Add(newEntry); } else { RecentlyViewedPatron recent = new RecentlyViewedPatron { Patron = patron, User = user, ViewedOn = DateTime.Now }; // Insert the new entry. _recentlyViewedPatrons.Add(recent); } _repository.SaveChanges(); // Now only keep the MAX_NUMBER_OF_RECENTLY_VIEWED_PATRONS for this patron. var currentEntries = _recentlyViewedPatrons.Where(i => i.UserId == user.UserId); if (currentEntries.Count() > MAX_NUMBER_OF_RECENTLY_VIEWED_PATRONS) { var toDelete = currentEntries.OrderByDescending(i => i.ViewedOn).Skip(MAX_NUMBER_OF_RECENTLY_VIEWED_PATRONS); foreach (RecentlyViewedPatron rvp in toDelete) { _recentlyViewedPatrons.Attach(rvp); _repository.Entry(rvp).State = EntityState.Deleted; } _repository.SaveChanges(); } }
public static Patron getPatronInfo(string barcode) { Patron patron = new Patron(); try { string failureResponse = String.Empty; SipConnection sip = new SipConnection(""); sip.Open(); sip.AuthorizeBarcode(barcode, ref patron, ref failureResponse); } catch (Exception) { return new Patron { Pin = "-1", Name = "Could not access patron information at this time." }; } return patron; }
public override void Update() { foreach (Key key in _Keys) { switch (key) { case Key.S: _angle += 3; break; case Key.W: _angle -= 3; break; case Key.F: _fire++; break; } } if (!_Keys.Contains(Key.F) && _fire != 0) { Patron _Patron = new Patron { _x = _Player._x, _y = _Player._y, _angle = _angle, _power = _fire, _right = _Player._right }; _Patron.Load(); _fire = 0; } base.Update(); }
public void Update(Patron patron, bool isUserAdmin) { patron = Validate(patron); if (!isUserAdmin) { Patron unmodifiedPatron = _patrons.SingleOrDefault(i => i.PatronId == patron.PatronId); if (unmodifiedPatron.IsFrozen && !patron.IsFrozen) throw new BusinessLogicException(string.Format("Only an administrator can un-freeze an account. Error while updating patron with ID {0}.", patron.PatronId)); // Detach because otherwise there is a conflict when the patron object is attached outside of this block. // We only needed it to read the current value. The patron object that was passed as an argument has the updated values. _repository.Entry(unmodifiedPatron).State = EntityState.Detached; } _patrons.Attach(patron); _repository.Entry(patron).State = EntityState.Modified; _repository.SaveChanges(); }
private Patron Validate(Patron input) { // Null and maximum length checks. if (input.Address1 != null) { input.Address1 = input.Address1.Trim(); if (input.Address1.Length == 0) input.Address1 = null; else if (input.Address1.Length > 200) input.Address1 = input.Address1.Substring(0, 200); } if (input.Address2 != null) { input.Address2 = input.Address2.Trim(); if (input.Address2.Length == 0) input.Address2 = null; else if (input.Address2.Length > 200) input.Address2 = input.Address2.Substring(0, 200); } if (input.City != null) { input.City = input.City.Trim(); if (input.City.Length == 0) input.City = null; else if (input.City.Length > 100) input.City = input.City.Substring(0, 100); } if (input.Country != null) { input.Country = input.Country.Trim(); if (input.Country.Length == 0) input.Country = null; else if (input.Country.Length > 100) input.Country = input.Country.Substring(0, 100); } if (input.Email != null) { input.Email = input.Email.Trim(); if (input.Email.Length == 0) input.Email = null; else if (input.Email.Length > 100) input.Email = input.Email.Substring(0, 100); } if (input.Fax != null) { input.Fax = input.Fax.Trim(); if (input.Fax.Length == 0) input.Fax = null; else if (input.Fax.Length > 100) input.Fax = input.Fax.Substring(0, 100); } if (input.FirstName != null) { input.FirstName = input.FirstName.Trim(); if (input.FirstName.Length == 0) input.FirstName = null; else if (input.FirstName.Length > 100) input.FirstName = input.FirstName.Substring(0, 100); } if (input.InmateNumber != null) { input.InmateNumber = input.InmateNumber.Trim(); if (input.InmateNumber.Length == 0) input.InmateNumber = null; else if (input.InmateNumber.Length > 100) input.InmateNumber = input.InmateNumber.Substring(0, 100); } if (input.LastName != null) { input.LastName = input.LastName.Trim(); if (input.LastName.Length == 0) input.LastName = null; else if (input.LastName.Length > 100) input.LastName = input.LastName.Substring(0, 100); } if (input.MiddleName != null) { input.MiddleName = input.MiddleName.Trim(); if (input.MiddleName.Length == 0) input.MiddleName = null; else if (input.MiddleName.Length > 100) input.MiddleName = input.MiddleName.Substring(0, 100); } if (input.Notes != null) { input.Notes = input.Notes.Trim(); if (input.Notes.Length == 0) input.Notes = null; } if (input.Office != null) { input.Office = input.Office.Trim(); if (input.Office.Length == 0) input.Office = null; else if (input.Office.Length > 200) input.Office = input.Office.Substring(0, 200); } if (input.Phone != null) { input.Phone = input.Phone.Trim(); if (input.Phone.Length == 0) input.Phone = null; else if (input.Phone.Length > 100) input.Phone = input.Phone.Substring(0, 100); } if (input.PhoneAlternate != null) { input.PhoneAlternate = input.PhoneAlternate.Trim(); if (input.PhoneAlternate.Length == 0) input.PhoneAlternate = null; else if (input.PhoneAlternate.Length > 100) input.PhoneAlternate = input.PhoneAlternate.Substring(0, 100); } if (input.State != null) { input.State = input.State.Trim(); if (input.State.Length == 0) input.State = null; else if (input.State.Length > 100) input.State = input.State.Substring(0, 100); } if (input.Zip != null) { input.Zip = input.Zip.Trim(); if (input.Zip.Length == 0) input.Zip = null; else if (input.Zip.Length > 100) input.Zip = input.Zip.Substring(0, 100); } // Logic checks. if (input.FirstName == null && input.Office == null) throw new BusinessLogicException("A name or an office name is required for a patron account."); return input; }
private void ScrubPatrons(HtmlNode Node) { // -- /userNext?p=2&ty=p&srt=2&u=503677 -- Get Pages of Patrons for a project // Parse Nav String var t_ProjectID = int.Parse( Node.ChildNodes.Where(x => x.Name == "a").First().Attributes["href"].Value.Split('&').Where(x => x.StartsWith("u=")).First().Split('=')[1] ); m_ProjectID = t_ProjectID; // Get all Patrons HtmlWeb t_Web = new HtmlWeb(); int t_Pages = 1; while (true) { // Construct URL string t_URL = @"https://www.patreon.com/userNext?p=" + t_Pages + @"&ty=p&srt=2&u=" + t_ProjectID; // Get Page var t_Doc = t_Web.Load(t_URL); // Parse Page var t_PatronList = t_Doc.DocumentNode.ChildNodes; if (t_PatronList.Count() > 0) { foreach (var t_Node in t_PatronList) { // Get Href Node var t_NodeHref = t_Node.Descendants("a").Where(x => x.Attributes.Contains("href") && x.Attributes.Contains("class") == false).First(); string t_Name = t_NodeHref.InnerText.Trim(); string t_PatronIDStr = ""; int t_PatronID = -1; if (t_NodeHref.Attributes["href"].Value.IndexOf("=") >= 0) // Split { t_PatronID = int.Parse(t_NodeHref.Attributes["href"].Value.Split('=')[1]); } else { t_PatronIDStr = t_NodeHref.Attributes["href"].Value;//.Split('/')[1]; } // Add Patron to Project Patron t_Pat = new Patron(); t_Pat.m_Name = t_Name; t_Pat.m_ID = t_PatronID; t_Pat.m_CustomID = t_PatronIDStr; t_Pat.m_URL = t_NodeHref.Attributes["href"].Value; // t_Pat.m_IsCreator = isProject(t_Web.Load(t_Pat.m_URL)); //Console.WriteLine("Patron Processed: " + t_Pat.m_Name); m_Patrons.Add(t_Pat); } } else break; Console.WriteLine("Scrubbing Patron Page: " + t_Pages); // Increment Page Index t_Pages++; } }
public Invoice Create(Patron patron, bool isTaxExempt, string username) { if (patron == null) throw new BusinessLogicException(string.Format("Patron object cannot be null when creating a new invoice. Attempt made by user {0}.", username)); if (patron.IsFrozen) throw new BusinessLogicException(string.Format("Patron #{0}'s account is frozen. You cannot create an invoice for a frozen account.", patron.PatronId)); if (username == null) throw new BusinessLogicException(string.Format("A username must be provided when creating a new invoice. Attempt made for patron #{0}.", patron.PatronId)); User creator = _users.SingleOrDefault(i => i.Username.Equals(username, StringComparison.InvariantCultureIgnoreCase)); if (creator == null) throw new BusinessLogicException(string.Format("Could not find user with username {0} when creating a new invoice for patron #{1}.", username, patron.PatronId)); Invoice invoice = new Invoice { CreatedById = creator.UserId, CreatedOn = DateTime.Now, InvoiceStatusId = _invoiceStatuses.SingleOrDefault(i => i.Description.Equals("Open", StringComparison.InvariantCultureIgnoreCase)).InvoiceStatusId, IsReadOnly = false, IsTaxExempt = isTaxExempt, PatronId = patron.PatronId }; return Insert(invoice); }
protected void GvRowCommand(object sender, GridViewCommandEventArgs e) { string editpage = "~/ControlRoom/Modules/Patrons/PatronDetails.aspx"; if (e.CommandName.ToLower() == "addrecord") { //Session["CURR_PATRON_ID"] = ""; //Session["CURR_PATRON"] = null; //Response.Redirect(editpage); Response.Redirect("~/ControlRoom/Modules/Patrons/PatronsAddSubAccount.aspx"); } if (e.CommandName.ToLower() == "editrecord") { int key = Convert.ToInt32(e.CommandArgument); Session["CURR_PATRON_ID"] = key; Session["CURR_PATRON"] = Patron.FetchObject(key); Response.Redirect(editpage); //Response.Redirect(String.Format("{0}?PK={1}", editpage, key)); } if (e.CommandName.ToLower() == "deleterecord") { var key = Convert.ToInt32(e.CommandArgument); //var masterPage = (IControlRoomMaster)Master; //if (masterPage != null) // masterPage.PageError = "Functionality Not Implemented (yet)."; try { var obj = Patron.FetchObject(key); if (obj.IsValid(BusinessRulesValidationMode.DELETE)) { obj.Delete(); GetData(); var masterPage = (IControlRoomMaster)Master; if (masterPage != null) { masterPage.PageMessage = SRPResources.DeleteOK; } } else { var masterPage = (IControlRoomMaster)Master; string message = String.Format(SRPResources.ApplicationError1, "<ul>"); foreach (BusinessRulesValidationMessage m in obj.ErrorCodes) { message = string.Format(String.Format("{0}<li>{{0}}</li>", message), m.ErrorMessage); } message = string.Format("{0}</ul>", message); if (masterPage != null) { masterPage.PageError = message; } } } catch (Exception ex) { var masterPage = (IControlRoomMaster)Master; if (masterPage != null) { masterPage.PageError = String.Format(SRPResources.ApplicationError1, ex.Message); } } } }
public ParkingRateCode SelectCorrectLegOnTestResult(Patron patron) { return(_node.Evaluate(patron)); }
private void Btn_Ajout_Click(object sender, EventArgs e) { if (Txt_Mat.Text != "" && Txt_Nom.Text != "" && Txt_Pren.Text != "") { if (Opt_P.Checked && Txt_CA.Text != "" && Txt_Pour.Text != "") { var p = new Patron(Convert.ToInt32(Txt_Mat.Text), Txt_Nom.Text, Txt_Pren.Text, Dat_Nais.Value, Convert.ToDouble(Txt_CA.Text), Convert.ToDouble(Txt_Pour.Text)); if (!p.Equals(Convert.ToInt32(Txt_Mat.Text))) { List_E.Add(p); } else { MessageBox.Show("Ce Patron existe deja !"); } } else if (Opt_C.Checked && (radioButton4.Checked || radioButton5.Checked || radioButton6.Checked || radioButton7.Checked)) { if (radioButton4.Checked) { var c = new Cadre(Convert.ToInt32(Txt_Mat.Text), Txt_Nom.Text, Txt_Pren.Text, Dat_Nais.Value, 1); if (!c.Equals(Convert.ToInt32(Txt_Mat.Text))) { List_E.Add(c); } else { MessageBox.Show("Cet cadre existe deja !"); } } else if (radioButton5.Checked) { var c = new Cadre(Convert.ToInt32(Txt_Mat.Text), Txt_Nom.Text, Txt_Pren.Text, Dat_Nais.Value, 2); if (!c.Equals(Convert.ToInt32(Txt_Mat.Text))) { List_E.Add(c); } else { MessageBox.Show("Cet cadre existe deja !"); } } else if (radioButton6.Checked) { var c = new Cadre(Convert.ToInt32(Txt_Mat.Text), Txt_Nom.Text, Txt_Pren.Text, Dat_Nais.Value, 3); if (!c.Equals(Convert.ToInt32(Txt_Mat.Text))) { List_E.Add(c); } else { MessageBox.Show("Cet cadre existe deja !"); } } else if (radioButton7.Checked) { var c = new Cadre(Convert.ToInt32(Txt_Mat.Text), Txt_Nom.Text, Txt_Pren.Text, Dat_Nais.Value, 4); if (!c.Equals(Convert.ToInt32(Txt_Mat.Text))) { List_E.Add(c); } else { MessageBox.Show("Cet cadre existe deja !"); } } } else if (Opt_O.Checked) { var o = new Ouvrier(Convert.ToInt32(Txt_Mat.Text), Txt_Nom.Text, Txt_Pren.Text, Dat_Nais.Value, Dat_Ent.Value); if (!o.Equals(Convert.ToInt32(Txt_Mat.Text))) { List_E.Add(o); } else { MessageBox.Show("Cet Ouvrier existe deja !"); } } displayGrid(); } }
public void Add(Patron newPatron) { _context.Add(newPatron); _context.SaveChanges(); }
public DataSet GetFilteredList() { SetFilterSessionValues(); return (Patron.CRSearch()); }
public void LoadControl() { //Session["CURR_PATRON_ID"] = key; //Session["CURR_PATRON"] = Patron.FetchObject(key); if (Session["CURR_PATRON_MODE"].ToString() == "ADDSUB") { // Need to adda sub var PID1 = int.Parse(Session["CURR_PATRON_ID"].ToString()); var p1 = Patron.FetchObject(PID1); //if (p1.IsMasterAccount) //{ // PatronID = ""; // MasterPatronID = PID1.ToString(); //} //else //{ // var p2 = Patron.FetchObject(p1.MasterAcctPID); // PatronID = ""; // MasterPatronID = p2.PID.ToString(); //} if (!p1.IsMasterAccount && p1.MasterAcctPID > 0) { var p2 = Patron.FetchObject(p1.MasterAcctPID); PatronID = ""; MasterPatronID = p2.PID.ToString(); } else { PatronID = ""; MasterPatronID = PID1.ToString(); } } if (PatronID != "") { SA.Text = PatronID; } else { SA.Text = "0"; } var key = int.Parse(SA.Text); rptr.DataSource = Patron.GetPatronForEdit(key); rptr.DataBind(); if (!IsAdd()) { ((TextBox)rptr.Items[0].FindControl("Username")).Enabled = false; ((RequiredFieldValidator)rptr.Items[0].FindControl("rfvUsername")).Enabled = false; } if (Session["CURR_PATRON_MODE"].ToString() == "ADDSUB") { var ima = ((CheckBox)(rptr.Items[0]).FindControl("IsMasterAccount")); ima.Enabled = false; ima.Checked = false; } }
protected void rptr_ItemCommand(object source, RepeaterCommandEventArgs e) { var masterPage = (IControlRoomMaster)((BaseControlRoomPage)Page).Master; if (e.CommandName.ToLower() == "back") { Response.Redirect("Default.aspx"); } if (e.CommandName.ToLower() == "refresh") { LoadControl(); if (masterPage != null) { masterPage.PageMessage = SRPResources.RefreshOK; } return; } lblError.Text = ""; Page.Validate(); if (Page.IsValid) { if (e.CommandName.ToLower() == "save" || e.CommandName.ToLower() == "saveandback") { var p = new Patron(); if (!IsAdd()) { p = Patron.FetchObject(int.Parse(SA.Text)); } DateTime _d; p.Username = ((TextBox)(e.Item).FindControl("Username")).Text; p.NewPassword = ((TextBox)(e.Item).FindControl("Password")).Text; var DOB = e.Item.FindControl("DOB") as TextBox; if (DOB != null && DOB.Text != "") { if (DateTime.TryParse(DOB.Text, out _d)) { p.DOB = _d; } } p.Age = FormatHelper.SafeToInt(((TextBox)(e.Item).FindControl("Age")).Text); //p.Custom2 = (((TextBox)(e.Item).FindControl("Custom2")).Text); p.MasterAcctPID = int.Parse(MasterPatronID); p.SchoolGrade = ((TextBox)(e.Item).FindControl("SchoolGrade")).Text; p.FirstName = ((TextBox)(e.Item).FindControl("FirstName")).Text; p.MiddleName = ((TextBox)(e.Item).FindControl("MiddleName")).Text; p.LastName = ((TextBox)(e.Item).FindControl("LastName")).Text; p.Gender = ((DropDownList)(e.Item).FindControl("Gender")).SelectedValue; p.EmailAddress = ((TextBox)(e.Item).FindControl("EmailAddress")).Text; p.PhoneNumber = ((TextBox)(e.Item).FindControl("PhoneNumber")).Text; p.PhoneNumber = FormatHelper.FormatPhoneNumber(p.PhoneNumber); p.StreetAddress1 = ((TextBox)(e.Item).FindControl("StreetAddress1")).Text; p.StreetAddress2 = ((TextBox)(e.Item).FindControl("StreetAddress2")).Text; p.City = ((TextBox)(e.Item).FindControl("City")).Text; p.State = ((TextBox)(e.Item).FindControl("State")).Text; p.ZipCode = ((TextBox)(e.Item).FindControl("ZipCode")).Text; p.ZipCode = FormatHelper.FormatZipCode(p.ZipCode); p.Country = ((TextBox)(e.Item).FindControl("Country")).Text; p.County = ((TextBox)(e.Item).FindControl("County")).Text; p.ParentGuardianFirstName = ((TextBox)(e.Item).FindControl("ParentGuardianFirstName")).Text; p.ParentGuardianLastName = ((TextBox)(e.Item).FindControl("ParentGuardianLastName")).Text; p.ParentGuardianMiddleName = ((TextBox)(e.Item).FindControl("ParentGuardianMiddleName")).Text; p.LibraryCard = ((TextBox)(e.Item).FindControl("LibraryCard")).Text; //p.PrimaryLibrary = ((DropDownList)(e.Item).FindControl("PrimaryLibrary")).SelectedValue.SafeToInt(); //p.SchoolName = ((DropDownList)(e.Item).FindControl("SchoolName")).SelectedValue; //p.District = ((DropDownList)(e.Item).FindControl("District")).SelectedValue; //p.SDistrict = ((DropDownList)(e.Item).FindControl("SDistrict")).SelectedValue.SafeToInt(); //p.SchoolType = ((DropDownList)(e.Item).FindControl("SchoolType")).SelectedValue.SafeToInt(); p.PrimaryLibrary = ((DropDownList)(e.Item).FindControl("PrimaryLibrary")).SelectedValue.SafeToInt(); p.SchoolName = ((DropDownList)(e.Item).FindControl("SchoolName")).SelectedValue; p.SchoolType = ((DropDownList)(e.Item).FindControl("SchoolType")).SelectedValue.SafeToInt(); var lc = LibraryCrosswalk.FetchObjectByLibraryID(p.PrimaryLibrary); if (lc != null) { p.District = lc.DistrictID == 0 ? ((DropDownList)(e.Item).FindControl("District")).SelectedValue : lc.DistrictID.ToString(); } else { p.District = ((DropDownList)(e.Item).FindControl("District")).SelectedValue; } var sc = SchoolCrosswalk.FetchObjectBySchoolID(p.SchoolName.SafeToInt()); if (sc != null) { p.SDistrict = sc.DistrictID == 0 ? ((DropDownList)(e.Item).FindControl("SDistrict")).SelectedValue.SafeToInt() : sc.DistrictID; p.SchoolType = sc.SchTypeID == 0 ? FormatHelper.SafeToInt(((DropDownList)(e.Item).FindControl("SchoolType")).SelectedValue) : sc.SchTypeID; } else { p.SDistrict = ((DropDownList)(e.Item).FindControl("SDistrict")).SelectedValue.SafeToInt(); } p.Teacher = ((TextBox)(e.Item).FindControl("Teacher")).Text; p.GroupTeamName = ((TextBox)(e.Item).FindControl("GroupTeamName")).Text; p.LiteracyLevel1 = ((TextBox)(e.Item).FindControl("LiteracyLevel1")).Text.SafeToInt(); p.LiteracyLevel2 = ((TextBox)(e.Item).FindControl("LiteracyLevel2")).Text.SafeToInt(); try { p.ParentPermFlag = ((CheckBox)(e.Item).FindControl("ParentPermFlag")).Checked; p.Over18Flag = ((CheckBox)(e.Item).FindControl("Over18Flag")).Checked; p.ShareFlag = ((CheckBox)(e.Item).FindControl("ShareFlag")).Checked; p.TermsOfUseflag = ((CheckBox)(e.Item).FindControl("TermsOfUseflag")).Checked; } catch { } var cr = CustomRegistrationFields.FetchObject(); p.Custom1 = cr.DDValues1 == "" ? ((TextBox)(e.Item).FindControl("Custom1")).Text : ((DropDownList)(e.Item).FindControl("Custom1DD")).SelectedValue; p.Custom2 = cr.DDValues2 == "" ? ((TextBox)(e.Item).FindControl("Custom2")).Text : ((DropDownList)(e.Item).FindControl("Custom2DD")).SelectedValue; p.Custom3 = cr.DDValues3 == "" ? ((TextBox)(e.Item).FindControl("Custom3")).Text : ((DropDownList)(e.Item).FindControl("Custom3DD")).SelectedValue; p.Custom4 = cr.DDValues4 == "" ? ((TextBox)(e.Item).FindControl("Custom4")).Text : ((DropDownList)(e.Item).FindControl("Custom4DD")).SelectedValue; p.Custom5 = cr.DDValues5 == "" ? ((TextBox)(e.Item).FindControl("Custom5")).Text : ((DropDownList)(e.Item).FindControl("Custom5DD")).SelectedValue; p.AvatarID = FormatHelper.SafeToInt(((DropDownList)e.Item.FindControl("AvatarID")).SelectedValue); p.ProgID = FormatHelper.SafeToInt(((DropDownList)e.Item.FindControl("ProgID")).SelectedValue); p.IsMasterAccount = ((CheckBox)(e.Item).FindControl("IsMasterAccount")).Checked; // do the save if (IsAdd()) { if (p.IsValid(BusinessRulesValidationMode.INSERT)) { p.Insert(); PatronID = p.PID.ToString(); SA.Text = PatronID; Session["CURR_PATRON_MODE"] = "EDIT"; LoadControl(); masterPage.PageMessage = SRPResources.AddedOK; if (e.CommandName.ToLower() == "saveandback") { Response.Redirect("Default.aspx"); } } else { string message = String.Format(SRPResources.ApplicationError1, "<ul>"); foreach (BusinessRulesValidationMessage m in p.ErrorCodes) { message = string.Format(String.Format("{0}<li>{{0}}</li>", message), m.ErrorMessage); } message = string.Format("{0}</ul>", message); masterPage.PageError = message; } var parent = Patron.FetchObject(p.MasterAcctPID); if (parent != null && !parent.IsMasterAccount) { parent.IsMasterAccount = true; parent.Update(); Session["CURR_PATRON"] = parent; PatronsRibbon.GetByAppContext((BaseControlRoomPage)Page); } } else { if (p.IsValid(BusinessRulesValidationMode.UPDATE)) { p.Update(); masterPage.PageMessage = SRPResources.SaveOK; if (e.CommandName.ToLower() == "saveandback") { Response.Redirect("Default.aspx"); } else { LoadControl(); } } else { string message = String.Format(SRPResources.ApplicationError1, "<ul>"); foreach (BusinessRulesValidationMessage m in p.ErrorCodes) { message = string.Format(String.Format("{0}<li>{{0}}</li>", message), m.ErrorMessage); } message = string.Format("{0}</ul>", message); masterPage.PageError = message; } } } } }
protected bool RegisterPatron() { var patron = new Patron(); patron.ProgID = Programs.GetDefaultProgramForAgeAndGrade(0, 0); patron.Username = Username.Text; patron.NewPassword = Password.Text; // hardcoding over 18 because there's no facility to ask here patron.Over18Flag = true; patron.FirstName = FirstName.Text.Trim(); patron.LastName = LastName.Text.Trim(); patron.EmailAddress = EmailAddress.Text.Trim(); patron.LibraryCard = LibraryCard.Text.Replace(" ", ""); int primaryLibrary = 0; if (int.TryParse(PrimaryLibrary.SelectedValue, out primaryLibrary)) { patron.PrimaryLibrary = primaryLibrary; } int avatarId; if (int.TryParse(AvatarID.Value, out avatarId)) { patron.AvatarID = avatarId; } if (!string.IsNullOrEmpty(MasterPID.Text)) { int masterPid = 0; if (int.TryParse(MasterPID.Text, out masterPid)) { var masterPatron = Patron.FetchObject(masterPid); if (!masterPatron.IsMasterAccount) { masterPatron.IsMasterAccount = true; masterPatron.Update(); new SessionTools(Session).EstablishPatron(masterPatron); } patron.MasterAcctPID = masterPid; patron.ParentGuardianFirstName = masterPatron.FirstName; patron.ParentGuardianLastName = masterPatron.LastName; } } try { if (patron.IsValid(BusinessRulesValidationMode.INSERT)) { patron.Insert(); this.Log().Info("New participant: {0} {1} ({2})", patron.FirstName, patron.LastName, patron.LibraryCard); } else { StringBuilder message = new StringBuilder("<strong>"); message.AppendFormat(SRPResources.ApplicationError1, "<ul>"); foreach (BusinessRulesValidationMessage m in patron.ErrorCodes) { this.Log().Warn("Business rule error creating patron: {0}", m.ErrorMessage); message.AppendFormat("<li>{0}</li>", m.ErrorMessage); } message.Append("</ul></strong>"); new SessionTools(Session).AlertPatron( message.ToString(), PatronMessageLevels.Warning, "exclamation-sign"); return(false); } var prog = Programs.FetchObject(patron.ProgID); var earnedBadgesList = new List <Badge>(); if (prog.RegistrationBadgeID != 0) { AwardPoints.AwardBadgeToPatron(prog.RegistrationBadgeID, patron, ref earnedBadgesList); } AwardPoints.AwardBadgeToPatronViaMatchingAwards(patron, ref earnedBadgesList); if (string.IsNullOrEmpty(MasterPID.Text)) { EarnedBadges.Text = string.Join("|", earnedBadgesList.Select(b => b.BID).Distinct()); MasterPID.Text = patron.PID.ToString(); new SessionTools(Session).EstablishPatron(patron); } else { new SessionTools(Session).AlertPatron( string.Format("Account created for: <strong>{0}</strong>", DisplayHelper.FormatName( patron.FirstName, patron.LastName, patron.Username)), glyphicon: "thumbs-up"); } } catch (Exception ex) { this.Log().Error(string.Format("A problem occurred during registration: {0}", ex.Message)); new SessionTools(Session).AlertPatron( string.Format("<strong>{0}</strong>", ex.Message), PatronMessageLevels.Warning, "exclamation-sign"); return(false); } return(true); }
public IActionResult Create(Patron newPatron) { db.Patrons.Add(newPatron); db.SaveChanges(); return(RedirectToAction("Index")); }