Beispiel #1
0
        public async Task UpdateMenuItem(RestaurantsMenu menuItem)
        {
            var     currentMenuItem      = restaurantsDbContext.RestaurantsMenu.Single(mi => mi.Id == menuItem.Id);
            decimal?currentMenuItemPrice = currentMenuItem.Price;

            currentMenuItem.Description  = menuItem.Description;
            currentMenuItem.IdDishType   = menuItem.IdDishType;
            currentMenuItem.IdRestaurant = menuItem.IdRestaurant;
            currentMenuItem.Name         = menuItem.Name;
            currentMenuItem.Price        = menuItem.Price;
            currentMenuItem.Promo        = menuItem.Promo;

            await restaurantsDbContext.SaveChangesAsync();

            if (menuItem.Price.Value != currentMenuItemPrice.Value)
            {
                var priceChangedEvent = new PriceChangedEvent
                {
                    itemId       = menuItem.Id,
                    restaurantId = menuItem.IdRestaurant,
                    newPrice     = menuItem.Price.Value
                };

                restaurantEventManager.ProductPriceChanged(priceChangedEvent);
            }
        }
        private ExistingFlight GetDiscount(ExistingFlight existingFlight, int luckyNumber)
        {
            if (random.Next(1, 10) == luckyNumber)
            {
                existingFlight.Price *= _discound;

                PriceChangedEvent?.Invoke();
            }

            return(existingFlight);
        }
        public void ProductPriceChanged(PriceChangedEvent priceChanged)
        {
            IBasicProperties props = _channel.CreateBasicProperties();

            props.Type = nameof(PriceChangedEvent);

            var body = MessageSerializationHelper.SerializeObjectToBin(priceChanged);

            _channel.BasicPublish(exchange: string.Empty,
                                  routingKey: ApplicationEvents.BasketQueue,
                                  basicProperties: props,
                                  body: body);
        }
Beispiel #4
0
        public void ProductPriceChanged(PriceChangedEvent priceChanged)
        {
            using (var connection = cFactory.CreateConnection())
                using (var channel = connection.CreateModel())
                {
                    IBasicProperties props = channel.CreateBasicProperties();
                    props.Type = nameof(PriceChangedEvent);

                    var body = MessageSerializationHelper.SerializeObjectToBin(priceChanged);

                    channel.BasicPublish(exchange: string.Empty,
                                         routingKey: ApplicationEvents.BasketQueue,
                                         basicProperties: props,
                                         body: body);
                }
        }
Beispiel #5
0
 private void HandlePriceChangedEvent(PriceChangedEvent 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.newPrice);
             }
         }
     }
 }
 private void OnFuelPriceChange(object sender, PriceChangedEvent e)
 {
     log.Debug("GradesViewModel: Fuel price is changed.Get grades.");
     GetGrades();
 }