public async Task <ActionResult <IEnumerable <OrderRepresentation> > > FindOrders([FromRoute] string customerId) { var customer = await this._customers.GetByIdAsync(customerId); var orders = customer.Orders; return(this.Ok(orders.Select(d => OrderRepresentation.FromEntity(d)))); }
public async Task <ActionResult <OrderRepresentation> > CreateOrder([FromRoute] string customerId, [FromBody] OrderSpecification spec) { var customer = await this._customers.GetByIdAsync(customerId); var order = await this._orders.AddAsync(customer, spec.Description, spec.Date); foreach (OrderLineSpecification line in spec.Lines) { Product product = await this._products.GetByIdAsync(line.ProductId); this._orders.AddLine(order, product, line.Amount); } return(this.Ok(OrderRepresentation.FromEntity(order))); }