public bool IsValid_PartTwo() { if (!IsValid_PartOne) { return(false); } if (BirthYear.Value < 1920 || BirthYear.Value > 2002) { return(false); } if (IssueYear.Value < 2010 || IssueYear.Value > 2020) { return(false); } if (ExpirationYear.Value < 2020 || ExpirationYear.Value > 2030) { return(false); } if (string.IsNullOrEmpty(Height.Unit)) { return(false); } if (Height.Unit.Equals("cm", StringComparison.InvariantCultureIgnoreCase) && (Height.HeightValue.Value < 150 || Height.HeightValue.Value > 193)) { return(false); } if (Height.Unit.Equals("in", StringComparison.InvariantCultureIgnoreCase) && (Height.HeightValue.Value < 59 || Height.HeightValue.Value > 76)) { return(false); } if (!ColorCheck.IsValid(HairColor)) { return(false); } if (!_validEyeColors.Contains(EyeColor)) { return(false); } var passportArray = PassportId.ToCharArray(); if (passportArray.Length != 9) { return(false); } foreach (var c in passportArray) { if (!int.TryParse(c.ToString(), out var passDigit)) { return(false); } } return(true); }
public bool IsValid2() { return(BirthYear != default && Int32.TryParse(BirthYear, out int birthYear) && birthYear >= 1920 && birthYear <= 2002 && IssueYear != default && Int32.TryParse(IssueYear, out int issueYear) && issueYear >= 2010 && issueYear <= 2020 && ExpirationYear != default && Int32.TryParse(ExpirationYear, out int expirationYear) && expirationYear >= 2020 && expirationYear <= 2030 && Height != default && IsValidHeightString(Height) && HairColor != default && Regex.Match(HairColor, @"#[0-9a-f]{6}").Success && EyeColor != default && Regex.Match(EyeColor, @"(amb|blu|brn|gry|grn|hzl|oth)").Success && PassportId != default && Int32.TryParse(PassportId, out _) && PassportId.Count() == 9); }
/// <summary> /// Gets the hash code /// </summary> /// <returns>Hash code</returns> public override int GetHashCode() { unchecked // Overflow is fine, just wrap { int hashCode = 41; if (PassportId != null) { hashCode = hashCode * 59 + PassportId.GetHashCode(); } hashCode = hashCode * 59 + PlanId.GetHashCode(); if (OptionalLinkedSubscriptionId != null) { hashCode = hashCode * 59 + OptionalLinkedSubscriptionId.GetHashCode(); } if (SubscriptionDate != null) { hashCode = hashCode * 59 + SubscriptionDate.GetHashCode(); } if (ExpirationDate != null) { hashCode = hashCode * 59 + ExpirationDate.GetHashCode(); } hashCode = hashCode * 59 + CurrentTokensUsed.GetHashCode(); hashCode = hashCode * 59 + ExtraTokens.GetHashCode(); if (ExtraTokensEndDate != null) { hashCode = hashCode * 59 + ExtraTokensEndDate.GetHashCode(); } hashCode = hashCode * 59 + IsYearlyPaid.GetHashCode(); hashCode = hashCode * 59 + IsActive.GetHashCode(); hashCode = hashCode * 59 + TokensPercentUsageAlert.GetHashCode(); hashCode = hashCode * 59 + TokensPercentUsageAlertSent.GetHashCode(); hashCode = hashCode * 59 + IsManaged.GetHashCode(); if (NextMonthlyTerm != null) { hashCode = hashCode * 59 + NextMonthlyTerm.GetHashCode(); } hashCode = hashCode * 59 + RemainingTokens.GetHashCode(); return(hashCode); } }
/// <summary> /// Returns true if PassportPDFPassport instances are equal /// </summary> /// <param name="input">Instance of PassportPDFPassport to be compared</param> /// <returns>Boolean</returns> public bool Equals(PassportPDFPassport input) { if (input == null) { return(false); } return (( PassportId == input.PassportId || (PassportId != null && PassportId.Equals(input.PassportId)) ) && ( PlanId == input.PlanId || PlanId.Equals(input.PlanId) ) && ( OptionalLinkedSubscriptionId == input.OptionalLinkedSubscriptionId || (OptionalLinkedSubscriptionId != null && OptionalLinkedSubscriptionId.Equals(input.OptionalLinkedSubscriptionId)) ) && ( SubscriptionDate == input.SubscriptionDate || (SubscriptionDate != null && SubscriptionDate.Equals(input.SubscriptionDate)) ) && ( ExpirationDate == input.ExpirationDate || (ExpirationDate != null && ExpirationDate.Equals(input.ExpirationDate)) ) && ( CurrentTokensUsed == input.CurrentTokensUsed || CurrentTokensUsed.Equals(input.CurrentTokensUsed) ) && ( ExtraTokens == input.ExtraTokens || ExtraTokens.Equals(input.ExtraTokens) ) && ( ExtraTokensEndDate == input.ExtraTokensEndDate || (ExtraTokensEndDate != null && ExtraTokensEndDate.Equals(input.ExtraTokensEndDate)) ) && ( IsYearlyPaid == input.IsYearlyPaid || IsYearlyPaid.Equals(input.IsYearlyPaid) ) && ( IsActive == input.IsActive || IsActive.Equals(input.IsActive) ) && ( TokensPercentUsageAlert == input.TokensPercentUsageAlert || TokensPercentUsageAlert.Equals(input.TokensPercentUsageAlert) ) && ( TokensPercentUsageAlertSent == input.TokensPercentUsageAlertSent || TokensPercentUsageAlertSent.Equals(input.TokensPercentUsageAlertSent) ) && ( IsManaged == input.IsManaged || IsManaged.Equals(input.IsManaged) ) && ( NextMonthlyTerm == input.NextMonthlyTerm || (NextMonthlyTerm != null && NextMonthlyTerm.Equals(input.NextMonthlyTerm)) ) && ( RemainingTokens == input.RemainingTokens || RemainingTokens.Equals(input.RemainingTokens) )); }
public bool IsValid() { // check if all data present if (!( BirthYear != null && IssueYear != null && ExpirationYear != null && Height != null && HairColor != null && EyeColor != null && PassportId != null)) { return(false); } // validate birth year if (BirthYear < 1920 || BirthYear > 2002) { return(false); } // validate issue year if (IssueYear < 2010 || IssueYear > 2020) { return(false); } // validate expiration year if (ExpirationYear < 2020 || ExpirationYear > 2030) { return(false); } // validate height if (!Height.EndsWith("cm") && !Height.EndsWith("in")) { return(false); } try { int heightNumber = Convert.ToInt32(Height.Substring(0, Height.Length - 2)); string heightType = Height.Substring(Height.Length - 2); if (heightType == "cm" && (heightNumber < 150 || heightNumber > 193)) { return(false); } if (heightType == "in" && (heightNumber < 59 || heightNumber > 76)) { return(false); } } catch { // Cannot parse throw new Exception("Cannot parse " + Height); } // validate hair color if (HairColor.Length != 7 || !HairColor.StartsWith("#")) { return(false); } var allowedChars = new List <char> { '#', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' }; for (var i = 0; i < HairColor.Length; i++) { var currentChar = Convert.ToChar(HairColor.Substring(i, 1)); if (!allowedChars.Contains(currentChar)) { return(false); } } // validate eye color var allowedValues = new List <string> { "amb", "blu", "brn", "gry", "grn", "hzl", "oth" }; if (!allowedValues.Contains(EyeColor)) { return(false); } // validate passport number if (PassportId.Length != 9) { return(false); } allowedChars = new List <char> { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' }; for (var i = 0; i < PassportId.Length; i++) { var currentChar = Convert.ToChar(PassportId.Substring(i, 1)); if (!allowedChars.Contains(currentChar)) { return(false); } } // Passed all validations - return true; return(true); }