Создание веб-приложения, сочетающего в себе проектирование и создание баз данных, работу со сторонними форматами данных, программирование в NET и веб-разработку, страница 66

                                sql = "UPDATE auth_user SET role = " + id_start_role + " WHERE id = " + usernames[i] + ";";

                                comm = new MySqlCommand(sql, conn);

                                comm.ExecuteNonQuery();

                            }

                        }

                    }

                    conn.Close();

                }

            }

            catch (MySqlException exp)

            {

                conn.Close();

                return;

            }

            catch (ProviderException exp)

            {

                conn.Close();

                return;

            }

        }

        public override bool RoleExists(string roleName)

        {

            MySqlConnection conn = null;

            try

            {

                if (roleName.Length > 25) throw new ProviderException();

                else if (roleName == "" || roleName == null) throw new ProviderException();

                else

                {

                    //ОБЪЯВЛЕНИЕ

                    conn = new MySqlConnection(connectionString);

                    conn.Open();

                    string sql;

                    MySqlDataAdapter adapter;

                    DataSet data = new DataSet();

                    //ПРОВЕРЯЕМ РОЛЬ В БАЗЕ

                    sql = "SELECT * FROM roles WHERE name = '" + roleName + "';";

                    adapter = new MySqlDataAdapter(sql, conn);

                    adapter.Fill(data);

                    if (data.Tables[0].Rows.Count == 0)

                    {

                        conn.Close();

                        return false;

                    }

                    else

                    {

                        conn.Close();

                        return true;

                    }

                }

            }

            catch (MySqlException exp)

            {

                conn.Close();

                return false;

            }

            catch (ProviderException exp)

            {

                conn.Close();

                return false;

            }

        }

    }

}

Е.3 Файл PowerPlayUserProvider.cs

namespace powerplay

{

    public static class PowerPlayUserProvider

    {

        private static string connectionString;

        public static string getAvatar(string UserName)

        {

            string database = "powerplay";

            string password_db = "admin";

            string user_db = "root";

            string server_db = "localhost";

            connectionString = ("server=" + server_db + "; user id=" + user_db + "; password=" + password_db + "; database=" + database + "");

            MySqlConnection conn = null;

            try

            {

                //ОБЪЯВЛЕНИЕ

                conn = new MySqlConnection(connectionString);

                conn.Open();

                string avatar = null;

                string sql;

                MySqlCommand comm = null;

                MySqlDataReader reader = null;

                //ПРОВЕРЯЕМ, ЕСТЬ ЛИ УЖЕ ТАКОЙ ЮЗЕР

                sql = "SELECT avatar_path FROM auth_user WHERE name = '" + UserName + "';";

                comm = new MySqlCommand(sql, conn);

                reader = comm.ExecuteReader();

                while (reader.Read())

                {

                    avatar = reader[0].ToString();

                }

                reader.Close();

                conn.Close();

                return avatar;

            }

            catch (MySqlException exp)

            {

                conn.Close();

                return null;

            }

        }

        public static void setAvatar(string UserName, string value)

        {

            string database = "powerplay";