Пример #1
0
        public void Subscribe(ICompositionEventsPublisher publisher)
        {
            publisher.Subscribe <ShoppingCartItemsLoaded>(async(@event, request) =>
            {
                var ids = String.Join(",", @event.CartItemsViewModel.Keys);

                var url    = $"http://localhost:5004/api/shopping-cart/products/{ids}";
                var client = new HttpClient();

                var response = await client.GetAsync(url);

                dynamic[] shippingDetails = await response.Content.AsExpandoArray();
                if (shippingDetails == null || shippingDetails.Length == 0)
                {
                    //eventual consitency is making fun of us
                    foreach (var item in @event.CartItemsViewModel.Values)
                    {
                        item.DeliveryEstimate = "not yet available";
                    }
                }
                else
                {
                    foreach (dynamic detail in shippingDetails)
                    {
                        @event.CartItemsViewModel[detail.ProductId].DeliveryEstimate = detail.DeliveryEstimate;
                    }
                }
            });
        }
        public void Subscribe(ICompositionEventsPublisher publisher)
        {
            publisher.Subscribe <ShoppingCartItemsLoaded>(async(@event, request) =>
            {
                var ids = String.Join(",", @event.CartItemsViewModel.Keys);

                var url    = $"http://localhost:5003/api/shopping-cart/products/{ids}";
                var client = new HttpClient();

                var response = await client.GetAsync(url);

                dynamic[] inventoryDetails = await response.Content.AsExpandoArray();
                if (inventoryDetails == null || inventoryDetails.Length == 0)
                {
                    //eventual consitency is making fun of us
                    foreach (var item in @event.CartItemsViewModel.Values)
                    {
                        item.Inventory = "evaluation in progress";
                    }
                }
                else
                {
                    foreach (dynamic detail in inventoryDetails)
                    {
                        @event.CartItemsViewModel[detail.ProductId].Inventory = $"{detail.Inventory} item(s) left in stock";
                    }
                }
            });
        }
Пример #3
0
 public void Subscribe(ICompositionEventsPublisher publisher)
 {
     publisher.Subscribe <TestEvent>((@event, request) =>
     {
         var vm           = request.GetComposedResponseModel();
         vm.AnotherString = "sample";
         return(Task.CompletedTask);
     });
 }
 public void Subscribe(ICompositionEventsPublisher publisher)
 {
     publisher.Subscribe <TestEvent>((@event, request) =>
     {
         var vm = request.GetComposedResponseModel();
         vm.ThisShouldNeverBeAppended = "sample";
         return(Task.CompletedTask);
     });
 }
        public void Subscribe(ICompositionEventsPublisher publisher)
        {
            publisher.Subscribe <AddItemToCartRequested>((@event, request) =>
            {
                @event.RequestData.Add("shipping-product-id", (string)request.HttpContext.GetRouteValue("id"));
                @event.RequestData.Add("shipping-quantity", request.Form["quantity"][0]);

                return(Task.CompletedTask);
            });
        }
Пример #6
0
        public void Subscribe(ICompositionEventsPublisher publisher)
        {
            publisher.Subscribe <AvailableProductsLoaded>(async(@event, request) =>
            {
                var ids = String.Join(",", @event.AvailableProductsViewModel.Keys);

                var url      = $"/api/prices/products/{ids}";
                var response = await _httpClient.GetAsync(url);

                dynamic[] productPrices = await response.Content.AsExpandoArray();

                foreach (dynamic productPrice in productPrices)
                {
                    @event.AvailableProductsViewModel[(int)productPrice.Id].ProductPrice = productPrice.Price;
                }
            });
        }
        public void Subscribe(ICompositionEventsPublisher publisher)
        {
            publisher.Subscribe <AvailableProductsLoaded>(async(@event, request) =>
            {
                var ids = string.Join(",", @event.AvailableProductsViewModel.Keys);

                var url      = $"/api/inventory/products/{ids}";
                var response = await _httpClient.GetAsync(url);

                dynamic[] stockItems = await response.Content.AsExpandoArray();

                foreach (dynamic stockItem in stockItems)
                {
                    @event.AvailableProductsViewModel[(int)stockItem.Id].Inventory = stockItem.Inventory;
                }
            });
        }
Пример #8
0
        public void Subscribe(ICompositionEventsPublisher publisher)
        {
            publisher.Subscribe <AvailableProductsLoaded>(async(@event, request) =>
            {
                var ids = string.Join(",", @event.AvailableProductsViewModel.Keys);

                var url      = $"/api/product-details/products/{ids}";
                var response = await _httpClient.GetAsync(url);

                dynamic[] productDetails = await response.Content.AsExpandoArray();

                foreach (dynamic detail in productDetails)
                {
                    @event.AvailableProductsViewModel[(int)detail.Id].ProductName        = detail.Name;
                    @event.AvailableProductsViewModel[(int)detail.Id].ProductDescription = detail.Description;
                }
            });
        }
        public void Subscribe(ICompositionEventsPublisher publisher)
        {
            publisher.Subscribe <ShoppingCartItemsLoaded>(async(@event, request) =>
            {
                var ids = String.Join(",", @event.CartItemsViewModel.Keys);

                var url    = $"http://localhost:5002/api/product-details/products/{ids}";
                var client = new HttpClient();

                var response = await client.GetAsync(url).ConfigureAwait(false);

                dynamic[] productDetails = await response.Content.AsExpandoArray().ConfigureAwait(false);

                foreach (dynamic detail in productDetails)
                {
                    @event.CartItemsViewModel[detail.Id].ProductName        = detail.Name;
                    @event.CartItemsViewModel[detail.Id].ProductDescription = detail.Description;
                }
            });
        }