I want to check the data provided by the user before taking them into processing. My user interfaces have text fields, mostly combos. In some fields, the user must provide data, in some fields only a certain type of data can be accepted, such as texts, dates / times, numbers, etc. When it comes to date / time, we need to check if the values ββprovided are in the acceptable range.
My question
Q1. Where to do validation in the MVP template?
My parameters
- Implement validation as a service available to presenters. (Via DI for example).
- Make a check in the user interface itself in an event such as KeyPress.
- The host himself processes the check.
Q2. How to check.
My parameters
I am. All controllers, such as text fields in a view, are encapsulated in properties (Getters / Setters)
public string Age
{
get { return txtAge.Text; }
set { txtAge.Text = value; }
}
II. UI fires Validate event (sender, e)
III. The host listens and connects it to the handler, which then calls the Validate () method
IV. In the Validate () method, it will detect that the controller raised the event (sender) and read the corresponding property to get the value in the controller.
v. He then checks the type for the type of model and determines the expiration date, and then alerts the user
The problem is that I may have to expose all the controllers using string properties, as other wise ones will throw exceptions when the user enters an invalid type.
If I do something like this
public int Age
{
get { return Convert.ToInt32(txtAge.Text); }
set { txtAge.Text = Convert.ToString(value); }
}
Then the problem would be that the host cannot check as already converted to int?