public bool Equals(BookingEndpoint other) { if (ReferenceEquals(null, other)) return false; if (ReferenceEquals(this, other)) return true; if (other.Id == 0 && Id == 0) return false; else return other.Id == Id; }
private static SubDivision GetSubDivision(LomsContext db, Booking booking, BookingEndpoint endpoint, DebugWriter debug, out bool autoPending, out double extras) { autoPending = false; extras = 0; int? subId = null; switch (endpoint.Type) { case BookingEndpointType.Suburb: { if (endpoint.Suburb != null) { Landmark autoPendingLandmark = db.Landmarks.FirstOrDefault(l => l.Address1 == endpoint.Address1 && l.SuburbId == endpoint.SuburbId && l.Autopend); if (autoPendingLandmark != null) { autoPending = true; debug.WriteLine("Suburb {0} has autopending landmark {1}!", endpoint.Suburb.FullName, autoPendingLandmark.Name); return null; } subId = endpoint.Suburb.SubDivisionId; debug.Write("Suburb: {0}", endpoint.Suburb.FullName); } else { debug.WriteLine("Suburb has been removed from system!"); return null; } } break; case BookingEndpointType.AirportPrivate: case BookingEndpointType.AirportOther: { if (endpoint.Airport != null) { subId = endpoint.Airport.SubDivisionId; debug.Write("Airport: {0}", endpoint.Airport.Name); //airport extras extras = RateHelper.GetAirportExtras(db, booking, endpoint.Airport.Id, booking.PickUpEndpointId == endpoint.Id, debug); } else { debug.WriteLine("Airport has been removed from system!"); return null; } } break; } if (subId == null) { debug.WriteLine("Sub Division is not specified!"); return null; } var sub = db.SubDivisions.FirstOrDefault(sd => sd.Id == subId); if (sub == null) { debug.WriteLine("Sub Division is not specified!"); return null; } return sub; }
private static SubDivision GetSubDivision(LomsContext db, Booking booking, BookingEndpoint endpoint) { int? subId = null; switch (endpoint.Type) { case BookingEndpointType.Suburb: subId = endpoint.Suburb.SubDivisionId; break; case BookingEndpointType.AirportPrivate: case BookingEndpointType.AirportOther: subId = endpoint.Airport.SubDivisionId; break; } return db.SubDivisions.FirstOrDefault(sd => sd.Id == subId); }
public bool IsEqualTo(BookingEndpoint endpoint) { if (Type != endpoint.Type) return false; if (endpoint.Type == BookingEndpointType.Suburb) { if (LandmarkName != endpoint.LandmarkName || BuildingName != endpoint.BuildingName || Address1 != endpoint.Address1 || Address2 != endpoint.Address2 || SuburbId != endpoint.SuburbId) return false; } else if (endpoint.Type == BookingEndpointType.AirportPrivate) { if (AirportId != endpoint.AirportId || Charter != endpoint.Charter || ArrivalOrDepartureTime != endpoint.ArrivalOrDepartureTime || OriginOrDestination != endpoint.OriginOrDestination) return false; } else if (endpoint.Type == BookingEndpointType.AirportOther) { if (AirportId != endpoint.AirportId || AirlineId != endpoint.AirlineId || FlightNumber != endpoint.FlightNumber || ArrivalOrDepartureTime != endpoint.ArrivalOrDepartureTime || OriginOrDestination != endpoint.OriginOrDestination) return false; } return Info == endpoint.Info; }
public BookingEndpointValidator(BookingEndpoint endpoint) { _endpoint = endpoint; }
public void SetDataFrom(BookingEndpoint endpoint) { if (endpoint.Type == BookingEndpointType.Suburb) { Type = BookingEndpointType.Suburb; LandmarkName = endpoint.LandmarkName; BuildingName = endpoint.BuildingName; Address1 = endpoint.Address1; Address2 = endpoint.Address2; SuburbId = endpoint.SuburbId; ClearAirportProperties(); } else if (endpoint.Type == BookingEndpointType.AirportPrivate) { Type = BookingEndpointType.AirportPrivate; AirportId = endpoint.AirportId; Charter = endpoint.Charter; ArrivalOrDepartureTime = endpoint.ArrivalOrDepartureTime; OriginOrDestination = endpoint.OriginOrDestination; Airline = null; AirlineId = null; FlightNumber = null; ClearSuburbProperties(); } else if (endpoint.Type == BookingEndpointType.AirportOther) { Type = BookingEndpointType.AirportOther; AirportId = endpoint.AirportId; AirlineId = endpoint.AirlineId; FlightNumber = endpoint.FlightNumber; ArrivalOrDepartureTime = endpoint.ArrivalOrDepartureTime; OriginOrDestination = endpoint.OriginOrDestination; Charter = null; ClearSuburbProperties(); } Info = endpoint.Info; }
static Suburb GetSuburb(LomsContext db, BookingEndpoint endpoint, DebugWriter debug) { Suburb suburb = null; switch (endpoint.Type) { case BookingEndpointType.Suburb: suburb = db.Suburbs.FirstOrDefault(s => s.Id == endpoint.SuburbId); break; case BookingEndpointType.AirportPrivate: case BookingEndpointType.AirportOther: { Airport airport = endpoint.Airport; if (airport == null) debug.WriteLine("Airport has been removed from system!"); else suburb = db.Suburbs.FirstOrDefault(s => s.Id == airport.SuburbId); } break; } if (suburb != null) debug.WriteLine("Suburb: {0}", suburb.FullName); else { debug.WriteLine("Suburb has been removed from system!"); return null; } return suburb; }
public BookingResponse SaveBookingDropOffEndpoint(int bookingId, BookingEndpoint endpoint) { try { using (var db = new LomsContext()) { var booking = GetBooking(db, bookingId); if (booking.DropOffEndpoint.Type != endpoint.Type || booking.DropOffEndpoint.Address1 != endpoint.Address1 || booking.DropOffEndpoint.SuburbId != endpoint.SuburbId || booking.DropOffEndpoint.AirportId != endpoint.AirportId) { booking.OnDropOffEndpointChanged(); } booking.DropOffEndpoint.SetDataFrom(endpoint); //airport default city if (booking.JourneyType == JourneyType.ToAirport) if (booking.DropOffEndpoint.Type == BookingEndpointType.AirportOther || booking.DropOffEndpoint.Type == BookingEndpointType.AirportPrivate) { var airportDefaultCity = db.AirportCities.SingleOrDefault(a => a.AirportId == booking.DropOffEndpoint.AirportId && a.IsDefault); if (airportDefaultCity != null && booking.CityId != airportDefaultCity.CityId) booking.CityId = airportDefaultCity.CityId; } db.Bookings.ApplyChanges(booking); db.SaveChanges(); booking = GetBooking(db, bookingId); return new BookingResponse { Booking = booking }; } } catch (Exception ex) { var response = new BookingResponse(); response.AddError("Response", ex.ToString()); return response; } }
public BookingResponse CreateBooking(CreateBookingRequest request) { try { using (var db = new LomsContext()) { var pickUpEndpoint = new BookingEndpoint(); var dropOffEndpoint = new BookingEndpoint(); db.BookingEndpoints.ApplyChanges(pickUpEndpoint); db.BookingEndpoints.ApplyChanges(dropOffEndpoint); db.SaveChanges(); var booking = new Booking() { Status = BookingStatus.New, CityId = request.CityId, CreatorId = request.CreatorId, PrimaryPassengerId = request.PrimaryPassengerId, PickUpEndpointId = pickUpEndpoint.Id, DropOffEndpointId = dropOffEndpoint.Id }; db.Bookings.ApplyChanges(booking); db.SaveChanges(); booking = GetBooking(db, booking.Id); return new BookingResponse { Booking = booking }; } } catch (Exception ex) { var response = new BookingResponse(); response.AddError("Response", ex.ToString()); return response; } }
private void FixupPickUpEndpoint(BookingEndpoint previousValue, bool skipKeys = false) { if (IsDeserializing) { return; } if (PickUpEndpoint != null) { PickUpEndpointId = PickUpEndpoint.Id; } else if (!skipKeys) { PickUpEndpointId = null; } if (ChangeTracker.ChangeTrackingEnabled) { if (ChangeTracker.OriginalValues.ContainsKey("PickUpEndpoint") && (ChangeTracker.OriginalValues["PickUpEndpoint"] == PickUpEndpoint)) { ChangeTracker.OriginalValues.Remove("PickUpEndpoint"); } else { ChangeTracker.RecordOriginalValue("PickUpEndpoint", previousValue); } if (PickUpEndpoint != null && !PickUpEndpoint.ChangeTracker.ChangeTrackingEnabled) { PickUpEndpoint.StartTracking(); } } }