Exemple #1
0
        //post request to add a route
        public async Task <HttpResponseMessage> PostAsync(Route route)
        {
            List <Route> routes = await sqlDbHelper.GetRoutes();

            List <Airport> airports = await sqlDbHelper.GetAirports();

            List <Airline> airlines = await sqlDbHelper.GetAirlines();


            // checks if there's a route with the same flight number exists, and if the carrier exists and also the dep airport and arrival airport

            if ((routes.Find(a => a.FlightNumber == route.FlightNumber) == null) &&

                (routes.Find(a => (a.Carrier == route.Carrier) &&
                             (a.Arrival == route.Arrival) &&
                             (a.Departure == route.Departure)) == null) &&

                (airports.Find(a => a.Code == route.Arrival) != null) &&
                (airports.Find(a => a.Code == route.Departure) != null) &&
                (airlines.Find(a => a.Code == route.Carrier) != null))
            {
                //if no route with the same flight number exists, and both carrier and dep and arrival airports exists then, the route is added
                // an ok status code and created message are returned
                await sqlDbHelper.AddRoute(route);

                return(Request.CreateResponse(HttpStatusCode.OK, "Created"));
            }
            else
            {
                //if condition is not met, ok status code and cannot be created message are returned
                return(Request.CreateResponse(HttpStatusCode.OK, "Cannot be created!"));
            }
        }