コード例 #1
0
        //The method for handling transactions
        public bool ReservTrip(TripReservation trip)
        {
            bool reserved = false;

            //Define the scope for bundling the transaction
            using (var txscope = new TransactionScope(TransactionScopeOption.RequiresNew))
            {
                try
                {
                    //The Flight Information
                    flight.FlightBookings.Add(trip.Filght);
                    flight.SaveChanges();
                    //The Hotel Infirmation
                    hotel.Reservations.Add(trip.Hotel);
                    hotel.SaveChanges();

                    reserved = true;
                    //The Transaction will be completed
                    txscope.Complete();
                }
                catch
                {
                }
            }
            return(reserved);
        }
コード例 #2
0
 public TripReservationViewModel ToViewModel(TripReservation model, bool includeTripSchedule = false)
 {
     return(new TripReservationViewModel
     {
         Id = model.Id,
         UserId = model.UserId,
         Status = (int)model.Status,
         TripScheduleId = model.TripScheduleId,
         TripStart = model.TripStart,
         TripStartLat = model.TripStartLat,
         TripStartLng = model.TripStartLng,
         TripTo = model.TripTo,
         TripToLat = model.TripToLat,
         TripToLng = model.TripToLng
     });
 }
コード例 #3
0
ファイル: TripController.cs プロジェクト: striveCj/StudyCode
 public ActionResult Create(TripReservation tripinfo)
 {
     try
     {
         tripinfo.Filght.TravellingDate = DateTime.Now;
         tripinfo.Hotel.BookingDate     = DateTime.Now;
         var res = reserv.ReservTrip(tripinfo);
         if (!res)
         {
             return(View("Error"));
         }
     }
     catch (Exception)
     {
         return(View("Error"));
     }
     return(View("Success"));
 }
コード例 #4
0
        public bool ReserveTrip(TripReservation trip)
        {
            bool reserved = false;

            using (var ts = new TransactionScope(TransactionScopeOption.RequiresNew))
            {
                try
                {
                    _flight.FlightBookings.Add(trip.Flight);
                    _flight.SaveChanges();

                    _hotel.Reservations.Add(trip.Hotel);
                    _hotel.SaveChanges();

                    reserved = true;
                    ts.Complete();
                }
                catch (Exception)
                {
                }
            }

            return reserved;
        }