public Committees GetCommittees() { string COMMITTEE_API_PATH = BASE_URL + "committees"; string committeesData = ""; Committees committees = null; httpClient.BaseAddress = new Uri(COMMITTEE_API_PATH); // It can take a few requests to get back a prompt response, if the API has not received // calls in the recent past and the server has put the service on hibernation try { HttpResponseMessage response = httpClient.GetAsync(COMMITTEE_API_PATH).GetAwaiter().GetResult(); Debug.WriteLine(response.IsSuccessStatusCode); if (response.IsSuccessStatusCode) { committeesData = response.Content.ReadAsStringAsync().GetAwaiter().GetResult(); Debug.WriteLine(committeesData); } if (!committeesData.Equals("")) { // JsonConvert is part of the NewtonSoft.Json Nuget package committees = JsonConvert.DeserializeObject <Committees>(committeesData); } } catch (Exception e) { // This is a useful place to insert a breakpoint and observe the error message Console.WriteLine(e.Message); } return(committees); }
public IActionResult Committees() { HomeController webHandler = new HomeController(dbContext); Committees committee = webHandler.GetCommittees(); return(View(committee)); }
public Committees GetCommittees() { string COMMITTEES_API_PATH = BASE_URL + "/committees/?sort_nulls_last=false&sort=name&page=1&sort_null_only=false&per_page=20&candidate_id=P60009115&candidate_id=P60009313&candidate_id=P60017647&candidate_id=P60017654&candidate_id=P00013565&candidate_id=P00011379&candidate_id=P00012468&candidate_id=P60017951&candidate_id=P60017084&candidate_id=H6MD35013&candidate_id=P60014164&candidate_id=S4AK00164&candidate_id=P60012648&candidate_id=P60022878&candidate_id=P60009578&candidate_id=P60017571&candidate_id=P60002375&candidate_id=S2CA00542&candidate_id=P60010501&candidate_id=P60013943&sort_hide_null=false"; string committeesData = ""; Committees committees = null; httpClient.BaseAddress = new Uri(COMMITTEES_API_PATH); // It can take a few requests to get back a prompt response, if the API has not received // calls in the recent past and the server has put the service on hibernation try { HttpResponseMessage response = httpClient.GetAsync(COMMITTEES_API_PATH).GetAwaiter().GetResult(); if (response.IsSuccessStatusCode) { committeesData = response.Content.ReadAsStringAsync().GetAwaiter().GetResult(); Console.WriteLine(committeesData); } if (!committeesData.Equals("")) { // JsonConvert is part of the NewtonSoft.Json Nuget package committees = JsonConvert.DeserializeObject <Committees>(committeesData); } } catch (Exception e) { // This is a useful place to insert a breakpoint and observe the error message Console.WriteLine(e.Message); } return(committees); }
public IActionResult Committees() { APIHandler webHandler = new APIHandler(); Committees committees = webHandler.GetCommittees(); foreach (var item in committees.results) { if (dbContext.Committees.Where(c => c.committee_id.Equals(item.committee_id)).Count() == 0) { dbContext.Committees.Add(item); } } dbContext.SaveChanges(); foreach (var item in committees.results) { Committee can = dbContext.Committees.First(a => a.committee_id == item.committee_id); string candi = string.Join(",", item.candidate_ids); can.candidate_id = candi; } dbContext.SaveChanges(); return(View(committees)); }
public IActionResult Index() { httpClient = new HttpClient(); httpClient.DefaultRequestHeaders.Accept.Clear(); httpClient.DefaultRequestHeaders.Add("X-Api-Key", API_KEY); httpClient.DefaultRequestHeaders.Accept.Add( new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); string ELECTION_API_PATH = BASE_URL + "committees/?api_key=d1OdWVY6fL8IOGhIgjhyMPMYvXs5K3inmCAtg3Wc"; string committeesData = ""; Committees committees = null; httpClient.BaseAddress = new Uri(ELECTION_API_PATH); try { HttpResponseMessage response = httpClient.GetAsync(ELECTION_API_PATH).GetAwaiter().GetResult(); if (response.IsSuccessStatusCode) { committeesData = response.Content.ReadAsStringAsync().GetAwaiter().GetResult(); } if (!committeesData.Equals("")) { // JsonConvert is part of the NewtonSoft.Json Nuget package committees = JsonConvert.DeserializeObject <Committees>(committeesData); async Task <ViewResult> DatabaseOperations() { foreach (var comm in committees.results) { CommitteeDT com = new CommitteeDT { name = comm.name }; Party p = new Party { party_code = comm.party, party_name = comm.party_full }; dbContext.CommitteeDT.Add(com); dbContext.Party.Add(p); dbContext.SaveChanges(); } return(View()); } } } catch (Exception e) { // This is a useful place to insert a breakpoint and observe the error message Console.WriteLine(e.Message); } return(View(committees)); }
public void T020_AllForLegislator_FirstOnList() { // first, read all legislators var legislators_req = new Legislators(ConfigData.API_KEY); var legislators_result = legislators_req.GetList(false); Assert.IsTrue(legislators_result.Count() > 0, "Legislators.GetList failed to return even one current legislator"); // read all committee memberships, allowing an error to occur bool ok = false; foreach (var legislator in legislators_result) { var name = legislator.firstname + " " + legislator.lastname; try { // now read the committee membership for legislator var req = new Committees(ConfigData.API_KEY); var result = req.AllForLegislator(legislator.bioguide_id); Assert.Greater(result.Count(), 0, "AllForLegislator failed to return values for " + name); ok = true; break; } catch (Infrastructure.ErrorException) { // this is OK System.Console.WriteLine("Failed reading data for " + name + " (retrying)"); } } if (!ok) { Assert.Fail("Could find no committee memberships in the entire house"); } }
//public dtoCommitteesSummaryItem(UserSubmission s, String anonymousUser) // : base(s, anonymousUser) //{ // Committees = new List<dtoCommitteeDisplayItem>(); // Counters = new Dictionary<EvaluationStatus, long>() { { EvaluationStatus.Evaluated, 0 }, { EvaluationStatus.Evaluating, 0 }, { EvaluationStatus.EvaluatorReplacement, 0 }, { EvaluationStatus.Invalidated, 0 }, { EvaluationStatus.None, 0 } }; //} public void UpdateCounters() { var query = Committees.Where(c => c.Evaluations != null).SelectMany(c => c.Evaluations); Counters[EvaluationStatus.None] = query.Where(s => s.Status == EvaluationStatus.None).Count(); Counters[EvaluationStatus.Evaluated] = query.Where(s => s.Status == EvaluationStatus.Evaluated).Count(); Counters[EvaluationStatus.Evaluating] = query.Where(s => s.Status == EvaluationStatus.Evaluating).Count(); Counters[EvaluationStatus.EvaluatorReplacement] = query.Where(s => s.Status == EvaluationStatus.EvaluatorReplacement).Count(); Counters[EvaluationStatus.Invalidated] = query.Where(s => s.Status == EvaluationStatus.Invalidated).Count(); }
public void T001_GetList_All() { var req = new Committees(ConfigData.API_KEY); var result = req.GetList(Globals.CHAMBER_TYPE.HOUSE); Assert.IsTrue(result.Count() > 0, "GetList failed for HOUSE"); result = req.GetList(Globals.CHAMBER_TYPE.JOINT); Assert.IsTrue(result.Count() > 0, "GetList failed for JOINT"); result = req.GetList(Globals.CHAMBER_TYPE.SENATE); Assert.IsTrue(result.Count() > 0, "GetList failed for SENATE"); }
public List <dtoCommitteePartialAssignment> GetPartialAssignments(Dictionary <long, Dictionary <long, String> > evaluators) { List <dtoCommitteePartialAssignment> items = new List <dtoCommitteePartialAssignment>(); items.AddRange(Committees.Where(c => c.Evaluators.Count != evaluators[c.IdCommittee].Values.Count).Select(c => new dtoCommitteePartialAssignment() { CommitteeName = c.Name, Display = c.Display, SubmitterName = this.DisplayName, SubmitterType = this.SubmitterType, SubmittedOn = this.SubmittedOn, AssignedEvaluators = c.Evaluators.Count, AvailableEvaluators = evaluators[c.IdCommittee].Values.Count , IdSubmission = this.IdSubmission }).ToList()); return(items); }
public IActionResult PopulateCommittees() { // Retrieve the companies that were saved in the symbols method // List<Candidates> candidate = JsonConvert.DeserializeObject<Candidates>(TempData["Candidates"].ToString()); HomeController webHandler = new HomeController(dbContext); Committees committee = webHandler.GetCommittees(); List <Committee> cm = committee.results; foreach (Committee cm1 in cm) { if (dbContext.Committee.Where(c => c.committee_id.Equals(cm1.committee_id)).Count() == 0) { dbContext.Committee.Add(cm1); } } dbContext.SaveChanges(); ViewBag.dbSuccessComp = 1; return(View("Committees", committee)); }
private Committees GetCommitteeMembers() { var committeesData = HttpHelper.Get<CommitteesData>(serviceBaseUri+"/Committees"); mapper = new AutoDataContractMapper(); var committees = new Committees(); mapper.MapList(committeesData, committees, typeof(Committee)); return committees; }
public void T010_Get_JSPR() { var req = new Committees(ConfigData.API_KEY); var result = req.Get("JSPR"); Assert.IsNotNull(result, "Get failed to read info about JSPR"); }