public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } TieBreaker tieBreaker = await _context.TieBreaker.FirstOrDefaultAsync(tie => tie.TieBreakerId.Equals(id)); Team team = await _context.Team.FirstOrDefaultAsync(t => t.TeamId.Equals(tieBreaker.TeamID)); if (team == null) { RedirectToPage("JudgeVotes"); } JudgeWinner judgeWinner = new JudgeWinner() { EventID = tieBreaker.EventID, TeamID = tieBreaker.TeamID, UserID = tieBreaker.EventID, TeamName = team.TeamName }; _context.JudgeWinner.Add(judgeWinner); await _context.SaveChangesAsync(); return(RedirectToPage("./JudgeWinnerList")); }
public int CompareTo(Combatant other) { if (Initiative != other.Initiative) { return(Initiative.CompareTo(other.Initiative)); } // If it comes down to a tiebreaker, order by ascending return(TieBreaker.CompareTo(other.TieBreaker) * -1); }
public async Task <IActionResult> OnGetAsync(int?id) { if (id == null) { return(NotFound()); } TieBreaker = await _context.TieBreaker.FirstOrDefaultAsync(m => m.TieBreakerId == id); if (TieBreaker == null) { return(NotFound()); } return(Page()); }
public async Task <IActionResult> OnPostAsync(int?id) { //Here id refers to tiebreaker id as due to design flaws if (id == null) { return(RedirectToPage("PeopleWinnerList")); } AppCondition app = await _context.AppCondition.FirstOrDefaultAsync(app => app.AppConditionId.Equals(1)); TieBreaker tie = await _context.TieBreaker.FirstOrDefaultAsync(tie => tie.TieBreakerId.Equals(id) && tie.EventID.Equals(app.EventID)); if (tie == null) { //Something obviosuly went wrong return(RedirectToPage("PeopleVotes")); } Team = await _context.Team.FirstOrDefaultAsync(t => t.TeamId.Equals(tie.TeamID) && t.EventID.Equals(tie.EventID)); if (Team.TeamId != tie.TeamID) { //Which shouldn't be the case considering the OnGet function return(RedirectToPage("PeopleVotes")); } PeopleWinner peopleWinner = new PeopleWinner() { EventID = Team.EventID, TeamID = Team.TeamId, TeamName = Team.TeamName, UserID = Team.UserID }; _context.PeopleWinner.Add(peopleWinner); await _context.SaveChangesAsync(); //Now that winner has been found we need to remove the tie breaker teams IList <TieBreaker> tieBreakers = await _context.TieBreaker.ToListAsync(); foreach (var ties in tieBreakers) { _context.TieBreaker.Remove(ties); await _context.SaveChangesAsync(); } return(RedirectToPage("./PeopleWinnerList")); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } TieBreaker = await _context.TieBreaker.FindAsync(id); if (TieBreaker != null) { _context.TieBreaker.Remove(TieBreaker); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnGetAsync(int?id) { string username = HttpContext.Session.GetString("username"); AppCondition app = await _context.AppCondition.FirstOrDefaultAsync(app => app.AppConditionId.Equals(1)); if (app.AdminName != username) { //As only admin decide who can be the winner return(RedirectToPage("Privacy")); } if (id == null) { //Which shouldn't be possible if the admin correct path and procedure return(RedirectToPage("TieBreak")); } TieBreaker tie = await _context.TieBreaker.FirstOrDefaultAsync(tie => tie.TieBreakerId.Equals(id) && tie.EventID.Equals(app.EventID)); if (tie == null) { //Which means the tie breaker team is not found return(RedirectToPage("PeopleVotes")); } Event eve = await _context.Event.FirstOrDefaultAsync(eve => eve.EventId.Equals(tie.EventID)); EventCode = eve.EventCode; Team = await _context.Team.FirstOrDefaultAsync(t => t.TeamId.Equals(tie.TeamID) && t.EventID.Equals(tie.EventID)); if (Team == null) { //Which is not possible unless someone deletes the team //In this case we jus send the admin back to the total votes return(RedirectToPage("PeopleVotes")); } User leader = await _context.User.FirstOrDefaultAsync(u => u.UserId.Equals(Team.UserID)); LeaderName = leader.UserName; return(Page()); }
public async Task <IActionResult> OnGetAsync() { string username = HttpContext.Session.GetString("username"); AppCondition app = await _context.AppCondition.FirstOrDefaultAsync(app => app.AppConditionId.Equals(1)); TieBreaker = await _context.TieBreaker.Where(tie => tie.EventID.Equals(app.EventID)).ToListAsync(); if (TieBreaker.Count() == 0) { //The user tried to access it via url possibly return(RedirectToPage("PeopleVotes")); } allEvents = await _context.Event.ToListAsync(); allTeams = await _context.Team.Where(t => t.EventID.Equals(app.EventID)).ToListAsync(); allUsers = await _context.User.ToListAsync(); return(Page()); }
public async Task <IActionResult> OnPostAsync() { string username = HttpContext.Session.GetString("username"); AppCondition app = await _context.AppCondition.FirstOrDefaultAsync(app => app.AppConditionId.Equals(1)); //Since there is possibility of a tie we just get rid of the tie teams from before IList <TieBreaker> ties = await _context.TieBreaker.ToListAsync(); allEvents = await _context.Event.ToListAsync(); allUsers = await _context.User.ToListAsync(); if (ties != null) { foreach (var tie in ties) { _context.TieBreaker.Remove(tie); await _context.SaveChangesAsync(); } } if (username.Equals(app.AdminName)) { isAdmin = true; } else { isAdmin = false; return(RedirectToPage("Privacy")); } int highvotes = 0; IList <Judge> allJudges = await _context.Judge.Where(j => j.EventID.Equals(app.EventID)).ToListAsync(); if (Team == null) { Team = await _context.Team.Where(t => t.EventID.Equals(app.EventID)).ToListAsync(); foreach (var team in Team) { team.UserID = 0; } if (Team.Count() == 0) { //Which means no team has been created for the specific event Message = "Unfortunalty no team has been created for this event!!"; return(Page()); } if (app.AdminName.Equals(username)) { isAdmin = true; } else { isAdmin = false; } foreach (var judge in allJudges) { //We need to load all the votes each judge has made IList <Vote> allVotes = await _context.Vote.Where(v => v.UserID.Equals(judge.UserID) && v.EventID.Equals(app.EventID)).ToListAsync(); foreach (var vote in allVotes) { foreach (var team in Team) { if (vote.TeamID.Equals(team.TeamId)) { //So now that we have found the vote for the team //We wil just increment the vote for each team team.UserID += 1; } } } } } foreach (var team in Team) { if (team.UserID >= highvotes) { highvotes = team.UserID; } } JudgeWinner judgeWinner = await _context.JudgeWinner.FirstOrDefaultAsync(jw => jw.EventID.Equals(app.EventID)); if (judgeWinner != null) { Message = "Winner for the event has been finalized!!"; isAdmin = true; return(Page()); } foreach (var team in Team) { //Now we find how many teams have got the highest votes Team newTeam = await _context.Team.FirstOrDefaultAsync(t => t.TeamId.Equals(team.TeamId) && t.EventID.Equals(app.EventID)); if (team.UserID.Equals(highvotes)) { TieBreaker tieBreaker = new TieBreaker() { UserID = newTeam.UserID, EventID = newTeam.EventID, TeamID = newTeam.TeamId, }; //Then we store each team with the highest votes _context.TieBreaker.Add(tieBreaker); await _context.SaveChangesAsync(); } } //Now we perform checks wether there is a tie breaker or not //For that we load all the teams which have been aded for the event IList <TieBreaker> tieBreakers = await _context.TieBreaker.Where(tie => tie.EventID.Equals(app.EventID)).ToListAsync(); if (tieBreakers.Count() == 1) { Team team = await _context.Team.FirstOrDefaultAsync(t => t.TeamId.Equals(tieBreakers[0].TeamID) && t.EventID.Equals(tieBreakers[0].EventID)); JudgeWinner judgeWinner1 = new JudgeWinner() { EventID = team.EventID, TeamID = team.TeamId, TeamName = team.TeamName, UserID = team.UserID }; _context.JudgeWinner.Add(judgeWinner1); await _context.SaveChangesAsync(); //Now that we have saved the winner for the event to the judge winner list //Now we just have to delete the tie breaker before we exit _context.TieBreaker.Remove(tieBreakers[0]); await _context.SaveChangesAsync(); return(RedirectToPage("JudgeWinnerList")); } else { return(RedirectToPage("TieBreaakForJudgeWinner")); } }
public async Task <IActionResult> OnPostAsync() { string username = HttpContext.Session.GetString("username"); AppCondition app = await _context.AppCondition.FirstOrDefaultAsync(app => app.AppConditionId.Equals(1)); IList <TieBreaker> tiees = await _context.TieBreaker.Where(tie => tie.EventID.Equals(app.EventID)).ToListAsync(); if (tiees != null) { foreach (var tie in tiees) { _context.TieBreaker.Remove(tie); await _context.SaveChangesAsync(); } } if (username.Equals(app.AdminName)) { isAdmin = true; } else { //Since only admin is supposed to use this functionality we send the other user back isAdmin = false; return(RedirectToPage("Privacy")); } int highVotes = 0; if (Team == null) { Team = await _context.Team.Where(t => t.EventID.Equals(app.EventID)).ToListAsync(); IList <User> Users = await _context.User.ToListAsync(); foreach (var team in Team) { //WE will be using Userid as a place to store the total votes for a team team.UserID = 0; } User loginUser = await _context.User.FirstOrDefaultAsync(u => u.UserName.Equals(username)); if (app.AdminName.Equals(username)) { isAdmin = true; } else { isAdmin = false; } foreach (var user in Users) { //Firstly we need to fetch all the vote users has for this session IList <Vote> userVotes = await _context.Vote.Where(v => v.UserID.Equals(user.UserId) && v.EventID.Equals(app.EventID)).ToListAsync(); //Next based on the vote we assign or increment each vote by one based on the respective user votes foreach (var vote in userVotes) { foreach (var team in Team) { if (vote.TeamID.Equals(team.TeamId)) { //That is the user has voted for this team in the event //So we just increament the team vote by one team.UserID += 1; } } } } } foreach (var team in Team) { if (team.UserID >= highVotes) { highVotes = team.UserID; } } PeopleWinner peopleWinner = await _context.PeopleWinner.FirstOrDefaultAsync(peopleWin => peopleWin.EventID.Equals(app.EventID)); if (peopleWinner != null) { Message = "People Winner has already been decided before!! If you wish to change remove that team first"; isAdmin = true; return(Page()); } //Now that we have to the highest votes we need to find the teams which have recieve high votes foreach (var team in Team) { //We store the team details of each team in a dummy team object for later use Team newTeam = await _context.Team.FirstOrDefaultAsync(t => t.TeamId.Equals(team.TeamId) && t.EventID.Equals(app.EventID)); if (team.UserID.Equals(highVotes)) { TieBreaker tie = new TieBreaker() { UserID = newTeam.UserID, EventID = newTeam.EventID, TeamID = newTeam.TeamId, }; //Now that we know that a team has got highest votes we need to store it within tie breaker _context.TieBreaker.Add(tie); await _context.SaveChangesAsync(); } } //Now we load the team which have got the highest votes for the current event //So we check if we have a tie by checkingthe tie team for the current event IList <TieBreaker> ties = await _context.TieBreaker.Where(tie => tie.EventID.Equals(app.EventID)).ToListAsync(); if (ties.Count() == 1) { Team team = await _context.Team.FirstOrDefaultAsync(t => t.TeamId.Equals(ties[0].TeamID) && t.EventID.Equals(ties[0].EventID)); PeopleWinner people = new PeopleWinner() { EventID = ties[0].EventID, TeamID = ties[0].TeamID, TeamName = team.TeamName, UserID = ties[0].UserID }; _context.PeopleWinner.Add(people); await _context.SaveChangesAsync(); //Now that we know that we don't have a tie breaker for people winner //We will just have to remove the tie breaker teams IList <TieBreaker> tiebreakers = await _context.TieBreaker.Where(tie => tie.EventID.Equals(app.EventID)).ToListAsync(); foreach (var tie in tiebreakers) { _context.TieBreaker.Remove(tie); await _context.SaveChangesAsync(); } return(RedirectToPage("PeopleWinnerList")); } else { //Which would mean that there is same votes among current event teams return(RedirectToPage("TieBreak")); //So for now we won't delete teams but will do it later on } }