Ejemplo n.º 1
0
        public static SpecialtyClass 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 feature     = "";

            while (rdr.Read())
            {
                specialtyId = rdr.GetInt32(0);
                feature     = rdr.GetString(1);
            }
            SpecialtyClass foundSpecialty = new SpecialtyClass(feature, specialtyId);

            conn.Close();
            if (conn != null)
            {
                conn.Dispose();
            }
            return(foundSpecialty);
        }
Ejemplo n.º 2
0
        public static List <SpecialtyClass> GetAll()
        {
            List <SpecialtyClass> allSpecialties = new List <SpecialtyClass> {
            };
            MySqlConnection conn = DB.Connection();

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

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

            while (rdr.Read())
            {
                int            id           = rdr.GetInt32(0);
                string         feature      = rdr.GetString(1);
                SpecialtyClass newSpecialty = new SpecialtyClass(feature, id);
                allSpecialties.Add(newSpecialty);
            }

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

            return(allSpecialties);
        }
Ejemplo n.º 3
0
        public void AddSpecialty(SpecialtyClass newSpecialty)
        {
            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         = _id;
            cmd.Parameters.Add(stylist_Id);
            MySqlParameter specialty_Id = new MySqlParameter();

            specialty_Id.ParameterName = "@specialtyId";
            specialty_Id.Value         = newSpecialty.GetId();
            cmd.Parameters.Add(specialty_Id);
            cmd.ExecuteNonQuery();

            conn.Close();
            if (conn != null)
            {
                conn.Dispose();
            }
        }
Ejemplo n.º 4
0
 public override bool Equals(System.Object otherSpecialty)
 {
     if (!(otherSpecialty is SpecialtyClass))
     {
         return(false);
     }
     else
     {
         SpecialtyClass newSpecialty      = (SpecialtyClass)otherSpecialty;
         bool           specialtyEquality = (this.GetFeature() == newSpecialty.GetFeature() && this.GetId() == newSpecialty.GetId());
         return(specialtyEquality);
     }
 }
Ejemplo n.º 5
0
        public List <SpecialtyClass> GetSpecialties()
        {
            List <SpecialtyClass> allSpecialties = new List <SpecialtyClass> {
            };
            MySqlConnection conn = DB.Connection();

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

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

            stylistId.ParameterName = "@stylistId";
            stylistId.Value         = this._id;
            cmd.Parameters.Add(stylistId);
            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            specialty_Id = rdr.GetInt32(0);
                string         feature      = rdr.GetString(1);
                SpecialtyClass newSpecialty = new SpecialtyClass(feature, specialty_Id);
                allSpecialties.Add(newSpecialty);
            }
            conn.Close();
            if (conn != null)
            {
                conn.Dispose();
            }
            return(allSpecialties);
        }