Пример #1
0
 public List <Teams> RetrieveAll()
 {
     using (var db = new FootballProjectContext())
     {
         return(db.Teams.Include(t => t.Players).ToList());
     }
 }
Пример #2
0
        public void RemoveTest()
        {
            using (var db = new FootballProjectContext())
            {
                var newTeam = new Teams()
                {
                    TeamName         = "Test Team",
                    TeamDescription  = "Boing boing Baggies!",
                    LeagueTrophies   = 1,
                    EuropeanTrophies = 1
                };

                db.Teams.Add(newTeam);

                db.SaveChanges();

                var newTeamID = newTeam.TeamId;

                var numberOfTeamsBefore = db.Teams.ToList().Count();

                _crudManager.DeleteTeam(newTeamID);

                var numberOfTeamsAfter = db.Teams.ToList().Count();

                Assert.AreEqual(numberOfTeamsBefore - 1, numberOfTeamsAfter);
            }
        }
Пример #3
0
 public List <Players> RetrieveAllPlayers()
 {
     using (var db = new FootballProjectContext())
     {
         return(db.Players.ToList());
     }
 }
Пример #4
0
        public void UpdateTest()
        {
            using (var db = new FootballProjectContext())
            {
                var newTeam = new Teams()
                {
                    TeamName         = "West Brom",
                    TeamDescription  = "Boing boing Baggies!",
                    LeagueTrophies   = 1,
                    EuropeanTrophies = 1
                };

                db.Teams.Add(newTeam);

                db.SaveChanges();

                _crudManager.UpdateTeamLeagueTrophies("West Brom", 2);

                var updatedTeam =
                    from t in db.Teams
                    where t.TeamName == "West Brom"
                    select t;

                foreach (var item in updatedTeam)
                {
                    item.LeagueTrophies = 2;
                }
                // save back to database
                db.SaveChanges();
            }
        }
Пример #5
0
        public void TeamAddedTest()
        {
            using (var db = new FootballProjectContext())
            {
                var numberOfTeamsBefore = db.Teams.ToList().Count();
                _crudManager.CreateTeam("Test Team", "Boing boing Baggies!", 1, 1);
                var numberOfTeamsAfter = db.Teams.ToList().Count();

                Assert.AreEqual(numberOfTeamsBefore + 1, numberOfTeamsAfter);
            }
        }
Пример #6
0
        //Update team
        public void Update(int teamId, string teamName, string teamDescription, int leagueTrophies, int europeanTrophies /*, string players*/)
        {
            using (var db = new FootballProjectContext())
            {
                SelectedTeams                  = db.Teams.Where(t => t.TeamId == teamId).FirstOrDefault();
                SelectedTeams.TeamName         = teamName;
                SelectedTeams.TeamDescription  = teamDescription;
                SelectedTeams.LeagueTrophies   = leagueTrophies;
                SelectedTeams.EuropeanTrophies = europeanTrophies;

                db.SaveChanges();
            }
        }
Пример #7
0
        public void CreateTeam(string name, string description, int leagueTrophiesWon, int europeanTrophiesWon)
        {
            using (var db = new FootballProjectContext())
            {
                var newTeam = new Teams()
                {
                    TeamName         = name.Trim(),
                    TeamDescription  = description.Trim(),
                    LeagueTrophies   = leagueTrophiesWon,
                    EuropeanTrophies = europeanTrophiesWon
                };

                db.Teams.Add(newTeam);
                db.SaveChanges();
            }
        }
Пример #8
0
        //Create player stats
        public void AddPlayerStats(int goalsScored, int goalsAssisted, int leagueTrophiesWon, int europeanTrophiesWon)
        {
            using (var db = new FootballProjectContext())
            {
                var newPlayerStats = new PlayerStats()
                {
                    GoalsScored         = goalsScored,
                    GoalsAssisted       = goalsAssisted,
                    LeagueTrophiesWon   = leagueTrophiesWon,
                    EuropeanTrophiesWon = europeanTrophiesWon
                };

                db.PlayerStats.Add(newPlayerStats);
                db.SaveChanges();
            }
        }
Пример #9
0
        public void DeletePlayer(int playerid)
        {
            using (var db = new FootballProjectContext())
            {
                var selectedPlayer =
                    from p in db.Players
                    where p.PlayerId == playerid
                    select p;
                foreach (var item in selectedPlayer)
                {
                    db.Players.Remove(item);
                }

                db.SaveChanges();
            }
        }
Пример #10
0
        public void DeleteTeam(int teamid)
        {
            using (var db = new FootballProjectContext())
            {
                var selectedTeam =
                    from t in db.Teams
                    where t.TeamId == teamid
                    select t;
                foreach (var item in selectedTeam)
                {
                    db.Teams.Remove(item);
                }

                db.SaveChanges();
            }
        }
Пример #11
0
        public List <Players> RetrieveTeamPlayers()
        {
            using (var db = new FootballProjectContext())
            {
                var TeamPlayers = new List <Players>();
                var AllPlayers  = db.Players.ToList();
                foreach (var player in AllPlayers)
                {
                    if (player.TeamId == SelectedTeams.TeamId)
                    {
                        TeamPlayers.Add(player);
                    }
                }

                return(TeamPlayers);
            }
        }
Пример #12
0
 //Update team's league trophies
 public void UpdateTeamLeagueTrophies(string teamName, int leagueTrophies)
 {
     using (var db = new FootballProjectContext())
     {
         // obtain selected player
         var selectedTeam =
             from t in db.Teams
             where t.TeamName == teamName
             select t;
         // now update the Team
         foreach (var item in selectedTeam)
         {
             item.LeagueTrophies = leagueTrophies;
         }
         // save back to database
         db.SaveChanges();
     }
 }
Пример #13
0
        public void TearDown()
        {
            using (var db = new FootballProjectContext())
            {
                var selectedTeams =
                    from t in db.Teams
                    where t.TeamName == "Test Team"
                    select t;


                foreach (var item in selectedTeams)
                {
                    db.Teams.Remove(item);
                }

                db.SaveChanges();
            }
        }
Пример #14
0
        public void Setup()
        {
            using (var db = new FootballProjectContext())
            {
                var selectedTeam =
                    from t in db.Teams
                    where t.TeamName == "Test Team"
                    select t;


                foreach (var c in selectedTeam)
                {
                    db.Teams.Remove(c);
                }

                db.SaveChanges();
            }
        }
Пример #15
0
 //Update Player's team
 public void UpdatePlayerTeam(string playerName, int team)
 {
     using (var db = new FootballProjectContext())
     {
         // obtain selected player
         var selectedPlayer =
             from p in db.Players
             where p.Name == playerName
             select p;
         // now update the Team
         foreach (var item in selectedPlayer)
         {
             item.TeamId = team;
         }
         // save back to database
         db.SaveChanges();
     }
 }
Пример #16
0
        //Create Player
        public void CreatePlayer(string name, int age, string nationality, int team, int height, string strongestFoot, string position)
        {
            using (var db = new FootballProjectContext())
            {
                var newPlayer = new Players()
                {
                    Name          = name,
                    Age           = age,
                    Nationality   = nationality,
                    TeamId        = team,
                    HeightInches  = height,
                    StrongestFoot = strongestFoot,
                    Position      = position,
                };

                db.Players.Add(newPlayer);
                db.SaveChanges();
            }
        }
Пример #17
0
        public void UpdatePlayer(int playerId, string name, int age, string nationality, int height, string strongestFoot, string position)
        {
            using (var db = new FootballProjectContext())
            {
                SelectedPlayers               = db.Players.Where(p => p.PlayerId == playerId).FirstOrDefault();
                SelectedPlayers.Name          = name;
                SelectedPlayers.Age           = age;
                SelectedPlayers.Nationality   = nationality;
                SelectedPlayers.HeightInches  = height;
                SelectedPlayers.StrongestFoot = strongestFoot;
                SelectedPlayers.Position      = position;
                /* SelectedPlayers.Name = players;*//*db.Players.Include(t => db.Teams).Where(p => p.TeamId == players && t.TeamID == players);*/
                //from p in db.Players
                //join t in db.Teams on p.TeamId equals t.TeamId
                //where p.TeamId == t.TeamId
                //select { players };

                // write changes to database
                db.SaveChanges();
            }
        }
Пример #18
0
        public void TeamAddedDetailsCorrectTest()
        {
            using (var db = new FootballProjectContext())
            {
                var numberOfTeamsBefore = db.Teams.ToList().Count();
                _crudManager.CreateTeam("Test Team", "Boing boing Baggies!", 1, 1);
                var numberOfTeamsAfter = db.Teams.ToList().Count();

                Assert.AreEqual(numberOfTeamsBefore + 1, numberOfTeamsAfter);

                var createdTeam =
                    from t in db.Teams
                    where t.TeamName == "Test Team"
                    select t;

                foreach (var item in createdTeam)
                {
                    Assert.AreEqual("Test Team", item.TeamName);
                    Assert.AreEqual("Boing boing Baggies!", item.TeamDescription);
                    Assert.AreEqual(1, item.LeagueTrophies);
                    Assert.AreEqual(1, item.EuropeanTrophies);
                }
            }
        }
Пример #19
0
 static void Main(string[] args)
 {
     using (var db = new FootballProjectContext())
     {
     }
 }