Esempio n. 1
0
        public static void AddIsElectableCandidate(string filename)
        {
            const int firstnameIndex = 1;
            const int lastnameIndex = 2;
            const int partynameIndex = 3;
            const int wahlkreisIdIndex = 4;

            var parsedFile = DataImportGeneral.ParseFile(filename);

            const int startIndex = 1;

            using (var context = new ElectionDBEntities())
            {
                for (var i = startIndex; i < parsedFile.Count; i++)
                {
                    var line = parsedFile.ElementAt(i);

                    var result = GetTitleFirstnameLastnamePartynameFromLine(line);
                    var firstname = result.ElementAt(firstnameIndex);
                    var lastname = result.ElementAt(lastnameIndex);
                    var partyname = result.ElementAt(partynameIndex);

                    int wahlkreisId;
                    var parsed = int.TryParse(line[wahlkreisIdIndex], out wahlkreisId);
                    if (!parsed)
                    {
                        continue;
                    }

                    var existing = GetExistingCandidate(context, firstname, lastname, partyname, line[2]);

                    var entry = new IsElectableCandidate
                    {
                        Election_Id = electionId,
                        Person_Id = existing.Id,
                        Wahlkreis_Id = wahlkreisId
                    };

                    context.IsElectableCandidates.Add(entry);

                    Console.WriteLine("Added person {0} is electable at wahlkreis {1} in election {2}", existing.Id, wahlkreisId, electionId);
                }

                context.SaveChanges();
            }
        }
Esempio n. 2
0
        public static void AddIsElectableCandidate(string filename)
        {
            const int personIdIndex = 1;
            const int wahlkreisIdIndex = 7;

            var parsedFile = DataImportGeneral.ParseFile(filename);

            const int startIndex = 1;

            using (var context = new ElectionDBEntities())
            {
                for (var i = startIndex; i < parsedFile.Count; i++)
                {
                    var line = parsedFile.ElementAt(i);

                    int wahlkreisId;
                    var parsed = int.TryParse(line[wahlkreisIdIndex], out wahlkreisId);
                    if (!parsed)
                    {
                        continue;
                    }

                    var personId = int.Parse(line[personIdIndex]);

                    var entry = new IsElectableCandidate
                    {
                        Election_Id = electionId,
                        Person_Id = personId,
                        Wahlkreis_Id = wahlkreisId
                    };

                    context.IsElectableCandidates.Add(entry);

                    Console.WriteLine("Added person {0} is electable in wahlkreis {1} for election {2}", personId, wahlkreisId, electionId);
                }

                context.SaveChanges();
            }
        }