public List <Specialty> GetSpecialties()
        {
            MySqlConnection conn = DB.Connection();

            conn.Open();
            var cmd = conn.CreateCommand() as MySqlCommand;

            cmd.CommandText = @"SELECT specialties.* FROM stylists
                                JOIN stylists_specialties ON (stylists.id = stylists_specialties.stylist_id)
                                JOIN specialties ON (stylists_specialties.specialty_id = specialties.id)
                                WHERE stylists.id = @stylistId;";

            MySqlParameter stylistIdParameter = new MySqlParameter();

            stylistIdParameter.ParameterName = "@stylistId";
            stylistIdParameter.Value         = _id;
            cmd.Parameters.Add(stylistIdParameter);

            var rdr = cmd.ExecuteReader() as MySqlDataReader;

            List <Specialty> specialties = new List <Specialty> {
            };

            while (rdr.Read())
            {
                int       specialtyId          = rdr.GetInt32(0);
                string    specialtyDescription = rdr.GetString(1);
                Specialty newSpecialty         = new Specialty(specialtyDescription, specialtyId);
                specialties.Add(newSpecialty);
            }

            conn.Close();
            if (conn != null)
            {
                conn.Dispose();
            }

            return(specialties);
        }
Beispiel #2
0
        public static List <Specialty> GetAll()
        {
            List <Specialty> allSpecialties = new List <Specialty>();
            MySqlConnection  conn           = DB.Connection();

            conn.Open();
            var cmd = conn.CreateCommand();

            cmd.CommandText = @"SELECT * FROM specialty;";
            var rdr = cmd.ExecuteReader() as MySqlDataReader;

            while (rdr.Read())
            {
                int    specialtyId   = rdr.GetInt32(0);
                string specialtyName = rdr.GetString(1);

                Specialty newSpecialty = new Specialty(specialtyName, specialtyId);
                allSpecialties.Add(newSpecialty);
            }

            return(allSpecialties);
        }
Beispiel #3
0
        public static List <Specialty> GetAllByStylist(int stylistId)
        {
            List <Specialty> specialties = new List <Specialty> {
            };
            MySqlConnection conn         = DB.Connection();

            conn.Open();
            var cmd = conn.CreateCommand() as MySqlCommand;

            cmd.CommandText = @"SELECT DISTINCT specialties.* FROM stylists JOIN specialties_stylists ON (stylists.id = specialties_stylists.stylist_id) JOIN specialties ON (specialties_stylists.specialty_id = specialties.id) WHERE stylist_id = @stylistId;";
            cmd.Parameters.AddWithValue("@stylistId", stylistId);
            MySqlDataReader rdr = cmd.ExecuteReader() as MySqlDataReader;

            while (rdr.Read())
            {
                Specialty newSpecialty = new Specialty(rdr.GetString(1));
                newSpecialty.Id = rdr.GetInt32(0);
                specialties.Add(newSpecialty);
            }
            DB.Close(conn);
            return(specialties);
        }
        public void AddSpecialty(Specialty newSpecialty)
        {
            MySqlConnection conn = DB.Connection();

            conn.Open();
            MySqlCommand cmd = conn.CreateCommand() as MySqlCommand;

            cmd.CommandText = @"INSERT INTO stylists_specialties (stylist_id, specialty_id) 
                                                        VALUES (@stylistId, @specialtyId);";


            cmd.Parameters.Add(new MySqlParameter("@stylistId", this._stylistId));
            cmd.Parameters.Add(new MySqlParameter("@specialtyId", newSpecialty.GetSpecialtyId()));

            cmd.ExecuteNonQuery();

            conn.Close();
            if (conn != null)
            {
                conn.Dispose();
            }
        }
        public static Specialty Find(int id)
        {
            MySqlConnection conn = DB.Connection();

            conn.Open();
            var cmd = conn.CreateCommand() as MySqlCommand;

            cmd.CommandText = @"SELECT * FROM specialties WHERE id = (@searchId);";

            MySqlParameter searchId = new MySqlParameter();

            searchId.ParameterName = "@searchId";
            searchId.Value         = id;
            cmd.Parameters.Add(searchId);

            var    rdr            = cmd.ExecuteReader() as MySqlDataReader;
            int    specialtyId    = 0;
            string specialtyName  = "";
            string specialtyPrice = "";

            while (rdr.Read())
            {
                specialtyId    = rdr.GetInt32(0);
                specialtyName  = rdr.GetString(1);
                specialtyPrice = rdr.GetString(2);
            }

            Specialty newSpecialty = new Specialty(specialtyName, specialtyPrice);

            newSpecialty._specialtyId = specialtyId;

            conn.Close();
            if (conn != null)
            {
                conn.Dispose();
            }
            return(newSpecialty);
        }
Beispiel #6
0
        public static Specialty GetByID(int searchID)
        {
            Specialty result = null;

            MySqlConnection conn = DB.Connection();

            conn.Open();
            MySqlCommand cmd = conn.CreateCommand() as MySqlCommand;

            cmd.CommandText = $"SELECT * FROM specialties WHERE (id = {searchID});";

            MySqlDataReader rdr = cmd.ExecuteReader() as MySqlDataReader;

            while (rdr.Read())
            {
                int    id   = rdr.GetInt32(0);
                string name = rdr.GetString(1);
                result = new Specialty(name, id);
            }
            DB.Close(conn);

            return(result);
        }
        public static Specialty Find(int id)
        {
            MySqlConnection conn = DB.Connection();

            conn.Open();

            var cmd = conn.CreateCommand() as MySqlCommand;

            cmd.CommandText = @"SELECT * FROM `specialties` WHERE id = @thisId;";

            MySqlParameter thisId = new MySqlParameter();

            thisId.ParameterName = "@thisId";
            thisId.Value         = id;
            cmd.Parameters.Add(thisId);

            var rdr = cmd.ExecuteReader() as MySqlDataReader;

            int    specialtyId = 0;
            string description = string.Empty;

            while (rdr.Read())
            {
                specialtyId = rdr.GetInt32(0);
                description = rdr.GetString(1);
            }

            Specialty foundSpecialty = new Specialty(description, specialtyId);

            conn.Close();
            if (conn != null)
            {
                conn.Dispose();
            }

            return(foundSpecialty);
        }
Beispiel #8
0
        public static List <Specialty> GetAll()
        {
            List <Specialty> allSpecialtys = new List <Specialty> {
            };
            MySqlConnection conn           = DB.Connection();

            conn.Open();
            MySqlCommand    cmd = new MySqlCommand(@"SELECT * FROM specialties;", conn);
            MySqlDataReader rdr = cmd.ExecuteReader() as MySqlDataReader;

            while (rdr.Read())
            {
                int       stylistId    = rdr.GetInt32(0);
                string    stylistName  = rdr.GetString(1);
                Specialty newSpecialty = new Specialty(stylistName, stylistId);
                allSpecialtys.Add(newSpecialty);
            }
            conn.Close();
            if (conn != null)
            {
                conn.Dispose();
            }
            return(allSpecialtys);
        }
 public List <Specialty> GetAllSpecialties()
 {
     return(Specialty.GetAll());
 }
Beispiel #10
0
 public void AddSpecialty(Specialty specialty)
 {
     specialty.AddStylist(_id);
 }
Beispiel #11
0
        public void AddSpecialty(string s)
        {
            Specialty newSpecialty = new Specialty(s);

            newSpecialty.Save();
        }