Example #1
0
        public int CreerUnSondage()
        {
            Sondage sondage = new Sondage {
                Date = DateTime.Now
            };

            bdd.Sondages.Add(sondage);
            bdd.SaveChanges();
            return(sondage.Id);
        }
Example #2
0
        public bool ADejaVote(int idSondage, string idStr)
        {
            int id;

            if (int.TryParse(idStr, out id))
            {
                Sondage sondage = bdd.Sondages.First(s => s.Id == idSondage);
                if (sondage.Votes == null)
                {
                    return(false);
                }
                return(sondage.Votes.Any(v => v.Utilisateur != null && v.Utilisateur.Id == id));
            }
            return(false);
        }
Example #3
0
        public void AjouterVote(int idSondage, int idResto, int idUtilisateur)
        {
            Vote vote = new Vote
            {
                Resto       = bdd.Restos.First(r => r.Id == idResto),
                Utilisateur = bdd.Utilisateurs.First(u => u.Id == idUtilisateur)
            };

            Sondage sondage = bdd.Sondages.First(s => s.Id == idSondage);

            if (sondage.Votes == null)
            {
                sondage.Votes = new List <Vote>();
            }
            sondage.Votes.Add(vote);
            bdd.SaveChanges();
        }
Example #4
0
        public List <Resultats> ObtenirLesResultats(int idSondage)
        {
            List <Resto>     restaurants = ObtientTousLesRestaurants();
            List <Resultats> resultats   = new List <Resultats>();
            Sondage          sondage     = bdd.Sondages.First(s => s.Id == idSondage);

            foreach (IGrouping <int, Vote> grouping in sondage.Votes.GroupBy(v => v.Resto.Id))
            {
                int   idRestaurant  = grouping.Key;
                Resto resto         = restaurants.First(r => r.Id == idRestaurant);
                int   nombreDeVotes = grouping.Count();
                resultats.Add(new Resultats {
                    Nom = resto.Nom, Telephone = resto.Telephone, NombreDeVotes = nombreDeVotes
                });
            }
            return(resultats);
        }