Beispiel #1
0
        /// <summary>
        /// Méthode permettant d'obtenir un ensemble de plats sauvegardé dans la base de données.
        /// </summary>
        /// <param name="args">Les arguments permettant de retrouver les plats.</param>
        /// <returns>Une liste contenant les plats.</returns>
        public IList <Plat> RetrieveSome(RetrieveSuiviPlatArgs args)
        {
            List <Plat> resultat = new List <Plat>();

            try
            {
                connexion = new MySqlConnexion();

                string requete = string.Format("SELECT * FROM SuiviPlats WHERE idMembre = {0}", args.IdMembre);

                DataSet   dataSetPlats = connexion.Query(requete);
                DataTable tablePlats   = dataSetPlats.Tables[0];

                foreach (DataRow rowPlat in tablePlats.Rows)
                {
                    Plat plat = platService.Retrieve(new RetrievePlatArgs {
                        IdPlat = ((int)rowPlat["idPlat"])
                    });

                    plat.EstTricherie = ((bool)rowPlat["estTricherie"]);

                    resultat.Add(plat);
                }
            }
            catch (Exception)
            {
                throw;
            }

            return(resultat);
        }
Beispiel #2
0
        /// <summary>
        /// Méthode permettant d'obtenir l'ensemble des plats sauvegardé dans la base de données.
        /// </summary>
        /// <returns>Une liste contenant les plats.</returns>
        public IList <Plat> RetrieveAll()
        {
            List <Plat> resultat = new List <Plat>();

            try
            {
                connexion = new MySqlConnexion();

                string requete = "SELECT * FROM Plats p INNER JOIN TypesPlats tp ON tp.idTypePlat = p.idTypePlat INNER JOIN Membres m ON m.idMembre = p.idMembre ORDER BY p.nom asc";

                DataSet   dataSetPlats = connexion.Query(requete);
                DataTable tablePlats   = dataSetPlats.Tables[0];

                foreach (DataRow rowPlat in tablePlats.Rows)
                {
                    Plat plat = ConstruirePlat(rowPlat);

                    plat.ListeIngredients = RetrieveAlimentsPlat(new RetrievePlatArgs {
                        IdPlat = plat.IdPlat
                    });

                    resultat.Add(plat);
                }
            }
            catch (Exception)
            {
                throw;
            }

            return(resultat);
        }
Beispiel #3
0
        /// <summary>
        /// Méthode permettant de mettre à jour un plat dans la base de données suite à un vote.
        /// </summary>
        /// <param name="plat">Le plat à mettre à jour.</param>
        public void UpdateVote(Plat plat)
        {
            try
            {
                connexion = new MySqlConnexion();

                // Obtenir le idTypePlat.
                string requete = string.Format("SELECT idTypePlat FROM TypesPlats WHERE typePlat = '{0}'", plat.TypePlat);

                DataSet   dataSetType = connexion.Query(requete);
                DataTable tableType   = dataSetType.Tables[0];
                int       idTypePlat  = (int)(tableType.Rows[0]["idTypePlat"]);

                string note = plat.Note.ToString();

                if (note.Contains(","))
                {
                    note = note.Replace(",", ".");
                }

                requete = string.Format("UPDATE Plats SET idTypePlat = {0}, nom = '{1}', imageUrl = '{2}', note = {3}, nbVotes = {4} WHERE idPlat = {5}", idTypePlat, plat.Nom.Replace("'", "''"), plat.ImageUrl, note, plat.NbVotes, plat.IdPlat);
                connexion.Query(requete);
            }
            catch (Exception)
            {
                throw;
            }
        }
Beispiel #4
0
        /// <summary>
        /// Méthode d'insertion d'un nouveau plat dans la base de données.
        /// </summary>
        /// <param name="unAliment"></param>
        public void Insert(Plat unPlat)
        {
            try
            {
                connexion = new MySqlConnexion();

                string requeteTypePlat = string.Format("SELECT * FROM TypesPlats WHERE typePlat = '{0}'", unPlat.TypePlat);

                DataSet dataSetTypes = connexion.Query(requeteTypePlat);
                DataTable tableTypes = dataSetTypes.Tables[0];

                int idType = 0;

                foreach (DataRow rowType in tableTypes.Rows)
                {
                    idType = (int)rowType["idTypePlat"];
                }

                string requeteCreateur = string.Format("SELECT * FROM Membres WHERE nomUtilisateur = '{0}'", unPlat.Createur);

                DataSet dataSetCreateur = connexion.Query(requeteCreateur);
                DataTable tableCreateur = dataSetCreateur.Tables[0];

                int idMembre = 0;

                foreach (DataRow rowCreateur in tableCreateur.Rows)
                {
                    idMembre = (int)rowCreateur["idMembre"];
                }

                string requeteInsert = string.Format("INSERT INTO Plats (idMembre, idTypePlat, nom, description, imageUrl, dateAjout) VALUES ({0}, {1}, '{2}', '{3}', '{4}', '{5}')", idMembre, idType, unPlat.Nom.Replace("'", "''"), unPlat.Description, unPlat.ImageUrl, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
                connexion.Query(requeteInsert);

                string requetePlat = string.Format("SELECT * FROM Plats WHERE nom = '{0}'", unPlat.Nom.Replace("'", "''"));

                DataSet dataSetPlat = connexion.Query(requetePlat);
                DataTable tablePlat = dataSetPlat.Tables[0];

                int idPlat = 0;

                foreach (DataRow rowPlat in tablePlat.Rows)
                {
                    idPlat = (int)rowPlat["idPlat"];
                }

                for (int i = 0; i < unPlat.ListeIngredients.Count; i++)
                {
                    string requeteInsertAlimentPlat = string.Format("INSERT INTO PlatsAliments (idPlat, idAliment, quantite) VALUES ({0}, {1}, {2})", idPlat, unPlat.ListeIngredients[i].IdAliment, unPlat.ListeIngredients[i].Quantite);
                    connexion.Query(requeteInsertAlimentPlat);
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Beispiel #5
0
        /// <summary>
        /// Méthode d'insertion d'un nouveau plat dans la base de données.
        /// </summary>
        /// <param name="unPlat">Le plat à insérer dans la base de donnée.</param>
        public void Insert(Plat unPlat)
        {
            try
            {
                connexion = new MySqlConnexion();

                string requeteTypePlat = string.Format("SELECT * FROM TypesPlats WHERE typePlat = '{0}'", unPlat.TypePlat);

                DataSet   dataSetTypes = connexion.Query(requeteTypePlat);
                DataTable tableTypes   = dataSetTypes.Tables[0];

                int idType = 0;

                foreach (DataRow rowType in tableTypes.Rows)
                {
                    idType = (int)rowType["idTypePlat"];
                }

                string requeteCreateur = string.Format("SELECT * FROM Membres WHERE nomUtilisateur = '{0}'", unPlat.Createur);

                DataSet   dataSetCreateur = connexion.Query(requeteCreateur);
                DataTable tableCreateur   = dataSetCreateur.Tables[0];

                int idMembre = 0;

                foreach (DataRow rowCreateur in tableCreateur.Rows)
                {
                    idMembre = (int)rowCreateur["idMembre"];
                }

                string requeteInsert = string.Format("INSERT INTO Plats (idMembre, idTypePlat, nom, description, imageUrl) VALUES ({0}, {1}, '{2}', '{3}', '{4}')", idMembre, idType, unPlat.Nom.Replace("'", "''"), unPlat.Description, unPlat.ImageUrl);
                connexion.Query(requeteInsert);

                string requetePlat = string.Format("SELECT * FROM Plats WHERE nom = '{0}'", unPlat.Nom.Replace("'", "''"));

                DataSet   dataSetPlat = connexion.Query(requetePlat);
                DataTable tablePlat   = dataSetPlat.Tables[0];

                int idPlat = 0;

                foreach (DataRow rowPlat in tablePlat.Rows)
                {
                    idPlat = (int)rowPlat["idPlat"];
                }

                for (int i = 0; i < unPlat.ListeIngredients.Count; i++)
                {
                    string requeteInsertAlimentPlat = string.Format("INSERT INTO PlatsAliments (idPlat, idAliment, quantite) VALUES ({0}, {1}, {2})", idPlat, unPlat.ListeIngredients[i].IdAliment, unPlat.ListeIngredients[i].Quantite);
                    connexion.Query(requeteInsertAlimentPlat);
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Beispiel #6
0
        /// <summary>
        /// Méthode de mise à jour d'un plat modifié dans la base de données.
        /// </summary>
        /// <param name="unPlat">Le plat à mettre à jour.</param>
        public void Update(Plat unPlat)
        {
            try
            {
                connexion = new MySqlConnexion();

                string requeteTypePlat = string.Format("SELECT * FROM TypesPlats WHERE typePlat = '{0}'", unPlat.TypePlat);

                DataSet   dataSetTypes = connexion.Query(requeteTypePlat);
                DataTable tableTypes   = dataSetTypes.Tables[0];

                int idType = 0;

                foreach (DataRow rowType in tableTypes.Rows)
                {
                    idType = (int)rowType["idTypePlat"];
                }

                string note = unPlat.Note.ToString();
                string requeteUpdate;
                if (!String.IsNullOrWhiteSpace(note))
                {
                    if (note.Contains(","))
                    {
                        note = note.Replace(",", ".");
                    }
                    requeteUpdate = string.Format("UPDATE Plats SET idTypePlat = {0}, nom = '{1}', imageUrl = '{2}', note = '{3}', nbVotes = {4}, description = '{5}' WHERE idPlat = {6}", idType, unPlat.Nom.Replace("'", "''"), unPlat.ImageUrl, note, unPlat.NbVotes, unPlat.Description, unPlat.IdPlat);
                }
                else
                {
                    //string.Format remplace un NULL, par un espace vide, ce qui est invalide dans MySql et lance une exception puisqu'il essait de convertir un string vide à un Double (le type de donnée en bd pour note)
                    //Dois vérifier manuellement et écrire NULL.
                    requeteUpdate = string.Format("UPDATE Plats SET idTypePlat = {0}, nom = '{1}', imageUrl = '{2}', note = NULL, nbVotes = {3}, description = '{4}' WHERE idPlat = {5}", idType, unPlat.Nom.Replace("'", "''"), unPlat.ImageUrl, unPlat.NbVotes, unPlat.Description, unPlat.IdPlat);
                }

                connexion.Query(requeteUpdate);

                int idPlat = (int)unPlat.IdPlat;

                string requeteDelete = string.Format("DELETE FROM PlatsAliments WHERE idPlat = {0}", idPlat);
                connexion.Query(requeteDelete);

                for (int i = 0; i < unPlat.ListeIngredients.Count; i++)
                {
                    string requeteInsertAlimentPlat = string.Format("INSERT INTO PlatsAliments (idPlat, idAliment, quantite) VALUES ({0}, {1}, {2})", idPlat, unPlat.ListeIngredients[i].IdAliment, unPlat.ListeIngredients[i].Quantite);
                    connexion.Query(requeteInsertAlimentPlat);
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Beispiel #7
0
        /// <summary>
        /// Méthode permettant de mettre à jour un plat dans la base de données.
        /// </summary>
        /// <param name="plat">Le plat à mettre à jour.</param>
        public void UpdateVote(Plat plat)
        {
            try
            {
                connexion = new MySqlConnexion();

                // Obtenir le idTypePlat.
                string requete = string.Format("SELECT idTypePlat FROM TypesPlats WHERE typePlat = '{0}'", plat.TypePlat);

                DataSet dataSetType = connexion.Query(requete);
                DataTable tableType = dataSetType.Tables[0];
                int idTypePlat = (int)(tableType.Rows[0]["idTypePlat"]);

                string note = plat.Note.ToString();

                if (note.Contains(","))
                {
                    note = note.Replace(",", ".");
                }

                requete = string.Format("UPDATE Plats SET idTypePlat = {0}, nom = '{1}', imageUrl = '{2}', note = {3}, nbVotes = {4} WHERE idPlat = {5}", idTypePlat, plat.Nom.Replace("'", "''"), plat.ImageUrl, note, plat.NbVotes, plat.IdPlat);
                connexion.Query(requete);
            }
            catch (Exception)
            {
                throw;
            }
        }
Beispiel #8
0
        /// <summary>
        /// Méthode de mise à jour d'un plat dans la base de données.
        /// </summary>
        /// <param name="unAliment"></param>
        public void Update(Plat unPlat)
        {
            try
            {
                connexion = new MySqlConnexion();

                string requeteTypePlat = string.Format("SELECT * FROM TypesPlats WHERE typePlat = '{0}'", unPlat.TypePlat);

                DataSet dataSetTypes = connexion.Query(requeteTypePlat);
                DataTable tableTypes = dataSetTypes.Tables[0];

                int idType = 0;

                foreach (DataRow rowType in tableTypes.Rows)
                {
                    idType = (int)rowType["idTypePlat"];
                }

                string note = unPlat.Note.ToString();

                if (note.Contains(","))
                {
                    note = note.Replace(",", ".");
                }

                string requeteUpdate = string.Format("UPDATE Plats SET idTypePlat = {0}, nom = '{1}', imageUrl = '{2}', note = '{3}', nbVotes = {4}, description = '{5}' WHERE idPlat = {6}", idType, unPlat.Nom.Replace("'", "''"), unPlat.ImageUrl, note, unPlat.NbVotes, unPlat.Description, unPlat.IdPlat);
                connexion.Query(requeteUpdate);

                int idPlat = (int)unPlat.IdPlat;

                string requeteDelete = string.Format("DELETE FROM PlatsAliments WHERE idPlat = {0}", idPlat);
                connexion.Query(requeteDelete);

                for (int i = 0; i < unPlat.ListeIngredients.Count; i++)
                {
                    string requeteInsertAlimentPlat = string.Format("INSERT INTO PlatsAliments (idPlat, idAliment, quantite) VALUES ({0}, {1}, {2})", idPlat, unPlat.ListeIngredients[i].IdAliment, unPlat.ListeIngredients[i].Quantite);
                    connexion.Query(requeteInsertAlimentPlat);
                }

            }
            catch (Exception)
            {
                throw;
            }
        }
Beispiel #9
0
        /// <summary>
        /// Méthode permettant d'obtenir un ensemble de plats sauvegardé dans la base de données.
        /// </summary>
        /// <param name="args">Les arguments permettant de retrouver les plats.</param>
        /// <returns>Une liste contenant les plats.</returns>
        public IList <Plat> RetrieveSome(RetrievePlatArgs args)
        {
            List <Plat> resultat = new List <Plat>();

            try
            {
                connexion = new MySqlConnexion();

                string requete = "SELECT * FROM Plats p INNER JOIN TypesPlats tp ON tp.idTypePlat = p.idTypePlat INNER JOIN Membres m ON m.idMembre = p.idMembre";

                if (args.Categorie != null && args.Categorie != string.Empty)
                {
                    requete += string.Format(" WHERE typePlat = '{0}'", args.Categorie);
                }

                if (args.NbResultats != null)
                {
                    if (args.PlusPopulaires == true)
                    {
                        requete += " ORDER BY note DESC ";
                    }
                    else if (args.PlusPopulaires == false)
                    {
                        requete += " ORDER BY note ASC ";
                    }
                    else if (args.PlusPopulaires == null)
                    {
                        if (args.Depart != null && args.Depart != string.Empty)
                        {
                            requete += " ORDER BY idPlat ";

                            if (args.Depart == "Fin")
                            {
                                requete += "DESC";
                            }
                            else
                            {
                                requete += "ASC";
                            }
                        }
                    }

                    requete += string.Format(" LIMIT {0} ", args.NbResultats);
                }

                DataSet   dataSetPlats = connexion.Query(requete);
                DataTable tablePlats   = dataSetPlats.Tables[0];

                foreach (DataRow rowPlat in tablePlats.Rows)
                {
                    Plat plat = ConstruirePlat(rowPlat);

                    plat.ListeIngredients = RetrieveAlimentsPlat(new RetrievePlatArgs {
                        IdPlat = plat.IdPlat
                    });

                    resultat.Add(plat);
                }
            }
            catch (Exception)
            {
                throw;
            }

            return(resultat);
        }