Exemple #1
0
        public JsonResult Delete(int id)
        {
            Lapin l = db.lapins.Find(id);

            db.lapins.Remove(l);
            db.SaveChanges();
            return(Json(0, JsonRequestBehavior.AllowGet));
        }
Exemple #2
0
        public JsonResult Update(Lapin lpn)
        {
            Lapin l = db.lapins.Find(lpn.id);

            l.age        = lpn.age;
            l.nomlapalin = lpn.nomlapalin;
            db.SaveChanges();
            return(Json(1, JsonRequestBehavior.AllowGet));
        }
Exemple #3
0
 private void delete(Lapin lapin)
 {
     using (MySqlConnection cnx = DaoConnectionSingleton.GetMySqlConnection()) {
         cnx.Open();
         using (MySqlCommand cmd = new MySqlCommand("delete from Lapin where id=@id", cnx)) {
             cmd.Parameters.Add(new MySqlParameter("@id", MySqlDbType.Int32));
             cmd.Parameters["@id"].Value = lapin.Id;
             cmd.ExecuteNonQuery();
         }
     }
 }
Exemple #4
0
 private void update(Lapin lapin)
 {
     using (MySqlConnection cnx = DaoConnectionSingleton.GetMySqlConnection()) {
         cnx.Open();
         using (MySqlCommand cmd = new MySqlCommand("update Lapin set surnom=@surnom,age=@age,position=@position,dossard=@dossard idCourse=@idCourse where id=@id", cnx)) {
             cmd.Parameters.Add(new MySqlParameter("@id", MySqlDbType.Int32));
             cmd.Parameters.Add(new MySqlParameter("@age", MySqlDbType.Int32));
             cmd.Parameters.Add(new MySqlParameter("@position", MySqlDbType.Int32));
             cmd.Parameters.Add(new MySqlParameter("@dossard", MySqlDbType.Int32));
             cmd.Parameters.Add(new MySqlParameter("@surnom", MySqlDbType.VarChar));
             cmd.Parameters["@id"].Value       = lapin.Id;
             cmd.Parameters["@age"].Value      = lapin.Age;
             cmd.Parameters["@position"].Value = lapin.GetPosition();
             cmd.Parameters["@dossard"].Value  = lapin.Dossard;
             cmd.Parameters["@surnom"].Value   = lapin.GetSurnom();
             cmd.ExecuteNonQuery();
         }
     }
     lapin.State = State.unChanged;
 }
Exemple #5
0
 private void insert(Lapin lapin)
 {
     using (MySqlConnection cnx = DaoConnectionSingleton.GetMySqlConnection()) {
         cnx.Open();
         using (MySqlCommand cmd = new MySqlCommand("insert into Lapin(surnom,age,position,dossard,idCourse) values(@surnom,@age,@position,@dossard,@idCourse)", cnx)) {
             cmd.Parameters.Add(new MySqlParameter("@idCourse", MySqlDbType.Int32));
             cmd.Parameters.Add(new MySqlParameter("@age", MySqlDbType.Int32));
             cmd.Parameters.Add(new MySqlParameter("@position", MySqlDbType.Int32));
             cmd.Parameters.Add(new MySqlParameter("@dossard", MySqlDbType.Int32));
             cmd.Parameters.Add(new MySqlParameter("@surnom", MySqlDbType.VarChar));
             cmd.Parameters["@id"].Value       = lapin.Id;
             cmd.Parameters["@age"].Value      = lapin.Age;
             cmd.Parameters["@position"].Value = lapin.GetPosition();
             cmd.Parameters["@dossard"].Value  = lapin.Dossard;
             cmd.Parameters["@surnom"].Value   = lapin.Surnom;
             cmd.ExecuteNonQuery();
             // Todo coder la récupération de LastId
         }
     }
     lapin.State = State.unChanged;
 }
Exemple #6
0
        public void SaveChanges(List <Lapin> lapins)
        {
            for (int i = 0; i < lapins.Count; i++)
            {
                Lapin lapin = lapins[i];
                switch (lapin.State)
                {
                case State.added:
                    this.insert(lapin);
                    break;

                case State.modified:
                    this.update(lapin);
                    break;

                case State.deleted:
                    this.delete(lapin);
                    lapins.Remove(lapin);
                    break;
                }
            }
        }
Exemple #7
0
        static void Main()
        {
            /*
             * List<Lapin> mesLapins= new List<Lapin>();
             *
             * mesLapins.Add(new Lapin("jeannot",2));
             * mesLapins.Add(new Lapin("panpan", 6));
             * mesLapins.Add(new Lapin("jelly", 5));
             *
             * for (int j = 0; j < 42; j++) {
             *  for (int i = 0; i < mesLapins.Count; i++) {
             *      ((Lapin)mesLapins[i]).Avancer();
             *      Console.WriteLine(mesLapins[i].ToString());
             *  }
             *
             * }
             * Console.ReadLine();
             */

            ArrayList mesLapins = new ArrayList();

            mesLapins.Add(new Lapin("Jeannot", 2));
            mesLapins.Add(new Lapin("Panpan", 6));
            mesLapins.Add(new Lapin("Jelly", 5));

            for (int j = 0; j < 40; j++)
            {
                for (int i = 0; i < mesLapins.Count; i++)
                {
                    ((Lapin)mesLapins[i]).Avancer();
                    Console.WriteLine(((Lapin)mesLapins[i]).ToString());
                }
            }

            Lapin gagnant = (Lapin)mesLapins[0];

            foreach (Lapin lapin in mesLapins)
            {
                if (lapin.Position() > gagnant.Position())
                {
                    gagnant = lapin;
                }
            }
            Console.WriteLine("Le gagnant est {0} !", gagnant.Surnom);
            Console.ReadLine();


            /*
             * Lapin l1 = new Lapin("Guy",2);
             * Lapin l2 = new Lapin("Matthias",3);
             * Lapin l3 = new Lapin("David",4);
             * Lapin[] tabL = new Lapin[3];
             * tabL[0] = l1;
             * tabL[1] = l2;
             * tabL[2] = l3;
             *
             * for (int i = 0; i < tabL.Length; i++)
             * {
             *  tabL[i].Avancer();
             *  Console.WriteLine(tabL[i].ToString());
             * }
             *
             *
             * Console.ReadLine();
             */
        }
Exemple #8
0
 public JsonResult Add(Lapin lpn)
 {
     db.lapins.Add(lpn);
     db.SaveChanges();
     return(Json(1, JsonRequestBehavior.AllowGet));
 }