コード例 #1
0
        public bool DeleteGroup(Groupe g)
        {
            string       query = "DELETE FROM liste_groupe_client WHERE id_groupe_fk=@id_groupe";
            MySqlCommand cmd   = new MySqlCommand(query);

            cmd.Parameters.AddWithValue("@id_groupe", g.id_groupe);

            if (!ExecuteNonQuery(cmd))
            {
                return(false);
            }

            query = "DELETE FROM invitation WHERE id_groupe_fk=@id_groupe";
            cmd   = new MySqlCommand(query);
            cmd.Parameters.AddWithValue("@id_groupe", g.id_groupe);
            if (!ExecuteNonQuery(cmd))
            {
                return(false);
            }

            query = "DELETE FROM fichier WHERE id_groupe_fk=@id_groupe";
            cmd   = new MySqlCommand(query);
            cmd.Parameters.AddWithValue("@id_groupe", g.id_groupe);
            if (!ExecuteNonQuery(cmd))
            {
                return(false);
            }

            query = "DELETE FROM groupe WHERE id_groupe=@id_groupe";
            cmd   = new MySqlCommand(query);
            cmd.Parameters.AddWithValue("@id_groupe", g.id_groupe);
            LAST_TIME_SYNC_GROUPS = DateTime.Now;
            return(ExecuteNonQuery(cmd));
        }
コード例 #2
0
        public bool ModifyGroup(Groupe g)
        {
            string       query = "UPDATE groupe SET admin=@admin, nom=@nom WHERE id_groupe=@id_groupe";
            MySqlCommand cmd   = new MySqlCommand(query);

            cmd.Parameters.AddWithValue("@id_groupe", g.id_groupe);
            cmd.Parameters.AddWithValue("@admin", g.admin);
            cmd.Parameters.AddWithValue("@nom", g.nom);
            LAST_TIME_SYNC_GROUPS = DateTime.Now;
            return(ExecuteNonQuery(cmd));
        }
コード例 #3
0
        // GROUP //

        private Groupe ReaderToGroup(MySqlDataReader reader)
        {
            Groupe groupe = new Groupe
            {
                id_groupe = reader["id_groupe"] != DBNull.Value ? reader.GetInt32("id_groupe") : 0,
                nom       = reader["nom"] != DBNull.Value ? reader.GetString("nom") : null,
                admin     = reader["admin"] != DBNull.Value ? reader.GetInt32("admin") : 0
            };

            LAST_TIME_SYNC_GROUPS = DateTime.Now;
            return(groupe);
        }
コード例 #4
0
        public bool CreateGroup(Groupe g)
        {
            string       query = "INSERT INTO groupe(admin, nom) VALUES(@admin,@nom)";
            MySqlCommand cmd   = new MySqlCommand(query);

            cmd.Parameters.AddWithValue("@admin", g.admin);
            cmd.Parameters.AddWithValue("@nom", g.nom);
            bool success = ExecuteNonQuery(cmd);

            if (success && cmd.LastInsertedId != 0)
            {
                AddMemberToGroup((int)cmd.LastInsertedId, g.admin);
            }
            LAST_TIME_SYNC_GROUPS = DateTime.Now;
            return(success);
        }
コード例 #5
0
        public Groupe GetGroup(int id_groupe)
        {
            string       query = "SELECT * FROM groupe WHERE id_groupe=@id_groupe";
            MySqlCommand cmd   = new MySqlCommand(query);

            cmd.Parameters.AddWithValue("@id_groupe", id_groupe);

            using (var reader = ExecuteReader(cmd))
            {
                if (!reader.HasRows)
                {
                    return(null);
                }

                reader.Read();
                Groupe groupe = ReaderToGroup(reader);
                bdd.CloseConnection();
                LAST_TIME_SYNC_GROUPS = DateTime.Now;
                return(groupe);
            }
        }
コード例 #6
0
        /// <exception cref="Exception"/>
        public List <Groupe> GetAllGroup()
        {
            List <Groupe> lst = new List <Groupe>();

            try
            {
                MySqlCommand cmd = new MySqlCommand("SELECT * FROM groupe");
                using (var reader = ExecuteReader(cmd))
                {
                    while (reader.Read())
                    {
                        Groupe g = ReaderToGroup(reader);
                        lst.Add(g);
                    }
                }
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine(ex.Message);
            }
            bdd.CloseConnection();
            LAST_TIME_SYNC_GROUPS = DateTime.Now;
            return(lst);
        }
コード例 #7
0
 public bool SetGroupAdministrator(Groupe group, Client admin)
 {
     group.admin           = admin.id_client;
     LAST_TIME_SYNC_GROUPS = DateTime.Now;
     return(ModifyGroup(group));
 }