Example #1
0
        public Passenger Get(int id)
        {
            Passenger p   = null;
            DbBooking dbb = new DbBooking();
            DbSeat    dbs = new DbSeat();

            using (SqlConnection con = new SqlConnection(data.GetConnectionString()))
            {
                con.Open();
                SqlCommand cmd = con.CreateCommand();
                cmd.CommandText = "SELECT * FROM dbo.Booking_Passenger WHERE Id = @Id";
                cmd.Parameters.Add("@Id", SqlDbType.Int).Value = id;
                SqlDataReader reader = cmd.ExecuteReader();

                if (reader.HasRows)
                {
                    reader.Read();

                    p = new Passenger
                    {
                        Id         = (int)reader["Id"],
                        Booking    = dbb.Get((int)reader["Booking_Id"]),
                        SeatNumber = dbs.Get((int)reader["Seat_Id"]),
                        FirstName  = (string)reader["FirstName"],
                        LastName   = (string)reader["LastName"],
                        CPR        = (long)reader["CPR"],
                        PassportId = (long)reader["PassportId"],
                        Luggage    = (bool)reader["Luggage"]
                    };
                }
            }
            return(p);
        }
Example #2
0
        public IEnumerable <Passenger> GetAll()
        {
            DbBooking        dbb        = new DbBooking();
            DbSeat           dbs        = new DbSeat();
            List <Passenger> passengers = new List <Passenger>();

            using (SqlConnection con = new SqlConnection(DB.DataAccess.Instance.GetConnectionString()))
            {
                con.Open();

                using (SqlCommand cmd = con.CreateCommand())
                {
                    cmd.CommandText = "SELECT * FROM dbo.Booking_Passenger";
                    var rdr = cmd.ExecuteReader();

                    while (rdr.Read())
                    {
                        Passenger p = new Passenger
                        {
                            Id         = (int)rdr["Id"],
                            Booking    = dbb.Get((int)rdr["Booking_Id"]),
                            SeatNumber = dbs.Get((int)rdr["Seat_Id"]),
                            FirstName  = (string)rdr["FirstName"],
                            LastName   = (string)rdr["LastName"],
                            CPR        = (long)rdr["Cpr"],
                            PassportId = (long)rdr["PassportId"],
                            Luggage    = (bool)rdr["Luggage"]
                        };
                        passengers.Add(p);
                    }
                }
            }
            return(passengers);
        }