예제 #1
0
        public override Task Handle(Message message, CancellationToken arg2)
        {
            var messageString = "";

            if (message.Body != null)
            {
                messageString = Encoding.UTF8.GetString(message.Body);
            }


            var userRetrieved = JsonConvert.DeserializeObject <UserRetrievedMessage>(messageString);

            if (userRetrieved.AreRestrictionsSet)
            {
                GetProductsRequest request = new GetProductsRequest()
                {
                    StoreName = "Los Angeles - Pasadena"
                };

                var response = _storeCatalogService.GetProducts(request).Result;

                _serviceBus.AddToMessageList(new ShowProductsListMessage()
                {
                    Products = response.ConvertToMessageProduct(response.Products, this.RequesterId)
                }, "ShowProductsList");
                _serviceBus.SendMessagesAsync("UICommand");
            }
            else
            {
                _serviceBus.AddToMessageList(new ShowFoodRestrictionsFormMessage()
                {
                    UserId = userRetrieved.UserId, RequesterId = this.RequesterId
                }, "ShowFoodRestrictionsForm");
                _serviceBus.SendMessagesAsync("UICommand");
            }

            return(Task.CompletedTask);
        }
예제 #2
0
 public IActionResult PostOrder([FromBody] CreateOrderRequest request, CancellationToken cancellationToken)
 {
     try
     {
         _serviceBus.AddToMessageList(request.ConvertToNewOrderMessage(), "8048e9ec-80fe-4bad-bc2a-e4f4a75c834e");
         _serviceBus.SendMessagesAsync("NewOrder");
         return(Ok("Order posted"));
     }
     catch (Exception ex)
     {
         //log
         return(StatusCode(StatusCodes.Status400BadRequest, string.Format("Error trying to post order: {0}", ex.Message)));
     }
 }
예제 #3
0
        public override Task Handle(Message message, CancellationToken arg2)
        {
            var messageString = "";

            if (message.Body != null)
            {
                messageString = Encoding.UTF8.GetString(message.Body);
            }

            //TODO: be more generic
            var storeCatalogReady = JsonConvert.DeserializeObject <StoreCatalogReadyMessage>(messageString);

            if (storeCatalogReady.Ready)
            {
                STORE_ID = storeCatalogReady.StoreId;
                _uiServiceBus.AddToMessageList(new ShowWelcomePageMessage(), "ShowWelcomePage");
                _uiServiceBus.SendMessagesAsync("UICommand");
            }

            return(Task.CompletedTask);
        }