public string this[string columnName] { get { if (columnName == "AccountNumber" && !string.IsNullOrEmpty(AccountNumber)) { var accountNumberLength = AccountNumber.ToString().Length; if (accountNumberLength > 10 || accountNumberLength < 5) { return("Account number length should be between 5 to 10. "); } } else if (columnName == "AccountNumber1" && !string.IsNullOrEmpty(AccountNumber1)) { var accountNumberLength = AccountNumber1.ToString().Length; if (AccountNumber1 != AccountNumber) { return("Account numbers do not match."); } else if (accountNumberLength > 10 || accountNumberLength < 5) { return("Account number length should be between 5 to 10. "); } } else if (columnName == "Amount") { if (Amount <= 0) { return("Amount should be more than zero."); } } else if (columnName == "Email") { if (string.IsNullOrEmpty(Email)) { return(string.Empty); } return(!emailRegex.IsMatch(Email) ? "Email ID not in correct format." : null); } else if (columnName == "Password") { if (string.IsNullOrEmpty(Password)) { return(string.Empty); } if (Password != "password") { return("Password is incorrect"); } } return(string.Empty); } }
public IEnumerable GetErrors(string propertyName) { if (propertyName == null) { return(null); } List <string> errors = new List <string>(); if (propertyName == "AccountNumber") { if (!string.IsNullOrEmpty(AccountNumber)) { propErrors.Remove("AccountNumber"); var accountNumberLength = AccountNumber.ToString().Length; if (accountNumberLength > 10 || accountNumberLength < 5) { if (!propErrors.TryGetValue(propertyName, out errors)) { errors = new List <string>(); errors.Add("Length should be between 5 and 10."); propErrors.Add("AccountNumber", errors); } } else if (propErrors.TryGetValue(propertyName, out errors)) { errors.Clear(); propErrors.Remove(propertyName); } } else if (propErrors.TryGetValue(propertyName, out errors)) { errors.Clear(); propErrors.Remove(propertyName); } } else if (propertyName == "AccountNumber1") { if (!string.IsNullOrEmpty(AccountNumber1)) { var accountNumberLength = AccountNumber1.ToString().Length; var error = string.Empty; if (AccountNumber1 != AccountNumber) { error = "Account numbers don't match."; } else if (accountNumberLength > 10 || accountNumberLength < 5) { error = "Length should be between 5 and 10."; } else if (propErrors.TryGetValue(propertyName, out errors)) { errors.Clear(); propErrors.Remove(propertyName); } if (!propErrors.TryGetValue(propertyName, out errors) && !string.IsNullOrEmpty(error)) { errors = new List <string>(); errors.Add(error); propErrors.Add("AccountNumber1", errors); } } else if (propErrors.TryGetValue(propertyName, out errors)) { errors.Clear(); propErrors.Remove(propertyName); } } else if (propertyName == "Amount") { if (Amount <= 0) { if (!propErrors.TryGetValue(propertyName, out errors)) { errors = new List <string>(); errors.Add("Amount should be greater than 0."); propErrors.Add("Amount", errors); } } else if (propErrors.TryGetValue(propertyName, out errors)) { errors.Clear(); propErrors.Remove(propertyName); } } else if (propertyName == "SWIFT") { if (string.IsNullOrEmpty(this.SWIFT)) { return(string.Empty); } if (!swiftRegex.IsMatch(this.SWIFT)) { if (!propErrors.TryGetValue(propertyName, out errors)) { errors = new List <string>(); errors.Add("SWIFT code should be 8 or 11 upper case letters."); propErrors.Add("SWIFT", errors); } } else if (propErrors.TryGetValue(propertyName, out errors)) { errors.Clear(); propErrors.Remove(propertyName); } } else if (propertyName == "Password") { if (string.IsNullOrEmpty(this.Password)) { return(string.Empty); } var error = string.Empty; if (Password != "password") { error = "Password is incorrect."; } if (!propErrors.TryGetValue(propertyName, out errors) && !string.IsNullOrEmpty(error)) { errors = new List <string>(); errors.Add(error); propErrors.Add("Password", errors); } else if (propErrors.TryGetValue(propertyName, out errors)) { errors.Clear(); propErrors.Remove(propertyName); } } if (propErrors.TryGetValue(propertyName, out errors)) { return(errors); } return(null); }