public void ProductAvailabilityChanged(ProductAvailabilityChangedEvent productAvailabilityChanged)
        {
            IBasicProperties props = _channel.CreateBasicProperties();

            props.Type = nameof(ProductAvailabilityChangedEvent);

            var body = MessageSerializationHelper.SerializeObjectToBin(productAvailabilityChanged);

            _channel.BasicPublish(exchange: string.Empty,
                                  routingKey: ApplicationEvents.BasketQueue,
                                  basicProperties: props,
                                  body: body);
        }
Exemple #2
0
 private void HandleProductAvailabilityChangedEvent(ProductAvailabilityChangedEvent e)
 {
     using (var scope = _serviceScopeFactory.CreateScope())
     {
         IBasketService basketService = scope.ServiceProvider.GetRequiredService <IBasketService>();
         var            keys          = basketService.GetItems();
         foreach (var key in keys)
         {
             var basket = basketService.GetBasket(int.Parse(key));
             if (basket.Result.restaurantId == e.restaurantId && basket.Result.basketItems.Any(ba => ba.menuItemId == e.itemId))
             {
                 basketService.UpdateItem(int.Parse(key), e.itemId, e.available);
             }
         }
     }
 }
Exemple #3
0
        public async Task DeleteMenuItem(int menuItemId)
        {
            var menuItemToDel = restaurantsDbContext.RestaurantsMenu.Single(rm => rm.Id == menuItemId);

            restaurantsDbContext.RestaurantsMenu.Remove(menuItemToDel);
            await restaurantsDbContext.SaveChangesAsync();


            var productAvailabilityChanged = new ProductAvailabilityChangedEvent
            {
                itemId       = menuItemId,
                available    = false,
                restaurantId = menuItemToDel.IdRestaurant
            };

            restaurantEventManager.ProductAvailabilityChanged(productAvailabilityChanged);
        }
Exemple #4
0
        public void ProductAvailabilityChanged(ProductAvailabilityChangedEvent productAvailabilityChanged)
        {
            using (var connection = cFactory.CreateConnection())
                using (var channel = connection.CreateModel())
                {
                    IBasicProperties props = channel.CreateBasicProperties();
                    props.Type = nameof(ProductAvailabilityChangedEvent);

                    var body = MessageSerializationHelper.SerializeObjectToBin(productAvailabilityChanged);


                    channel.BasicPublish(exchange: string.Empty,
                                         routingKey: ApplicationEvents.BasketQueue,
                                         basicProperties: props,
                                         body: body);
                }
        }
 public Task <AnotherProjection> ProjectEvent(AnotherProjection prevState, ProductAvailabilityChangedEvent @event)
 {
     prevState.Available = @event.Available;
     return(Task.FromResult(prevState));
 }
Exemple #6
0
 private void Apply(ProductAvailabilityChangedEvent @event)
 {
     _available = @event.Available;
 }