Beispiel #1
0
        public void UpdateBillData(HttpContext context)
        {
            _context = context;
            PopulateConstituencies();
            PopulateMPs();

            var newBillList = _rssClient.GetBills("http://services.parliament.uk/bills/AllBills.rss");

            foreach (var newBillData in newBillList)
            {
                var bill = _db.Single <BillDataModel>(b => b.Url == newBillData.Url);
                if (bill != null)
                {
                    if (bill.UpdatedDate < newBillData.UpdatedDate)
                    {
                        bill.UpdatedDate = newBillData.UpdatedDate;
                        bill.BillType    = newBillData.BillType;
                        bill.Description = newBillData.Description;
                        bill.House       = newBillData.House;
                        bill.Stage       = newBillData.Stage;
                        bill.Title       = newBillData.Title;
                        bill.IsUpdated   = true;
                    }
                    _db.Update <BillDataModel>(bill);
                    _db.CommitChanges();
                }
                else
                {
                    newBillData.IsNew = true;
                    _db.Add <BillDataModel>(newBillData);
                    _db.CommitChanges();
                    bill = _db.Single <BillDataModel>(b => b.Url == newBillData.Url);
                }

                var parliamentaryDebates = PopulateParliamentaryDebatesForBill(bill.Id);
                if (parliamentaryDebates.Count > 0)
                {
                    var debates = new List <DebateDataModel>();
                    foreach (var debateResult in parliamentaryDebates)
                    {
                        if (debateResult.speaker != null)
                        {
                            var mpId       = Convert.ToInt32(debateResult.speaker.person_id);
                            var speakingMP = _db.Single <MPDataModel>(m => m.TWFYPersonId == mpId);
                            debates.Add(new DebateDataModel
                            {
                                Body    = debateResult.body,
                                Date    = DateTime.Parse(debateResult.hdate),
                                Speaker = speakingMP,
                                BillId  = bill.Id
                            });
                        }
                    }
                    _db.Add <DebateDataModel>(debates);
                }
            }
            var voteDataProvider = new VoteData(_db);

            voteDataProvider.PopulateVoteData();
        }
Beispiel #2
0
        public List <BillViewModel> GetAllBills()
        {
            var bills     = new List <BillViewModel>();
            var billsData = _db.All <BillDataModel>().ToList();

            if (!billsData.Any())
            {
                //UpdateBillData();
                var voteDataProvider = new VoteData(_db);
                voteDataProvider.PopulateVoteData();
                billsData = _db.All <BillDataModel>().ToList();
            }
            foreach (var billDataModel in billsData)
            {
                var bill = new BillViewModel();
                bill.MapBillDataModel(billDataModel);
                bills.Add(bill);
            }
            return(bills);
        }