Пример #1
0
        public async Task <IActionResult> PostAsync(int customerId, [FromBody] SaveCustomerOrderResource resource)
        {
            var customer = await _customerOrderService.FindCustomerAsync(customerId);


            if (customer == null)
            {
                return(NotFound());
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState.GetErrorMessages()));
            }

            var order = _mapper.Map <SaveCustomerOrderResource, Order>(resource);
            //public Discount discount;


            var result = await _customerOrderService.SaveAsync(customerId, order, customer, discount);

            if (!result.Success)
            {
                return(BadRequest(result.Message));
            }


            var customerOrderResource = _mapper.Map <Order, CustomerOrderResource>(result.Order);

            return(Ok(customerOrderResource));
        }