Skip to content

Instantly share code, notes, and snippets.

@erichexter
Last active August 29, 2015 14:25
Show Gist options
  • Save erichexter/f54c86f2d878377ac16b to your computer and use it in GitHub Desktop.
Save erichexter/f54c86f2d878377ac16b to your computer and use it in GitHub Desktop.
Example Of CQS to keep framework entry classes light.
namespace QS.Admin.Controllers
{
public class BusinessesController : CommandQueryControllerBase
{
private IRepository _repository;
public BusinessController(IRepository repository){
_repository=repository;
}
public ActionResult Index()
{
try{
var businesses = _repository.GetAll<Business>().ToList().AsEnumerable());
var model = businesses.Select(b => b.AsListingViewModel());
return View(model.ToArray());
}
catch(Exception ex)
{
Logging.Exception(ex);
ViewData["errormessage"]="Unable to retrieve businesses";
}
return View(new BusinessListingViewModel[0]);
}
}
}
namespace QS.Admin.Controllers
{
public class BusinessesController : CommandQueryControllerBase
{
public ActionResult Index()
{
var response = Query(new GetBusinessesQuery());
if (response.Success())
{
var model = response.Result.Select(b => b.AsListingViewModel());
return View(model.ToArray());
}
return View(new BusinessListingViewModel[0]);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment