Skip to content

Commit

Permalink
Update NameProcessingExtensions.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
idormenco committed Nov 4, 2024
1 parent fe613e8 commit 01de2bf
Showing 1 changed file with 22 additions and 10 deletions.
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;
}
}
}
}

0 comments on commit 01de2bf

Please sign in to comment.