Beispiel #1
0
        protected static void GetRandomMovieAndRate()
        {
            var random = new Random();

            using var conn = new MySqlConnection(ConnStr);
            conn.Open();
            const string sql = "SELECT COUNT(*) FROM movies_tbl";

            using var cmd = new MySqlCommand(sql, conn);
            var count = cmd.ExecuteScalar();
            var rand  = random.Next(1, int.Parse(count.ToString() !));
            var l     = 0;

            while (CheckIfRated(rand.ToString()))
            {
                rand = random.Next(1, int.Parse(count.ToString() !));
                if (l + 1 == int.Parse(count.ToString() !))
                {
                    Console.WriteLine("you have rate every movie");
                    break;
                }
                l++;
            }
            Movie randomMovie = GetShowFromIndex(rand.ToString());

            Console.WriteLine("Show Selected '{0}'", randomMovie.MovieName);
            Console.WriteLine($"what would you rate the selected show?(max. 10) ");
            var rating = Console.ReadLine();

            while (int.Parse(rating !) > 10)
            {
                Console.WriteLine("what would you rate the selected show?(max. 10)");
                rating = Console.ReadLine();
            }

            RateShow.Rate(rand.ToString(), rating);
            Console.WriteLine($"You rerate '{randomMovie.MovieName}' {rating}/10");

            Console.ReadKey();
        }
Beispiel #2
0
        protected static void GetSearchResAndRate(string term)
        {
            var titles  = new List <string>();
            var ratings = new List <string>();
            var ids     = new List <string>();

            var sql = "SELECT * FROM movies_tbl WHERE movie_name LIKE" + "'%" + term + "%'" + "";

            using var conn = new MySqlConnection(ConnStr);
            conn.Open();
            using var cmd = new MySqlCommand(sql, conn);
            using var rdr = cmd.ExecuteReader();
            while (rdr.Read())
            {
                titles.Add(rdr.GetString(1));
                ratings.Add(rdr.GetString(3));
                ids.Add(rdr.GetString(0));
            }

            for (var i = 0; i < titles.Count; i++)
            {
                Console.WriteLine(CheckIfRated(ids[i])
                    ? $"{i + 1}) {titles[i]} | Rating : {ratings[i]}/10  | your Rating ?/10"
                    : $"{i + 1}) {titles[i]} | Rating : {ratings[i]}/10");
            }

            Console.WriteLine("-------------------------------");
            Console.WriteLine("Would you like to rate/add to your list one of the shows?(y/n)");
            if (Console.ReadLine()?.ToLower() == "y")
            {
                try
                {
                    Console.WriteLine("input the index");
                    var z = int.Parse(Console.ReadLine() ?? string.Empty);
                    if (CheckIfRated((ids[z - 1])))
                    {
                        Console.WriteLine(
                            "what would you rate '{0}'? (max Rating = 10) Note : you've already review this show this actions will simply update your score",
                            titles[z - 1]);
                        var rating = Console.ReadLine();
                        RateShow.RateUpdate(ids[z - 1], rating);
                        Console.WriteLine($"You rated '{titles[z - 1]}' {rating}/10");
                        Console.ReadKey();
                    }
                    else
                    {
                        Console.WriteLine("what would you rate '{0}'? (max Rating = 10)", titles[z - 1]);
                        var rating = Console.ReadLine();
                        RateShow.Rate(ids[z - 1], rating);
                        Console.WriteLine($"You rated '{titles[z - 1]}' {rating}/10");
                        Console.ReadKey();
                    }
                }
                catch (ArgumentOutOfRangeException)
                {
                    Console.WriteLine("bro..");
                }
            }

            conn.Close();
        }