Last active
August 29, 2015 14:25
-
-
Save erichexter/f54c86f2d878377ac16b to your computer and use it in GitHub Desktop.
Example Of CQS to keep framework entry classes light.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]); | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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