Esempio n. 1
0
 private bool SelectionMemberExist(Selection_member member, FTDatabaseEntities context)
 {
     if (context.Selection_member.Where(s => s.selectionId == member.selectionId && s.parliamentMemberId == member.parliamentMemberId).Any())
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Esempio n. 2
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;
                        }
                    }
                }
            }
        }