public void CalculatePlayerResult(Player playerInput)
 {
     using (var dc = ThaitaeDataDataContext.Create())
     {
         var playerTeamList =
             dc.Players.Where(item => item.SeasonId == playerInput.SeasonId && item.TeamId == playerInput.TeamId).ToList();
         foreach (var player in playerTeamList)
         {
             var playerUpdate = dc.Players.Single(item => item.PlayerId == player.PlayerId);
             playerUpdate.PlayerGoal =
                 dc.PlayerMatches.Count(
                     item =>
                     item.PlayerGoal == 1 && item.PlayerId == player.PlayerId && item.TeamId == player.TeamId && item.SeasonId == player.SeasonId);
             playerUpdate.PlayerRedCard =
                 dc.PlayerMatches.Count(
                     item =>
                     item.PlayerRedCard == 1 && item.PlayerId == player.PlayerId && item.TeamId == player.TeamId && item.SeasonId == player.SeasonId);
             playerUpdate.PlayerYellowCard =
                 dc.PlayerMatches.Count(
                     item =>
                     item.PlayerYellowCard == 1 && item.PlayerId == player.PlayerId && item.TeamId == player.TeamId && item.SeasonId == player.SeasonId);
             dc.SubmitChanges();
         }
     }
 }
 public Player CalculatePlayerMatch(int playerMatchId, int playerNumber, string playerName)
 {
     Player playerUpdate;
     using (var dc = ThaitaeDataDataContext.Create())
     {
         var playerMatch = dc.PlayerMatches.Single(item => item.PlayerMatchId == playerMatchId);
         var playerCheck =
             dc.Players.Count(
                 item =>
                 item.SeasonId == playerMatch.SeasonId && item.TeamId == playerMatch.TeamId &&
                 item.PlayerNumber == playerNumber);
         if (playerCheck == 0)
         {
             var player = new Player
             {
                 PlayerNumber = playerNumber,
                 PlayerName = playerName,
                 TeamId = playerMatch.TeamId,
                 SeasonId = playerMatch.SeasonId
             };
             dc.Players.InsertOnSubmit(player);
             dc.SubmitChanges();
             playerMatch.PlayerId = player.PlayerId;
             dc.SubmitChanges();
             playerUpdate = player;
         }
         else
         {
             var player =
             dc.Players.Single(
                 item =>
                 item.SeasonId == playerMatch.SeasonId && item.TeamId == playerMatch.TeamId &&
                 item.PlayerNumber == playerNumber);
             playerMatch.PlayerId = player.PlayerId;
             playerMatch.PlayerId = player.PlayerId;
             if (!string.IsNullOrEmpty(playerName))
             {
                 player.PlayerName = playerName;
             }
             dc.SubmitChanges();
             playerUpdate = player;
         }
     }
     return playerUpdate;
 }
 partial void DeletePlayer(Player instance);
 partial void UpdatePlayer(Player instance);
 partial void InsertPlayer(Player instance);
		private void detach_Players(Player entity)
		{
			this.SendPropertyChanging();
			entity.Team = null;
		}
		private void attach_Players(Player entity)
		{
			this.SendPropertyChanging();
			entity.Team = this;
		}