public ExtendedPlayer GetPlayerByAlias(string alias) { using (var db = new FoostatsContext()) { var player = db.Players.First(x => x.DisplayName == alias); if (player == null) { throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.NotFound) { ReasonPhrase = string.Format("Player '{0}' could not be found.", alias) }); } var trueskill = db.Trueskill.Include(x => x.Player).First(x => x.Player.DisplayName == alias); trueskill.Player = null; var winloss = db.WinLoss.Include(x => x.Player).First(x => x.Player.DisplayName == alias); winloss.Player = null; var extendedPlayer = new ExtendedPlayer() { Id = player.Id, DisplayName = player.DisplayName, MutableDisplayName = player.MutableDisplayName, Password = player.Password, Salt = player.Salt, Trueskill = trueskill, WinLoss = winloss }; return(extendedPlayer); } }
public IEnumerable <ExtendedPlayer> GetPlayerByDisplayName(string displayName) { using (var db = new FoostatsContext()) { var players = db.Players.Where(x => x.MutableDisplayName == displayName); var trueskill = db.Trueskill.Include(x => x.Player).Where(x => x.Player.MutableDisplayName == displayName); var winloss = db.WinLoss.Include(x => x.Player).Where(x => x.Player.MutableDisplayName == displayName); List <ExtendedPlayer> extendedPlayers = new List <ExtendedPlayer>(); foreach (var player in players) { var thisTrueSkill = trueskill.FirstOrDefault(x => x.Player.Id == player.Id); if (thisTrueSkill != null) { thisTrueSkill.Player = null; } var thisWinLoss = winloss.FirstOrDefault(x => x.Player.Id == player.Id); if (thisWinLoss != null) { thisWinLoss.Player = null; } extendedPlayers.Add(new ExtendedPlayer() { Id = player.Id, DisplayName = player.DisplayName, MutableDisplayName = player.MutableDisplayName, Password = player.Password, Salt = player.Salt, Trueskill = thisTrueSkill, WinLoss = thisWinLoss }); } return(extendedPlayers); } }
public ActionResult GetByTeamName(String TeamDisplayName) { using (var db = new FoostatsContext()) { var matches = db.Matches. Include(x => x.Team1). Include(x => x.Team1.Player1). Include(x => x.Team1.Player2). Include(x => x.Team2.Player1). Include(x => x.Team2.Player2). Include(x => x.Team2).Where(x => x.Team1.DisplayName.Equals(TeamDisplayName, StringComparison.InvariantCultureIgnoreCase) || x.Team2.DisplayName.Equals(TeamDisplayName, StringComparison.InvariantCultureIgnoreCase)).ToList(); // convert to local time foreach (var match in matches) { if (match.Team1Validated.HasValue) { match.Team1Validated = match.Team1Validated.Value.ToLocalTime(); } if (match.Team2Validated.HasValue) { match.Team2Validated = match.Team2Validated.Value.ToLocalTime(); } } return(View("ListMatches", matches)); } }
public ActionResult GetRivalry(String playerDisplayName) { using (var db = new FoostatsContext()) { var thisPlayer = db.Players.FirstOrDefault(x => x.DisplayName == User.Identity.Name); if (thisPlayer == null) { return(View("ListMatches", null)); } var thatPlayer = db.Players.FirstOrDefault(x => x.DisplayName == playerDisplayName); if (thatPlayer == null) { return(View("ListMatches", null)); } var theseMatches = GetMatches(db, thisPlayer.Id); var thoseMatches = GetMatches(db, thatPlayer.Id); var matches = theseMatches.Intersect(thoseMatches).ToList(); var matches2 = new List <Match>(); // filter out matches where they are on the same team foreach (var match in matches) { if (!((match.Team1.Player1 == thisPlayer && match.Team1.Player2 == thatPlayer) || (match.Team1.Player2 == thisPlayer && match.Team1.Player1 == thatPlayer) || (match.Team2.Player1 == thisPlayer && match.Team2.Player2 == thatPlayer) || (match.Team2.Player2 == thisPlayer && match.Team2.Player1 == thatPlayer))) { matches2.Add(match); } } matches = matches2; // convert to local time foreach (var match in matches) { if (match.Team1Validated.HasValue) { match.Team1Validated = match.Team1Validated.Value.ToLocalTime(); } if (match.Team2Validated.HasValue) { match.Team2Validated = match.Team2Validated.Value.ToLocalTime(); } } var wins = matches.Count(x => ((x.Team1.Player1 == thisPlayer || x.Team1.Player2 == thisPlayer) && x.Score1 > x.Score2) || ((x.Team2.Player1 == thisPlayer || x.Team2.Player2 == thisPlayer) && x.Score2 > x.Score1)); var losses = matches.Count - wins; ViewBag.Wins = wins; ViewBag.Losses = losses; ViewBag.OpposingPlayer = playerDisplayName; ViewBag.PreferredPlayer = User.Identity.Name; return(View("ListMatches", matches)); } }
public ActionResult TopPlayers() { using (var db = new FoostatsContext()) { var players = db.Trueskill.Include(x => x.Player).OrderByDescending(x => x.ConservativeRating).ToList(); return(View(players)); } }
public IEnumerable <ExtendedPlayer> ListAll() { using (var db = new FoostatsContext()) { var players = db.Players.Take(MaxListAll).Select(x => x as ExtendedPlayer).ToList(); // cast it because it is anyway :/ return(players); } }
public ActionResult List() { using (var db = new FoostatsContext()) { List <string> players = db.Players.Select(x => x.DisplayName).ToList(); return(Json(players, JsonRequestBehavior.AllowGet)); } }
// // GET: /Tournament/ public ActionResult Index() { using (var db = new FoostatsContext()) { var Users = db.Players.ToList().Select(x => x.MutableDisplayName != null ? string.Format("{0} <{1}>", x.MutableDisplayName, x.DisplayName) : x.DisplayName); ViewBag.Users = Users; } return(View("Tournament")); }
public ActionResult Index() { using (var db = new FoostatsContext()){ var players = db.Trueskill.Include(x => x.Player).OrderByDescending(x => x.ConservativeRating).Take(10).ToList(); ViewBag.Players = players; ViewBag.Users = db.Players.ToList().Select(x => x.MutableDisplayName != null ? string.Format("{0} <{1}>", x.MutableDisplayName, x.DisplayName) : x.DisplayName); } return(View()); }
public static Player getPlayer(FoostatsContext db, string playerName) { Player player = null; if (!String.IsNullOrEmpty(playerName)) { player = db.Players.FirstOrDefault(x => x.DisplayName == playerName); } return(player); }
public ActionResult CreateBracket(TeamViewModel [] models) { List <TeamViewModel> teams; using (var db = new FoostatsContext()) { // Process all the players and get their ratings teams = preProcessTeams(models, db); } return(Json(createBracket(teams, 0))); }
protected IQueryable <Match> GetMatches(FoostatsContext context, int playerId) { return(context.Matches.Include(x => x.Team1).Include(x => x.Team2). Include(x => x.Team1.Player1). Include(x => x.Team1.Player2). Include(x => x.Team2.Player1). Include(x => x.Team2.Player2).Where(x => x.Team1.Player1.Id == playerId || x.Team1.Player2.Id == playerId || x.Team2.Player1.Id == playerId || x.Team2.Player2.Id == playerId).OrderByDescending(x => x.Team1Validated)); }
public static Team getTeam(FoostatsContext db, Player player1, Player player2) { // Two player team Team matchTeam; if (player1 != null && player2 != null) { matchTeam = db.Teams.Include(x => x.Player1).Include(x => x.Player2).FirstOrDefault(x => (x.Player1.Id == player1.Id && x.Player2.Id == player2.Id) || (x.Player2.Id == player1.Id && x.Player1.Id == player2.Id)); if (matchTeam == null) { matchTeam = db.Teams.Add(new Team() { DisplayName = string.Format("{0}, {1}", player1.DisplayName, player2.DisplayName), Player1 = player1, Player2 = player2 }); } return(matchTeam); } else { if (player2 == null) { matchTeam = db.Teams.Include(x => x.Player1).Include(x => x.Player2).FirstOrDefault(x => (x.Player1.Id == player1.Id && x.Player2 == null) || (x.Player2.Id == player1.Id && x.Player1 == null)); } else { matchTeam = db.Teams.Include(x => x.Player1).Include(x => x.Player2).FirstOrDefault(x => (x.Player1.Id == player2.Id && x.Player2 == null) || (x.Player2.Id == player2.Id && x.Player1 == null)); } if (matchTeam == null) { matchTeam = db.Teams.Add(new Team() { DisplayName = player1 != null? player1.DisplayName : player2.DisplayName, Player1 = player1, Player2 = player2 }); } return(matchTeam); } }
public ActionResult SetMutableDisplayName(string mutableDisplayName) { using (var db = new FoostatsContext()) { var player = db.Players.FirstOrDefault(x => x.DisplayName == User.Identity.Name); if (player != null) { player.MutableDisplayName = mutableDisplayName; db.SaveChanges(); } } return(Profile(User.Identity.Name)); }
public IEnumerable <Match> ListAll() { using (var db = new FoostatsContext()) { return(db.Matches .Include(x => x.Team1) .Include(x => x.Team2) .Include(x => x.Team1.Player1) .Include(x => x.Team1.Player2) .Include(x => x.Team2.Player1) .Include(x => x.Team2.Player2) .Take(MaxListAll) .ToList()); } }
public ActionResult Recalculate() { using (var db = new FoostatsContext()) { var matches = db.Matches.Include(x => x.Team1).Include(x => x.Team2).OrderBy((x) => x.Team1Validated); foreach (var match in matches) { foreach (var plugin in MetricCalculators) { plugin.UpdateMetrics(match.Team1, match.Team2, match.Score1, match.Score2); } } } return(View()); }
public ActionResult AddMatches(MatchModel[] matches) { using (var db = new FoostatsContext()) { foreach (MatchModel match in matches) { #region Initialize Players //Possibly use a for loop for this later Player t1p1 = getPlayer(db, match.Team1Players[0]); Player t1p2 = getPlayer(db, match.Team1Players[1]); Player t2p1 = getPlayer(db, match.Team2Players[0]); Player t2p2 = getPlayer(db, match.Team2Players[1]); #endregion #region Initialize Teams Team team1 = getTeam(db, t1p1, t1p2); Team team2 = getTeam(db, t2p1, t2p2); #endregion var newMatch = db.Matches.Add(new Match() { Team1 = team1, Team2 = team2, Score1 = match.Team1Score, Score2 = match.Team2Score, Team1Validated = DateTime.UtcNow, Team2Validated = null }); db.SaveChanges(); } } return(Json("success")); }
public ActionResult Add(String Team1Player1, String Team1Player2, String Team2Player1, String Team2Player2, int Score1, int Score2) { //Database.SetInitializer(new DropCreateDatabaseAlways<FoostatsContext>()); Match match = null; Team team1, team2; using (var db = new FoostatsContext()) { // after initialize players, Player objects are stored in t1p1, t1p2 (optional), t2p1, t2p2 (optional) #region Initialize Players // Parse out actual player names var startPosition = Team1Player1.IndexOf('<') + 1; if (startPosition != 0) // implies actual returned value is -1 { var length = Team1Player1.LastIndexOf('>') - startPosition; Team1Player1 = Team1Player1.Substring(startPosition, length); } if (!string.IsNullOrEmpty(Team1Player2)) { startPosition = Team1Player2.IndexOf('<') + 1; if (startPosition != 0) // implies actual returned value is -1 { var length = Team1Player2.LastIndexOf('>') - startPosition; Team1Player2 = Team1Player2.Substring(startPosition, length); } } startPosition = Team2Player1.IndexOf('<') + 1; if (startPosition != 0) // implies actual returned value is -1 { var length = Team2Player1.LastIndexOf('>') - startPosition; Team2Player1 = Team2Player1.Substring(startPosition, length); } if (!string.IsNullOrEmpty(Team2Player2)) { startPosition = Team2Player2.IndexOf('<') + 1; if (startPosition != 0) // implies actual returned value is -1 { var length = Team2Player2.LastIndexOf('>') - startPosition; Team2Player2 = Team2Player2.Substring(startPosition, length); } } // Team 1 Player t1p1 = db.Players.FirstOrDefault(x => x.DisplayName == Team1Player1); if (t1p1 == null) // team 1 player 1 exists but is not created { t1p1 = db.Players.Add(new Player() { DisplayName = Team1Player1 }); } Player t1p2 = null; if (!String.IsNullOrEmpty(Team1Player2)) { t1p2 = db.Players.FirstOrDefault(x => x.DisplayName == Team1Player2); if (t1p2 == null) // team 1 player 2 exists but is not created { t1p2 = db.Players.Add(new Player() { DisplayName = Team1Player2 }); } } // Team 2 Player t2p1 = db.Players.FirstOrDefault(x => x.DisplayName == Team2Player1); if (t2p1 == null) // team 2 player 1 exists but is not created { t2p1 = db.Players.Add(new Player() { DisplayName = Team2Player1 }); } Player t2p2 = null; if (!String.IsNullOrEmpty(Team2Player2)) { t2p2 = db.Players.FirstOrDefault(x => x.DisplayName == Team2Player2); if (t2p2 == null) // team 2 player 2 exists but is not created { t2p2 = db.Players.Add(new Player() { DisplayName = Team2Player2 }); } } db.SaveChanges(); #endregion // after initialize teams, Team objects are stored in team1 and team2 #region Initialize Teams if (t1p2 == null) { team1 = db.Teams.Include(x => x.Player1).Include(x => x.Player2).FirstOrDefault(x => (x.Player1.Id == t1p1.Id && x.Player2 == null) || (x.Player2.Id == t1p1.Id && x.Player1 == null)); } else { team1 = db.Teams.Include(x => x.Player1).Include(x => x.Player2).FirstOrDefault(x => (x.Player1.Id == t1p1.Id && x.Player2.Id == t1p2.Id) || (x.Player2.Id == t1p1.Id && x.Player1.Id == t1p2.Id)); } if (team1 == null) { team1 = db.Teams.Add(new Team() { DisplayName = t1p2 == null ? t1p1.DisplayName : string.Format("{0},{1}", t1p1.DisplayName, t1p2.DisplayName), Player1 = t1p1, Player2 = t1p2 }); } if (t2p2 == null) { team2 = db.Teams.FirstOrDefault(x => (x.Player1.Id == t2p1.Id && x.Player2 == null) || (x.Player2.Id == t2p1.Id && x.Player1 == null)); } else { team2 = db.Teams.FirstOrDefault(x => (x.Player1.Id == t2p1.Id && x.Player2.Id == t2p2.Id) || (x.Player2.Id == t2p1.Id && x.Player1.Id == t2p2.Id)); } if (team2 == null) { team2 = db.Teams.Add(new Team() { DisplayName = t2p2 == null ? t2p1.DisplayName : string.Format("{0},{1}", t2p1.DisplayName, t2p2.DisplayName), Player1 = t2p1, Player2 = t2p2 }); } db.SaveChanges(); #endregion match = db.Matches.Add(new Match() { Team1 = team1, Team2 = team2, Score1 = Score1, Score2 = Score2, Team1Validated = DateTime.UtcNow, Team2Validated = null }); db.SaveChanges(); } #region Update Metrics foreach (var plugin in MetricCalculators) { plugin.UpdateMetrics(team1, team2, Score1, Score2); } #endregion return(GetByTeamName(team1.DisplayName)); }
public IEnumerable <ExtendedPlayer> ListAllOrderedBy(ListAllInput input) { using (var db = new FoostatsContext()) { var players = db.Players; IEnumerable <ExtendedPlayer> extendedPlayers = null; List <Trueskill> trueskill = null; List <WinLoss> winloss = null; if (input.IncludeExtendedData) { trueskill = db.Trueskill.Include(x => x.Player).ToList(); winloss = db.WinLoss.Include(x => x.Player).ToList(); } IQueryable <Player> queryAble = null; if (string.Compare(input.OrderBy, "DisplayName", StringComparison.InvariantCultureIgnoreCase) == 0) { queryAble = input.Desc ? players.OrderByDescending(x => x.MutableDisplayName) : players.OrderBy(x => x.MutableDisplayName); } else if (string.Compare(input.OrderBy, "Alias", StringComparison.InvariantCultureIgnoreCase) == 0) { queryAble = input.Desc ? players.OrderByDescending(x => x.DisplayName) : players.OrderBy(x => x.DisplayName); } else if (string.Compare(input.OrderBy, "Id", StringComparison.InvariantCultureIgnoreCase) == 0 || string.IsNullOrEmpty(input.OrderBy)) { queryAble = input.Desc ? players.OrderByDescending(x => x.Id) : players.OrderBy(x => x.Id); } else if (input.IncludeExtendedData && string.Compare(input.OrderBy, "Trueskill", StringComparison.InvariantCultureIgnoreCase) == 0) { // have to match first extendedPlayers = players.ToList().Select(x => new ExtendedPlayer() { Id = x.Id, DisplayName = x.DisplayName, MutableDisplayName = x.MutableDisplayName, Password = x.Password, Salt = x.Salt, Trueskill = trueskill.FirstOrDefault(y => y.Player.Id == x.Id), WinLoss = winloss.FirstOrDefault(z => z.Player.Id == x.Id) }); extendedPlayers = input.Desc ? extendedPlayers.OrderByDescending(x => x.Trueskill == null ? 0 : x.Trueskill.ConservativeRating) : extendedPlayers.OrderBy(x => x => x.Trueskill == null ? 0 : x.Trueskill.ConservativeRating); } else if (input.IncludeExtendedData && string.Compare(input.OrderBy, "Trueskill", StringComparison.InvariantCultureIgnoreCase) == 0) { // have to match first extendedPlayers = players.ToList().Select(x => new ExtendedPlayer() { Id = x.Id, DisplayName = x.DisplayName, MutableDisplayName = x.MutableDisplayName, Password = x.Password, Salt = x.Salt, Trueskill = trueskill.FirstOrDefault(y => y.Player.Id == x.Id), WinLoss = winloss.FirstOrDefault(z => z.Player.Id == x.Id) }); extendedPlayers = input.Desc ? extendedPlayers.OrderByDescending(x => (x.WinLoss.Win) / ((x.WinLoss.Win + x.WinLoss.Loss))) : extendedPlayers.OrderBy(x => (x.WinLoss.Win) / ((x.WinLoss.Win + x.WinLoss.Loss))); } else { throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.BadRequest) { ReasonPhrase = string.Format("OrderBy value '{0}' is unknown.", input.OrderBy) }); } if (input.IncludeExtendedData && extendedPlayers == null) { // we have a queryable to deal with then extendedPlayers = queryAble.ToList().Select(x => new ExtendedPlayer() { Id = x.Id, DisplayName = x.DisplayName, MutableDisplayName = x.MutableDisplayName, Password = x.Password, Salt = x.Salt, Trueskill = trueskill.FirstOrDefault(y => y.Player.Id == x.Id), WinLoss = winloss.FirstOrDefault(z => z.Player.Id == x.Id) }); } if (input.StartIndex != 0) { if (extendedPlayers == null) { queryAble = queryAble.Skip(input.StartIndex - 1); } else { extendedPlayers = extendedPlayers.Skip(input.StartIndex - 1); } } if (input.Limit != 0) { if (extendedPlayers == null) { queryAble = queryAble.Take(input.Limit); } else { extendedPlayers = extendedPlayers.Take(input.Limit); } } if (extendedPlayers == null) { var playersResult = queryAble.ToList(); // resolve extendedPlayers = playersResult.Select(x => new ExtendedPlayer() { Id = x.Id, DisplayName = x.DisplayName, MutableDisplayName = x.MutableDisplayName, Password = x.Password, Salt = x.Salt }); } extendedPlayers = extendedPlayers.ToList(); // load // strip away player data foreach (var player in extendedPlayers) { if (player.Trueskill != null) { player.Trueskill.Player = null; } if (player.WinLoss != null) { player.WinLoss.Player = null; } } return(extendedPlayers); } }
public IEnumerable <Match> ListAllOrderedBy(ListAllInput input) { using (var db = new FoostatsContext()) { var dbSet = db.Matches .Include(x => x.Team1) .Include(x => x.Team2) .Include(x => x.Team1.Player1) .Include(x => x.Team1.Player2) .Include(x => x.Team2.Player1) .Include(x => x.Team2.Player2); if (!string.IsNullOrEmpty(input.SearchKey)) { if (string.Compare(input.SearchKey, "Alias", StringComparison.InvariantCultureIgnoreCase) == 0) { if (!string.IsNullOrEmpty(input.SearchTerm)) { dbSet = db.Matches.Where(x => (x.Team1.Player1.DisplayName == input.SearchTerm || x.Team1.Player2.DisplayName == input.SearchTerm || x.Team2.Player1.DisplayName == input.SearchTerm || x.Team2.Player2.DisplayName == input.SearchTerm)); } else { throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.BadRequest) { ReasonPhrase = string.Format("SearchTerm value unspecified for SearchKey {0}.", input.SearchKey) }); } } else { throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.BadRequest) { ReasonPhrase = string.Format("SearchKey value '{0}' is unknown.", input.SearchKey) }); } } IQueryable <Match> queryAble = null; if (string.IsNullOrEmpty(input.OrderBy)) { input.OrderBy = "Date"; // date by default } if (string.Compare(input.OrderBy, "Date", StringComparison.InvariantCulture) == 0) { queryAble = input.Desc ? dbSet.OrderByDescending(x => x.Team1Validated) : dbSet.OrderBy(x => x.Team1Validated); } else { throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.BadRequest) { ReasonPhrase = string.Format("OrderBy value '{0}' is unknown.", input.OrderBy) }); } if (input.StartIndex != 0) { queryAble = queryAble.Skip(input.StartIndex - 1); } if (input.Limit > 0) { queryAble = queryAble.Take(input.Limit); } return(queryAble.ToList()); } }
public List <TeamViewModel> preProcessTeams(TeamViewModel [] teams, FoostatsContext db) { List <TeamViewModel> models = new List <TeamViewModel>(); foreach (TeamViewModel team in teams) { // Process all the players and get their ratings Player t1p1 = null; if (!String.IsNullOrEmpty(team.Player1)) { String player1Name = FoosHelpers.getPlayerName(team.Player1); // May need to fix this t1p1 = db.Players.FirstOrDefault(x => x.DisplayName == player1Name); if (t1p1 == null) { t1p1 = db.Players.Add(new Player() { DisplayName = player1Name }); } var trueskill1 = db.Trueskill.Include(x => x.Player).FirstOrDefault(x => x.Player.DisplayName == t1p1.DisplayName); if (trueskill1 != null) { team.Rating += trueskill1.ConservativeRating; } else { team.Rating += 0; } } Player t1p2 = null; if (!String.IsNullOrEmpty(team.Player2)) { String player2Name = FoosHelpers.getPlayerName(team.Player2); t1p2 = db.Players.FirstOrDefault(x => x.DisplayName == player2Name); if (t1p2 == null) // team 1 player 1 exists but is not created { t1p2 = db.Players.Add(new Player() { DisplayName = player2Name }); } var trueskill1 = db.Trueskill.Include(x => x.Player).FirstOrDefault(x => x.Player.DisplayName == t1p2.DisplayName); if (trueskill1 != null) { team.Rating += trueskill1.ConservativeRating; } else { team.Rating += 0; } } // Two player team if (t1p1 != null && t1p2 != null) { Team matchTeam = db.Teams.Include(x => x.Player1).Include(x => x.Player2).FirstOrDefault(x => (x.Player1.Id == t1p1.Id && x.Player2.Id == t1p2.Id) || (x.Player2.Id == t1p1.Id && x.Player1.Id == t1p2.Id)); if (matchTeam == null) { matchTeam = db.Teams.Add(new Team() { DisplayName = string.Format("{0}, {1}", t1p1.DisplayName, t1p2.DisplayName), Player1 = t1p1, Player2 = t1p2 }); } } else { Team matchTeam; if (t1p2 == null) { matchTeam = db.Teams.Include(x => x.Player1).Include(x => x.Player2).FirstOrDefault(x => (x.Player1.Id == t1p1.Id && x.Player2 == null) || (x.Player2.Id == t1p1.Id && x.Player1 == null)); } else { matchTeam = db.Teams.Include(x => x.Player1).Include(x => x.Player2).FirstOrDefault(x => (x.Player1.Id == t1p2.Id && x.Player2 == null) || (x.Player2.Id == t1p2.Id && x.Player1 == null)); } if (matchTeam == null) { matchTeam = db.Teams.Add(new Team() { DisplayName = t1p1 != null? t1p1.DisplayName : t1p2.DisplayName, Player1 = t1p1, Player2 = t1p2 }); } } models.Add(team); } if (models.Count % 2 != 0) { TeamViewModel byeTeam = new TeamViewModel(); byeTeam.TeamName = "Bye"; byeTeam.Player1 = String.Empty; byeTeam.Player2 = String.Empty; byeTeam.Rating = 0; models.Add(byeTeam); } return(models.OrderByDescending(x => x.Rating).ToList()); }