I currently have a repository based on Entity Framework v4 entities (CRUD and GET operations implemented). I'm in the process of creating the corresponding View Models for these entities. Where should I put the conversion/mapping between them? In the controller or modify the repository to perform the mapping in its methods and return back (or accept) the View Model typed objects?
Should I do this
public ActionResult Index()
{
var person = new PersonRepository().Get();
var personViewModel = new PersonViewModel();
personViewModel.InjectFrom(person)
.InjectFrom<CountryToLookup>(person);
return View(personViewModel);
}
or this
public ActionResult Index()
{
var personViewModel = new PersonRepository().Get(); // returns object of type PersonViewModel
// and move this to repository
// var personViewModel = new PersonViewModel();
// personViewModel.InjectFrom(person)
// .InjectFrom<CountryToLookup>(person);
return View(personViewModel);
}