/// <summary> /// Creates a Customer in the Database /// </summary> /// <param name="customer"></param> /// <returns></returns> public HttpResponseMessage Post(CustomerDto customerDto) { try { var customer = new CustomerConverter().Convert(customerDto); facade.GetCustomerRepository().Add(customer); var response = Request.CreateResponse<CustomerDto>(HttpStatusCode.Created, customerDto); var uri = Url.Link("GetCustomerById", new { customer.Id }); response.Headers.Location = new Uri(uri); return response; } catch (Exception) { var response = new HttpResponseMessage(HttpStatusCode.Conflict) { Content = new StringContent("Could not add a customer to the database") }; throw new HttpResponseException(response); } }
/// <summary> /// Updates a Customer in Database /// </summary> /// <param name="customer"></param> /// <returns></returns> public HttpResponseMessage Put(CustomerDto customerDto) { try { Customer customer = new CustomerConverter().Convert(customerDto); facade.GetCustomerRepository().Edit(customer); var response = Request.CreateResponse<CustomerDto>(HttpStatusCode.OK, customerDto); var uri = Url.Link("GetCustomerById", new { customer.Id }); response.Headers.Location = new Uri(uri); return response; } catch (Exception) { var response = new HttpResponseMessage(HttpStatusCode.Conflict) { Content = new StringContent("No matching customer") }; throw new HttpResponseException(response); } }