private void SaveAndPop() { UserTable userChanges = new UserTable(); userChanges = user; userChanges.UserName = UserName.Trim(); userChanges.FirstName = FirstName.Trim(); userChanges.LastName = LastName.Trim(); userChanges.Email = Email.Trim(); userChanges.Address1 = Address1.Trim(); if (Address2 != null) { userChanges.Address2 = Address2.Trim(); } if (Address3 != null) { userChanges.Address3 = Address3.Trim(); } userChanges.PostCode = PostCode.Trim(); userChanges.City = City.Trim(); userChanges.Country = Country.Trim(); userChanges.Phone = int.Parse(Phone.Trim()); }
public override bool Equals(object obj) { var a = obj as Address; if (a == null) { return(false); } // Addresses can be equal even if the case differs or the leading/trailing whitespace differs return( string.Equals(Address1?.Trim(), a.Address1?.Trim(), StringComparison.OrdinalIgnoreCase) && string.Equals(Address2?.Trim(), a.Address2?.Trim(), StringComparison.OrdinalIgnoreCase) && string.Equals(City?.Trim(), a.City?.Trim(), StringComparison.OrdinalIgnoreCase) && string.Equals(ProvinceStateCode?.Trim(), a.ProvinceStateCode?.Trim(), StringComparison.OrdinalIgnoreCase) && string.Equals(CountryCode?.Trim(), a.CountryCode?.Trim(), StringComparison.OrdinalIgnoreCase) && string.Equals(OtherCountry?.Trim(), a.OtherCountry?.Trim(), StringComparison.OrdinalIgnoreCase) && string.Equals(PostalZipCode?.Trim(), a.PostalZipCode?.Trim(), StringComparison.OrdinalIgnoreCase) ); }
public override string ToString() { return(string.Format("{0}, {1}, {2}, {3}, {4}", Name.Trim(), Address1.Trim(), City.Trim(), State.Trim(), PostalCode.Trim())); }
public override bool Equals(object obj) { if (obj is OrganisationAddress) { obj = Create((OrganisationAddress)obj); } var address = obj as AddressModel; if (address == null) { return(false); } if (obj is OrganisationAddress) { } if ((!string.IsNullOrWhiteSpace(Address1) || !string.IsNullOrWhiteSpace(address.Address1)) && Address1?.Trim() != address.Address1?.Trim()) { return(false); } if ((!string.IsNullOrWhiteSpace(Address2) || !string.IsNullOrWhiteSpace(address.Address2)) && Address2?.Trim() != address.Address2?.Trim()) { return(false); } if ((!string.IsNullOrWhiteSpace(Address3) || !string.IsNullOrWhiteSpace(address.Address3)) && Address3?.Trim() != address.Address3?.Trim()) { return(false); } if ((!string.IsNullOrWhiteSpace(City) || !string.IsNullOrWhiteSpace(address.City)) && City?.Trim() != address.City?.Trim()) { return(false); } if ((!string.IsNullOrWhiteSpace(County) || !string.IsNullOrWhiteSpace(address.County)) && County?.Trim() != address.County?.Trim()) { return(false); } if ((!string.IsNullOrWhiteSpace(Country) || !string.IsNullOrWhiteSpace(address.Country)) && Country?.Trim() != address.Country?.Trim()) { return(false); } if ((!string.IsNullOrWhiteSpace(PostCode) || !string.IsNullOrWhiteSpace(address.PostCode)) && PostCode?.Trim() != address.PostCode?.Trim()) { return(false); } if ((!string.IsNullOrWhiteSpace(PoBox) || !string.IsNullOrWhiteSpace(address.PoBox)) && PoBox?.Trim() != address.PoBox?.Trim()) { return(false); } return(true); }
/// <summary> /// Simplify address /// </summary> /// <remarks> /// This basically is intended to remove empty lines from the address fields and push the remainder up. /// It can mess up the consistency for named fields but that is always a risk with user input /// Postcode is ignored - previously it may have been added to the last line /// </remarks> public void Simplify() { var dummyLine = "##DUMMY ADDRESS LINE##"; // first tidy up Address1 = Address1 == null ? "" : Address1.Trim(); Address2 = Address2 == null ? "" : Address2.Trim(); Address3 = Address3 == null ? "" : Address3.Trim(); Address4 = Address4 == null ? "" : Address4.Trim(); Address5 = Address5 == null ? "" : Address5.Trim(); Address6 = Address6 == null ? "" : Address6.Trim(); // check for house number // we only check the first two addresses and deal if needed // house number is intended to be in address 2 but it could be swapped so we check here var houseNameIsNumeric = Address1.Trim().IsLong(); var houseNameIsPartialNumeric = Address1.Trim().FirstWord().IsLong(); var houseNumberIsNumeric = Address2.Trim().IsLong(); var houseNumberIsPartialNumeric = Address2.Trim().FirstWord().IsLong(); if (houseNameIsNumeric) { long.TryParse(Address1, out var houseNumber); // address1 is fully numeric so we swap Address1 = Address2 == null || Address2.Trim() == "" ? dummyLine : Address2; Address2 = houseNumber.ToString(); } else { if (houseNameIsPartialNumeric) { // address1 is partial numeric, if address2 is empty we move the number if (Address2 == null || Address2.Trim() == "") { long.TryParse(Address1.Trim().FirstWord(), out var houseNumber); Address1 = Address1.Substring(houseNumber.ToString().Length); Address2 = houseNumber.ToString(); } } else { if (houseNumberIsNumeric && (Address1 == null || Address1.Trim() == "")) { // housenumber is numeric and house nameis empty so we add dummy line to prevent losing empty line which will throw out the order Address1 = dummyLine; } else { if (houseNumberIsPartialNumeric && (Address1 == null || Address1.Trim() == "")) { // housenumber contains a partial numeric e.g. 32 High street so we split it out long.TryParse(Address2.Trim().FirstWord(), out var house2Number); Address1 = Address2.Substring(house2Number.ToString().Length); Address2 = house2Number.ToString(); } } } } var tempFullAddress = FullAddress(Address1, Address2, Address3, Address4, Address5, Address6, false); // remove any redundancy so that we have a comma separated string tempFullAddress.ReplaceAllMid(",,", "", 0, tempFullAddress.Length); // now split on comma var tempAddress = tempFullAddress.Split(','); var tempAddressLen = tempAddress.Length; switch (tempAddressLen) { case 1: Address1 = tempAddress[0].Trim(); Address2 = ""; Address3 = ""; Address4 = ""; Address5 = ""; Address6 = ""; break; case 2: Address1 = tempAddress[0].Trim(); Address2 = tempAddress[1].Trim(); Address3 = ""; Address4 = ""; Address5 = ""; Address6 = ""; break; case 3: Address1 = tempAddress[0].Trim(); Address2 = tempAddress[1].Trim(); Address3 = tempAddress[2].Trim(); Address4 = ""; Address5 = ""; Address6 = ""; break; case 4: Address1 = tempAddress[0].Trim(); Address2 = tempAddress[1].Trim(); Address3 = tempAddress[2].Trim(); Address4 = tempAddress[3].Trim(); Address5 = ""; Address6 = ""; break; case 5: Address1 = tempAddress[0].Trim(); Address2 = tempAddress[1].Trim(); Address3 = tempAddress[2].Trim(); Address4 = tempAddress[3].Trim(); Address5 = tempAddress[4].Trim(); Address6 = ""; break; case 6: Address1 = tempAddress[0].Trim(); Address2 = tempAddress[1].Trim(); Address3 = tempAddress[2].Trim(); Address4 = tempAddress[3].Trim(); Address5 = tempAddress[4].Trim(); Address6 = tempAddress[5].Trim(); break; default: Address1 = tempAddress[0].Trim(); Address2 = tempAddress[1].Trim(); Address3 = tempAddress[2].Trim(); Address4 = tempAddress[3].Trim(); Address5 = tempAddress[4].Trim(); Address6 = tempAddress[5].Trim(); break; } // now remove dummy if it exists if (Address1 == dummyLine) { Address1 = ""; } }
public bool hasAddress1() { return(Address1 != null && Address1.Trim().Length != 0); }
// Public Methods /// <summary> /// Ensures that all required fields are present. /// </summary> public CCResponse ValidateFields() { //Security Defect - Added the below code to trim all the fields FirstName = FirstName.Trim(); LastName = LastName.Trim(); City = City.Trim(); Zip = Zip.Trim(); Email = Email.Trim(); State = State.Trim(); Address1 = Address1.Trim(); Address2 = Address2.Trim(); Country = Country.Trim(); //Security Defect - Added the below code to trim all the fields CCResponse c = new CCResponse(); //Security Defects - START - Added the below lines to validate the fields in the BillToInfo if (IsMissing(FirstName)) { c.Message = CSAAWeb.Constants.ERR_AUTHVALIDATION + "FirstName"; c.ActualMessage = c.Message; c.Flag = Config.Setting("ERRCDE_FIRSTNAME"); Logger.Log(c.Message + c.Flag); return(c); } //Security Defects- CH4 -Commented the required field check for lastname since Empty spaces are coming from EXG in this field. //else if (IsMissing(LastName)) //{ // c.Message = CSAAWeb.Constants.ERR_AUTHVALIDATION + "LastName"; // c.ActualMessage = c.Message; // c.Flag = Config.Setting("ERRCDE_LASTNAME"); // Logger.Log(c.Message + c.Flag); // return c; //} //Security Defects-CH4 - Commented the required field check for lastname since Empty spaces are coming from EXG in this field. else if (IsMissing(City) || (City.Length > 25) || junkValidation(City)) { c.Message = CSAAWeb.Constants.ERR_AUTHVALIDATION + "City"; c.ActualMessage = c.Message; c.Flag = Config.Setting("ERRCDE_CITY"); Logger.Log(c.Message + c.Flag); return(c); } else if (IsMissing(Zip) || (Zip.Length > 10) || junkValidation(Zip) || !CSAAWeb.Validate.IsValidZip(Zip)) { c.Message = CSAAWeb.Constants.ERR_AUTHVALIDATION + "Zip"; c.ActualMessage = c.Message; c.Flag = Config.Setting("ERRCDE_CITY"); Logger.Log(c.Message + c.Flag); return(c); } else if ((Email.Length > 90) || (Email != "" && !CSAAWeb.Validate.IsValidEmailAddress(Email))) { c.Message = CSAAWeb.Constants.ERR_AUTHVALIDATION + "Email"; c.ActualMessage = c.Message; c.Flag = Config.Setting("ERRCDE_EMAIL"); Logger.Log(c.Message + c.Flag); return(c); } else if (IsMissing(State) || (State.Length > 2) || junkValidation(State)) { c.Message = CSAAWeb.Constants.ERR_AUTHVALIDATION + "State"; c.ActualMessage = c.Message; c.Flag = Config.Setting("ERRCDE_STATE"); Logger.Log(c.Message + c.Flag); return(c); } //Security defects -Ch3-Removed junk validation in BillToInfo field else if (IsMissing(Address1) || (Address1.Length > 40)) { c.Message = CSAAWeb.Constants.ERR_AUTHVALIDATION + "Address1"; c.Flag = Config.Setting("ERRCDE_ADDRESS1"); c.ActualMessage = c.Message; Logger.Log(c.Message + c.Flag); return(c); } //Security defects -Ch3-Removed junk validation in BillToInfo field else if ((Address2.Length > 40)) { c.Message = CSAAWeb.Constants.ERR_AUTHVALIDATION + "Address2"; c.ActualMessage = c.Message; c.Flag = Config.Setting("ERRCDE_ADDRESS2"); return(c); } else if ((Country.Length > 2) || junkValidation(Country)) { c.Message = CSAAWeb.Constants.ERR_AUTHVALIDATION + "Country"; c.ActualMessage = c.Message; c.Flag = Config.Setting("ERRCDE_COUNTRY"); return(c); } //Security Defects -CH1 - END- Added the below lines to validate the fields in the BillToInfo /*Security Defects - CH2 - sTART - Commented the below code * else if (IsMissing(FirstName) || IsMissing(LastName)) * { * Logger.Log("Field missing, FirstName=" + FirstName + ", LastName=" + LastName); * return null; * throw new BusinessRuleException(EXP_MISSING_CONTACT); * } * * // CSAA.COM CH1:START- Removed Address1 from required field check . * // if (IsMissing(Address1) || IsMissing(City) || IsMissing(State) || IsMissing(Zip)) * else if ( IsMissing(City) || IsMissing(State) || IsMissing(Zip)) * { * //Logger.Log("Field missing, Address1=" + Address1 + ", City=" + City + ", State=" + State + ", Zip=" + Zip); * Logger.Log("Field missing, City=" + City + ", State=" + State + ", Zip=" + Zip); * return null; * * throw new BusinessRuleException(EXP_MISSING_ADDRESS); * } * // CSAA.COM CH1:END-//Security Defects - CH2 - Commented the below code */ else if (IsMissing(Country)) { _Country = Default_Country; return(null); } else if (IsMissing(Currency)) { _Currency = Default_Currency; return(null); } else { return(null); } }
public string GenerateAddressHtmlString(string LineBreak) { StringBuilder sb = new StringBuilder(); if (Address1 != null && Address1.Trim() != "") { sb.Append(Address1 + LineBreak); } if (Address2 != null && Address2.Trim() != "") { sb.Append(Address2 + LineBreak); } if (Address3 != null && Address3.Trim() != "") { sb.Append(Address3 + LineBreak); } //CITY if (City != null && City != "") { sb.Append(City); if (StateCode != null && StateCode != "") { sb.Append(", "); } else if (PostalCode != null && PostalCode != "") { sb.Append(" "); } else if (CountryCode != null && CountryCode != "" && CountryCode.ToLower() != "us" && CountryCode.ToLower() != "usa") { sb.Append("; "); } } //STATE if (StateCode != null && StateCode != "") { sb.Append(StateCode); if (PostalCode != null && PostalCode != "") { sb.Append(" "); } else if (CountryCode != null && CountryCode != "" && CountryCode.ToLower() != "us" && CountryCode.ToLower() != "usa") { sb.Append("; "); } } //POSTAL if (PostalCode != null && PostalCode != "") { sb.Append(PostalCode); if (CountryCode != null && CountryCode != "" && CountryCode.ToLower() != "us" && CountryCode.ToLower() != "usa") { sb.Append(LineBreak); } } //COUNTRY if (CountryCode != null && CountryCode != "" && CountryCode.ToLower() != "us" && CountryCode.ToLower() != "usa") { sb.Append(CountryCode); } sb.Append(LineBreak); return(sb.ToString()); }