Esempio n. 1
0
        public List <Movie> GetAllMoviesByShowTime(string date, string operater)
        {
            string       query     = "SELECT * FROM Movie INNER JOIN ShowTime ON Movie.PK_movieName = ShowTime.FK_movieName WHERE ShowTime.FK_time " + operater + "  '" + date + "'";
            Movie        newMovie  = null;
            List <Movie> movieList = new List <Movie>();

            if (ConnectToDB() == true)
            {
                MySqlCommand    cmd        = new MySqlCommand(query, con);
                MySqlDataReader dataReader = cmd.ExecuteReader();
                List <string>   movieNames = new List <string>();
                ShowTime        showTime;
                Theater         theater;
                bool            listCheck = false;

                //Read the data and store them in the list
                while (dataReader.Read())
                {
                    // Making sure we only use unique movieNames displayed on the frontpage
                    // And inserting times to the list on the movie if we are getting more than 1 showtime

                    if (movieNames.Contains(dataReader["PK_movieName"].ToString()))
                    {
                        listCheck = true;
                    }

                    if (listCheck == false)
                    {
                        newMovie            = new Movie(dataReader["PK_movieName"].ToString(), dataReader["FK_type"].ToString(), dataReader["runTime"].ToString(), dataReader["description"].ToString(), dataReader["coverImage"].ToString());
                        showTime            = new ShowTime();
                        theater             = new Theater();
                        showTime.ShowTimeId = Convert.ToInt32(dataReader["PK_showTimeId"]);
                        showTime.Time       = Convert.ToDateTime(dataReader["FK_time"]);
                        theater.Number      = Convert.ToInt32(dataReader["FK_theaterNumber"]);
                        showTime.Theater    = theater;
                        newMovie.ShowTimes.Add(showTime);
                        movieNames.Add(dataReader["PK_movieName"].ToString());
                        movieList.Add(newMovie);
                    }
                    else
                    {
                        showTime         = new ShowTime();
                        theater          = new Theater();
                        theater.Number   = Convert.ToInt32(dataReader["FK_theaterNumber"]);
                        showTime.Theater = theater;
                        showTime.Time    = Convert.ToDateTime(dataReader["FK_time"]);
                        newMovie.ShowTimes.Add(showTime);
                    }

                    listCheck = false;
                }

                //close Data Reader
                dataReader.Close();

                //close Connection
                con.Close();

                return(movieList);
            }
            else
            {
                return(movieList);
            }
        }