public DatabasePlayer(FluffTailRanking.BusinessLayer.BusinessObjects.Player player) { this.eloid = player.ELOID; this.email = player.Email; this.nickname = player.Nickname; this.forename = player.Forename; this.lastname = player.Lastname; this.gravatarhash = player.GetHashCode().ToString(); }
public int AddPlayer(FluffTailRanking.BusinessLayer.BusinessObjects.Player newplayer) { try { return persistentManager.SavePlayer(newplayer); } catch (Exception ex) { return 0; } }
/// <summary> /// Save a Player to the Database /// </summary> /// <param name="player">Playerobject to Save</param> /// <returns>1 if successfull, otherwise 0</returns> public int SavePlayer(FluffTailRanking.BusinessLayer.BusinessObjects.Player player) { player = player == null ? new FluffTailRanking.BusinessLayer.BusinessObjects.Player() : player; try { using (KickerEntities context = new KickerEntities()) { FluffTailRanking.BusinessLayer.Persistence.Player current = new FluffTailRanking.BusinessLayer.Persistence.Player() { id = player.ID, lastname = player.Lastname, forename = player.Forename, eloid = player.ELOID, email = player.Email, gravatarhash = player.GetHashCode().ToString() }; context.Player.Add(current); context.SaveChanges(); } return 1; } catch (Exception ex) { return 0; } }
/// <summary> /// Save a Team to the Database /// </summary> /// <param name="team">Teamobject to Save</param> /// <returns>1 if successfull, otherwise 0</returns> public int SaveTeam(FluffTailRanking.BusinessLayer.BusinessObjects.Team team) { try { using (KickerEntities context = new KickerEntities()) { FluffTailRanking.BusinessLayer.Persistence.Team current = new FluffTailRanking.BusinessLayer.Persistence.Team() { teamname = team.Name, eloid = team.ELOID, playerone = team.Players[0].ID, playertwo = team.Players[2].ID, id = team.ID, wins = team.Wins }; context.Team.Add(current); context.SaveChanges(); } return 1; } catch (Exception ex) { return 0; } }
/// <summary> /// Save a Game to the Database /// </summary> /// <param name="game">Gameobject to Save</param> /// <returns>1 if successfull, otherwise 0</returns> public int SaveGame(FluffTailRanking.BusinessLayer.BusinessObjects.Game game) { try { using (KickerEntities context = new KickerEntities()) { FluffTailRanking.BusinessLayer.Persistence.Game current = new FluffTailRanking.BusinessLayer.Persistence.Game() { date = DateTime.Now, teamone = game.Team1.ID, teamtwo = game.Team2.ID, winner = game.Winner.ID }; //TODO: Update Player wins / losts on save context.Game.Add(current); context.SaveChanges(); } return 1; } catch (Exception ex) { return 0; } }
/// <summary> /// Checks if a player is in a team /// </summary> /// <param name="team">(Team) Team to proof</param> /// <param name="player">(Player) Player to proof</param> /// <returns>(Bool) True or False</returns> public bool IsPlayerInTeam(FluffTailRanking.BusinessLayer.BusinessObjects.Team team, FluffTailRanking.BusinessLayer.BusinessObjects.Player player) { if (team.Players[0].ID == player.ID || team.Players[1].ID == player.ID) { return true; } return false; }
/// <summary> /// Get all wins of a team /// </summary> /// <param name="t">Team to get wins</param> /// <returns>Integer counting wins</returns> public int GetWinsOfTeam(FluffTailRanking.BusinessLayer.BusinessObjects.Team t) { int wins = 0; IEnumerable<FluffTailRanking.BusinessLayer.BusinessObjects.Game> games = GetAllGames(); foreach(var that in games) { if (that.Winner.ID == t.ID) { wins++; } } return wins; }
/// <summary> /// Get wins of a player /// </summary> /// <param name="p">Player object</param> /// <returns>Integer counting wins</returns> public int GetWinsOfPlayer(FluffTailRanking.BusinessLayer.BusinessObjects.Player p) { return GetTeamsByPlayer(p).Count(); }
/// <summary> /// Get all teams by player ID /// </summary> /// <param name="p">Player Object</param> /// <returns>List of Teams</returns> public IEnumerable<FluffTailRanking.BusinessLayer.BusinessObjects.Team> GetTeamsByPlayer(FluffTailRanking.BusinessLayer.BusinessObjects.Player p) { IEnumerable<FluffTailRanking.BusinessLayer.BusinessObjects.Game> allGames = GetAllGames(); List<FluffTailRanking.BusinessLayer.BusinessObjects.Team> pTeams = new List<FluffTailRanking.BusinessLayer.BusinessObjects.Team>(); foreach (var game in allGames) { if (IsPlayerInTeam(game.Team1, p)) { pTeams.Add(game.Team1); } else if (IsPlayerInTeam(game.Team2, p)) { pTeams.Add(game.Team2); } } return pTeams; }