public static AccountInfo GetAccountInformation() { if (!IsLoggedIn()) throw new ApplicationException("GetAccountInformation() was called out of " + "sequence. An authenticated Tessitura session is required."); string cacheKey = AccountInfoCacheKeyBase + "[" + HttpContext.Current.Session[UsernameSessionKey].ToString() + "]"; AccountInfo info = (AccountInfo)HttpContext.Current.Cache[cacheKey]; if (info == null) { DataSet accountResults = unsecuredClient.GetAccountInfo( HttpContext.Current.Session[TessSessionKeySessionKey].ToString()); DataRow data = accountResults.Tables["AccountInformation"].Rows[0]; AccountPerson person1 = null; AccountPerson person2 = null; if (data["name_status"].ToString() != "Deceased" && data["lname"].ToString() != "") { char? gender = null; if (data["gender_1"] != DBNull.Value) gender = Convert.ToChar(data["gender_1"]); person1 = new AccountPerson( data["prefix"].ToString(), data["fname"].ToString(), data["mname"].ToString(), data["lname"].ToString(), data["suffix"].ToString(), gender, false); } if (data["name2_status"].ToString() != "Deceased" && data["lname2"].ToString() != "") { char? gender = null; if (data["gender_2"] != DBNull.Value) gender = Convert.ToChar(data["gender_2"]); person2 = new AccountPerson( data["prefix2"].ToString(), data["fname2"].ToString(), data["mname2"].ToString(), data["lname2"].ToString(), data["suffix2"].ToString(), gender, false); } AccountPersonPair personPair = null; if (person1 != null || person2 != null) personPair = new AccountPersonPair(person1, person2); info = new AccountInfo(); info.CustomerNumber = Convert.ToInt32(data["customer_no"]); info.People = personPair; info.Address = data["street1"].ToString(); info.SubAddress = data["street2"].ToString(); info.City = data["city"].ToString(); info.StateId = data["state"].ToString(); info.PostalCode = data["postal_code"].ToString(); info.SetNewCountryIdWithDesc( Convert.ToInt32(data["country"]), data["country_name"].ToString()); string phone = data["phone"].ToString(); info.EmailUnprotected = data["email"].ToString(); // data["use_avs"] string phone2 = data["phone2"].ToString(); string fax = data["fax_phone"].ToString(); // data["esal1_desc"] // data["esal2_desc"] // data["lsal_desc"] info.BusinessTitle = data["business_title"].ToString(); info.CanReceiveHtmlEmail = data["html_ind"].ToString() == "Y"; // data["original_source"] info.WantsMail = data["mail_ind_id"] == DBNull.Value || Convert.ToInt32(data["mail_ind_id"]) == 3; info.WantsPhone = data["phone_ind_id"] == DBNull.Value || Convert.ToInt32(data["phone_ind_id"]) == 3; info.WantsEmail = data["emarket_ind_id"] == DBNull.Value || Convert.ToInt32(data["emarket_ind_id"]) == 3; // data["email_inactive"] DataSet constituentResults = unsecuredClient.GetConstituentInfoEx( HttpContext.Current.Session[TessSessionKeySessionKey].ToString(), null); if (constituentResults.Tables["Addresses"].Rows.Count > 0) { foreach (DataRow address in constituentResults.Tables["Addresses"].Rows) { if (address["primary_ind"].ToString() == "Y") { info.SetAddressTypeIdWithDesc( Convert.ToInt32(address["address_type"]), address["address_type_desc"].ToString()); break; } } } int? phoneId = null; int? phone2Id = null; int? faxId = null; if (constituentResults.Tables["Phones"].Rows.Count > 0) { foreach (DataRow phoneNumber in constituentResults.Tables["Phones"].Rows) { string number = Regex.Replace(phoneNumber["phone"].ToString(), "[^0-9]", ""); if (!String.IsNullOrWhiteSpace(phone) && number == phone) phoneId = Convert.ToInt32(phoneNumber["phone_no"]); if (!String.IsNullOrWhiteSpace(phone2) && number == phone2) phone2Id = Convert.ToInt32(phoneNumber["phone_no"]); if (!String.IsNullOrWhiteSpace(fax) && number == fax) faxId = Convert.ToInt32(phoneNumber["phone_no"]); } if (phoneId != null) info.SetPhoneWithId(phone, phoneId); else info.Phone = phone; if (phone2Id != null) info.SetPhone2WithId(phone2, phone2Id); else info.Phone2 = phone2; if (faxId != null) info.SetFaxWithId(fax, faxId); else info.Fax = fax; } HttpContext.Current.Cache.Insert(cacheKey, info, null, DateTime.MaxValue, new TimeSpan(0, 10, 0)); } return info; }
public static bool UpdateAccountInfo(AccountInfo newInfo, bool allowEmailChange) { if (!IsLoggedIn()) { throw new ApplicationException("UpdateAccountInfo() was called out of " + "sequence. An authenticated Tessitura session is required."); } // TODO: retrieve original email address and phone numbers for comparisons: AccountInfo oldInfo = GetAccountInformation(); // Check if email has changed (if necessary) if (!allowEmailChange && oldInfo.Email != newInfo.Email) return false; AccountPerson person1 = newInfo.People.Person1; AccountPerson person2 = newInfo.People.Person2; if (person2 == null) person2 = new AccountPerson(); // Update the constituent string sessionKey = HttpContext.Current.Session[TessSessionKeySessionKey].ToString(); HttpContext.Current.Cache.Remove(AccountInfoCacheKeyBase + "[" + HttpContext.Current.Session[UsernameSessionKey] + "]"); try { unsecuredClient.UpdateAccountInfoEx2( sSessionKey: sessionKey, sEmail: newInfo.Email ?? oldInfo.Email, sPhone: newInfo.Phone ?? "[]", sStreet1: newInfo.Address ?? "[]", sStreet2: newInfo.SubAddress ?? "[]", sCity: newInfo.City ?? "[]", sStateProv: String.IsNullOrWhiteSpace(newInfo.StateId) ? "NY" : newInfo.StateId, // won't delete via API call (API bug) sPostalCode: newInfo.PostalCode ?? "0", // won't delete via API call (API bug) iCountry: newInfo.CountryId ?? 1, sPhone2: newInfo.Phone2 ?? "[]", iPhone2Type: 0, sFax: newInfo.Fax ?? "[]", sFirstName: person1.FirstName ?? "[]", sLastName: person1.LastName, sMiddleName: person1.MiddleName ?? "[]", sPrefix: person1.Prefix ?? "[]", sSuffix: person1.Suffix ?? "[]", sBusinessTitle: newInfo.BusinessTitle ?? "[]", iEmailIndicator: (newInfo.WantsEmail ?? true) ? 3 : 1, iMailIndicator: (newInfo.WantsMail ?? true) ? 3 : 1, iPhoneIndicator: (newInfo.WantsPhone ?? true) ? 3 : 1, sHtmlIndicator: (newInfo.CanReceiveHtmlEmail ?? true) ? "Y" : "N", sGender: person1.Gender == null ? "[]" : person1.Gender.ToString(), sGender2: person2.Gender == null ? "[]" : person2.Gender.ToString(), sFirstName2: person2.FirstName ?? "[]", sMiddleName2: person2.MiddleName ?? "[]", sLastName2: person2.LastName ?? "[]", sPrefix2: person2.Prefix ?? "[]", sSuffix2: person2.Suffix ?? "[]", iOriginalSourceNumber: 0, bUpdateSalutation: true, iAddressTypeOverwrite: newInfo.AddressTypeId ?? 0, iEaddressTypeOverwrite: 0, sEsal1DescriptionOverwrite: "", sEsal2DescriptionOverwrite: "", sLsalDescriptionOverwrite: "", iConstituentTypeOverwrite: 0, iNameStatus: 1, iName2Status: 1); } catch (Exception e) { if (e.Message.Contains("TESSITURA_DUPLICATE_EMAIL_EXCEPTION")) return false; else throw e; } if (oldInfo.Email != newInfo.Email) { // TODO: update username with new email } if (oldInfo.Phone != null && newInfo.Phone == null) unsecuredClient.RemovePhone(sessionKey, oldInfo.PhoneId.Value); if (oldInfo.Phone2 != null && newInfo.Phone2 == null) unsecuredClient.RemovePhone(sessionKey, oldInfo.Phone2Id.Value); if (oldInfo.Fax != null && newInfo.Fax == null) unsecuredClient.RemovePhone(sessionKey, oldInfo.FaxId.Value); return true; }
public static bool UpdateAccountInfo(AccountInfo newInfo) { return UpdateAccountInfo(newInfo, false); }
protected bool SubmitUpdate() { AccountPerson person1 = null; AccountPerson person2 = null; if (/*FirstNameField.Text.Trim() != "" &&*/ LastNameField.Text.Trim() != "") { char? gender = null; if (GenderField.SelectedValue != "0") gender = GenderField.SelectedValue[0]; person1 = new AccountPerson( PrefixField.SelectedValue, FirstNameField.Text, MiddleNameField.Text, LastNameField.Text, SuffixField.Value, gender); } if (/*FirstName2Field.Text.Trim() != "" &&*/ LastName2Field.Text.Trim() != "") { char? gender = null; if (Gender2Field.SelectedValue != "0") gender = Gender2Field.SelectedValue[0]; person2 = new AccountPerson( Prefix2Field.SelectedValue, FirstName2Field.Text, MiddleName2Field.Text, LastName2Field.Text, Suffix2Field.Value, gender); } AccountPersonPair pair = new AccountPersonPair(person1, person2); AccountInfo newInfo = new AccountInfo(); newInfo.BusinessTitle = BusinessTitleField.Value; newInfo.CanReceiveHtmlEmail = Boolean.Parse(CanReceiveHtmlEmailField.Value); if (CountryField.SelectedValue != "0") { newInfo.CountryId = Int32.Parse(CountryField.SelectedValue); newInfo.PostalCode = ZipField.Text; if (StateField.SelectedValue != "0") newInfo.StateId = StateField.SelectedValue; newInfo.SubAddress = SubAddressField.Text; newInfo.City = CityField.Text; newInfo.Address = AddressField.Text; if (AddressTypeField.SelectedValue != "0") newInfo.AddressTypeId = Int32.Parse(AddressTypeField.SelectedValue); } newInfo.Email = EmailField.Text; newInfo.Fax = FaxField.Text; newInfo.People = pair; newInfo.Phone = PhoneField.Text; newInfo.Phone2 = Phone2Field.Text; newInfo.WantsEmail = Boolean.Parse(WantEmailField.Value); newInfo.WantsMail = Boolean.Parse(WantMailField.Value); newInfo.WantsPhone = Boolean.Parse(WantPhoneField.Value); return WebClient.UpdateAccountInfo(newInfo, true); }