Exemple #1
0
        public void HandleTripStatusMessage(string payload)
        {
            if (payload == null || string.IsNullOrWhiteSpace(payload))
            {
                throw new ArgumentNullException(nameof(payload));
            }

            var message =
                _serialisationService.DeSerialise <TripStatusMessage>(payload);

            Console.WriteLine($"TripId: {message.TripId} TripStatus: {message.TripStatus} Time:{message.Time}");
        }
        public async Task HandleTripStatusMessage(string payload)
        {
            if (payload == null || string.IsNullOrWhiteSpace(payload))
            {
                throw new ArgumentNullException(nameof(payload));
            }

            var message =
                _serialisationService.DeSerialise <TripStatusMessage>(payload);

            await using (_context)
            {
                var trip = await _context.Trips.FindAsync(message.TripId);

                if (trip != null && trip.Status != message.TripStatus)
                {
                    trip.Status = message.TripStatus;
                    _context.Trips.Update(trip);
                    await _context.SaveChangesAsync();
                }
            }
        }