Esempio n. 1
0
        //post request to add an airline
        public async Task <HttpResponseMessage> PostAsync(Airline airline)
        {
            List <Airline> airlines = await sqlDbHelper.GetAirlines();

            //to check if there's no airline with the same code in the table
            if (airlines.Find(a => a.Code == airline.Code) == null)
            {
                //in case it doesn't exist then the airline will be added and ok status code is returned
                await sqlDbHelper.AddAirline(airline);

                return(Request.CreateResponse(HttpStatusCode.OK, "Created"));
            }
            else
            {
                // in case an airline with the same code exists then it won't be added and cannot be created message is returned
                return(Request.CreateResponse(HttpStatusCode.OK, "Cannot be created!"));
            }
        }