I have a question regarding organization of properties in viewModel. As far as I understand the viewmodel should be as simple as possible, and the main thing that it should do is bind data to view.
The question is how to distinguish properties in viewmodel from BL model. I mean for example I have a BL model like :
public class UserDetailsModel
{
public string UserName {get;set;}
public string SomeInfo{get;set;}
public string AnotherInfo{get;set;}
public string Anything{get;set;}
public string Something {get;set;}
...
}
then I have another BL model say:
public class UserInfoModel
{
public string Info1{get;set;}
public string Info2{get;set;}
public string Info3{get;set;}
public string Info4{get;set;}
public string Info5 {get;set;}
...
}
Now the question is what is the best practices to Create ViewModel that should have data of both BL models.
1) Duplicate the properties from 2 models , and use Default Model binding to transfer data from view to controller , then create BL models from ViewModels and via repository update data ? In this case we have code duplication ...
2) ViewModel should look something like:
public class UsersIdentificationViewModel
{
public UsersIdentificationViewModel()
{
UserInfoModel = new UserInfoModel();
}
public UserInfoModel UsersInfo { get; set; }
public UserDetailsModel UserDetails { get; set; }
}
The default binding will not work in this case (Correct me if I am mistaking) and I should write custom Model binder or something like this... What approach is better for unit testing , or maybe there is another approach ?