public async Task CreateFlight(CreateFlight command, ICorrelationContext context) { Airplane airplane; try { airplane = await _airplanesService.Get(command.PlaneId); } catch (Exception) { // log connection exception airplane = null; } if (airplane is null) { throw new BeComfyException("cannot_create_flight", $"Airplane with id: '{command.PlaneId}' does not exist"); } if (ValidateAvailableSeats(airplane.AvailableSeats, command.AvailableSeats)) { var flight = new Flight(command.Id, command.PlaneId, command.AvailableSeats, command.StartAirport, command.TransferAirports, command.EndAirport, FlightStatus.Continues, command.FlightType, command.FlightDate, command.ReturnDate); await _flightsRepository.AddAsync(flight); await _busPublisher.PublishAsync(new FlightCreated(flight.Id, flight.PlaneId, flight.FlightDate, flight.ReturnDate), context); } else { throw new BeComfyException("cannot_create_flight", $"Invalid seats count"); } }