Esempio n. 1
0
        //Create new parliament
        public void AddParliament()
        {
            Parliament parliament = new Parliament();
            DateTime   date       = DateTime.Now;

            parliament.startYear = date.Year;
            entities.Parliament.Add(parliament);
            entities.SaveChanges();
        }
Esempio n. 2
0
 public void CreateNewPolitician(Politician politician, ContactInfo contact)
 {
     if (!CheckPoliticianExist(politician))
     {
         db.Politician.Add(politician);
         db.SaveChanges();
     }
     if (true)
     {
     }
 }
Esempio n. 3
0
 public void CreatePM(ParliamentMember pm)
 {
     if (!CheckPMExist(pm.politicianId, pm.parliamentId))
     {
         db.ParliamentMember.Add(pm);
         db.SaveChanges();
     }
 }
 public void CreateNewMinisterTitle(MinisterialPost title)
 {
     if (!CheckIfPartyExist(title))
     {
         db.MinisterialPost.Add(title);
         db.SaveChanges();
     }
 }
Esempio n. 5
0
 public void CreateNewMinister(Minister minister)
 {
     if (!CheckIfMinisterExist(minister))
     {
         db.Minister.Add(minister);
         db.SaveChanges();
     }
 }
Esempio n. 6
0
 public void CreateNewParty(Party party)
 {
     if (!CheckIfPartyExist(party))
     {
         db.Party.Add(party);
         db.SaveChanges();
     }
 }
Esempio n. 7
0
 //Add ministers
 public void AddMinister(Minister minister)
 {
     using (var context = new FTDatabaseEntities())
     {
         context.Minister.Add(minister);
         context.SaveChanges();
     }
 }
Esempio n. 8
0
 //Add contact info
 public void AddContactInfo(ContactInfo contact)
 {
     using (var context = new FTDatabaseEntities())
     {
         context.ContactInfo.Add(contact);
         context.SaveChanges();
     }
 }
Esempio n. 9
0
 public void AddPolitician(Politician politician)
 {
     using (var context = new FTDatabaseEntities())
     {
         context.Politician.Add(politician);
         context.SaveChanges();
     }
 }
Esempio n. 10
0
        public void AddMembers()
        {
            using (var entities = new FTDatabaseEntities())
            {
                DBService service                 = new DBService();
                ParliamentMemberFilter filter     = new ParliamentMemberFilter();
                List <ExtractedValues> values     = filter.GetParliamentMembers();
                List <CustomPolitcian> politcians = new List <CustomPolitcian>();
                foreach (var item in values)
                {
                    Politician politician = service.GetPolitician(item.Firstname, item.Lastname);
                    if (politician == null)
                    {
                        politician           = new Politician();
                        politician.firstname = item.Firstname;
                        politician.lastname  = item.Lastname;
                        politician.partyId   = entities.Party.Where(p => p.name.Equals(item.Party)).SingleOrDefault().id;
                        service.AddPolitician(politician);

                        politician = service.GetPolitician(item.Firstname, item.Lastname);
                        UpdateContact(politician.id, item.Contact);
                    }
                    else
                    {
                        var partyId = entities.Party.Where(p => p.name.Equals(item.Party)).SingleOrDefault().id;
                        politician.partyId = partyId;
                        entities.Politician.Attach(politician);
                        entities.Entry(politician).Property(pol => pol.partyId).IsModified = true;
                        entities.SaveChanges();
                    }
                    UpdateContact(politician.id, item.Contact);
                    ParliamentMember member = new ParliamentMember();
                    member.politicianId = politician.id;
                    member.parliamentId = 1;
                    entities.ParliamentMember.Add(member);
                }
                entities.SaveChanges();
            }
        }
Esempio n. 11
0
        private void CreateSelectionMembers(Object data)
        {
            ThreadData indexes       = (ThreadData)data;
            string     pattern       = "^\\d+$";
            bool       shouldInclude = true;
            var        tdList        = documents[indexes.Index].DocumentNode.SelectNodes("//td");

            foreach (var node in tdList)
            {
                var value = RemoveExcessWhiteSpace(node.InnerText);
                if (!value.Equals(""))
                {
                    if (!Regex.IsMatch(value, pattern))
                    {
                        if (shouldInclude)
                        {
                            string[]         fullname         = SplitName(value);
                            string           firstname        = fullname[0];
                            string           lastname         = fullname[1];
                            Selection_member selection_Member = new Selection_member();
                            //saving the retrieved data to db
                            using (var context = new FTDatabaseEntities())
                            {
                                if (context.Politician.Where(p => p.firstname.Equals(firstname) && p.lastname.Equals(lastname)).Any())
                                {
                                    Debug.WriteLine(firstname + " " + lastname + " " + indexes.SelectionIndex);
                                    selection_Member.parliamentMemberId =
                                        context.ParliamentMember.Where(p => p.Politician.firstname.Equals(firstname) &&
                                                                       p.Politician.lastname.Equals(lastname) && p.Parliament.id == parliamentId).Single().id;
                                    selection_Member.selectionId = indexes.SelectionIndex;
                                    if (!SelectionMemberExist(selection_Member, context))
                                    {
                                        context.Selection_member.Add(selection_Member);
                                    }
                                    context.SaveChanges();
                                }
                            }
                            shouldInclude = false;
                        }
                        else
                        {
                            shouldInclude = true;
                        }
                    }
                }
            }
        }
Esempio n. 12
0
        //Add Minister to db
        public void AddMinisters()
        {
            using (var entities = new FTDatabaseEntities())
            {
                MinisterScraper        scraper   = new MinisterScraper();
                List <ExtractedValues> values    = scraper.GetMinisters();
                List <CustomMinister>  ministers = new List <CustomMinister>();
                foreach (var item in values)
                {
                    Politician politician = service.GetPolitician(item.Firstname, item.Lastname);
                    if (politician == null)
                    {
                        politician           = new Politician();
                        politician.firstname = item.Firstname;
                        politician.lastname  = item.Lastname;
                        politician.partyId   = entities.Party.Where(p => p.name.Equals(item.Party)).SingleOrDefault().id;
                        service.AddPolitician(politician);

                        politician = service.GetPolitician(item.Firstname, item.Lastname);
                        ContactInfo contactInfo = item.Contact;
                        contactInfo.politicianId = politician.id;
                        Debug.WriteLine(politician.id);
                        service.AddContactInfo(contactInfo);
                    }
                    MinisterialPost post = service.GetMinisterialPost(item.Title);
                    if (post == null)
                    {
                        using (var context = new FTDatabaseEntities())
                        {
                            context.MinisterialPost.Add(new MinisterialPost()
                            {
                                governmentId = 1, title = item.Title
                            });
                            context.SaveChanges();
                        }
                    }
                    Minister minister = new Minister();
                    minister.ministerialPostId = service.GetMinisterialPost(item.Title).id;
                    minister.politicianId      = politician.id;
                    minister.startDate         = DateTime.Now.Date;
                    entities.Minister.Add(minister);
                }
                entities.SaveChanges();
            }
        }
Esempio n. 13
0
        public void AddMayors(List <CustomMayor> mayors)
        {
            using (var entity = new FTDatabaseEntities())
            {
                List <CustomMayor> ministers = new List <CustomMayor>();

                foreach (var item in mayors)
                {
                    Politician politician = service.GetPolitician(item.Firstname, item.Lastname);
                    if (politician == null)
                    {
                        politician           = new Politician();
                        politician.firstname = item.Firstname;
                        politician.lastname  = item.Lastname;
                        politician.partyId   = entity.Party.Where(p => p.name.Equals(item.Party)).SingleOrDefault().id;
                        service.AddPolitician(politician);

                        politician = service.GetPolitician(item.Firstname, item.Lastname);
                        ContactInfo contactInfo = new ContactInfo();
                        contactInfo.email        = item.Email;
                        contactInfo.phone        = item.Phone;
                        contactInfo.politicianId = politician.id;
                        service.AddContactInfo(contactInfo);
                    }
                    Municipality municipality = service.GetMunicipality(item.Municipality);
                    if (municipality == null)
                    {
                        using (var context = new FTDatabaseEntities())
                        {
                            context.Municipality.Add(new Municipality()
                            {
                                regionId = 1, name = item.Municipality
                            });
                            context.SaveChanges();
                        }
                    }
                    Mayor mayor = new Mayor();
                    mayor.politicianId   = politician.id;
                    mayor.municipalityId = service.GetMunicipality(item.Municipality).id;
                    entity.Mayor.Add(mayor);
                }
                entity.SaveChanges();
            }
        }
Esempio n. 14
0
        private void UpdateContact(int politicianId, ContactInfo newContact)
        {
            DBService   service      = new DBService();
            ContactInfo contactInfo  = newContact;
            var         checkContact = entities.ContactInfo.Where(c => c.email.Equals(contactInfo.email) && c.phone.Equals(contactInfo.phone));

            if (!checkContact.Any())
            {
                contactInfo.politicianId = politicianId;
                service.AddContactInfo(contactInfo);
            }
            else
            {
                checkContact.First().email = newContact.email;
                checkContact.First().phone = newContact.phone;
                using (var context = new FTDatabaseEntities())
                {
                    ContactInfo testContact = checkContact.First();
                    testContact.phone = newContact.phone;
                    testContact.email = newContact.email;
                    context.SaveChanges();
                }
            }
        }