Example #1
0
        //Movie checker. it checks before inserting the movie into user's database if it already exist or not
        public List <Model.MoviesModel> MovieChecker(int ActiveUser_ID, int MovieId)
        {
            string connstring           = GetMysqlConnectionString();
            string mysql                = $"SELECT user_ID,tmdbID FROM Movie where user_ID={ActiveUser_ID} AND tmdbID={MovieId}";
            List <Model.MoviesModel> ml = new List <Model.MoviesModel>();

            Model.MoviesModel m = new Model.MoviesModel();

            using (MySqlConnection conn = new MySqlConnection(connstring))
            {
                conn.Open();
                using (MySqlCommand cmd = new MySqlCommand(mysql, conn))
                {
                    using (MySqlDataReader reader = cmd.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            m.OwnerId = int.Parse(reader.GetString(0));
                            m.ID      = int.Parse(reader.GetString(1));
                            ml.Add(m);
                        }
                        return(ml);
                    }
                }
            }
        }
Example #2
0
        //getting a list of all movies of a user saved in  mysql database
        public static List <Model.MoviesModel> GetAllMyMovies(int ActiveUser_ID)
        {
            try
            {
                string connstring = GetMysqlConnectionString();
                string mysql      = $"SELECT tmdbID FROM Movie WHERE user_ID={ActiveUser_ID}";

                List <Model.MoviesModel> ml = new List <Model.MoviesModel>();


                using (MySqlConnection conn = new MySqlConnection(connstring))
                {
                    conn.Open();
                    using (MySqlCommand cmd = new MySqlCommand(mysql, conn))
                    {
                        using (MySqlDataReader reader = cmd.ExecuteReader())
                        {
                            while (reader.Read())
                            {
                                Model.MoviesModel m = new Model.MoviesModel();
                                m.ID = int.Parse(reader.GetString(0));
                                ml.Add(m);
                            }
                            return(ml);
                        }
                    }
                }
            }
            catch
            {
                throw;
            }
        }