/// <summary> /// Validates the objects fields content /// </summary> /// <param name="validationType">Validation level to use on this model</param> /// <exception cref="OrderFieldBadFormatException">throws an exception if one of the parameters doesn't match the expected format</exception> public override void Validate(Validations validationType = Validations.Weak) { base.Validate(validationType); if (validationType == Validations.Weak) { if (string.IsNullOrEmpty(FirstName) && string.IsNullOrEmpty(LastName)) { throw new Exceptions.OrderFieldBadFormatException("Both First name and last name are missing or empty - at least one should be specified"); } } else { InputValidators.ValidateValuedString(FirstName, "First Name"); InputValidators.ValidateValuedString(LastName, "Last Name"); InputValidators.ValidatePhoneNumber(Phone); // make sure phone exists and has a value (addition to validation of BaseAddress) } InputValidators.ValidateValuedString(Address1, "Address 1"); InputValidators.ValidateValuedString(City, "City"); if (string.IsNullOrEmpty(Country) && string.IsNullOrEmpty(CountryCode)) { throw new Exceptions.OrderFieldBadFormatException("Both Country or Country Code fields are missing - at least one should be speicified"); } }
/// <summary> /// Validates the objects fields content /// </summary> /// <param name="validationType">Validation level to use on this model</param> /// <exception cref="OrderFieldBadFormatException">throws an exception if one of the parameters doesn't match the expected format</exception> public virtual void Validate(Validations validationType = Validations.Weak) { // optional fields validations if (!string.IsNullOrEmpty(Phone)) { InputValidators.ValidatePhoneNumber(Phone); } if (!string.IsNullOrEmpty(CountryCode)) { InputValidators.ValidateCountryOrProvinceCode(CountryCode); } if (!string.IsNullOrEmpty(ProvinceCode)) { InputValidators.ValidateCountryOrProvinceCode(ProvinceCode); } }
/// <summary> /// Validates the objects fields content /// </summary> /// <param name="validationType">Validation level to use on this Model</param> /// <exception cref="OrderFieldBadFormatException"> /// throws an exception if one of the parameters doesn't match the expected /// format /// </exception> public void Validate(Validations validationType = Validations.Weak) { // optional fields validations if (!string.IsNullOrEmpty(Email)) { InputValidators.ValidateEmail(Email); } if (!string.IsNullOrEmpty(Phone)) { InputValidators.ValidatePhoneNumber(Phone); } Social?.Validate(validationType); if (Social == null && string.IsNullOrEmpty(Email) && string.IsNullOrEmpty(Phone)) { throw new OrderFieldBadFormatException("All recipient fields are missing - at least one should be specified"); } }