Exemplo n.º 1
0
        internal void GetInvitaions(Friends s, string username)
        {
            if (string.IsNullOrWhiteSpace(username))
            {
                throw new ArgumentNullException(nameof(username));
            }

            string query = $"Select * from Friends where FriendsUsername = '******' and Accepted = 'N'";

            using (MySqlConnection connection = new MySqlConnection(connectionString))
            {
                connection.OpenAsync();
                //create command and assign the query and connection from the constructor
                MySqlCommand cmd = new MySqlCommand(query, connection);

                MySqlDataReader dataReader = cmd.ExecuteReader();

                //Read the data and store them in the list
                while (dataReader.Read())
                {
                    Console.WriteLine("Username: "******"UserName"].ToString().ToLowerInvariant() + " has invited you.");
                    Console.Write("Do you want to accept him (Y/N): ");
                    string answer = Console.ReadLine().ToUpperInvariant();
                    if (answer == "Y")
                    {
                        AcceptFriendInvitation(username, dataReader["UserName"].ToString().ToLowerInvariant());
                        s.AddacceptedFriend(dataReader["UserName"].ToString().ToLowerInvariant());
                    }
                    else if (answer == "N")
                    {
                        RemoveInvitation(dataReader["UserName"].ToString().ToLowerInvariant(), username);
                    }
                    else
                    {
                        Console.WriteLine("Not answered!");
                    }
                }

                dataReader.Close();

                connection.CloseAsync();
            }
        }