예제 #1
0
        public void AddStylist(StylistClass newStylist)
        {
            MySqlConnection conn = DB.Connection();

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

            cmd.CommandText = @"INSERT INTO stylists_specialties (stylist_Id, specialty_Id) VALUES (@stylistId, @specialtyId);";
            MySqlParameter stylist_Id = new MySqlParameter();

            stylist_Id.ParameterName = "@stylistId";
            stylist_Id.Value         = newStylist.GetId();
            cmd.Parameters.Add(stylist_Id);
            MySqlParameter specialty_Id = new MySqlParameter();

            specialty_Id.ParameterName = "@specialtyId";
            specialty_Id.Value         = _id;
            cmd.Parameters.Add(specialty_Id);
            cmd.ExecuteNonQuery();
            conn.Close();
            if (conn != null)
            {
                conn.Dispose();
            }
        }
예제 #2
0
        public List <StylistClass> GetStylists()
        {
            List <StylistClass> allStylists = new List <StylistClass> {
            };
            MySqlConnection conn            = DB.Connection();

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

            cmd.CommandText = @"SELECT stylists.* FROM stylists JOIN stylists_specialties ON (stylists.Id = stylists_specialties.stylist_Id) JOIN specialties ON (stylists_specialties.specialty_Id = specialties.Id) WHERE specialties.Id = (@specialtyId);";
            MySqlParameter specialtyId = new MySqlParameter();

            specialtyId.ParameterName = "@specialtyId";
            specialtyId.Value         = this._id;
            cmd.Parameters.Add(specialtyId);
            MySqlDataReader rdr = cmd.ExecuteReader() as MySqlDataReader;

            while (rdr.Read())
            {
                int          stylistId   = rdr.GetInt32(0);
                string       name        = rdr.GetString(1);
                string       phoneNumber = rdr.GetString(2);
                StylistClass newStylist  = new StylistClass(name, phoneNumber, stylistId);
                allStylists.Add(newStylist);
            }
            conn.Close();
            if (conn != null)
            {
                conn.Dispose();
            }
            return(allStylists);
        }
예제 #3
0
        public static StylistClass Find(int id)
        {
            MySqlConnection conn = DB.Connection();

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

            cmd.CommandText = @"SELECT * FROM stylists WHERE Id = (@thisId);";
            MySqlParameter thisId = new MySqlParameter();

            thisId.ParameterName = "@thisId";
            thisId.Value         = id;
            cmd.Parameters.Add(thisId);
            var    rdr         = cmd.ExecuteReader() as MySqlDataReader;
            int    stylistId   = 0;
            string name        = "";
            string phoneNumber = "";

            while (rdr.Read())
            {
                stylistId   = rdr.GetInt32(0);
                name        = rdr.GetString(1);
                phoneNumber = rdr.GetString(2);
            }
            StylistClass foundStylist = new StylistClass(name, phoneNumber, stylistId);

            conn.Close();
            if (conn != null)
            {
                conn.Dispose();
            }
            return(foundStylist);
        }
예제 #4
0
        public static List <StylistClass> GetAll()
        {
            List <StylistClass> allStylists = new List <StylistClass>();
            MySqlConnection     conn        = DB.Connection();

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

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

            while (rdr.Read())
            {
                int          stylistId   = rdr.GetInt32(0);
                string       name        = rdr.GetString(1);
                string       phoneNumber = rdr.GetString(2);
                StylistClass newStylist  = new StylistClass(name, phoneNumber, stylistId);
                allStylists.Add(newStylist);
            }

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

            return(allStylists);
        }
예제 #5
0
 public override bool Equals(System.Object otherStylist)
 {
     if (!(otherStylist is StylistClass))
     {
         return(false);
     }
     else
     {
         StylistClass newStylist      = (StylistClass)otherStylist;
         bool         stylistEquality = (this.GetName() == newStylist.GetName() && this.GetPhoneNumber() == newStylist.GetPhoneNumber() && this.GetId() == newStylist.GetId());
         return(stylistEquality);
     }
 }