public Departure Get(int id) { DbPlane dbp = new DbPlane(); DbDestination dbd = new DbDestination(); using (SqlConnection con = new SqlConnection(data.GetConnectionString())) { con.Open(); SqlCommand cmd = new SqlCommand("SELECT * FROM dbo.Booking_Departure WHERE Id = @id", con); cmd.Parameters.Add("@Id", SqlDbType.Int).Value = id; SqlDataReader rdr = cmd.ExecuteReader(); rdr.Read(); return(new Departure { Id = (int)rdr["Id"], Plane = dbp.Get((int)rdr["Plane_Id"]), EndDestination = dbd.Get((int)rdr["EndDestination"]), StartDestination = dbd.Get((int)rdr["StartDestination"]), DepartureTime = (DateTime)rdr["DepartureTime"], Seats = dbSeat.GetAll((int)rdr["Id"]) }); // husk at tilføje seats til listen } }
public IEnumerable <Departure> GetAllDeparturesFromTo(int start, int end, DateTime fromDate, DateTime toDate) { DbPlane dbp = new DbPlane(); DbDestination dbd = new DbDestination(); List <Departure> departures = new List <Departure>(); using (SqlConnection con = new SqlConnection(data.GetConnectionString())) { con.Open(); using (SqlCommand cmd = con.CreateCommand()) { cmd.CommandText = "SELECT * FROM dbo.Booking_Departure Where StartDestination = @start AND EndDestination = @end AND DepartureTime >= @fromDate AND DepartureTime <= @toDate ORDER BY DepartureTime ASC"; cmd.Parameters.Add("@start", SqlDbType.Int).Value = start; cmd.Parameters.Add("@end", SqlDbType.Int).Value = end; cmd.Parameters.Add("@fromDate", SqlDbType.DateTime).Value = fromDate; cmd.Parameters.Add("@toDate", SqlDbType.DateTime).Value = toDate; var rdr = cmd.ExecuteReader(); while (rdr.Read()) { departures.Add(new Departure { Id = (int)rdr["Id"], //Plane = dbp.Get((int)rdr["Plane_Id"]), //EndDestination = dbd.Get((int)rdr["EndDestination"]), //StartDestination = dbd.Get((int)rdr["StartDestination"]), DepartureTime = (DateTime)rdr["DepartureTime"] }); // husk seats } } } return(departures); }
public IEnumerable <Departure> GetAll() { DbPlane dbp = new DbPlane(); DbDestination dbd = new DbDestination(); List <Departure> departures = new List <Departure>(); Departure d = null; using (SqlConnection con = new SqlConnection(data.GetConnectionString())) { con.Open(); using (SqlCommand cmd = con.CreateCommand()) { cmd.CommandText = "SELECT * FROM dbo.Booking_Departure ORDER BY DepartureTime ASC"; var rdr = cmd.ExecuteReader(); while (rdr.Read()) { d = new Departure { Id = (int)rdr["Id"], Plane = dbp.Get((int)rdr["Plane_Id"]), EndDestination = dbd.Get((int)rdr["EndDestination"]), StartDestination = dbd.Get((int)rdr["StartDestination"]), DepartureTime = (DateTime)rdr["DepartureTime"] }; // husk seats departures.Add(d); } } } return(departures); }