Exemplo n.º 1
0
        public async Task <ActionResult <OrderDto> > CreateOrderForCustomer(int customerID, OrderForCreateDto orderForCreateDto)
        {
            //Change status to waiting for treatment of order
            orderForCreateDto.StatusID = 1;
            _orm.OpenConn();
            if (!await _orm.CustomerExist(customerID))
            {
                return(NotFound());
            }
            Order orderFromDB = _mapper.Map <Order>(orderForCreateDto);

            orderFromDB.CustomerID = customerID;
            Order result = await _orm.CreateOrderAndOrderLines(orderFromDB);

            OrderDto orderDto = _mapper.Map <OrderDto>(result);
            await _orm.CloseConn();

            return(CreatedAtRoute("GetOrder", new { customerID = customerID, orderID = orderDto.Ordernumber }, orderDto));
        }