Пример #1
0
        public static List <Duty> GetAll()
        {
            List <Duty> allDutys = new List <Duty> {
            };
            MySqlConnection conn = DB.Connection();

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

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

            while (rdr.Read())
            {
                int    dutyId          = rdr.GetInt32(0);
                string dutyDescription = rdr.GetString(1);
                Duty   newDuty         = new Duty(dutyDescription, dutyId);
                allDutys.Add(newDuty);
            }
            conn.Close();
            if (conn != null)
            {
                conn.Dispose();
            }
            return(allDutys);
        }
Пример #2
0
        public static Duty Find(int id)
        {
            MySqlConnection conn = DB.Connection();

            conn.Open();

            var cmd = conn.CreateCommand() as MySqlCommand;

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

            MySqlParameter thisId = new MySqlParameter();

            thisId.ParameterName = "@thisId";
            thisId.Value         = id;
            cmd.Parameters.Add(thisId);
            MySqlDataReader rdr             = cmd.ExecuteReader() as MySqlDataReader;
            int             dutyId          = 0;
            string          dutyDescription = "";

            while (rdr.Read())
            {
                dutyId          = rdr.GetInt32(0);
                dutyDescription = rdr.GetString(1);
            }
            Duty foundDuty = new Duty(dutyDescription, dutyId);

            conn.Close();
            if (conn != null)
            {
                conn.Dispose();
            }
            return(foundDuty);
        }
Пример #3
0
 public override bool Equals(System.Object otherDuty)
 {
     if (!(otherDuty is Duty))
     {
         return(false);
     }
     else
     {
         Duty newDuty             = (Duty)otherDuty;
         bool idEquality          = (this.Id == newDuty.Id);
         bool descriptionEquality = (this.DutyDescription == newDuty.DutyDescription);
         return(idEquality && descriptionEquality);
     }
 }
 public void AddDuty(Duty duty)
 {
     Dutys.Add(duty);
 }