コード例 #1
0
 public async Task <Team> ToggleTeamPlayer(TeamToggleRequest req)
 {
     using (var db = new TtcDbContext())
     {
         var team     = db.Teams.Include(x => x.Players).Single(x => x.Id == req.TeamId);
         var exPlayer = team.Players.SingleOrDefault(x => x.PlayerId == req.PlayerId);
         if (exPlayer == null)
         {
             team.Players.Add(new TeamPlayerEntity
             {
                 PlayerId   = req.PlayerId,
                 TeamId     = req.TeamId,
                 PlayerType = (TeamPlayerType)Enum.Parse(typeof(TeamPlayerType), req.Role)
             });
         }
         else
         {
             db.Entry(exPlayer).State = EntityState.Deleted;
         }
         db.SaveChanges();
         return(await GetTeam(req.TeamId, false));
     }
 }
コード例 #2
0
 public Team ToggleTeamPlayer(TeamToggleRequest req)
 {
     using (var db = new TtcDbContext())
     {
         var team = db.Teams.Include(x => x.Players).Single(x => x.Id == req.TeamId);
         var exPlayer = team.Players.SingleOrDefault(x => x.PlayerId == req.PlayerId);
         if (exPlayer == null)
         {
             team.Players.Add(new TeamPlayerEntity
             {
                 PlayerId = req.PlayerId,
                 TeamId = req.TeamId,
                 PlayerType = (TeamPlayerType)Enum.Parse(typeof(TeamPlayerType), req.Role)
             });
         }
         else
         {
             db.Entry(exPlayer).State = EntityState.Deleted;
         }
         db.SaveChanges();
         return GetTeam(req.TeamId, false);
     }
 }