Exemplo n.º 1
0
        private Guid[] GetTeamPlayers(TeamUpdate teamUpdate)
        {
            var lineup   = teamUpdate.Payload["lineup"].AsBsonArray.Select(x => x.AsGuidString());
            var rotation = teamUpdate.Payload["rotation"].AsBsonArray.Select(x => x.AsGuidString());
            var bullpen  = teamUpdate.Payload["bullpen"].AsBsonArray.Select(x => x.AsGuidString());
            var bench    = teamUpdate.Payload["bench"].AsBsonArray.Select(x => x.AsGuidString());

            return(lineup.Concat(rotation).Concat(bullpen).Concat(bench).ToArray());
        }
Exemplo n.º 2
0
        public bool UpdateTeam(TeamUpdate model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity =
                    ctx
                    .Teams
                    .Single(e => e.TeamId == model.TeamId && e.TeamManagerId == _userId);

                entity.TeamName          = model.TeamName;
                entity.IsActive          = model.IsActive;
                entity.Contract.IsActive = model.IsActive;

                return(ctx.SaveChanges() == 1);
            }
        }
Exemplo n.º 3
0
        public IHttpActionResult Put(TeamUpdate team)
        {
            CreateTeamService();

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (!_teamService.UpdateTeam(team))
            {
                return(InternalServerError());
            }

            return(Ok());
        }
Exemplo n.º 4
0
        public override void Unpack(byte[] data)
        {
            TeamUpdates.Clear();
            Reset(data);

            int count = ReadByte();

            for (int i = 0; i < count; i++)
            {
                TeamUpdate team = new TeamUpdate();
                team.TeamID = (TeamColors)ReadUInt16();
                team.Size   = ReadUInt16();
                team.Wins   = ReadUInt16();
                team.Losses = ReadUInt16();
                TeamUpdates.Add(team);
            }
        }
Exemplo n.º 5
0
        public async Task <IActionResult> Update(int userId, [FromBody] TeamUpdate team)
        {
            if (userId != int.Parse(User.FindFirst(ClaimTypes.Name)?.Value))
            {
                return(Unauthorized());
            }

            var _team = await _tRepo.GetTeam(team.Id);

            if (_team.UserId != userId)
            {
                return(Unauthorized());
            }

            _mapper.Map(team, _team);

            if (!await _tRepo.SaveChanges())
            {
                return(BadRequest(new { message = $"Something when wrong while updating Event {team.Id}..." }));
            }

            return(Ok(team));
        }
Exemplo n.º 6
0
        public JsonResult Update(int id, TeamUpdate update)
        {
            var  activeUser = this.GetActiveUser(this.Request);
            Team team       = _teamService.GetTeam(id);

            if (activeUser == null || !team.CanEdit(activeUser.Id))
            {
                throw new HttpException((int)HttpStatusCode.Unauthorized, "Not authorized to edit this team");
            }

            // Update seasons in delta update
            if (update.Seasons != null)
            {
                foreach (var season in update.Seasons)
                {
                    if (season.TeamId != team.Id)
                    {
                        throw new HttpException((int)HttpStatusCode.BadRequest, "Cannot submit updates for non-matching team id");
                    }
                    _gameService.UpdateSeason(season);
                }
            }

            // Update events in delta update
            if (update.Events != null)
            {
                foreach (var teamEvent in update.Events)
                {
                    if (teamEvent.HomeTeamId != team.Id)
                    {
                        throw new HttpException((int)HttpStatusCode.BadRequest, "Cannot submit updates for non-matching team id");
                    }
                    _gameService.UpdateGate(teamEvent);

                    // And their duties
                    if (teamEvent.Duties != null)
                    {
                        foreach (var duty in teamEvent.Duties)
                        {
                            if (duty.EventId != teamEvent.Id)
                            {
                                throw new HttpException((int)HttpStatusCode.BadRequest, "Cannot submit updates for non-matching event id");
                            }
                            _gameService.UpdateEventDuty(duty);
                        }
                    }
                }
            }

            // Update player groups in delta update
            if (update.PlayerGroups != null)
            {
                foreach (var playerGroup in update.PlayerGroups)
                {
                    if (playerGroup.TeamId != team.Id)
                    {
                        throw new HttpException((int)HttpStatusCode.BadRequest, "Cannot submit updates for non-matching team id");
                    }
                    _playerService.UpdatePlayerGroup(playerGroup);
                }
            }

            // Update players in delta update
            if (update.Players != null)
            {
                foreach (var player in update.Players)
                {
                    if (_playerService.GetPlayerGroup(player.GroupId).TeamId != team.Id)
                    {
                        throw new HttpException((int)HttpStatusCode.BadRequest, "Cannot submit updates for non-matching team id");
                    }
                    _playerService.UpdatePlayer(player);

                    // And their availabilities
                    if (player.Availability != null)
                    {
                        foreach (var ab in player.Availability)
                        {
                            _playerService.UpdatePlayerAvailability(player.Id, ab);
                        }
                    }
                }
            }

            return(Json(team));
        }
Exemplo n.º 7
0
 public bool UpdateTeam(TeamUpdate model)
 {
     return(ReturnValue);
 }