Skip to content

Instantly share code, notes, and snippets.

@jmarnold
Created June 4, 2010 19:13
Show Gist options
  • Save jmarnold/425824 to your computer and use it in GitHub Desktop.
Save jmarnold/425824 to your computer and use it in GitHub Desktop.
public class RenderEntityDetailsAction<TEntity, TRequestModel, TDetailsModel>
where TEntity : class
where TRequestModel : class
where TDetailsModel : class
{
private readonly IEntityService _entityService;
private readonly IMappingRegistry _mappingRegistry;
public RenderEntityDetailsAction(IEntityService entityService, IMappingRegistry mappingRegistry)
{
_mappingRegistry = mappingRegistry;
_entityService = entityService;
}
public TDetailsModel Get(TRequestModel requestModel)
{
var entity = _entityService.Get<TEntity>(requestModel);
if (entity == null)
{
throw new EntityNotFoundException<TEntity>(string.Format("{0} could not be found.", typeof(TEntity).Name));
}
return _mappingRegistry.Map<TEntity, TDetailsModel>(entity);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment