示例#1
0
        public async Task <IActionResult> Delete([FromBody] CancelOrderDTO request)
        {
            if (!ModelState.IsValid)
            {
                BadRequest("Bad request");
            }

            if (!string.IsNullOrWhiteSpace(request.OrderIds.FirstOrDefault()))
            {
                foreach (var orderId in request.OrderIds)
                {
                    var order = await _context.Orders.Where(x => x.IsActive && x.Id.ToString() == orderId).FirstOrDefaultAsync();

                    if (order != null)
                    {
                        order.IsActive = false;
                        _context.Update(order);
                        await _context.SaveChangesAsync();
                    }
                    else
                    {
                        return(BadRequest("There's no active order with that Id."));
                    }
                }
            }

            return(Ok(new { canceledOrders = request.OrderIds }));
        }
示例#2
0
        public async Task <ActionResult <Result> > CancelOrderAsync([FromBody] CancelOrderDTO cancelOrderDTO)
        {
            var command = new CancelOrderCommand(cancelOrderDTO.OrderNumber);

            var commandResult = await _mediator.Send(command);

            if (commandResult.IsFailure)
            {
                return(BadRequest());
            }

            return(Ok());
        }