public IHttpActionResult PostCustomer(CustomerDto customerDto) { if (!ModelState.IsValid) { BadRequest(); } var dbCustomer = _db.Customers.Add(CustomerDto.MapFromCustomerDto(customerDto, new Customer())); _db.SaveChanges(); customerDto.Id = dbCustomer.Id; return(Created(new Uri($"{Request.RequestUri}/{dbCustomer.Id}"), customerDto)); }
public IHttpActionResult PutCustomer(CustomerDto customerDto) { if (!ModelState.IsValid) { return(BadRequest()); } var dbCustomer = _db.Customers.SingleOrDefault(c => c.Id == customerDto.Id); if (dbCustomer == null) { return(NotFound()); } dbCustomer = CustomerDto.MapFromCustomerDto(customerDto, dbCustomer); _db.SaveChanges(); return(Ok(CustomerDto.MapToCustomersDto(new List <Customer>() { _db.Customers.SingleOrDefault(c => c.Id == dbCustomer.Id) }).Single())); }