コード例 #1
0
        public override Task <OrderResponse> SubmitOrder(OrderRequest request, grpc::ServerCallContext context)
        {
            Console.WriteLine("Handling Order Request Submission");
            var response = new OrderResponse();

            if (!isValidRequest(request))
            {
                response.Accepted = false;
                return(Task.FromResult(response));
            }

            var evt = OrderAcceptedEvent.FromProto(request);

            if (eventEmitter.EmitOrderAcceptedEvent(evt))
            {
                foreach (var li in evt.LineItems)
                {
                    var reservedEvent = new InventoryReservedEvent
                    {
                        OrderID    = evt.OrderID,
                        ReservedOn = (ulong)DateTime.UtcNow.Ticks,
                        SKU        = li.SKU,
                        Quantity   = li.Quantity,
                        UserID     = evt.UserID
                    };
                    if (!eventEmitter.EmitInventoryReservedEvent(reservedEvent))
                    {
                        response.Accepted = false;
                        return(Task.FromResult(response));
                    }
                }
                response.OrderID  = evt.OrderID;
                response.Accepted = true;
            }
            else
            {
                response.Accepted = false;
            }
            return(Task.FromResult(response));
        }