public void DeleteTeam(int teamId)
 {
     var db = new MyTeamTrackerContext();
     var teamToRemove = db.Teams.Single(x => x.Id == teamId);
     db.Teams.Remove(teamToRemove);
     db.SaveChanges();
 }
 public void DeletePlayer(int playerId)
 {
     var db = new MyTeamTrackerContext();
     var playerToRemove = db.Players.Single(x => x.Id == playerId);
     db.Players.Remove(playerToRemove);
     db.SaveChanges();
 }
 public void AddPlayerToTeam(int playerId, int teamId)
 {
     var db = new MyTeamTrackerContext();
     var playerToAdd = db.Players.Single(x => x.Id == playerId);
     var team = db.Teams.Single(x => x.Id == teamId);
     team.Players.Add(playerToAdd);
     db.SaveChanges();
 }
 public void PostRemovePlayerFromTeam(int playerId, int teamId)
 {
     var db = new MyTeamTrackerContext();
     var playerToRemove=db.Players.Single(x=>x.Id==playerId);
     var team=db.Teams.Single(x=>x.Id==teamId);
     team.Players.Remove(playerToRemove);
     db.SaveChanges();
 }
        public VmPlayer PostPlayerChanges(VmPlayer memberToSave)
        {
            var db = new MyTeamTrackerContext();
            Player player;
            if (memberToSave.Id == 0)
            {
                player = db.Players.SingleOrDefault(x => x.FirstName == memberToSave.FirstName && x.LastName == memberToSave.LastName);
                if (player == null)
                {
                    player = new Player { LastName = memberToSave.LastName, FirstName = memberToSave.FirstName };
                    db.Players.Add(player);
                }
                else
                {

                }
            }
            else
            {
                player = db.Players.Single(x => x.Id == memberToSave.Id);
                player.FirstName = memberToSave.FirstName;
                player.LastName = memberToSave.LastName;
            }
            db.SaveChanges();
            return new VmPlayer(player);
        }
        public VmTeam PostTeamChanges(VmTeam teamToSave)
        {
            var db = new MyTeamTrackerContext();
            Team team;
            if (teamToSave.Id == 0)
            {
                team = db.Teams.SingleOrDefault(x => x.Name == teamToSave.Name);
                if (team == null)
                {
                    team = new Team { Name = teamToSave.Name };
                    db.Teams.Add(team);
                }
                else
                {

                }
            }
            else
            {
                team = db.Teams.Single(x => x.Id == teamToSave.Id);
                team.Name = teamToSave.Name;
            }
            db.SaveChanges();
            return new VmTeam(team);
        }