I'm wondering: how complex a mapper abstraction can be?
Let's say I have a controller's action
ActionResult Find(QueryInputModel query)
with the model looks like this
class QueryInputModel
{
public string Text {get;set;}
public IEnumerable<string> RegionCodes {get;set;}
}
Among other things, it's the action's responsibility to turn an input model into a view model
class QueryViewModel
{
public string Text {get;set;}
public IEnumerable<Region> Regions {get;set;}
}
class Region
{
public string Name {get;set;}
public string Code {get;set;}
}
where region names in a view model should be taken from db using the codes in a input model.
Right now it's done by the QueryMapper.Map(src)
method which looks like this
public QueryViewModel Map(QueryInputModel source)
{
var regions = regionRepository.Get(source.RegionCodes);
var result = new QueryViewModel {Text=source.Text, Regions=regions};
}
Is it correct to call such an abstraction a Mapper? Is it OK to have straight-forward mapping and db querying mixed in a single method?