Beispiel #1
0
        public Bookings Get(int id)
        {
            DbPayment   dbp = new DbPayment();
            DbCustomer  dbc = new DbCustomer();
            DbDeparture dbd = new DbDeparture();

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

                SqlDataReader rdr = cmd.ExecuteReader();
                rdr.Read();
                return(new Bookings
                {
                    Id = (int)rdr["Id"],
                    Payment = dbp.Get((int)rdr["Payment_Id"]),
                    Customer = dbc.Get((int)rdr["Customer_Id"]),
                    Departure = dbd.Get((int)rdr["Departure_Id"]),
                    Date = (DateTime)rdr["Date"],
                    TotalPrice = (int)rdr["Price"]
                });
            }
        }
Beispiel #2
0
        public IEnumerable <Bookings> GetAllBookings()
        {
            DbPayment       dbp      = new DbPayment();
            DbCustomer      dbc      = new DbCustomer();
            DbDeparture     dbd      = new DbDeparture();
            List <Bookings> bookings = new List <Bookings>();
            DbCity          dbCity   = new DbCity();

            using (SqlConnection con = new SqlConnection(data.GetConnectionString()))
            {
                con.Open();

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

                    while (rdr.Read())
                    {
                        bookings.Add(new Bookings
                        {
                            Id         = (int)rdr["Id"],
                            Payment    = dbp.Get((int)rdr["Payment_Id"]),
                            Customer   = dbc.Get((int)rdr["Customer_Id"]),
                            Departure  = dbd.Get((int)rdr["Departure_Id"]),
                            Date       = (DateTime)rdr["Date"],
                            TotalPrice = (int)rdr["Price"]
                        });
                    }
                }
            }
            return(bookings);
        }