Skip to content

Instantly share code, notes, and snippets.

@aramkoukia
Created January 21, 2018 22:38
Show Gist options
  • Select an option

  • Save aramkoukia/bdff6acfc561bbccde03857353129668 to your computer and use it in GitHub Desktop.

Select an option

Save aramkoukia/bdff6acfc561bbccde03857353129668 to your computer and use it in GitHub Desktop.
Orders Controller
using System;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using Sales.Service.DataTransferObjects.Commands;
using Sales.Service.MicroServices.Order.Commands;
namespace Sales.Service.Controllers
{
public class OrdersController : ApiController
{
[HttpPost]
public IHttpActionResult Post(PlaceOrderCommand cmd)
{
if (Guid.Empty.Equals(cmd.Id))
{
var response = new HttpResponseMessage(HttpStatusCode.Forbidden) {
Content = new StringContent("order information must be supplied in the POST body"),
ReasonPhrase = "Missing Order Id"
};
throw new HttpResponseException(response);
}
var command = new StartNewOrder(cmd.Id, cmd.ProductId, cmd.Quantity);
try
{
ServiceLocator.OrderCommands.Handle(command);
var link = new Uri(string.Format("http://localhost:8182/api/orders/{0}", command.Id));
return Created(link, command);
}
catch (ArgumentException argEx)
{
return BadRequest(argEx.Message);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment