Ejemplo n.º 1
0
        /*
         * select sum(f.price)
         * from flights f, company c
         * where f.companyName = c.name and c.name = "Lufthansa"
         */

        public double Query6()
        {
            return
                (FlightTable.Join(
                     CompanyTable, t => t.Item1.CompanyName == t.Item2.Name && t.Item2.Name == "Lufthansa").Reduce(
                     0.0, (s, t) => s += t.Item1.Price));
        }
Ejemplo n.º 2
0
        /*
         * select *
         * from flights f, airport a
         * where f.destinationAirport = a.name && f.destinationCity = a.city
         * */

        public IEnumerable <Tuple <Flight, Airport> > Query4()
        {
            return
                (FlightTable.Join
                     (AirportTable, t => t.Item1.DestinationAirport == t.Item2.Name &&
                     t.Item1.DestinationCity == t.Item2.City));
        }
Ejemplo n.º 3
0
        public async Task <BundleModel> GetBundleItems(int bundleId)
        {
            FlightModel flight;
            BundleModel bundle = await BundleTable.GetBundleById(_dbConnection, bundleId);

            var flights_id = await BundleTable.GetBundleFlights(_dbConnection, bundleId);

            foreach (int flight_id in flights_id)
            {
                var k = await FlightTable.GetFlightById(_dbConnection, flight_id);

                if (k is null)
                {
                    throw new Exception();
                }
                else
                {
                    flight = k;
                }
                bundle.Flights.Append(flight);
            }
            if (bundle is null)
            {
                throw new Exception();
            }
            else
            {
                return(bundle);
            }
        }
Ejemplo n.º 4
0
        /*
         * select f.code, f.company, a.size
         * from flights f, airport a
         * where f.destinationAirport = a.name && f.destinationCity = a.city && f.company = Lufthansa
         * */

        public IEnumerable <Tuple <string, string, AirportSize> > Query5()
        {
            return
                (FlightTable.Join(
                     AirportTable, t => t.Item1.DestinationAirport == t.Item2.Name &&
                     t.Item1.DestinationCity == t.Item2.City &&
                     t.Item1.CompanyName == "Lufthansa").Map(
                     t => new Tuple <string, string, AirportSize>(t.Item1.Code, t.Item1.CompanyName, t.Item2.Size)));
        }
 // POST api/<controller>
 public HttpResponseMessage Post(FlightTable f1)
 {
     try
     {
         db.FlightTables.Add(f1);
         db.SaveChanges();
         return(new HttpResponseMessage(HttpStatusCode.Created));
     }
     catch
     {
         return(new HttpResponseMessage(HttpStatusCode.InternalServerError));
     }
 }
Ejemplo n.º 6
0
        /*
         * select code, destinationAirport
         * from flight
         * where company = 'Lufthansa'
         */

        public IEnumerable <Tuple <string, string> > Query3()
        {
            return
                (FlightTable.Reduce
                     (new List <Flight>(), (l, flight) =>
            {
                if (flight.CompanyName == "Lufthansa")
                {
                    l.Add(flight);
                }
                return l;
            }).Map
                     (flight => new Tuple <string, string>(flight.Code, flight.DestinationAirport)));
        }
 // PUT api/<controller>/5
 public HttpResponseMessage Put(string id, FlightTable f1)
 {
     try
     {
         if (id == f1.FlightNo)
         {
             db.Entry(f1).State = System.Data.Entity.EntityState.Modified;
             return(new HttpResponseMessage(HttpStatusCode.OK));
         }
         else
         {
             return(new HttpResponseMessage(HttpStatusCode.NotFound));
         }
     }
     catch (Exception ex)
     {
         return(new HttpResponseMessage(HttpStatusCode.InternalServerError));
     }
 }
 // DELETE api/<controller>/5
 public HttpResponseMessage Delete(string id)
 {
     try
     {
         FlightTable f = db.FlightTables.Find(id);
         if (f != null)
         {
             db.FlightTables.Remove(f);
             db.SaveChanges();
             return(new HttpResponseMessage(HttpStatusCode.OK));
         }
         else
         {
             return(new HttpResponseMessage(HttpStatusCode.NotFound));
         }
     }
     catch (Exception ex)
     {
         return(new HttpResponseMessage(HttpStatusCode.InternalServerError));
     }
 }
Ejemplo n.º 9
0
 public Task <int> CreateAsync([FromBody] FlightDTO flight)
 => FlightTable.CreateFlight(_dbConnection, flight.DepartureAirportId, flight.ArrivalAirportId, flight.TotalSeatCount);
Ejemplo n.º 10
0
 public Task <bool> DeleteById(int flightId) => FlightTable.DeleteFlightById(_dbConnection, flightId);
Ejemplo n.º 11
0
        public async Task <IActionResult> GetAsync(int flightId)
        {
            var res = await FlightTable.GetFlightById(_dbConnection, flightId);

            return(res == null?NotFound() : (IActionResult)Ok(res));
        }
Ejemplo n.º 12
0
 public Task <IEnumerable <FlightModel> > GetAll() => FlightTable.GetAllFlights(_dbConnection);
Ejemplo n.º 13
0
        /*
         * select code, company, destinationAirport
         * from flight
         */

        public IEnumerable <Tuple <string, string, string> > Query2()
        {
            return(FlightTable.Map(flight => new Tuple <string, string, string>(flight.Code, flight.CompanyName, flight.DestinationAirport)));
        }
Ejemplo n.º 14
0
 /*
  * select *
  * from flight
  */
 public IEnumerable <Flight> Query1()
 {
     return(FlightTable.Map(x => x));
 }