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"] }); } }
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); }
public IEnumerable <Customer> GetAllCustomers() { List <Customer> customers = new List <Customer>(); DbCity dbCity = new DbCity(); DbPayment dbp = new DbPayment(); using (SqlConnection con = new SqlConnection(data.GetConnectionString())) { con.Open(); using (SqlCommand cmd = con.CreateCommand()) { cmd.CommandText = "SELECT * FROM dbo.Booking_Customer"; var rdr = cmd.ExecuteReader(); while (rdr.Read()) { customers.Add(new Customer { Id = (int)rdr["Id"], FirstName = (string)rdr["FirstName"], LastName = (string)rdr["LastName"], Email = (string)rdr["Email"], CPR = (long)rdr["Cpr"], PhoneNumber = (long)rdr["PhoneNo"], City = dbCity.Get((int)rdr["City_Id"]), Address = (string)rdr["Address"], Password = (string)rdr["Password"], Confirmed = (bool)rdr["Cofirmed"], Role = (string)rdr["Roles"] }); } } } return(customers); }