예제 #1
0
        /*
         * Asynchronus add to flight database
         */
        public async Task Add(IFlight flight)
        {
            // case IFlight to flight, get current flight list from db
            Flight f       = (Flight)flight;
            var    flights = await db.Flights.ToListAsync();

            // check if flight conflicts, if so throw SqlException
            if (!FlightDeconfliction.Deconflict(f, flights))
            {
                // throw sql exception and return... no way to manually throw SqlException in C#
                SqlConnection connection = new SqlConnection("Server=(localdb)\\mssqllocaldb;Database=OpenAirLocalTestDb;Trusted_Connection=True;MultipleActiveResultSets=true");
                SqlCommand    cmd        =
                    new SqlCommand("raiserror('Manual SQL exception', 16, 1)", connection);
                cmd.ExecuteNonQuery();
                return;
            }
            // no conflict so add the new flight
            await db.Flights.AddAsync((Flight)flight);

            await db.SaveChangesAsync();
        }
예제 #2
0
        /*
         * Add method, Adds a user to the database context and prompts an update with the database
         */
        public async Task Add(IUser user)
        {
            await db.Pilots.AddAsync((Pilot)user);

            await db.SaveChangesAsync();
        }