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

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.