public FetchResult <Baggage> FetchBaggage(string whereClause = null, SqlParameter[] sqlParams = null) { DatabaseTable baggageTargetTable = new DatabaseTable("baggage"); baggageTargetTable.AddAttribute("Id"); baggageTargetTable.AddAttribute("FlightId"); baggageTargetTable.AddAttribute("PassengerId"); baggageTargetTable.AddAttribute("Weight"); baggageTargetTable.AddAttribute("Fee"); ObjectRelationalMapper <Baggage> baggageMapper = new ObjectRelationalMapper <Baggage>(Config.DB_CONNECTION_STRING, baggageTargetTable); return(baggageMapper.Fetch(attr => new Baggage((int)attr["Id"], (int)attr["FlightId"], (decimal)attr["Weight"], (decimal)attr["Fee"]), whereClause, sqlParams)); }
private void FetchBaggageFeeInfo() { FetchResult <BaggageFeeInfo> baggageFeeFetchResult = _baggageFeeMapper.Fetch(attr => new BaggageFeeInfo { WeightLimit = (decimal)attr["Limit"], FeePerExtraKilogram = (decimal)attr["FeePerKilogram"] }); if (baggageFeeFetchResult.HasError || baggageFeeFetchResult.RetrievedItems.FirstOrDefault() == null) { MessageBox.Show(ERROR_FEE_INFO + "\r\n\r\nFehler-Details:\r\n" + baggageFeeFetchResult.ErrorDetails, "Fehler", MessageBoxButton.OK, MessageBoxImage.Error); } else { _baggageFeeInfo = baggageFeeFetchResult.RetrievedItems.FirstOrDefault(); } PreviewBaggage.WeightLimit = _baggageFeeInfo.WeightLimit; PreviewBaggage.FeePerExtraKilogram = _baggageFeeInfo.FeePerExtraKilogram; }
public FetchResult <Flight> FetchFlights(string whereClause = null, SqlParameter[] sqlParams = null) { JoinableDatabaseTable flightSourceTable = new JoinableDatabaseTable("flights"); flightSourceTable.AddAttribute("flights.Id"); flightSourceTable.AddAttribute("depAirport.Country"); flightSourceTable.AddAttribute("depAirport.City"); flightSourceTable.AddAttribute("destAirport.Country"); flightSourceTable.AddAttribute("destAirport.City"); flightSourceTable.AddAttribute("TimeOfDeparture"); flightSourceTable.AddAttribute("TimeOfArrival"); flightSourceTable.AddAttribute("SeatRows"); flightSourceTable.AddAttribute("SeatsPerRow"); flightSourceTable.CreateJoin("airports", "DepartureAirportId", "Id", "depAirport"); flightSourceTable.CreateJoin("airports", "DestinationAirportId", "Id", "destAirport"); ObjectRelationalMapper <Flight> flightsMapper = new ObjectRelationalMapper <Flight>(Config.DB_CONNECTION_STRING, flightSourceTable); FetchResult <Flight> flightsFetched = flightsMapper.Fetch(attr => { Airport departureAp = new Airport(attr["depAirport.Country"].ToString(), attr["depAirport.City"].ToString()); Airport destinationAp = new Airport(attr["destAirport.Country"].ToString(), attr["destAirport.City"].ToString()); return (new Flight((int)attr["flights.Id"], (DateTime)attr["TimeOfDeparture"], (DateTime)attr["TimeOfArrival"], departureAp, destinationAp, (int)attr["SeatRows"], (int)attr["SeatsPerRow"])); }, whereClause, sqlParams); if (!flightsFetched.HasError) { foreach (Flight flight in flightsFetched.RetrievedItems) { flight.TakenSeatNumbers = FetchTakenSeats(flight.Id); } } return(flightsFetched); }
public IEnumerable <SeatNumber> FetchTakenSeats(int flightId) { DatabaseTable seatsTable = new DatabaseTable("seats"); seatsTable.AddAttribute("PosX"); seatsTable.AddAttribute("PosY"); seatsTable.AddAttribute("Id"); seatsTable.AddAttribute("FlightId"); seatsTable.AddAttribute("PassengerId"); ObjectRelationalMapper <SeatNumber> seatNumberMapper = new ObjectRelationalMapper <SeatNumber>(Config.DB_CONNECTION_STRING, seatsTable); string whereClause = "FlightId = " + flightId; FetchResult <SeatNumber> fetchResultSeatNumbers = seatNumberMapper.Fetch(attr => new SeatNumber((int)attr["PosX"], (int)attr["PosY"]), whereClause); if (fetchResultSeatNumbers.HasError) { return(new SeatNumber[0]); } return(fetchResultSeatNumbers.RetrievedItems); }
public FetchResult <Booking> FetchBookings(string whereClause = null, SqlParameter[] sqlParams = null) { JoinableDatabaseTable bookingSourceTable = new JoinableDatabaseTable("bookings"); bookingSourceTable.AddAttribute("bookings.Id"); bookingSourceTable.AddAttribute("bookings.PassengerId"); bookingSourceTable.AddAttribute("passengers.Title"); bookingSourceTable.AddAttribute("passengers.FirstName"); bookingSourceTable.AddAttribute("passengers.LastName"); bookingSourceTable.AddAttribute("bookings.FlightId"); bookingSourceTable.AddAttribute("depAirport.Country"); bookingSourceTable.AddAttribute("depAirport.City"); bookingSourceTable.AddAttribute("destAirport.Country"); bookingSourceTable.AddAttribute("destAirport.City"); bookingSourceTable.AddAttribute("flights.TimeOfDeparture"); bookingSourceTable.AddAttribute("flights.TimeOfArrival"); bookingSourceTable.AddAttribute("flights.SeatRows"); bookingSourceTable.AddAttribute("flights.SeatsPerRow"); bookingSourceTable.AddAttribute("seats.PosX"); bookingSourceTable.AddAttribute("seats.PosY"); bookingSourceTable.AddAttribute("bookings.IsWaiting"); Join j = bookingSourceTable.CreateJoin("seats", "bookings.PassengerId", "PassengerId", null, JoinTypes.Left); j.CustomCondition = "AND bookings.FlightId = seats.FlightId"; bookingSourceTable.CreateJoin("passengers", "bookings.PassengerId", "Id"); bookingSourceTable.CreateJoin("flights", "bookings.FlightId", "Id"); bookingSourceTable.CreateJoin("airports", "flights.DepartureAirportId", "Id", "depAirport"); bookingSourceTable.CreateJoin("airports", "flights.DestinationAirportId", "Id", "destAirport"); ObjectRelationalMapper <Booking> bookingMapper = new ObjectRelationalMapper <Booking>(Config.DB_CONNECTION_STRING, bookingSourceTable); FetchResult <Booking> fetchResult = bookingMapper.Fetch(CreateBookingInstance, whereClause, sqlParams); return(fetchResult); }