Esempio n. 1
0
        public async Task Handle(FlightCreatedEvent notification, CancellationToken cancellationToken)
        {
            Log.Information($"Entered event handler {nameof(FlightCreatedEventHandler)}");

            var flight = await _flightRepository.GetByIdAsync(notification.Id);

            var departureAirport = await _airportRepository.GetByIdAsync(flight.DepartureAirportId);

            var destinationAirport = await _airportRepository.GetByIdAsync(flight.DestinationAirportId);

            var distance = departureAirport.GetDistanceTo(destinationAirport);

            var report = new ReportItem(nameof(FlightCreatedEvent), new
            {
                flight.Id,
                DepartureAirport           = departureAirport.ToString(),
                DestinationAirport         = destinationAirport.ToString(),
                FlightDistanceInKilometers = distance.Kilometers,
                FlightDuration             = flight.GetFlightDuration(distance),
                FuelRequiredInLitres       = flight.GetFuelRequired(distance).Litres,
                flight.CreatedAt
            });

            await _reportItemRepository.AddAsync(report);
        }
Esempio n. 2
0
        public async Task Handle(FlightDeletedEvent notification, CancellationToken cancellationToken)
        {
            Log.Information($"Entered event handler {nameof(FlightDeletedEventHandler)}");

            var report = new ReportItem(nameof(FlightDeletedEvent), new
            {
                notification.Id
            });

            await _reportItemRepository.AddAsync(report);
        }