public ValidationResult Validate <TModel>(TModel model)
        {
            if (ReferenceEquals(model, null))
            {
                throw new ArgumentNullException(nameof(model));
            }

            var validator = _validationProvider.GetValidator <TModel>();

            return(validator.Validate(model));
        }
 public virtual bool Validate(object item)
 {
     if (_validationProvider != null && _message != null)
     {
         var validator = _validationProvider.GetValidator <T>();
         var value     = item as T;
         if (validator != null && value != null)
         {
             if (validator.IsValid(value))
             {
                 return(true);
             }
             var msg = validator.GetErrorMessages(value);
             _message.ShowUserMessage(SharpQuant.UI.UserMessage.UserMessageCategories.Error, "Validation error", "Entity has some invalid values:\r\n" + string.Join("\r\n", msg));
             return(false);
         }
     }
     return(true);
 }
        public void EditObject <T>(IPropertyEditableObject value) where T : class
        {
            if (value != null)// && value.Action != EPropertyEditAction.None)
            {
                IValidator <T> validator = null;
                if (_validationProvider != null)
                {
                    validator = _validationProvider.GetValidator <T>();
                    if (validator != null)
                    {
                        _validate = () =>
                        {
                            if (validator.IsValid(value.Object as T))
                            {
                                return(true);
                            }
                            var msg = validator.GetErrorMessages(value.Object as T);
                            _message.ShowUserMessage(UserMessageCategories.Error, "Validation error", "Entity has some invalid values:\r\n" + string.Join("\r\n", msg));
                            return(false);
                        };
                    }
                    else
                    {
                        _validate = () => true;
                    }
                }
            }

            if (_editedObject == null || _editedObject.Action == EPropertyEditAction.None)
            {
                goto set_value;
            }
            if (!_editedObject.IsNew && !_editedObject.IsDirty)
            {
                goto set_value;
            }


            try
            {
                if (_editedObject.Action == EPropertyEditAction.Autosave)
                {
                    SaveEditedObject();
                }
                else
                {
                    DialogResult result = _message.ShowUserMessage(UserMessageCategories.YesNo, "Save object", "Do you want to save the changes to the object?");
                    if (result == System.Windows.Forms.DialogResult.OK || result == System.Windows.Forms.DialogResult.Yes)
                    {
                        SaveEditedObject();
                    }
                }
            }
            catch (Exception e)
            {
                throw e;
            }
set_value:
            _editedObject = value;
            propertyGrid.SelectedObject = (_editedObject == null) ? null : _editedObject.Object;
            CheckDBSaveStatus();
            return;
        }