Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display candidate name when presidential elections #224

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 22 additions & 10 deletions src/ElectionResults.Core/Extensions/NameProcessingExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ namespace ElectionResults.Core.Extensions
{
public static class NameProcessingExtensions
{
public static List<CandidateResponse> OrderForReferendum(this List<CandidateResponse> candidates, Election election)
public static List<CandidateResponse> OrderForReferendum(this List<CandidateResponse> candidates,
Election election)
{
var yesCandidate = candidates.Find(c => c.Name == "DA");
var noCandidate = candidates.Find(c => c.Name == "NU");
Expand Down Expand Up @@ -37,27 +38,38 @@ public static List<CandidateResponse> OrderForReferendum(this List<CandidateResp
return candidates;
}

public static string GetCandidateShortName(this CandidateResult c, Ballot ballot)
public static string GetCandidateShortName(this CandidateResult candidate, Ballot ballot)
{
try
{
if(c.PartyId != null)
if (ballot.BallotType == BallotType.President)
{
return c.ShortName;
return candidate.Name;
}

if (candidate.PartyId != null)
{
return candidate.ShortName;
}

if (ballot.BallotType == BallotType.EuropeanParliament || ballot.BallotType == BallotType.Senate ||
ballot.BallotType == BallotType.House)
return c.ShortName;
if (c.Name.IsParty() || c.Name.IsEmpty())
return c.ShortName;
var processedName = ParseShortName(c.Name);
{
return candidate.ShortName;
}

if (candidate.Name.IsParty() || candidate.Name.IsEmpty())
{
return candidate.ShortName;
}

var processedName = ParseShortName(candidate.Name);
return processedName;
}
catch (Exception e)
{
Console.WriteLine(e);
return c.ShortName;
return candidate.ShortName;
}
}

Expand Down Expand Up @@ -98,4 +110,4 @@ public static string GetCandidateName(this CandidateResult c, Ballot ballot)
return c.Name.IsEmpty() ? c.PartyName : c.Name;
}
}
}
}