Example #1
0
        public void UpdateTrip(TripUpdateDto trip)
        {
            using (IReservationRepository reservationRepository = new ReservationRepository(ConnectionName))
            {
                Reservation reservation  = reservationRepository.FindBy(r => r.ConfirmationCode == trip.ReservationConfirmationCode).FirstOrDefault();
                Trip        originalTrip = null;

                if (reservation == null)
                {
                    throw new FaultException("The confirmation code of the reservation is invalid");
                }

                switch (trip.FlightDirection)
                {
                case FlightDirections.Departing:
                    originalTrip = reservation.DepartureFlight;
                    break;

                case FlightDirections.Returning:
                    originalTrip = reservation.ReturnFlight;
                    break;
                }

                if (originalTrip == null)
                {
                    throw new FaultException("The requested trip was not found");
                }

                FlightStatus originalStatus = originalTrip.Status;
                FlightStatus newStatus      = trip.TripToUpdate.Status;
                reservationRepository.UpdateTrip(
                    originalTrip,
                    new Trip()
                {
                    TripId           = originalTrip.TripId,
                    ThumbnailImage   = originalTrip.ThumbnailImage,
                    FlightInfo       = originalTrip.FlightInfo,
                    FlightScheduleID = originalTrip.FlightScheduleID,
                    Status           = trip.TripToUpdate.Status,
                    Class            = trip.TripToUpdate.Class
                });

                using (TransactionScope scope = new TransactionScope())
                {
                    // TODO: 2 - Call the Frequent Flyer service to add the miles if the traveler has checked-in
                    if (originalStatus != newStatus && newStatus == FlightStatus.CheckedIn)
                    {
                        IFrequentFlyerService proxy = _frequentFlyerChannnelFactory.CreateChannel();
                        int earnedMiles             = originalTrip.FlightInfo.Flight.FrequentFlyerMiles;
                        proxy.AddFrequentFlyerMiles(reservation.TravelerId, earnedMiles);
                    }

                    // TODO: 3 - Wrap the save and the service call in a transaction scope
                    reservationRepository.Save();

                    scope.Complete();
                }
            }
        }
        public void UpdateTrip(TripUpdateDto trip)
        {
            using (IReservationRepository reservationRepository = new ReservationRepository(ConnectionName))
            {
                Reservation reservation  = reservationRepository.FindBy(r => r.ConfirmationCode == trip.ReservationConfirmationCode).FirstOrDefault();
                Trip        originalTrip = null;

                if (reservation == null)
                {
                    throw new FaultException("The confirmation code of the reservation is invalid");
                }

                switch (trip.FlightDirection)
                {
                case FlightDirections.Departing:
                    originalTrip = reservation.DepartureFlight;
                    break;

                case FlightDirections.Returning:
                    originalTrip = reservation.ReturnFlight;
                    break;
                }

                if (originalTrip == null)
                {
                    throw new FaultException("The requested trip was not found");
                }

                FlightStatus originalStatus = originalTrip.Status;
                FlightStatus newStatus      = trip.TripToUpdate.Status;
                reservationRepository.UpdateTrip(
                    originalTrip,
                    new Trip()
                {
                    TripId           = originalTrip.TripId,
                    ThumbnailImage   = originalTrip.ThumbnailImage,
                    FlightInfo       = originalTrip.FlightInfo,
                    FlightScheduleID = originalTrip.FlightScheduleID,
                    Status           = trip.TripToUpdate.Status,
                    Class            = trip.TripToUpdate.Class
                });
            }
        }
Example #3
0
        static public void Publish(FlightSchedule updatedSchedule)
        {
            var flightsRepository      = new FlightRepository();
            var reservationsRepository = new ReservationRepository();

            Flight updatedFlight = flightsRepository.GetFlight(updatedSchedule.Flight.FlightId);
            var    reservations  = reservationsRepository.FindBy(
                r => r.DepartureFlight.FlightScheduleID == updatedSchedule.FlightScheduleId);

            var travelers = from r in reservations
                            select r.TravelerId;

            var notification = new ToastNotificationTextAndImage
            {
                TargetClientDevices = travelers.ToList(),
                TextHeading         = string.Format("Flight {0} Was Rescheduled", updatedFlight.FlightNumber),
                TextBodyWrap        = string.Format("Flight {0} was rescheduled for {1}", updatedFlight.FlightNumber, updatedSchedule.ActualDeparture)
            };

            WNSManager.DispatchNotification(notification);
        }
        public void CancelReservation(string confirmationCode)
        {
            using (IReservationRepository reservationRepository = new ReservationRepository(ConnectionName))
            {
                var existingReservation = reservationRepository.FindBy(r => r.ConfirmationCode == confirmationCode).SingleOrDefault();

                if (existingReservation == null)
                {
                    throw new FaultException("Reservation not found");
                }

                // Canceling a reservation is logical, not physical
                // meaning the trips are marked as canceled, instead of
                // being deleted from the database
                existingReservation.DepartureFlight.Status = FlightStatus.Canceled;
                if (existingReservation.ReturnFlight != null)
                {
                    existingReservation.ReturnFlight.Status = FlightStatus.Canceled;
                }
                reservationRepository.Save();
            }
        }