private static AddressViewModel AddressFrom(PostalAddress address, bool aptFlag = true) { if (address == null) { address = new PostalAddress(); } return(new AddressViewModel { StreetNumber = address.StreetNumber, StreetName = address.StreetName, Apartment = address.Apartment, City = address.City, StateCode = address.State, State = CPConvert.ParseStateCode(address.State), Zip = address.Zip != null?address.Zip.ToString() : null, HasApartment = aptFlag }); }
public static BankAccountViewModel BankAccountFrom(BankAccount source, char committeeID) { return(source == null ? new BankAccountViewModel() : new BankAccountViewModel { CommitteeID = committeeID, ID = source.ID, BankName = source.BankName, City = source.City, State = CPConvert.ParseStateCode(source.State), StateCode = source.State, Zip = source.Zip == null ? null : source.Zip.ToString(), AccountNumber = source.Number, FriendlyName = source.Name, OpenedDate = source.OpeningDate, ClosedDate = source.ClosingDate, Balance = source.CurrentBalance, BalanceDate = source.CurrentBalanceDate, Type = source.Type == BankAccountType.Other ? source.OtherTypeSpecification : CPConvert.ToString(source.Type), Purpose = source.Purpose == BankAccountPurpose.Other ? source.OtherPurposeSpecification : CPConvert.ToString(source.Purpose), DirectDeposit = source.HasDirectDeposit }); }
/// <summary> /// Updates control fields with an active candidate's profile information. /// </summary> /// <param name="ac">The active candidate profile to display.</param> private void ShowCandidate(ActiveCandidate ac) { if (ac == null) { _errorMessage.Text = string.Format("You do not currently have an active candidate profile for the {0} election.", CPProfile.ElectionCycle); _errorMessage.Visible = true; _details.Visible = false; } else { PostalAddress address; // basic candidate info _ID.Value = ac.ID; _salutation.Value = CPConvert.ToString(ac.Honorific); _lastName.Value = ac.LastName; _firstName.Value = ac.FirstName; _mi.Value = ac.MiddleInitial.HasValue ? ac.MiddleInitial.Value.ToString() : null; address = ac.Address; if (!object.Equals(address, null)) { _streetNumber.Value = address.StreetNumber; _streetName.Value = address.StreetName; _apartment.Value = address.Apartment; _city.Value = address.City; _state.Value = CPConvert.ParseStateCode(address.State); if (!object.Equals(address.Zip, null)) { _zip.Value = address.Zip.ToString(); } } if (!object.Equals(ac.DaytimePhone, null)) { _daytimePhone.Value = ac.DaytimePhone.ToString(); } if (!object.Equals(ac.EveningPhone, null)) { _eveningPhone.Value = ac.EveningPhone.ToString(); } if (!object.Equals(ac.Fax, null)) { _fax.Value = ac.Fax.ToString(); } if (!string.IsNullOrEmpty(ac.Email)) { _email.Value = string.Format("<a href=\"mailto:{0}\">{0}</a>", ac.Email); } // employer info Entity employer = ac.Employer; if (!object.Equals(employer, null)) { _empName.Value = employer.Name; address = employer.Address; if (!object.Equals(address, null)) { _empStreetNumber.Value = address.StreetNumber; _empStreetName.Value = address.StreetName; _empCity.Value = address.City; _empState.Value = CPConvert.ParseStateCode(address.State); if (!object.Equals(address.Zip, null)) { _empZip.Value = address.Zip.ToString(); } } if (!object.Equals(employer.DaytimePhone, null)) { _empPhone.Value = employer.DaytimePhone.ToString(); } if (!object.Equals(employer.Fax, null)) { _empFax.Value = employer.Fax.ToString(); } } // candidate activation info if (ac.FilerRegistrationDate.HasValue) { _frDate.Value = ac.FilerRegistrationDate.Value.ToDateString(); } else { _frDate.Value = "(n/a)"; } _party.Value = ac.PoliticalParty; if (_isTIE) { _office.Visible = _certDate.Visible = _terminationDate.Visible = _boroDistrict.Visible = _classification.Visible = _ddAuth.Visible = _rrddAuth.Visible = false; } else { _office.Value = CPConvert.ToString(ac.Office.Type); if (ac.CertificationDate.HasValue) { _certDate.Value = ac.CertificationDate.Value.ToDateString(); } else { _certDate.Value = "(n/a)"; } if (ac.IsTerminated) { _terminationDate.Value = ac.TerminationDate.Value.ToDateString(); _terminationDate.Visible = true; } if (_boroDistrict.Visible = (ac.Office.Type == NycPublicOfficeType.BoroughPresident) || (ac.Office.Type == NycPublicOfficeType.CityCouncilMember)) { NycBorough borough; byte district; if (ac.Office.TryGetBorough(out borough)) { _boroDistrict.LabelText = "Borough"; _boroDistrict.Value = CPConvert.ToString(borough); } else if (ac.Office.TryGetDistrict(out district)) { _boroDistrict.LabelText = "District"; _boroDistrict.Value = district.ToString(); } } _classification.Value = CPConvert.ToString(ac.Classification); _ddAuth.Value = ac.IsDirectDepositAuthorized ? "Yes" : "No"; if (_rrddAuth.Visible = HasRRAccounts(ac)) { _rrddAuth.Value = ac.IsRRDirectDepositAuthorized ? "Yes" : "No"; } } _lastUpdated.Text = "Data last modified: " + ac.LastUpdated.ToDateString(); } }
/// <summary> /// Event handler for updating control fields with a campaign liaison's details. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">An <see cref="EventArgs"/> object that contains the event data.</param> protected void ShowLiaison(object sender, EventArgs e) { Liaison l; PostalAddress address; byte id = 0; if (byte.TryParse(_liaisonList.SelectedValue.Substring(1), out id) && (id > 0)) { string committeeID = _liaisonList.SelectedValue.Substring(0, 1); AuthorizedCommittee ac = GetAuthorizedCommittee(committeeID); // fetch liaison if (!ac.Liaisons.TryGetValue(id, out l)) { _liaisonError.Text = "Sorry, the requested campaign contact could not be retrieved."; _liaisonError.Visible = true; _liaisonDetails.Visible = false; return; } if (l == null) { // error: no liaisons _liaisonError.Text = string.Format("You do not currently have any campaign liaisons or consultants for the {0} election.", CPProfile.ElectionCycle); _liaisonError.Visible = true; _liaisonDetails.Visible = false; } else { // show liaison data _liaisonError.Visible = false; _liaisonDetails.Visible = true; _liaisonType.Value = l.LiaisonType.ToString <LiaisonType>(); _liaisonOrder.Value = CPConvert.ToString(l.ContactOrder); _liaisonSalutation.Value = CPConvert.ToString(l.Honorific); _liaisonLastName.Value = l.LastName; _liaisonFirstName.Value = l.FirstName; _liaisonMiddleInitial.Value = l.MiddleInitial.HasValue ? l.MiddleInitial.Value.ToString() : null; address = l.Address; if (address != null) { _liaisonStreetNumber.Value = address.StreetNumber; _liaisonStreetName.Value = address.StreetName; _liaisonApartment.Value = address.Apartment; _liaisonCity.Value = address.City; _liaisonState.Value = CPConvert.ParseStateCode(address.State); _liaisonZip.Value = (address.Zip != null) ? address.Zip.ToString() : null; } else { _liaisonStreetNumber.Value = _liaisonStreetName.Value = _liaisonApartment.Value = _liaisonCity.Value = _liaisonState.Value = _liaisonZip.Value = null; } _liaisonDaytimePhone.Value = (l.DaytimePhone != null) ? l.DaytimePhone.ToString() : null; _liaisonEveningPhone.Value = (l.EveningPhone != null) ? l.EveningPhone.ToString() : null; _liaisonFax.Value = (l.Fax != null) ? l.Fax.ToString() : null; _liaisonEmail.Value = l.Email; _liaisonManagerial.Value = l.HasManagerialControl ? "Yes" : "No"; _liaisonVG.Value = l.IsVGLiaison ? "Yes" : "No"; _entityName.Visible = l.LiaisonType == LiaisonType.Consultant; _entityName.Value = l.EntityName; } } else { _liaisonDetails.Visible = false; } _liaisonUpdatePanel.Update(); }
/// <summary> /// Updates control fields with an authorized committee's details. /// </summary> /// <param name="ac">The authorized committee to display.</param> private void ShowCommittee(AuthorizedCommittee ac) { PostalAddress address; if (ac == null) { _errorMessage.Text = string.Format("You do not currently have any committees authorized for the {0} election.", CPProfile.ElectionCycle); _errorMessage.Visible = true; _committeeDetails.Visible = false; } else { // show committee data _committeeDetails.Visible = true; // committee info _principal.Value = ac.IsPrincipal ? "Yes" : "No"; _active.Value = ac.IsActive ? "Yes" : "No"; _boeDate.Value = (ac.BoeDate != null) ? ((DateTime)ac.BoeDate).ToDateString() : null; _terminationDate.Value = (_terminationDate.Visible = (ac.TerminationDate != null)) ? ((DateTime)ac.TerminationDate).ToDateString() : null; // address info address = ac.Address; if (address != null) { _StreetNumber.Value = address.StreetNumber; _StreetName.Value = address.StreetName; _Apartment.Value = address.Apartment; _City.Value = address.City; _State.Value = CPConvert.ParseStateCode(address.State); _Zip.Value = (address.Zip != null) ? address.Zip.ToString() : null; } else { _StreetNumber.Value = _StreetName.Value = _Apartment.Value = _City.Value = _State.Value = _Zip.Value = null; } // last election info _lastDate.Value = (ac.LastElectionDate != null) ? ((DateTime)ac.LastElectionDate).ToDateString() : null; _lastOffice.Value = ac.LastElectionOffice; _lastDistrict.Value = ac.LastElectionDistrict; _lastParty.Value = ac.LastPrimaryParty; // mailing address info address = ac.MailingAdress; if (address != null) { _mailingLine1.Value = address.AddressLine1; _mailingStreetNumber.Value = address.StreetNumber; _mailingStreetName.Value = address.StreetName; _mailingApartment.Value = address.Apartment; _mailingCity.Value = address.City; _mailingState.Value = CPConvert.ParseStateCode(address.State); _mailingZip.Value = (address.Zip != null) ? address.Zip.ToString() : null; } else { _mailingLine1.Value = _mailingStreetNumber.Value = _mailingStreetName.Value = _mailingApartment.Value = _mailingCity.Value = _mailingState.Value = _mailingZip.Value = null; } // contact info _daytimePhone.Value = (ac.DaytimePhone != null) ? ac.DaytimePhone.ToString() : null; _eveningPhone.Value = (ac.EveningPhone != null) ? ac.EveningPhone.ToString() : null; _fax.Value = (ac.Fax != null) ? ac.Fax.ToString() : null; _email.Value = (!string.IsNullOrWhiteSpace(ac.Email)) ? string.Format("<a href=\"mailto:{0}\">{0}</a>", ac.Email) : null; if (!string.IsNullOrWhiteSpace(ac.WebsiteUrl)) { string url = ac.WebsiteUrl; if (!url.StartsWith("http://")) { url = "http://" + url; } _webUrl.Value = string.Format("<a href=\"{0}\" target=\"_blank\">{0}</a>", url); } else { _webUrl.Value = null; } // treasurer info Entity treasurer = ac.Treasurer; if (treasurer != null) { _salutation.Value = CPConvert.ToString(treasurer.Honorific); _lastName.Value = treasurer.LastName; _firstName.Value = treasurer.FirstName; _mi.Value = treasurer.MiddleInitial.HasValue ? treasurer.MiddleInitial.Value.ToString() : null; _contactOrder.Value = treasurer.ContactOrder.ToString(); address = treasurer.Address; if (address != null) { _treasStreetNumber.Value = address.StreetNumber; _treasStreetName.Value = address.StreetName; _treasApartment.Value = address.Apartment; _treasCity.Value = address.City; _treasState.Value = CPConvert.ParseStateCode(address.State); _treasZip.Value = (address.Zip != null) ? address.Zip.ToString() : null; } else { _treasStreetNumber.Value = _treasStreetName.Value = _treasApartment.Value = _treasCity.Value = _treasState.Value = _treasZip.Value = null; } _treasDaytimePhone.Value = (treasurer.DaytimePhone != null) ? treasurer.DaytimePhone.ToString() : null; _treasEveningPhone.Value = (treasurer.EveningPhone != null) ? treasurer.EveningPhone.ToString() : null; _treasFax.Value = (treasurer.Fax != null) ? treasurer.Fax.ToString() : null; _treasEmail.Value = !string.IsNullOrWhiteSpace(treasurer.Email) ? string.Format("<a href=\"mailto:{0}\">{0}</a>", treasurer.Email) : null; // treasurer employer info Entity employer = treasurer.Employer; if (employer != null) { _empName.Value = employer.LastName; address = employer.Address; if (address != null) { _empStreetNumber.Value = address.StreetNumber; _empStreetName.Value = address.StreetName; _empCity.Value = address.City; _empState.Value = CPConvert.ParseStateCode(address.State); _empZip.Value = (address.Zip != null) ? address.Zip.ToString() : null; } else { _empStreetNumber.Value = _empStreetName.Value = _empCity.Value = _empState.Value = _empZip.Value = null; } _empPhone.Value = (employer.DaytimePhone != null) ? employer.DaytimePhone.ToString() : null; _empFax.Value = (employer.Fax != null) ? employer.Fax.ToString() : null; } else { _empName.Value = _empStreetNumber.Value = _empStreetName.Value = _empCity.Value = _empState.Value = _empZip.Value = _empPhone.Value = _empFax.Value = _empPhone.Value = _empFax.Value = null; } } else { _treasStreetNumber.Value = _treasStreetName.Value = _treasApartment.Value = _treasCity.Value = _treasState.Value = _treasZip.Value = _treasDaytimePhone.Value = _treasEveningPhone.Value = _treasFax.Value = null; } // update liaison list _liaisonError.Visible = false; _liaisonDetails.Visible = false; ListItem item = _liaisonList.Items[0]; _liaisonList.Items.Clear(); _liaisonList.Items.Add(item); foreach (Liaison l in ac.Liaisons.Values) { string name = l.Name; if (l.LiaisonType == LiaisonType.Consultant) { name += " *"; } _liaisonList.Items.Add(new ListItem(name, ac.ID + l.ID.ToString())); } // update bank accounts list _bankError.Visible = false; _bankAccountDetails.Visible = false; item = _bankAccountsList.Items[0]; _bankAccountsList.Items.Clear(); _bankAccountsList.Items.Add(item); foreach (BankAccount ba in ac.BankAccounts.Values) { _bankAccountsList.Items.Add(new ListItem(string.Format("{0} ({1})", ba.BankName, ba.Number), ac.ID + ba.ID.ToString())); } } }