示例#1
0
        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))));
        }
示例#2
0
        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)));
        }