From 3528c1d0d37c183fb126109086f01a4b96b69069 Mon Sep 17 00:00:00 2001 From: Simon Date: Sat, 9 Jan 2021 21:56:17 +0100 Subject: [PATCH] Final release --- .../controller/VotingController.java | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/github/cato447/AbizeitungVotingSystem/controller/VotingController.java b/src/main/java/com/github/cato447/AbizeitungVotingSystem/controller/VotingController.java index d4389ff..1abcf02 100644 --- a/src/main/java/com/github/cato447/AbizeitungVotingSystem/controller/VotingController.java +++ b/src/main/java/com/github/cato447/AbizeitungVotingSystem/controller/VotingController.java @@ -193,23 +193,28 @@ public class VotingController { long index = 1; for (PossibleCandidate posCandidate : posCandidates) { if (posCandidate.getName() != "") { - if (possibleCandidateRepository.findByNameAndCategory(posCandidate.getName(), categoryRepository.findById(index).get()) != null) { + if (possibleCandidateRepository.findByNameAndCategory(posCandidate.getName(), categoryRepository.findById(index).get()) != null || + possibleCandidateRepository.findByNameAndCategory(posCandidate.getName().split(" ")[posCandidate.getName().split(" ").length-1], categoryRepository.findById(index).get()) != null) { PossibleCandidate p = possibleCandidateRepository.findByNameAndCategory(posCandidate.getName(), categoryRepository.findById(index).get()); p.setVotes(p.getVotes() + 1); possibleCandidateRepository.save(p); } else { if (index > 31 && posCandidate.getName().indexOf(" ") != -1) { - if (posCandidate.getName().split(" ")[posCandidate.getName().split(" ").length-1] == "Neumann" || - posCandidate.getName().split(" ")[posCandidate.getName().split(" ").length-1] == "neumann" || - posCandidate.getName().split(" ")[posCandidate.getName().split(" ").length-1] == "Mecklenburg" || - posCandidate.getName().split(" ")[posCandidate.getName().split(" ").length-1] == "mecklenburg" ){ - posCandidate.setName(posCandidate.getName()); + if (posCandidate.getName().split(" ")[posCandidate.getName().split(" ").length-1].equals("Neumann") || + posCandidate.getName().split(" ")[posCandidate.getName().split(" ").length-1].equals("neumann") || + posCandidate.getName().split(" ")[posCandidate.getName().split(" ").length-1].equals("Mecklenburg") || + posCandidate.getName().split(" ")[posCandidate.getName().split(" ").length-1].equals("mecklenburg")){ + PossibleCandidate possibleCandidate = new PossibleCandidate(posCandidate.getName(), categoryRepository.findById(index).get()); + possibleCandidateRepository.save(possibleCandidate); } else { posCandidate.setName(posCandidate.getName().split(" ")[posCandidate.getName().split(" ").length - 1]); + PossibleCandidate possibleCandidate = new PossibleCandidate(posCandidate.getName(), categoryRepository.findById(index).get()); + possibleCandidateRepository.save(possibleCandidate); } + } else { + PossibleCandidate possibleCandidate = new PossibleCandidate(posCandidate.getName(), categoryRepository.findById(index).get()); + possibleCandidateRepository.save(possibleCandidate); } - PossibleCandidate possibleCandidate = new PossibleCandidate(posCandidate.getName(), categoryRepository.findById(index).get()); - possibleCandidateRepository.save(possibleCandidate); } } index++;