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(); } } } }
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(); } }