public ErrorResultViewModel ComprobarErrores(RegistroViewModel registro) { this.errorResult.details = new List <string>(); if (!FormatValidation.IsValidEmail(registro.Correo)) { this.errorResult.details.Add("El email no tiene un formato valido"); } if (!FormatValidation.IsValidPassword(registro.Contrasena)) { this.errorResult.details.Add("La contraseña no tiene un formato valido"); } if (!FormatValidation.IsValidPhone(registro.Telefono)) { this.errorResult.details.Add("El telefono no tiene un formato valido"); } if (this.errorResult.details.Count == 0) { return(null); } else { this.errorResult.message = "Han ocurrido errores al registrar el usuario"; return(this.errorResult); } }
public static void Initialize() { RegisterProperty(x => x.FirstName) .Validate((t, v, vr) => vr.Error <NotNull>(v), notifyChangeOnValidationError: true) .Validate((t, v, vr) => vr.Error(string.IsNullOrWhiteSpace(v), "Name cannot be empty or whitespace"), notifyChangeOnValidationError: true) .Coerce(name => name.Trim(), name => char.ToUpper(name[0]) + name.Substring(1).ToLower()); RegisterProperty(x => x.LastName) .Validate((t, v, vr) => vr.Error(v != null && string.IsNullOrWhiteSpace(v), "LastName cannot be empty or whitespace"), notifyChangeOnValidationError: true) .Validate((t, v, vr) => vr.Warning(!FormatValidation.IsPersonName(v), "Last names are usually in the same format as first names")) .Coerce(name => name.Trim()); RegisterProperty(x => x.FullName) .DependOn(nameof(FirstName), nameof(LastName)) .Validate((t, v, vr) => vr.Error(string.IsNullOrWhiteSpace(v), "FullName cannot be empty or whitespace")); RegisterProperty(x => x.Age) .DependOn(x => x.Birthdate) .Validate((t, v, vr) => vr.Error(v < 0, "Age cannot be negative")); RegisterProperty(x => x.Email) .Validate((t, v, vr) => vr.Error(string.IsNullOrWhiteSpace(v), "Email cannot be empty or whitespace"), notifyChangeOnValidationError: true) .Validate((t, v, vr) => vr.Error(!FormatValidation.IsValidEmail(v), "Email is in invalid format"), notifyChangeOnValidationError: true) .Coerce(name => name.Trim()); }