public IActionResult Index(string postcode) { ConstituencyQuery query = new ConstituencyQuery(); ConstituencyResult constituencyResult = query.GetConstitutencyByPostCode(postcode); Constituency constituency = this.constituencyRepository.FindByName(constituencyResult.Name); ConstituencyViewModel vm = new ConstituencyViewModel() { Constituency = constituency, ConstituencyResult = constituencyResult, }; return(View(vm)); }
/// <summary> /// Gets a constituency result from a row. /// </summary> /// <param name="csv">The csv row.</param> /// <param name="onsCode">The ONS code of the constituency.</param> /// <param name="partyNames">The party names.</param> /// <returns>The parsed constituency result.</returns> public static ConstituencyResult GetConstituencyResultFromRecord( CsvReader csv, string onsCode, string[] partyNames) { // If here on a line with data convert it into a record - the format is: // (0) ONS Code // (1) Constituency // (2) Region // (3) Electorate // (4) Total ballots at the count // (5) Total valid votes cast // (6) Rejected ballots // (7) Ballot Box Turnout(%) // (8) Rejected ballots(%) // (9-n) CON LAB LIB SNP etc (votes) // (9+n+1-2n) CON LAB LIB SNP etc (%) ConstituencyResult constituencyResult = new ConstituencyResult { Code = onsCode, Constituency = csv.GetField <string>(1), Region = csv.GetField <string>(2), Electorate = ConvertInt(csv.GetField <string>(3)), TotalBallotsAtTheCount = ConvertInt(csv.GetField <string>(4)), TotalValidVotesCast = ConvertInt(csv.GetField <string>(5)), RejectedBallots = ConvertInt(csv.GetField <string>(6)), BallotBoxTurnoutPercentage = ConvertFloat(csv.GetField <string>(7)), RejectedBallotsPercentage = ConvertFloat(csv.GetField <string>(8)) }; constituencyResult.PartyResults = GetPartyConstituencyResults(csv, partyNames, constituencyResult.TotalValidVotesCast); List <PartyResult> sortedResults = constituencyResult.PartyResults.OrderByDescending(x => x.Votes).ToList(); constituencyResult.Win = sortedResults[0].PartyAbbreviation; constituencyResult.Second = sortedResults[1].PartyAbbreviation; constituencyResult.Majority = sortedResults[0].Votes - sortedResults[1].Votes; constituencyResult.MajorityPercentage = (constituencyResult.Majority * 100.0f) / constituencyResult.TotalValidVotesCast; return(constituencyResult); }