I'm wondering how to handle a ViewModel
in the traditional sense, which includes both properties and methods, and another "view model" which is simply just the properties -- perhaps the ViewModel would return a this view "entity", or something.
Let me explain:
Domain Model:
public class Workout
{
public int Id { get; set; }
public string Name { get; set; }
public string SomethingElse { get; set; }
public List<Exercise> Exercises { get; set; }
public DateTime CreatedDate { get; set; }
}
View Model:
public class WorkoutHistoryViewModel : IWorkoutHistoryViewModel
{
private IWorkoutRepository workoutRepository;
public WorkoutHistoryViewModel(IWorkoutRepository workoutRepository)
{
this.workoutRepository = workoutRepository;
}
// Here I'd like to return a slimmed down entity, not the full entity
public IEnumerable<WorkoutHistoryViewEntity> GetExistingWorkouts()
{
return this.workoutRepository.GetList(); // some mapping logic
}
}
And perhaps the desired "view entity" would just be:
public class WorkoutHistoryViewEntity
{
public int Id { get; set; }
public string Name { get; set; }
}
I will also need to do something similar for, say, a WorkoutDetailsViewModel
, which will require a different set of properties for its "view model", like:
public class WorkoutDetailsViewEntity
{
public int Id { get; set; }
public string Name { get; set; }
public List<Exercise> Exercises { get; set; }
}
So, I guess the questions are:
- Am I doing MVVM all wrong? Should this ViewModel also have the desired properties on it? If so, then, when I do a
GetExistingWorkouts()
, am I really supposed to return aList<WorkoutHistoryViewModel>
? In that case, I'd have a bunch of objects, all with repositories and methods, when really I just want the data. - If I should create a third class, like the
WorkoutHistoryViewEntity
, what are these typically called (as ViewEntity doesn't really sound right).