diff --git a/app/models/match.rb b/app/models/match.rb index a4f6d98..ef0029b 100644 --- a/app/models/match.rb +++ b/app/models/match.rb @@ -135,4 +135,15 @@ class Match < ActiveRecord::Base wrestler1.generatePoolNumber end end + + def swapWrestlers(wrestler1_id,wrestler2_id) + if self.m1 == wrestler1_id + self.m1 = wrestler2_id + self.save + elsif self.m2 == wrestler1_id + self.m2 = wrestler2_id + self.save + end + + end end diff --git a/app/models/tournament.rb b/app/models/tournament.rb index 0ed3e4d..3e24af4 100644 --- a/app/models/tournament.rb +++ b/app/models/tournament.rb @@ -140,37 +140,23 @@ class Tournament < ActiveRecord::Base w1 = Wrestler.find(wrestler1_id) w2 = Wrestler.find(wrestler2_id) - #placeholder guy - w3 = Wrestler.new - w3.name = w1.name - w3.school_id = w1.school_id - w3.weight_id = w1.weight_id - w3.season_win = w1.season_win - w3.season_loss = w1.season_loss - w3.criteria = w1.criteria - w3.original_seed = w1.original_seed - w3.seed = w1.seed + w1Matches = w1.allMatches + w1Seed = w1.seed + w2Matches = w2.allMatches + w2Seed = w2.seed - #Swap wrestler 1 and wrestler 2 - w1.name = w2.name - w1.school_id = w2.school_id - w1.weight_id = w2.weight_id - w1.season_win = w2.season_win - w1.season_loss = w2.season_loss - w1.criteria = w2.criteria - w1.original_seed = w2.original_seed - w1.seed = w2.seed + w1Matches.each do |m| + m.swapWrestlers(wrestler1_id,wrestler2_id) + end - w2.name = w3.name - w2.school_id = w3.school_id - w2.weight_id = w3.weight_id - w2.season_win = w3.season_win - w2.season_loss = w3.season_loss - w2.criteria = w3.criteria - w2.original_seed = w3.original_seed - w2.seed = w3.seed + w2Matches.each do |m| + m.swapWrestlers(wrestler2_id,wrestler1_id) + end + w1.seed = w2Seed w1.save + + w2.seed = w1Seed w2.save end