Ejemplo n.º 1
0
        public void CreerSondage(Sondage sondage)
        {
            Sondage so = s.Sondages.Add(sondage);

            s.SaveChanges();
            s.Dispose();
        }
Ejemplo n.º 2
0
        public void DesactiverSondage()
        {
            Sondage monSondage = new Sondage("Qui?", true);

            monSondage.DesactiverSondage();
            Assert.AreEqual("d", monSondage.ValiditeSondage);
        }
        //public RedirectToRouteResult AjoutSondage(string question, string reponse1, string reponse2, string reponse3, string reponse4) --> méthode intiale : pas conservée finalement
        public ActionResult AjoutSondage(string question, string reponse1, string reponse2, string reponse3, string reponse4, string codeSecret, bool reponseMultiple = false)
        { // action d'ajouter un sondage avec les paramètres de la question et des réponses, et initialise la réponse multiple à non activé
            //on autorise la création du sondage seulement si la question contient au moins 10 caractères et les réponses au moins 3 caractères
            if (question.Length > 9 && reponse1.Length > 2 && reponse2.Length > 2 && reponse3.Length > 2 && reponse4.Length > 2)
            {
                // on appelle ici la fonction qui permet de créer un code aléatoire avec xx (ici 20) caractères (voir plus bas)
                string randomCode = GenerateRandomCode(20);

                // insérer instance de sondage avec ses paramètres
                int idSondage = Sondage.InsererSondageEnBdd(question, randomCode, false, reponseMultiple);

                // insérer les différentes réponses en BDD
                Option.InsererOptionEnBdd(idSondage, reponse1);
                Option.InsererOptionEnBdd(idSondage, reponse2);
                Option.InsererOptionEnBdd(idSondage, reponse3);
                Option.InsererOptionEnBdd(idSondage, reponse4);

                // Redirection vers l'action de création du nouveau sondage, spéciale créateur (pour les autres c'est SondageVote)
                return(RedirectToAction("SondageCree", new { idSondage = idSondage, codeSecret = codeSecret }));
            }
            else
            {   // Redirection vers la page d'erreur pour les sondages ou questions trop courtes
                return(RedirectToAction("ErreurSondageMoinsDe10Caracs"));
            }
        }
Ejemplo n.º 4
0
        public IHttpActionResult PutSondage(int id, Sondage sondage)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != sondage.Id)
            {
                return(BadRequest());
            }

            db.Entry(sondage).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!SondageExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Ejemplo n.º 5
0
        public async Task <ActionResult <Sondage> > PostSondage(Sondage sondage)
        {
            _context.Sondage.Add(sondage);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetSondage", new { id = sondage.SondageId }, sondage));
        }
Ejemplo n.º 6
0
        public static Sondage getUnSondage(int semaine)
        {
            Sondage unSondage = new Sondage();

            try
            {
                MySqlConnection cnx = MySQL.getCnx();
                cnx.Ping();
                string       requete = "SELECT SON_ID,SON_titre, SON_MUSIQUEUN,SON_MUSIQUEDEUX,SON_MUSIQUETROIS,SON_MUSIQUEQUATRE FROM sondage WHERE SON_DATE='" + semaine + "'";
                MySqlCommand cmd     = new MySqlCommand(requete, cnx);
                var          reader  = cmd.ExecuteReader();
                if (reader.Read())
                {
                    unSondage.id       = reader.GetInt32(0);
                    unSondage.titre    = reader.GetString(1);
                    unSondage.musique1 = reader.GetString(2);
                    unSondage.musique2 = reader.GetString(3);
                    unSondage.musique3 = reader.GetString(4);
                    unSondage.musique4 = reader.GetString(5);
                }
                cnx.Close();
                return(unSondage);
            }
            catch (MySqlException ex)
            {
                unSondage.titre = ex.ToString();
                return(unSondage);
            }
        }
Ejemplo n.º 7
0
        // VUE CREATION SONDAGE  OK
        public ActionResult CreationSondage(string question, string choix1, string choix2, string choix3, string choix4, string isChoixMultiple)
        {
            bool coche1;

            if (isChoixMultiple == "true")
            {
                coche1 = true;
            }
            else
            {
                coche1 = false;
            }



            Sondage sondage = new Sondage(0, question, choix1, choix2, choix3, choix4, coche1);

            sondage.GetChiffre();
            CreationSondage Sondage = new CreationSondage(sondage);

            int nouveauIdSondage = DataAccess.CreationSondage(sondage);

            DataAccess.CreationReponse(nouveauIdSondage);

            return(RedirectToAction("Vote", new { idSondage = nouveauIdSondage, numProtection = sondage.NumProtection }));
        }
Ejemplo n.º 8
0
        public async Task <IActionResult> PutSondage(int id, Sondage sondage)
        {
            if (id != sondage.SondageId)
            {
                return(BadRequest());
            }

            _context.Entry(sondage).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!SondageExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Ejemplo n.º 9
0
        public void CreateSondage(Sondage monSondage)
        {
            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                connection.Open();

                //initiation de la date
                DateTime date       = DateTime.Today;
                string   dateString = date.Year.ToString("00") + "/" + date.Month.ToString("00") + "/" + date.Day.ToString("00");

                //1 création du paramètre pour la question
                SqlParameter param = new SqlParameter();
                param.ParameterName = "@question";         //on lui assigne un nom
                param.Value         = monSondage.question; //on lui assigne une valeur

                //1- ajout du vote dans la base
                SqlCommand cmd = new SqlCommand("INSERT INTO Sondage (DateDeCreationSondage, question, FK_idValiditeSondage, FK_idTypeDeChoixDuSondage) VALUES ('" + dateString + "', @question, 'a', '" + monSondage.TypeDeChoixDuSondage + "'); ", connection);

                cmd.Parameters.Add(param); //on rajoute le dans les paramètres à envoyer à la requête

                cmd.ExecuteNonQuery();

                //2- récupération de l'id du vote pour générer les URL
                cmd = new SqlCommand("SELECT MAX(numeroDeSondage) AS max_id FROM Sondage;", connection);
                monSondage.AffecterNumeroSondage((int)cmd.ExecuteScalar());

                //3- générer les url
                monSondage.GenererUrl("vote", date, monSondage.numeroDeSondage);
                monSondage.GenererUrl("desactivation", date, monSondage.numeroDeSondage);

                //4- update du sondage dans la base
                cmd = new SqlCommand("UPDATE Sondage SET lienVote = '" + monSondage.lienVote + "', lienDesactivation='" + monSondage.lienDesactivation + "' WHERE numeroDeSondage = " + monSondage.numeroDeSondage + ";", connection);
                cmd.ExecuteNonQuery();
            }
        }
Ejemplo n.º 10
0
        static Sondage[] getTestSondage()
        {
            string[] question1 =
            {
                "1. À quelle tranche d'âge appartenez-vous? a:0-25 ans, b:25-50 ans, c:50-75 ans, d:75 ans et plus",
                "2. Êtes-vous une femme ou un homme? a:Femme, b:Homme, c:Je ne veux pas répondre",
                "3. Quel journal lisez-vous à la maison? a:La Presse, b:Le Journal de Montréal, c:The Gazette, d:Le Devoir",
                "4. Combien de temps accordez-vous à la lecture de votre journal quotidiennement? a:Moins de 10 minutes; b:Entre 10 et 30 minutes, c:Entre 30 et 60 minutes, d:60 minutes ou plus"
            };

            string[] question2 =
            {
                "1. À quelle tranche d'âge appartenez-vous? a:0-25 ans, b:25-50 ans, c:50-75 ans, d:75 ans et +",
                "2. Êtes-vous une femme ou un homme? a:Femme, b:Homme, c:Je ne veux pas répondre",
                "3. Combien de tasses de café buvez-vous chaque jour? a:Je ne bois pas de café, b:Entre 1 et 5 tasses, c:Entre 6 et 10 tasses, d:10 tasses ou plus",
                "4. Combien de consommations alcoolisées buvez-vous chaque jour? a:0, b:1, c:2 ou 3, d:3 ou plus"
            };

            Sondage[] sondages = new Sondage[]
            {
                new Sondage {
                    Id = "Sondage 1", Questions = question1
                },
                new Sondage {
                    Id = "Sondage 2", Questions = question2
                }
            };

            return(sondages);
        }
Ejemplo n.º 11
0
        // View récuperation de mon sondage Creer
        public ActionResult Vote(int idSondage, int numProtection)
        {
            Sondage model = new Sondage(idSondage, numProtection);


            return(View(model));
        }
Ejemplo n.º 12
0
        public ActionResult DeleteConfirmed(int id)
        {
            Sondage sondage = db.Sondage.Find(id);

            db.Sondage.Remove(sondage);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 13
0
        public ActionResult Vote(int idSondage)
        {
            Sondage model = DataAccess.PageDeVote(idSondage);

            if (model.ActiveSondage == true)
            {
                return(RedirectToAction("ImpossibleDevoter", new { idSondage = idSondage }));
            }
            return(View(model));
        }
Ejemplo n.º 14
0
        public void CreationSondage()
        {
            Sondage monSondage = new Sondage("Qui?", true);


            Assert.AreEqual("Qui?", monSondage.question);
            Assert.AreEqual("s", monSondage.TypeDeChoixDuSondage);
            Assert.AreEqual("a", monSondage.ValiditeSondage);
            Assert.AreEqual(0, monSondage.numeroDeSondage);
        }
Ejemplo n.º 15
0
        // GESTION POUR LE CHOIX MULTIPLE
        public ActionResult VoteMultiple(string Choix1, string Choix2, string Choix3, int idSondage)
        {
            if (TestSondagevote(Request.Cookies, idSondage))
            {
                return(RedirectToAction("DejaVoter", new { idSondage = idSondage }));
            }

            DataAccess.InsertionVoteBDD(idSondage, Sondage.Nouvo(Choix1), Sondage.Nouvo(Choix2), Sondage.Nouvo(Choix3));
            SaveCookie(idSondage);
            return(RedirectToAction("ResultatVote", new { IDSondage = idSondage }));
        }
Ejemplo n.º 16
0
        public async Task <int> CreateSondage()
        {
            var sondage = new Sondage {
                Date = DateTime.Now
            };

            _unitOfWork.Sondages.CreateSondage();
            await _unitOfWork.CommitAsync();

            return(sondage.Id);
        }
Ejemplo n.º 17
0
        public IHttpActionResult GetSondage(int id)
        {
            Sondage sondage = db.Sondages.Find(id);

            if (sondage == null)
            {
                return(NotFound());
            }

            return(Ok(sondage));
        }
Ejemplo n.º 18
0
        public void AjouterVote(int idSondage, int idResto, int idUtilisateur)
        {
            Vote vote = new Vote
            {
                Resto       = listeDesRestaurants.First(r => r.Id == idResto),
                Utilisateur = listeDesUtilisateurs.First(u => u.Id == idUtilisateur)
            };
            Sondage sondage = listeDessondages.First(s => s.Id == idSondage);

            sondage.Votes.Add(vote);
        }
Ejemplo n.º 19
0
 public ActionResult Edit([Bind(Include = "id,date,idFormulaire,idSonde")] Sondage sondage)
 {
     if (ModelState.IsValid)
     {
         db.Entry(sondage).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.idFormulaire = new SelectList(db.Formulaire, "id", "titre", sondage.idFormulaire);
     ViewBag.idSonde      = new SelectList(db.Sonde, "id", "localisation", sondage.idSonde);
     return(View(sondage));
 }
Ejemplo n.º 20
0
    public int CreerUnSondage(string label)
    {
        Sondage sondage = new Sondage {
            Date = DateTime.Now, Label = label
        };

        //Sondage sondage = new Sondage { Date = DateTime.Now, Label = Label };

        bdd.Sondages.Add(sondage);
        bdd.SaveChanges();
        return(sondage.Id);
    }
Ejemplo n.º 21
0
        public bool ADejaVote(int idSondage, string idStr)
        {
            Utilisateur utilisateur = ObtenirUtilisateur(idStr);

            if (utilisateur == null)
            {
                return(false);
            }
            Sondage sondage = listeDessondages.First(s => s.Id == idSondage);

            return(sondage.Votes.Any(v => v.Utilisateur.Id == utilisateur.Id));
        }
Ejemplo n.º 22
0
        public IHttpActionResult PostSondage(Sondage sondage)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.Sondages.Add(sondage);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = sondage.Id }, sondage));
        }
Ejemplo n.º 23
0
 public ActionResult VoteMultiple(string choix1, string choix2, string choix3, string choix4, int idSondage)
 {
     //////////////////////////////////////////////////////////////////////////
     if (TestSondagevote(Request.Cookies, idSondage))
     {
         return(RedirectToAction("DejaVoter", new { idSondage = idSondage }));
     }
     ////////////////////////////////////////////////////////////////////
     DataAccess.InsertionVoteBDD(idSondage, Sondage.Coche(choix1), Sondage.Coche(choix2), Sondage.Coche(choix3), Sondage.Coche(choix4));
     SaveCookie(idSondage);
     return(RedirectToAction("Resultat", new { IDSondage = idSondage }));
 }
Ejemplo n.º 24
0
        //Enregistrement d'un sondage dans la BDD
        public ActionResult SondageCree(string question, List <string> Choix, string check)
        {
            //Les choix vides sont effacés de la liste "Choix" avant qu'elle ne soit enregistrée dans la BDD
            Choix.RemoveAll(string.IsNullOrEmpty);

            //Le FOR et le IF suivants empêchent la création d'un sondage
            //si le champ "QUESTION" est vide ou si l'utilisateur n'entre pas au moins 2 choix
            int choixVide = 0;

            for (int i = 0; i < Choix.Count; i++)
            {
                if (Choix[i] == "")
                {
                    choixVide++;
                }
            }


            if (question == "" || choixVide > 2)
            {
                return(View("NbQuestionEtChoixMin")); //Si les conditions précédentes ne sont pas remplies,
            }                                         //l'utilisateur est renvoyé vers une page d'erreur
            else
            {
                //Vérifie si les choix multiples sont autorisés pour le sondage
                bool choixMultiple;
                if (check == "checked")
                {
                    choixMultiple = true;
                }
                else
                {
                    choixMultiple = false;
                }

                Guid   generationCleDesactivation = Guid.NewGuid();                        //Génération d'une valeur aléatoire de type Guid pour le lien de désactivation du sondage
                string cleDesactivation           = generationCleDesactivation.ToString(); //Convertie la valeur du Guid en string


                Sondage NouveauSondage = new Sondage(question, Choix, choixMultiple, cleDesactivation);

                ViewBag.dernierIDBDD = SQL.SauvegarderEnBDD(NouveauSondage); //Appel de la méthode permettant de sauvegarder le sondage dans la BDD
                                                                             //et récupération de l'ID du sondage en cours



                ViewBag.cleDesactivation = cleDesactivation;


                return(View("SondageCree"));
            }
        }
Ejemplo n.º 25
0
        // CREATION SONDAGE

        public ActionResult CreationSondage(string question, string reponse1, string reponse2, string reponse3, bool?Choixmultiple)
        {
            bool choix = Choixmultiple.GetValueOrDefault(false);

            Sondage         sondage = new Sondage(0, question, reponse1, reponse2, reponse3, choix);
            creationsondage Sondage = new creationsondage(sondage);

            int idSondageCree = DataAccess.CreerNouveauSondage(sondage);

            DataAccess.CreerNouveauResultat(idSondageCree);

            return(RedirectToAction("ChoixVotant", new { idSondage = idSondageCree }));
        }
        public ActionResult SondageResultat(int idSondage)
        {
            // Get sondage by id
            Sondage monSondage = Sondage.ChargerSondageDepuisBDD(idSondage);
            // Get options by idSondage
            List <Option> optionList = Option.ChargerOptionsDepuisBDD(idSondage);

            // Grouper les objets
            SondageEtOptions sondageEtOptions = new SondageEtOptions(monSondage, optionList);

            // envoyer les données à la vue
            return(View(sondageEtOptions));
        }
        public ActionResult SondageCree(int idSondage)
        {  // action de création du sondage qui retourne la vue spéciale créateur (SondageCree) avec le modèle sondage et options pour définir l'instance de sondage et de la liste d'options
            // Get sondage by idSondage
            Sondage monSondage = Sondage.ChargerSondageDepuisBDD(idSondage);
            // Get options by idSondage
            List <Option> optionList = Option.ChargerOptionsDepuisBDD(idSondage);

            // Pour grouper les objets
            SondageEtOptions sondageEtOptions = new SondageEtOptions(monSondage, optionList);

            // envoyer les données à la vue
            return(View(sondageEtOptions));
        }
Ejemplo n.º 28
0
        public IHttpActionResult DeleteSondage(int id)
        {
            Sondage sondage = db.Sondages.Find(id);

            if (sondage == null)
            {
                return(NotFound());
            }

            db.Sondages.Remove(sondage);
            db.SaveChanges();

            return(Ok(sondage));
        }
Ejemplo n.º 29
0
        public ActionResult SupprimerSondage(int idSondage)
        {
            Sondage sondage = DataAccess.DesactiverSondage(idSondage);

            if (sondage.ActiveSondage == false)
            {
                DataAccess.EtatDuSondageMiseAjour(sondage);
                return(View(sondage));
            }
            else
            {
                return(RedirectToAction("SondageDejaSupprimer", new { IdSondage = idSondage }));
            }
        }
Ejemplo n.º 30
0
        //ActionResult lié à la désactivation d'un sondage
        #region Desactivation sondage

        //[AFF] - Page principale désactivation sondage
        public ActionResult Desactiver(int id, int cle)
        {
            //Regarde si le clé et l'id sont sur la même ligne dans la BDD
            if (DataAccess.CheckSiCleUniqueEstCorrect(id, cle) == true)
            {
                Sondage fusion = new Sondage(id, cle);
                return(View(fusion));
            }
            else
            {
                //Si ce n'est pas cohérent renvoie sur la page "Erreur404"
                return(RedirectToAction(nameof(Erreur404), new { ID = id }));
            }
        }