Skip to content

Instantly share code, notes, and snippets.

@aramkoukia
Created January 20, 2018 23:39
Show Gist options
  • Save aramkoukia/2c0e9600650f32ed2ffd6328d9c5e31f to your computer and use it in GitHub Desktop.
Save aramkoukia/2c0e9600650f32ed2ffd6328d9c5e31f to your computer and use it in GitHub Desktop.
Read Model Product Controller
using System;
using System.Web.Http;
using MicroServices.Common.Exceptions;
namespace Products.ReadModels.Service.Controllers
{
public class ProductsController : ApiController
{
[HttpGet]
public IHttpActionResult Get(Guid id)
{
var view = ServiceLocator.ProductView;
try
{
var dto = view.GetById(id);
return Ok(dto);
}
catch (ReadModelNotFoundException)
{
return NotFound();
}
}
[HttpGet]
public IHttpActionResult Get()
{
var view = ServiceLocator.ProductView;
var result = view.GetAll();
return Ok(result);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment