Esempio n. 1
0
        public void AddCandidates()
        {
            Candidates candidates = new Candidates();
            Exception  ex;

            if (candidates.CandidatesData != null)
            {
                ConnectSerwer s = new ConnectSerwer();
                s.GetCandidatesData(result => candidates = result, error => ex = error);
                foreach (CandidateXML i in candidates.CandidatesData)
                {
                    using (database = new ElectionDataContainer())
                    {
                        int d = (from st in database.CandidateSet
                                 where st.Name.Contains(i.Name)
                                 select st).Count <Candidate>();
                        if (d == 0)
                        {
                            Candidate candidate = new Candidate
                            {
                                Name  = i.Name,
                                Party = i.Party
                            };
                            database.CandidateSet.Add(candidate);
                        }
                        database.SaveChanges();
                    }
                }
            }
        }
Esempio n. 2
0
 public void AddPerson(string name, string surname, long pesel)
 {
     using (database = new ElectionDataContainer())
     {
         bool uniquePesel = (from st in database.PersonSet
                             where (st.Pesel == pesel)
                             select st).Any <Person>();
         if (!uniquePesel)
         {
             Person person = new Person
             {
                 Name    = name,
                 Surname = surname,
                 Pesel   = pesel,
                 Vote    = false
             };
             database.PersonSet.Add(person);
             database.SaveChanges();
         }
         else
         {
             bool ifExist = (from st in database.PersonSet
                             where (st.Pesel == pesel && st.Name == name && st.Surname == surname)
                             select st).Any <Person>();
             if (!ifExist)
             {
                 throw new Exception("pesel should be unique in database");
             }
         }
     }
 }
Esempio n. 3
0
 public void ChangeVote(long pesel, bool isVoted = true)
 {
     using (database = new ElectionDataContainer())
     {
         if (database.PersonSet.Any(rt => rt.Pesel == pesel))
         {
             var Person = database.PersonSet.Where(rt => rt.Pesel == pesel).Single <Person>();
             Person.Vote = isVoted;
             database.SaveChanges();
         }
     }
 }
Esempio n. 4
0
        public void AddVoice(long pesel, Candidate candidate = null)
        {
            ConnectSerwer s = new ConnectSerwer();
            Persons       personsUnauthorized = new Persons();
            Exception     ex;

            s.GetPersonUnAuthorizedData(result => personsUnauthorized = result, error => ex = error);
            bool notAuthorized = false;

            if (personsUnauthorized.PersonsData != null)
            {
                notAuthorized = (from Row in personsUnauthorized.PersonsData.AsEnumerable()
                                 where long.Parse(Row.Pesel) == pesel
                                 select Row).Any();
            }

            using (database = new ElectionDataContainer())
            {
                List <Vote> er = database.VoteSet.ToList <Vote>();
                Vote        vote;
                if (candidate == null)
                {
                    vote = new Vote()
                    {
                        CandidateId = null,
                        Valid       = false,
                        IsEntitled  = !notAuthorized
                    };
                }
                else
                {
                    vote = new Vote()
                    {
                        CandidateId = candidate.Id,
                        Valid       = true,
                        IsEntitled  = !notAuthorized
                    };
                }
                database.VoteSet.Add(vote);
                database.SaveChanges();
            }
        }