protected override ValidationResult IsValid(object value, ValidationContext validationContext) { ValidationResult retval = new ValidationResult(""); IAddressViewModel rvm = (IAddressViewModel)validationContext.ObjectInstance; bool isCorrect = true; if (rvm.City != null) { foreach (char c in rvm.City) { if (!char.IsLetter(c) && !char.IsWhiteSpace(c)) { isCorrect = false; break; } } } if (!isCorrect) { retval.ErrorMessage += "Nazwa miejscowości jest niepoprawna. "; } return(string.IsNullOrEmpty(retval.ErrorMessage) ? ValidationResult.Success : retval); }
protected override ValidationResult IsValid(object value, ValidationContext validationContext) { ValidationResult retval = new ValidationResult(""); IAddressViewModel rvm = (IAddressViewModel)validationContext.ObjectInstance; bool isCorrect = true; if (rvm.HouseNumber != null) { foreach (char c in rvm.HouseNumber.Replace(" ", "")) { if (!char.IsLetterOrDigit(c)) { isCorrect = false; break; } } } if (!isCorrect) { retval.ErrorMessage += "Numer domu może zawierać wyłącznie litery i cyfry. "; } return(string.IsNullOrEmpty(retval.ErrorMessage) ? ValidationResult.Success : retval); }
public static Address ToDTO(this IAddressViewModel source) { return(source == null ? null : new Address { Locality = source.Locality, PostalCode = source.PostalCode, Region = source.Region, CountryName = source.Country, StreetAddress = source.Street }); }
protected override ValidationResult IsValid(object value, ValidationContext validationContext) { ValidationResult retval = new ValidationResult(""); IAddressViewModel rvm = (IAddressViewModel)validationContext.ObjectInstance; bool isCorrect = true; if (rvm.ZipCode != null) { isCorrect = Regex.IsMatch(rvm.ZipCode, "^[0-9]{2}-[0-9]{3}$"); } if (!isCorrect) { retval.ErrorMessage += "Kod pocztowy jest niepoprawny. "; } return(string.IsNullOrEmpty(retval.ErrorMessage) ? ValidationResult.Success : retval); }
public string getAddress(IAddressViewModel Model) { string retval = string.Empty; if (!string.IsNullOrEmpty(Model.FlatNumber) && !string.IsNullOrEmpty(Model.Street)) { retval = Model.Street + " " + Model.HouseNumber + "/" + Model.FlatNumber + "\r\n" + Model.ZipCode + " " + Model.City; } else if (!string.IsNullOrEmpty(Model.FlatNumber)) { retval = Model.HouseNumber + "/" + Model.FlatNumber + "\r\n" + Model.ZipCode + " " + Model.City; } else if (!string.IsNullOrEmpty(Model.Street)) { retval = Model.Street + " " + Model.HouseNumber + "\r\n" + Model.ZipCode + " " + Model.City; } else { retval = Model.ZipCode + " " + Model.City + ", " + Model.HouseNumber; } return(retval); }
public override Address Map(IAddressViewModel source) => new Address(source.Address1, source.City, new State(source.State), new ZipCode(source.ZipCode), source.Address2);