예제 #1
0
        public async Task SaveTacticAsync(TacticDto dto)
        {
            var tactic = await context.Tactics
                         .Include(x => x.Frames)
                         .Where(x => x.Id == dto.Id)
                         .SingleOrDefaultAsync();

            foreach (var frameDto in dto.Frames)
            {
                if (frameDto.Id == 0)
                {
                    var frame = new Frame
                    {
                        Order    = dto.Frames.IndexOf(frameDto) + 1,
                        Details  = frameDto.Details,
                        TacticId = dto.Id,

                        Ball = new Ball
                        {
                            Position = new Position
                            {
                                X = frameDto.BallPosition.X,
                                Y = frameDto.BallPosition.Y
                            },
                            CoreId = tactic.BallId
                        },
                        Players = new List <Player>()
                    };

                    await CreatePlayers(frameDto.OwnTeamPlayers, frame, tactic.OwnTeamId);
                    await CreatePlayers(frameDto.OpponentTeamPlayers, frame, tactic.OpponentTeamId);

                    context.Frames.Add(frame);
                }
                else
                {
                    var frame = tactic.Frames
                                .Where(x => x.Id == frameDto.Id)
                                .SingleOrDefault();

                    frame.Order   = dto.Frames.IndexOf(frameDto) + 1;
                    frame.Details = frameDto.Details;

                    var ball = await context.Balls
                               .Include(x => x.Position)
                               .Where(x => x.Id == frame.BallId)
                               .SingleOrDefaultAsync();

                    frame.Ball.Position.X = frameDto.BallPosition.X;
                    frame.Ball.Position.Y = frameDto.BallPosition.Y;

                    await UpdatePlayersPosition(frameDto.OpponentTeamPlayers);
                    await UpdatePlayersPosition(frameDto.OwnTeamPlayers);

                    context.Frames.Update(frame);
                }
            }

            await context.SaveChangesAsync();
        }
예제 #2
0
        public async Task <ActionResult> UpdateTactic([FromBody] TacticDto tactic, int userId, int tacticId)
        {
            if (tactic.Id != tacticId)
            {
                return(BadRequest());
            }
            await tacticAppService.SaveTacticAsync(tactic);

            return(Ok());
        }
예제 #3
0
        public async Task <TacticDto> GetTacticAsync(int userId, int tacticId)
        {
            var tactic = await context.Tactics
                         .Include(x => x.Sport)
                         .Include(x => x.Ball)
                         .ThenInclude(y => y.Color)
                         .Include(x => x.OwnTeam)
                         .ThenInclude(y => y.PlayerColor)
                         .Include(x => x.OwnTeam)
                         .ThenInclude(y => y.GoalKeeperColor)
                         .Include(x => x.OpponentTeam)
                         .ThenInclude(y => y.PlayerColor)
                         .Include(x => x.OpponentTeam)
                         .ThenInclude(y => y.GoalKeeperColor)
                         .Where(x => x.Id == tacticId && x.UserId == userId)
                         .SingleOrDefaultAsync();

            var frames = await context.Frames
                         .Include(x => x.Ball)
                         .ThenInclude(y => y.Position)
                         .OrderBy(x => x.Order)
                         .Where(x => x.TacticId == tacticId)
                         .ToListAsync();

            var dto = new TacticDto
            {
                Id            = tactic.Id,
                SportName     = tactic.Sport.Name,
                HasGoalkeeper = tactic.Sport.HasGoalkeeper,
                ArenaPart     = tactic.ArenaPart,
                PlayerSize    = tactic.PlayerSize,
                Ball          = new BallDto
                {
                    Id        = tactic.Ball.Id,
                    IsVisible = tactic.Ball.IsVisible,
                    Color     = tactic.Ball.Color.PrimaryColor,
                    Size      = tactic.Ball.Size
                },
                OwnTeam      = CreateTeamDto(tactic.OwnTeam),
                OpponentTeam = CreateTeamDto(tactic.OpponentTeam),
                Frames       = new List <FrameDto>()
            };

            foreach (var frame in frames)
            {
                var ownTeamPlayers = await CreatePlayerDtoListAsync(frame.Id, tactic.OwnTeamId);

                var opponentTeamPlayers = await CreatePlayerDtoListAsync(frame.Id, tactic.OpponentTeamId);

                dto.Frames.Add(new FrameDto
                {
                    Id           = frame.Id,
                    Details      = frame.Details,
                    BallPosition = new PositionDto
                    {
                        X = frame.Ball.Position.X,
                        Y = frame.Ball.Position.Y
                    },
                    OwnTeamPlayers      = ownTeamPlayers,
                    OpponentTeamPlayers = opponentTeamPlayers
                });
            }

            return(dto);
        }