public override async Task <CommandExecutionResult> Execute(OrderDetailsCommand command)
        {
            Console.WriteLine($"Incoming request for order details for id = {command.OrderId}");
            if (command.OrderId <= 0)
            {
                return(CommandExecutionResult.ValidationFailure($"Invalid order ID: {command.OrderId}"));
            }

            Console.WriteLine("Getting order details...");
            var orderDetails = OrderDetailsRepo.Get(command.OrderId);

            Console.WriteLine("Ready.");

            return(CommandExecutionResult.Ok(orderDetails));
        }
Exemple #2
0
        public async Task <CommandExecutionResult> Execute(string commandBody)
        {
            var command = await Parse(commandBody);

            if (command == null)
            {
                return(CommandExecutionResult.NotRecognized());
            }

            if (_validator != null)
            {
                var(success, errors) = _validator.Validate(command);
                if (!success)
                {
                    return(CommandExecutionResult.ValidationFailure(string.Join("; ", errors)));
                }
            }

            return(await Execute(command));
        }
Exemple #3
0
        public override async Task <CommandExecutionResult> Execute(PostProcessOrderCommand command)
        {
            if (command.OrderId <= 0)
            {
                return(CommandExecutionResult.ValidationFailure($"Invalid order ID: {command.OrderId}"));
            }

            var orderId = command.OrderId;

            Console.WriteLine($"Post-process order id = {orderId}");

            Console.WriteLine("Getting order details...");
            var orderDetailsResult = await _web1.GetOrderDetails(orderId);

            if (orderDetailsResult.Status != SendStatus.Success || orderDetailsResult.Result == null)
            {
                Console.WriteLine("Getting order details failed.");
                return(CommandExecutionResult.Failure(orderDetailsResult.ErrorMessage, orderDetailsResult.ErrorReason));
            }

            var orderDetails = orderDetailsResult.Result;

            Console.WriteLine($"Retrieved order details: user is (id {orderDetails.UserId}, name {orderDetails.UserName}), order amount is {orderDetails.Amount}, created on {orderDetails.DateCreated}");

            Console.WriteLine($"Pass order details to Azure Functions HTTP microservice...");

            var captureResult = await _azureFunctionsHttpServiceClient.CaptureOrder(orderDetails.OrderId, orderDetails.UserName);

            if (captureResult.Status != SendStatus.Success)
            {
                Console.WriteLine($"Calling Azure Functions microservice failed: {captureResult.ErrorMessage}");
            }
            else
            {
                Console.WriteLine($"Azure Functions microservice replied: '{captureResult.Result.Message}'");
            }

            return(CommandExecutionResult.Ok());
        }