private void UpdateReservationOnBackendSystem(Reservation reservation, Trip trip, FlightDirections flightDirection) { IBookingService proxy = factory.CreateChannel(); try { (proxy as ICommunicationObject).Open(); TripUpdateDto tripUpdateRequest = new TripUpdateDto { FlightDirection = flightDirection, ReservationConfirmationCode = reservation.ConfirmationCode, TripToUpdate = new TripDto { FlightScheduleID = reservation.DepartureFlight.FlightScheduleID, Class = reservation.DepartureFlight.Class, Status = reservation.DepartureFlight.Status } }; proxy.UpdateTrip(tripUpdateRequest); (proxy as ICommunicationObject).Close(); } catch (Exception) { (proxy as ICommunicationObject).Abort(); } }
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 }); } }
private void UpdateReservationOnBackendSystem(Reservation reservation, Trip trip, FlightDirections flightDirection) { //Create channel to IBookingService //Open communication //Create tripUpdateDTO TripUpdateDto tripUpdateRequest = new TripUpdateDto { FlightDirection = flightDirection, ReservationConfirmationCode = reservation.ConfirmationCode, TripToUpdate = new TripDto { FlightScheduleID = reservation.DepartureFlight.FlightScheduleID, Class = reservation.DepartureFlight.Class, Status = reservation.DepartureFlight.Status } }; //Update trip on proxy //Close }