Ejemplo n.º 1
0
        public async Task RiderRatingChanged(int idRider, decimal newRating)
        {
            var newRatingEvt = new RiderRatingChangedEvent
            {
                IdRider = idRider
            };

            using (var scope = _serviceScopeFactory.CreateScope())
            {
                IReviewService reviewService = scope.ServiceProvider.GetRequiredService <IReviewService>();

                var riderReviews = await reviewService.GetRiderReviews(idRider);

                newRatingEvt.newAverageRating = riderReviews.Sum(rw => rw.Rating) / riderReviews.Count();
            }

            IBasicProperties props = _channel.CreateBasicProperties();

            props.Type = nameof(RiderRatingChangedEvent);

            var body = MessageSerializationHelper.SerializeObjectToBin(newRatingEvt);

            _channel.BasicPublish(exchange: string.Empty,
                                  routingKey: ApplicationEvents.DeliveryQueue,
                                  basicProperties: props,
                                  body: body);
        }
Ejemplo n.º 2
0
        public async Task RestaurantRatingChanged(int idRestaurant, decimal newRating)
        {
            var newRatingEvt = new RatingChangedEvent
            {
                idRestaurant = idRestaurant
            };

            using (var scope = _serviceScopeFactory.CreateScope())
            {
                IReviewService reviewService = scope.ServiceProvider.GetRequiredService <IReviewService>();

                var restaurantReviews = await reviewService.GetRestaurantReviews(idRestaurant);

                newRatingEvt.averageRating = restaurantReviews.Sum(rw => rw.Rating) / restaurantReviews.Count();
            }

            using (var connection = cFactory.CreateConnection())
                using (var channel = connection.CreateModel())
                {
                    IBasicProperties props = channel.CreateBasicProperties();
                    props.Type = nameof(RatingChangedEvent);

                    var body = MessageSerializationHelper.SerializeObjectToBin(newRatingEvt);

                    channel.BasicPublish(exchange: string.Empty,
                                         routingKey: ApplicationEvents.RestaurantQueue,
                                         basicProperties: props,
                                         body: body);
                }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Pubblica l'evento "Presa in consegna da rider" su coda Order
        /// </summary>
        /// <param name="deliveryPickedUp">Dati del messaggio</param>
        public void DeliveryPickedUp(DeliveryPickedUpEvent deliveryPickedUp)
        {
            IBasicProperties props = _channel.CreateBasicProperties();

            props.Type = nameof(DeliveryPickedUpEvent);
            var body = MessageSerializationHelper.SerializeObjectToBin(deliveryPickedUp);

            _channel.BasicPublish(exchange: string.Empty,
                                  routingKey: ApplicationEvents.OrderQueue,
                                  basicProperties: props,
                                  body: body);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Pubblica l'evento "Ordine Accettato da gestore" su coda Delivery
        /// </summary>
        /// <param name="orderRejected">Dati del messaggio</param>
        public void OrderAccepted(OrderAcceptedEvent orderAccepted)
        {
            IBasicProperties props = _channel.CreateBasicProperties();

            props.Type = nameof(OrderAcceptedEvent);
            var body = MessageSerializationHelper.SerializeObjectToBin(orderAccepted);

            _channel.BasicPublish(exchange: string.Empty,
                                  routingKey: ApplicationEvents.DeliveryQueue,
                                  basicProperties: props,
                                  body: body);
        }
Ejemplo n.º 5
0
        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);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Pubblica l'evento "Ordine Accettato da gestore" su coda Delivery
        /// </summary>
        /// <param name="orderRejected">Dati del messaggio</param>
        public void OrderAccepted(OrderAcceptedEvent orderAccepted)
        {
            using (var connection = _factory.CreateConnection())
                using (var channel = connection.CreateModel())
                {
                    IBasicProperties props = channel.CreateBasicProperties();
                    props.Type = nameof(OrderAcceptedEvent);
                    var body = MessageSerializationHelper.SerializeObjectToBin(orderAccepted);

                    channel.BasicPublish(exchange: string.Empty,
                                         routingKey: ApplicationEvents.DeliveryQueue,
                                         basicProperties: props,
                                         body: body);
                }
        }
Ejemplo n.º 7
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);
                }
        }