public int Save(Supplier obj, ref ValidationError validationError) { var validatorResults = _validator.Validate(obj); if (!validatorResults.IsValid) { foreach (var failure in validatorResults.Errors) { validationError.Message = failure.ErrorMessage; validationError.PropertyName = failure.PropertyName; return(0); } } return(Save(obj)); }
public (bool isValid, IEnumerable <ValidationResult> errors) Validate() { var validator = new SupplierValidator(); var result = validator.Validate(this); if (result.IsValid) { return(true, null); } return(false, result.Errors.Select(item => new ValidationResult(item.ErrorMessage, new [] { item.PropertyName }))); }
public void SaveData() { SupplierModel currentData = new SupplierModel(); currentData.Name = Name; currentData.Address = Address; currentData.ContactNumber = ContactNumber; SupplierValidator validator = new SupplierValidator(); ValidationResult result = validator.Validate(currentData); if (result.IsValid == false) { string errorMessage = (String.Join(Environment.NewLine + " • ", result.Errors.Select(error => error.ErrorMessage))); universalHelper.MessageDialog("Saving of data failed!", " • " + errorMessage); return; } else { helper.SaveItem(currentData); ClearFields(); } }