예제 #1
0
        public IEnumerable <Booking> GetAllCafeBookings(int cafeId)
        {
            DbCafe         dbCafe      = new DbCafe();
            DbCafeTable    dbCafeTable = new DbCafeTable();
            DbUser         dbUser      = new DbUser();
            List <Booking> bookings    = new List <Booking>();

            try
            {
                using (SqlConnection connection = new SqlConnection(_connectionString))
                {
                    connection.Open();
                    using (SqlCommand command = connection.CreateCommand())
                    {
                        command.CommandText = "SELECT * FROM Booking WHERE Booking.CafeID = @cafeId;";
                        command.Parameters.AddWithValue("@cafeId", cafeId);

                        SqlDataReader reader = command.ExecuteReader();
                        while (reader.Read())
                        {
                            Booking booking = new Booking
                            {
                                Id         = reader.GetInt32(reader.GetOrdinal("ID")),
                                BookedDate = reader.GetDateTime(reader.GetOrdinal("BookedDate")),
                                StartDate  = reader.GetDateTime(reader.GetOrdinal("StartDate")),
                                EndDate    = reader.GetDateTime(reader.GetOrdinal("EndDate")),
                                User       = dbUser.GetUserByID(reader.GetInt32(reader.GetOrdinal("UserID"))),
                                Cafe       = dbCafe.GetCafeById(reader.GetInt32(reader.GetOrdinal("CafeID"))),
                                Table      = dbCafeTable.GetTableByID(reader.GetInt32(reader.GetOrdinal("TableID")))
                            };
                            bookings.Add(booking);
                        }
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
            return(bookings);
        }
예제 #2
0
        public Booking GetBookingById(int Id)
        {
            DbCafe      dbCafe      = new DbCafe();
            DbCafeTable dbCafeTable = new DbCafeTable();
            DbUser      dbUser      = new DbUser();
            Booking     booking     = new Booking();

            try
            {
                using (SqlConnection connection = new SqlConnection(_connectionString))
                {
                    connection.Open();
                    using (SqlCommand command = connection.CreateCommand())
                    {
                        command.CommandText = "SELECT * FROM Booking WHERE booking.ID = @id";
                        command.Parameters.AddWithValue("@id", Id);

                        SqlDataReader reader = command.ExecuteReader();
                        while (reader.Read())
                        {
                            booking.Id         = reader.GetInt32(reader.GetOrdinal("ID"));
                            booking.BookedDate = reader.GetDateTime(reader.GetOrdinal("BookedDate"));
                            booking.StartDate  = reader.GetDateTime(reader.GetOrdinal("StartDate"));
                            booking.EndDate    = reader.GetDateTime(reader.GetOrdinal("EndDate"));
                            booking.User       = dbUser.GetUserByID(reader.GetInt32(reader.GetOrdinal("UserID")));
                            booking.Cafe       = dbCafe.GetCafeById(reader.GetInt32(reader.GetOrdinal("CafeID")));
                            booking.Table      = dbCafeTable.GetTableByID(reader.GetInt32(reader.GetOrdinal("TableID")));
                        }
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
            return(booking);
        }