Beispiel #1
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);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Get a specific Team with its Team ID
        /// </summary>
        /// <param name="tid">ID of Team</param>
        /// <returns>A team with the ID</returns>
        public FluffTailRanking.BusinessLayer.BusinessObjects.Team GetTeamById(int tid)
        {
            FluffTailRanking.BusinessLayer.BusinessObjects.Team team = new FluffTailRanking.BusinessLayer.BusinessObjects.Team();
            using (KickerEntities context = new KickerEntities())
            {
                var query =
                    from tm in context.Team
                    where tm.id == tid
                    select new
                {
                    tn    = tm.teamname,
                    w     = tm.wins,
                    eloid = tm.eloid,
                    p1id  = tm.playerone,
                    p2id  = tm.playertwo,
                    id    = tm.id
                };

                foreach (var matches in query)
                {
                    FluffTailRanking.BusinessLayer.BusinessObjects.Player p1 = GetPlayerById(matches.p1id),
                             p2 = GetPlayerById(matches.p2id);
                    team.Players.Add(p1);
                    team.Players.Add(p2);
                    team.ID              = matches.id;
                    team.TeamName        = matches.tn;
                    team.EloRatingNumber = matches.eloid;
                    team.Name            = matches.tn;
                    team.Wins            = (int)(p1.Wins + p2.Wins);
                }
                return(team);
            }
        }
Beispiel #3
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);
 }
Beispiel #4
0
        /// <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);
        }
Beispiel #5
0
        /// <summary>
        /// Get all Teams from the Database
        /// </summary>
        /// <returns>List with Teamobjects</returns>
        public List <FluffTailRanking.BusinessLayer.BusinessObjects.Team> GetAllTeams()
        {
            List <FluffTailRanking.BusinessLayer.BusinessObjects.Team> teams = new List <FluffTailRanking.BusinessLayer.BusinessObjects.Team>();

            using (KickerEntities contex = new KickerEntities())
            {
                var query =
                    from team in contex.Team
                    select new
                {
                    id = team.id
                };
                foreach (var matches in query)
                {
                    FluffTailRanking.BusinessLayer.BusinessObjects.Team team = GetTeamById(matches.id);
                    teams.Add(team);
                }
                return(teams);
            }
        }
Beispiel #6
0
 public int GetTeamWins(Team t)
 {
     return persistentManager.GetWinsOfTeam(t);
 }
 public int SaveTeam(Team team)
 {
     throw new NotImplementedException();
 }
 public int GetWinsOfTeam(Team team)
 {
     throw new NotImplementedException();
 }
        /// <summary>
        /// Get a specific Team with its Team ID
        /// </summary>
        /// <param name="tid">ID of Team</param>
        /// <returns>A team with the ID</returns>
        public FluffTailRanking.BusinessLayer.BusinessObjects.Team GetTeamById(int tid)
        {
            FluffTailRanking.BusinessLayer.BusinessObjects.Team team = new FluffTailRanking.BusinessLayer.BusinessObjects.Team();
            using (KickerEntities context = new KickerEntities())
            {
                var query =
                    from tm in context.Team
                    where tm.id == tid
                    select new
                    {
                        tn = tm.teamname,
                        w = tm.wins,
                        eloid = tm.eloid,
                        p1id = tm.playerone,
                        p2id = tm.playertwo,
                        id = tm.id
                    };

                foreach (var matches in query)
                {
                    FluffTailRanking.BusinessLayer.BusinessObjects.Player p1 = GetPlayerById(matches.p1id),
                                                         p2 = GetPlayerById(matches.p2id);
                    team.Players.Add(p1);
                    team.Players.Add(p2);
                    team.ID = matches.id;
                    team.TeamName = matches.tn;
                    team.EloRatingNumber = matches.eloid;
                    team.Name = matches.tn;
                    team.Wins = (int)(p1.Wins + p2.Wins);
                }
                return team;
            }
        }