Riskified.SDK.Model.OrderElements.Customer.Validate C# (CSharp) Method

Validate() public method

Validates the objects fields content
throws an exception if one of the parameters doesn't match the expected format
public Validate ( Validations validationType = Validations.Weak ) : void
validationType Validations Validation level to use on this Model
return void
        public void Validate(Validations validationType = Validations.Weak)
        {
            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");
            }

            // optional fields validations
            if (!string.IsNullOrEmpty(Email))
            {
                InputValidators.ValidateEmail(Email);
            }
            if (OrdersCount.HasValue)
            {
                InputValidators.ValidateZeroOrPositiveValue(OrdersCount.Value, "Orders Count");
            }
            if (CreatedAt.HasValue)
            {
                InputValidators.ValidateDateNotDefault(CreatedAt.Value, "Created At");
            }
            if(Social != null)
            {
                Social.ToList().ForEach(item => item.Validate(validationType));
            }
            if (Address != null)
            {
                Address.Validate(validationType);
            }
        }