Exemplo n.º 1
0
        public static Order ToModel(this UpdateOrderStatusCommand command)
        {
            var result = new Order
            {
                Id          = command.Id,
                CustomerId  = command.CustomerId,
                OrderNumber = command.OrderNumber,
                Total       = command.Total,
                CreatedDate = DateTime.Now,
                Status      = Enum.TryParse(command.Status, out OrderStatus orderStatus) ? orderStatus : 0
            };

            return(result);
        }
        public async Task <ActionResult <GenericCommandResult> > UpdateStatus(
            [FromBody] UpdateOrderStatusCommand command,
            [FromServices] OrderHandler handler,
            [FromServices] CouponHandler couponHandler
            )
        {
            var result = (GenericCommandResult)handler.Handle(command);
            var order  = (Order)result.Data;

            if (result.Success && order.Status.Equals("mercadoria devolvida", StringComparison.OrdinalIgnoreCase))
            {
                couponHandler.Handle(new CreateExchangeCouponCommand(order.CustomerId, order.ExchangedMerchandise));
            }
            return(Ok(result));
        }
        public async Task <IActionResult> UpdateOrderStatus([FromRoute] int id, [FromRoute] string status, [FromBody] UpdateOrderStatusCommand command)
        {
            if (id != command.Id)
            {
                return(BadRequest());
            }

            command.Status = status;
            var result = await _mediator.Send(command);

            return(Ok(result));
        }