5
\$\begingroup\$

I have a Winforms MVP application where I need to use the ErrorProvider on the view. I have added the following methods to my presenter to allow me to show the ErrorProvider but it just doesn't feel right. Please review my code and tell me if you think there is a more efficient way of carrying out the validation.

private bool IsValid(string sender)
{
    bool isValid = true;

    ResetValidation();

    //FilePath Validation
    if(!ValidationService.StringHasValue(_view.FilePath))
    {
        _view.SetFilePathErrorMessage(Messages.FieldRequired);
        isValid = false;
    }

    if (sender == "OnImportClicked") return isValid;

    //BatchRef Validation
    if (!ValidationService.StringHasValue(_view.BatchRef.ToString()))
    {
        _view.SetBatchRefErrorMessage(Messages.FieldRequired);
        isValid = false;
    }

    //Transfer Validaion
    if(!_transferredToHoldingTable)
    {
        _view.SetTransferErrorMessage(Messages.NoRawData);
        isValid = false;
    }

    return isValid;
}

private void ResetValidation()
{
    _view.SetFilePathErrorMessage(string.Empty);
    _view.SetBatchRefErrorMessage(string.Empty);
    _view.SetTransferErrorMessage(string.Empty);
}
\$\endgroup\$

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.