public async Task <OrderResponse> CreateOrderAsync(CreateOrder createOrder)
        {
            var newOrder = _mapper.Map <Order>(createOrder);

            var created = await _repo.CreateOrderAsync(newOrder);

            if (!created)
            {
                return(null);
            }

            return(await GetOrderByIdAsync(newOrder.Id));
        }
        public async Task <OrderReadDto> Handle(CreateOrderCommand request, CancellationToken cancellationToken)
        {
            var newOrder = _mapper.Map <Order>(request.OrderDto);

            var result = await _orderRepo.CreateOrderAsync(newOrder);

            if (result == null)
            {
                throw new ArgumentNullException(nameof(newOrder));
            }

            return(_mapper.Map <OrderReadDto>(newOrder));
        }
示例#3
0
        public async Task <ActionResult> Create(OrderVM vm)
        {
            //if (ModelState.IsValid)
            //{
            try
            {
                if (!await _orderRepo.CreateOrderAsync(vm.Order, vm.SelectedPizzasString))
                {
                    throw new Exception();
                }
                return(RedirectToAction(nameof(Index)));
            }
            catch
            {
                return(View(new OrderVM(vm.Order, _orderRepo, _pizzaRepo)));

                throw;
            }
            //}
            //else return View(vm.Order);
        }
示例#4
0
        public async Task <ActionResult <OrderDTO> > CreatePizzaAsync([FromBody] Order order)
        {
            try
            {
                if (order == null)
                {
                    _logger.LogInformation("Pizza object bevat niks");
                    BadRequest();
                }
                await _ordersRepo.CreateOrderAsync(order, null);

                //_logger.LogWarning("Pizza already exist");
                //return Conflict(new { message = $"An existing record with the name '{pizza.Name}' was already found." });


                return(CreatedAtAction(nameof(getOrder), new { id = order.OrderId }, order));
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message);
                throw ex;
            }
        }