Example #1
0
        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));
        }
Example #2
0
        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 })));
        }
Example #3
0
        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();
            }
        }