public CustomerDTO PostCustomer(Customer customer) { var outgoing = WebOperationContext.Current.OutgoingResponse; outgoing.SetStatusAsCreated(BuildCustomerUri(customer)); return MapCustomer(customer); }
private CustomerDTO MapCustomer(Customer customer) { return new CustomerDTO { Self = BuildCustomerUri(customer), Organisation = customer.Organisation, Invoices = BuildInvoiceUris(customer).ToList() }; }
private IEnumerable<Uri> BuildInvoiceUris(Customer customer) { if (customer.Invoices != null) { foreach (var invoice in customer.Invoices) { yield return BuildInvoiceUri(customer, invoice); } } }
private Uri BuildCustomerUri(Customer customer) { return new Uri(WebOperationContext.Current.IncomingRequest.UriTemplateMatch.BaseUri, "customers/" + customer.Organisation); }
private Uri BuildInvoiceUri(Customer customer, Invoice invoice) { return new Uri(WebOperationContext.Current.IncomingRequest.UriTemplateMatch.BaseUri, "customers/" + customer.Organisation + "/invoices/" + invoice.Id); }