//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); }
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 }); }
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")); }
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; }