Пример #1
0
        public async Task <MatchDay> UpdateMatchDayHandicaps(MatchDay matchDay)
        {
            var playerResults = GetPlayersResults(matchDay);

            foreach (var playerResult in playerResults)
            {
                var player = (await _playerRepository.Find(p => p.Id == playerResult.PlayerId)).FirstOrDefault();
                if (player != null)
                {
                    if (player.Handicap + playerResult.HandicapToAdd > 90)
                    {
                        player.Handicap = 90;
                    }
                    else if (player.Handicap + playerResult.HandicapToAdd < 0)
                    {
                        player.Handicap = 0;
                    }
                    else
                    {
                        player.Handicap += playerResult.HandicapToAdd;
                    }

                    await _playerRepository.AddOrUpdate(player);
                }
            }

            return(matchDay);
        }
Пример #2
0
        public async Task <Player> AddOrUpdate(Player player)
        {
            await _playerRepository.AddOrUpdate(player);

            await _playerRepository.SaveChangesAsync();

            return(player);
        }
Пример #3
0
        public void AddOrUpdate(IEnumerable <PlayerDto> players)
        {
            var playerDtos = players?.ToArray() ?? new PlayerDto[0];

            if (!playerDtos.Any())
            {
                return;
            }

            _playerRepository.AddOrUpdate(playerDtos);
            _validCache = false;
        }
Пример #4
0
        public ModelBaseReturn SaveFromScrapy(PlayerScrapy model, Player player)
        {
            try
            {
                bool isCreated = true;

                isCreated = player == null;

                var world = player?.World ?? _worldRepository.FindByName(model.WorldName);

                if (player == null)
                {
                    player = new Player();
                    var novoPlayer = _mapper.Map <Player>(model);

                    player.UpdatePlayer(novoPlayer)
                    .UpdateWorld(world)
                    .AddNewHistoryScrapy(novoPlayer, world);
                }
                else
                {
                    var updatePlayer = _mapper.Map <Player>(model);
                    player
                    .UpdatePlayer(updatePlayer)
                    .UpdateWorld(world)
                    .AddNewHistoryScrapy(updatePlayer, world);
                }


                _repository.AddOrUpdate(player);

                if (isCreated)
                {
                    return(CreateReturnCreated(player.Id));
                }
                else
                {
                    var retorno = _mapper.Map <PlayerScrapy>(player);
                    return(CreateReturnOk(retorno));
                }
            }
            catch (Exception ex)
            {
                return(CreateReturnErrorInternal(ex.Message));
            }
        }
Пример #5
0
        public bool RegisterPlayersInternal(IEnumerable <Player> list)
        {
            var players = list.ToList();

            if (!HaveChanges(players, x => x.Num))
            {
                return(false);
            }


            var guids = players.Select(x => x.Guid).ToList();

            var playersInDb = _playerRepository.GetPlayers(guids);
            var dbGuids     = playersInDb.Select(x => x.GUID).ToList();

            var historyToAdd   = new List <PlayerHistory>();
            var playerToUpdate = new List <PlayerDto>();

            foreach (var player in playersInDb)
            {
                var p = players.FirstOrDefault(x => x.Guid == player.GUID);
                if (p != null)
                {
                    var needUpdate = false;
                    if ((player.Name != p.Name) || (player.LastIp != p.IP))
                    {
                        historyToAdd.Add(new PlayerHistory
                        {
                            IP       = player.LastIp,
                            Name     = player.Name,
                            PlayerId = player.Id,
                            ServerId = _serverId
                        });

                        player.Name   = p.Name;
                        player.LastIp = p.IP;

                        needUpdate = true;
                    }
                    if ((DateTime.UtcNow - player.LastSeen).TotalHours > 2)
                    {
                        player.LastSeen = DateTime.UtcNow;
                        needUpdate      = true;
                    }

                    if (needUpdate)
                    {
                        playerToUpdate.Add(player);
                    }
                }
            }

            var newplayers = players.Where(x => !dbGuids.Contains(x.Guid)).ToList();

            if (newplayers.Any())
            {
                foreach (var p in newplayers)
                {
                    var np = new Arma3BEClient.Libs.ModelCompact.Player
                    {
                        GUID   = p.Guid,
                        Name   = p.Name,
                        Id     = Guid.NewGuid(),
                        LastIp = p.IP
                    };

                    playerToUpdate.Add(np);

                    historyToAdd.Add(new PlayerHistory
                    {
                        IP       = np.LastIp,
                        Name     = np.Name,
                        PlayerId = np.Id,
                        ServerId = _serverId
                    });
                }
            }

            _playerRepository.AddOrUpdate(playerToUpdate);
            _playerRepository.AddHistory(historyToAdd);


            return(true);
        }