Пример #1
0
        private List <TWFTDebate> PopulateParliamentaryDebatesForBill(int id)
        {
            var bill = _db.Single <BillDataModel>(b => b.Id == id);

            string searchTerm = bill.Title;

            if (bill.Title.Contains("Act"))
            {
                searchTerm = searchTerm.ToLower().Replace("act", "bill");
                searchTerm = Regex.Replace(searchTerm, @"\d+$", String.Empty);
            }

            Democracy.TheyWorkForYou.API theyWorkForYouApi = new Democracy.TheyWorkForYou.API();
            string result1 = theyWorkForYouApi.Query("getDebates",
                                                     new string[] { "type:commons", "num:10000", "order:d", "search:\"" + searchTerm + "\"" });
            //string result2 = theyWorkForYouApi.Query("getDebates", new string[] { "type:westminsterhall", "search:" + bill.Title });
            //string result3 = theyWorkForYouApi.Query("getDebates", new string[] { "type:lords", "search:" + bill.Title });
            //string result4 = theyWorkForYouApi.Query("getDebates", new string[] { "type:scotland", "search:" + bill.Title });
            //string result5 = theyWorkForYouApi.Query("getDebates", new string[] { "type:northernireland", "search:" + bill.Title });

            var filterResults = new List <TWFTDebate>();

            try
            {
                var commonsResults = JsonConvert.DeserializeObject <TWFYDebateSearchResults>(result1);
                filterResults = commonsResults.rows; //.Where(result => result.parent.body.ToLower().Contains(searchTerm.Trim())).ToList();
            }
            catch (Exception)
            {
            }



            return(filterResults);
        }
Пример #2
0
        private void PopulateMPs()
        {
            var dict = new Dictionary <string, PartyDataModel> {
                { "Conservative", PartyDataModel.Conservative },
                { "Labour", PartyDataModel.Labour },
                { "Liberal Democrat", PartyDataModel.LibDem },
                { "Green", PartyDataModel.Green },
                { "UKIP", PartyDataModel.UKIP },
                { "DUP", PartyDataModel.DUP },
                { "Social Democratic and Labour Party", PartyDataModel.SDL },
                { "Sinn Fein", PartyDataModel.SinnFain },
                { "Respect", PartyDataModel.Respect },
                { "Plaid Cymru", PartyDataModel.PalidCyeru },
                { "UUP", PartyDataModel.UUP },
                { "Independent", PartyDataModel.Independent },
                { "Scottish National Party", PartyDataModel.SNP },
                { "Deputy Speaker", PartyDataModel.DS },
                { "Independent Labour", PartyDataModel.IndependentLabour },
                { "Speaker", PartyDataModel.Speaker },
                { "Alliance", PartyDataModel.Alliance }
            };


            Democracy.TheyWorkForYou.API theyWorkForYouApi = new Democracy.TheyWorkForYou.API();
            string result = theyWorkForYouApi.Query("getMPs", new string[]
            {
                "date:01/01/2015",
                "output:js"
            });
            var MPsResults = JsonConvert.DeserializeObject <List <TWFYMPResults> >(result);

            foreach (var MPResult in MPsResults)
            {
                var mp = _db.Single <MPDataModel>(c => c.TWFYMemberId.ToString() == MPResult.member_id);

                if (mp == null)
                {
                    var newMP = new MPDataModel();
                    newMP.ImageUrl     = GetMpPicture(MPResult);
                    newMP.Name         = MPResult.name;
                    newMP.TWFYMemberId = Convert.ToInt32(MPResult.member_id);
                    newMP.TWFYPersonId = Convert.ToInt32(MPResult.person_id);
                    newMP.Party        = dict[MPResult.party];
                    newMP.Constituency = GetMPConstituancy(MPResult.constituency);
                    newMP.Offices      = SetMPOffices(MPResult);
                    _db.Add <MPDataModel>(newMP);
                }
            }
            _db.CommitChanges();
        }
Пример #3
0
        private void PopulateConstituencies()
        {
            Democracy.TheyWorkForYou.API theyWorkForYouApi = new Democracy.TheyWorkForYou.API();
            string result = theyWorkForYouApi.Query("getConstituencies", new string[] { });
            var    constituenciesResults = JsonConvert.DeserializeObject <List <TWFYConstituenciesSearchResults> >(result);

            foreach (var constituencyData in constituenciesResults)
            {
                var constituency = _db.Single <ConstituencyDataModel>(c => c.Name == constituencyData.Name);

                if (constituency == null)
                {
                    var newConstituency = new ConstituencyDataModel()
                    {
                        Name            = constituencyData.Name,
                        RegisterdVoters = GetVotersForConstituency(constituencyData.Name)
                    };
                    _db.Add <ConstituencyDataModel>(newConstituency);
                }
            }
            _db.CommitChanges();
        }