Example #1
0
        private bool Validate(IValidatableObject product)
        {
            var results = ObjectValidator.TryValidateObject(product);

            if (results.Count() > 0)
            {
                foreach (var result in results)
                {
                    MessageBox.Show(this, result.ErrorMessage, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                ;
                return(false);
            }
            ;
            return(true);
        }
Example #2
0
        private void OnSave(object sender, EventArgs e)
        {
            if (!ValidateChildren())
            {
                return;
            }
            ;

            var product = new Product()
            {
                Id             = Product?.Id ?? 0,
                Name           = _txtName.Text,
                Description    = _txtDescription.Text,
                Price          = GetPrice(_txtPrice),
                IsDiscontinued = _chkDiscontinued.Checked,
            };

            var results = ObjectValidator.TryValidateObject(product);

            Product      = product;
            DialogResult = DialogResult.OK;
            Close();
        }