示例#1
0
        public async Task <IActionResult> Create([FromBody] OrderCreateViewModel order)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }

                var success = await _domainService.Create(new Order
                {
                    UserId     = order.UserId,
                    OrderItems = order.OrderItems.Select(x => new OrderItem
                    {
                        ProductId    = x.ProductId,
                        Amount       = x.Amount,
                        CurrentPrice = x.CurrentPrice
                    }).ToList()
                });

                if (success)
                {
                    return(Ok("Order created."));
                }
                else
                {
                    return(NotFound("User or product not found."));
                }
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
示例#2
0
 public async Task <GetOrderOutput> Create(CreateOrderInput input)
 {
     return(await _orderDomainService.Create(input));
 }