I need to write a small tool which makes use of the MVVM pattern and WPF. Basically this tool shall perform the following tasks:
- Take a username and password from the GUI.
- Read rows with data from an external CSV file.
- Perform SOAP calls to an external webservice with the data read from the CSV.
The following data are used during the above (all strings):
- Data read from GUI
- Username
- Password
- Data read from CSV
- ID
- Description
Neither will the data from the CSV file ever be displayed in the GUI nor will the application store any data in a file, database, etc. It’s just a “connector”. Now, what should go into the model? Or do I need one at all in this case?
class MyData {
private string id;
private string description;
public string Id {
get { return id; }
set { id = value; }
}
public string Description {
get { return description; }
set { description= value; }
}
}
Note:
This question relates to my previous question: What is the model in MVVM for?
The model consists of the POCOs used to represent the data as objects, and the logic to retrieve the data.
The viewmodel is responsible for holding the subset of data specific to its purpose.
That means, reading from CSV is done in the Model (ViewModels shouldn’t even be aware there is a CSV involved), and the data read should be stored into objects defined in the Model as well (POCOs).
The viewmodels can then fetch whatever subset of data they require from the model.
If the app requires persistency, the viewmodels push back the POCOs that were modified to the model, that is then responsible for updating the CSV.