public static Reservation GetReservationsFromId(int idRes)
        {
            List <Reservation> reservations = new List <Reservation>();

            ConnectionStringSettings settings = ConfigurationManager.ConnectionStrings["ValaisBookingDBAccess"];
            string connectionString           = settings.ConnectionString;

            try
            {
                Reservation reservation = new Reservation();
                using (SqlConnection cn = new SqlConnection(connectionString))
                {
                    string     query = "Select * from Reservation where IdReservation = @Idreservation";
                    SqlCommand cmd   = new SqlCommand(query, cn);
                    cmd.Parameters.AddWithValue("@IdReservation", idRes);
                    cn.Open();

                    using (SqlDataReader dr = cmd.ExecuteReader())
                    {
                        if (dr.Read())
                        {
                            int idReservation = (int)dr["IdReservation"];

                            reservation = new Reservation
                            {
                                IdReservation = idReservation,
                                FirstNight    = (DateTime)dr["FirstNight"],
                                LastNight     = (DateTime)dr["LastNight"],
                                Cancelled     = (bool)dr["Cancelled"],
                                Price         = (double)dr["Price"],
                                Rooms         = RoomDB.GetRoomsFromReservationId(idReservation)
                            };
                            reservations.Add(reservation);
                        }
                    }
                }
                return(reservation);
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Пример #2
0
        public static Reservation GetReservation(int idReservation)
        {
            Reservation result = new Reservation();

            try
            {
                string connectionString = ConfigurationManager.ConnectionStrings["DatabaseDataAccess"].ConnectionString;

                using (SqlConnection cn = new SqlConnection(connectionString))
                {
                    string query = "SELECT * FROM Reservation WHERE IdReservation = @idReservation";

                    SqlCommand cmd = new SqlCommand(query, cn);
                    cmd.Parameters.AddWithValue("@idReservation", idReservation);
                    cn.Open();

                    using (SqlDataReader dr = cmd.ExecuteReader())
                    {
                        while (dr.Read())
                        {
                            result.IdReservation = idReservation;

                            result.Arrival = Convert.ToDateTime(dr["Arrival"]);

                            result.Departure = Convert.ToDateTime(dr["Departure"]);

                            result.Rooms = RoomDB.GetRoomsOfReservation(idReservation);

                            result.Client = ClientDB.GetClient((int)dr["IdClient"]);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                throw e;
            }

            return(result);
        }