Esempio n. 1
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();
            }
        }
Esempio n. 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);
            }
        }
Esempio n. 3
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();
            }
        }
Esempio n. 4
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();
            }
        }
Esempio n. 5
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();
            }
        }
Esempio n. 6
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();
            }
        }
Esempio n. 7
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();
            }
        }
Esempio n. 8
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();
            }
        }
Esempio n. 9
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();
            }
        }
Esempio n. 10
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();
     }
 }
Esempio n. 11
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();
     }
 }
Esempio n. 12
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();
            }
        }
Esempio n. 13
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();
            }
        }