// GET /api/customers/1
public IHttpActionResult GetCustomers(int id)
{
var customer = _context.Customers.SingleOrDefault(c => c.Id == id);
if (customer == null)
{
return NotFound();
}
return Ok(Mapper.Map<Customer, CustomerDto>(customer));
}
// POST /api/customers
[HttpPost]
public IHttpActionResult CreateCustomers(CustomerDto customerDto)
{
if (!ModelState.IsValid)
{
return BadRequest();
}
var customer = Mapper.Map<CustomerDto, Customer>(customerDto);
_context.Customers.Add(customer);
_context.SaveChanges();
customerDto.Id = customer.Id;
return Created(new Uri(Request.RequestUri + "/" + customer.Id), customer);
}