Skip to content

Commit

Permalink
Merge pull request #224 from code4romania/bugfix/show-candidate-name-…
Browse files Browse the repository at this point in the history
…when-presidential-elections

Display candidate name when presidential elections
  • Loading branch information
gheorghelupu17 authored Nov 4, 2024
2 parents fe613e8 + 01de2bf commit ae5eb2d
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 ae5eb2d

Please sign in to comment.