Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seangwright/6ca5f6980c5e75b9b59e37d2c83063c2 to your computer and use it in GitHub Desktop.
Save seangwright/6ca5f6980c5e75b9b59e37d2c83063c2 to your computer and use it in GitHub Desktop.
public class ProductsController : Controller
{
private readonly IProductsQuery productsQuery;
private readonly IProductDetailQuery productDetailQuery;
public ProductsController(
IProductsQuery productsQuery,
IProductDetailQuery productDetailQuery)
{
// ...
}
[HttpGet]
public ActionResult Index() =>
View(new ProductIndexViewModel(productsQuery.Execute()));
[HttpGet]
public ActionResult Detail(int productId)
{
var product = productDetailQuery.Execute(productId);
return product is null
? new HttpNotFoundResult($"Product with Id {productId}")
: View(new ProductDetailViewModel(product));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment