mirror of
https://github.com/jcwimer/wrestlingApp
synced 2026-03-25 01:14:43 +00:00
Swap page is now working and also moved swaping logic from tournament model to its own class
This commit is contained in:
@@ -9,7 +9,7 @@ class Tournament < ActiveRecord::Base
|
||||
has_many :wrestlers, through: :weights
|
||||
has_many :matches, dependent: :destroy
|
||||
has_many :delegates, class_name: "TournamentDelegate"
|
||||
|
||||
|
||||
validates :date, :name, :tournament_type, :address, :director, :director_email , presence: true
|
||||
|
||||
def self.search(search)
|
||||
@@ -136,36 +136,6 @@ class Tournament < ActiveRecord::Base
|
||||
end
|
||||
end
|
||||
|
||||
def swapWrestlers(wrestler1_id,wrestler2_id)
|
||||
w1 = Wrestler.find(wrestler1_id)
|
||||
w2 = Wrestler.find(wrestler2_id)
|
||||
|
||||
#placeholder guy
|
||||
w3 = Wrestler.new
|
||||
w3.weight_id = w1.weight_id
|
||||
w3.original_seed = w1.original_seed
|
||||
w3.seed = w1.seed
|
||||
swapWrestlerMatches(w1.allMatches,wrestler1_id,w3.id)
|
||||
|
||||
#Swap wrestler 1 and wrestler 2
|
||||
swapWrestlerMatches(w2.allMatches,wrestler2_id,wrestler1_id)
|
||||
w1.seed = w2.seed
|
||||
|
||||
|
||||
swapWrestlerMatches(w3.allMatches,w3.id,wrestler2_id)
|
||||
w2.seed = w3.seed
|
||||
|
||||
|
||||
w1.save
|
||||
w2.save
|
||||
end
|
||||
|
||||
def swapWrestlerMatches(matchesToSwap,w1_id,w2_id)
|
||||
matchesToSwap.each do |m|
|
||||
if m.bracket_position == "Pool"
|
||||
m.swapWrestlers(w1_id,w2_id)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user