public async Task CanAdd()
 {
     _logger.LogInformation("CanAdd");
     var player = new Player
     {
         Name = "New Player",
         Email = "*****@*****.**"
     };
     var newPlayer = await _playerRepository.AddAsync(player).ConfigureAwait(false);
     Assert.Equal("New Player", newPlayer.Name);
 }
Esempio n. 2
0
        public async Task <PlayerModel> AddAsync(PlayerModel model)
        {
            var entity   = mapper.Map <PlayerEntity>(model);
            var response = await playerRepo.AddAsync(entity);

            return(mapper.Map <PlayerModel>(response));
        }
        private async Task AddPlayersAsync(List <string> players, string clan = null)
        {
            WotService test  = new WotService();
            var        langs = UrlBuilder.WotLangs;
            var        count = 0;

            foreach (var player in players)
            {
                foreach (var lang in langs)
                {
                    if (count == 20)
                    {
                        Thread.Sleep(1200);
                        count = 0;
                    }
                    count++;
                    var playerData = await test.LoadPlayerDataAsync(player, lang);

                    var accountId = playerData.Data?.FirstOrDefault()?.AccountId;
                    if (!string.IsNullOrEmpty(accountId))
                    {
                        await _playerRepository.AddAsync(new Models.Entities.Player
                        {
                            Id       = Guid.NewGuid(),
                            WotId    = accountId,
                            Nickname = player,
                            Lang     = lang,
                            Clan     = clan
                        });

                        break;
                    }
                }
            }
        }
Esempio n. 4
0
        public async Task <BalanceResponse> SaveAsync(Balance balance)
        {
            var existingWallet = await _playerRepository.FindByIdAsync(balance.PlayerId);

            if (existingWallet == null)
            {
                await _playerRepository.AddAsync(new Player()
                {
                    Id = balance.PlayerId
                });

                await _unitOfWork.CompleteAsync();
            }

            var existingBalance = await _balanceRepository.FindAsync(balance);

            if (existingBalance != null)
            {
                return(new BalanceResponse("Asset already exist."));
            }

            try
            {
                await _balanceRepository.AddAsync(balance);

                await _unitOfWork.CompleteAsync();

                return(new BalanceResponse(balance));
            }
            catch (Exception ex)
            {
                // Do some logging stuff
                return(new BalanceResponse($"An error occurred when saving the asset: {ex.Message}"));
            }
        }
Esempio n. 5
0
        public async Task RegisterAsync(string connectionId, string name, string group)
        {
            var player = await _playerRepository.GetByNameAsync(name);

            if (player == null)
            {
                throw new Exception($"Player with name: '{0}' already exists.");
            }

            player = Player.Create(connectionId, name, group);
            await _playerRepository.AddAsync(player);
        }
Esempio n. 6
0
        public async Task <GenericResponse <Player> > SaveAsync(Player player)
        {
            try{
                await playerRepository.AddAsync(player);

                await unityOfWork.CompleteAsync();

                return(new GenericResponse <Player>(player));
            }
            catch (Exception ex) {
                return(new GenericResponse <Player>($"Error while saving plaer. Message:{ex.Message}"));
            }
        }
        public IEnumerable Handle(CreatePlayer c)
        {
            if (_repository.GetByIdAsync(c.Id) != null)
            {
                throw new PlayerAlreadyCreated();
            }

            _repository.AddAsync(new Player {
                Id = c.Id, Name = c.Name
            });

            yield return(new PlayerCreated(c.Id, c.Name));
        }
        public async Task <ActionResult <CreatePlayerResponse> > CreatePlayer([FromBody] CreatePlayerRequest createPlayerRequest, CancellationToken cancellationToken)
        {
            var player = new Player()
            {
                Name    = createPlayerRequest.Name,
                Surname = createPlayerRequest.Surname,
                Role    = PlayerRole.GetByAcronym(createPlayerRequest.RoleAcronym)
            };
            await _playersRepository.AddAsync(player, cancellationToken);

            var response = new CreatePlayerResponse();

            response.Player = _mapper.Map <PlayerDto>(player);
            return(Ok(response));
        }
Esempio n. 9
0
        public async Task RegisterAsync(Guid id, string nickname, string password)
        {
            var player = await _playerRepository.GetAsync(nickname);

            if (player != null)
            {
                throw new ServiceException(ErrorCodes.UserExist, "User with this nickname already exists.");
            }

            var salt = _encrypter.GetSalt(password);
            var hash = _encrypter.GetHash(password, salt);

            player = new Player(id, nickname, hash, salt);
            await _playerRepository.AddAsync(player);
        }
        public async Task <IActionResult> Create([FromBody] DTO.Player.Input.Player player)
        {
            var playerResult = await _playerRepository.AddAsync(new Models.Player.Player()
            {
                DateOfBirth = player.DateOfBirth,
                FirstName   = player.FirstName,
                LastName    = player.LastName,
                Growth      = player.Growth,
                Weight      = player.Weight
            });

            var result = AutoMapper.Mapper.Map <DTO.Player.Output.Player>(playerResult);

            return(Ok(result));
        }
Esempio n. 11
0
            public async Task <PlayerViewModel> Handle(AddPlayerCommand addPlayerCommand, CancellationToken cancellationToken) => await Task.Run(() =>
            {
                return(ExecuteAsync <PlayerViewModel>(async response =>
                {
                    var playerToAdd = new Player
                    {
                        Name = addPlayerCommand.Name,
                        Surname = addPlayerCommand.Surname,
                        Height = addPlayerCommand.Height,
                        EmailAddress = addPlayerCommand.EmailAddress
                    };

                    var addedPlayer = await _playerRepository.AddAsync(playerToAdd);

                    var playerDto = _mapper.Map <PlayerLookupModel>(addedPlayer);
                    response.PlayerLookupModel = playerDto;
                }));
            });
        private async Task <string> RegisterPlayer(Message message, IPlayerRepository playerRepository)
        {
            try
            {
                var existPlayer = await playerRepository.GetAsync(message.From.Id);

                var messageForUser = existPlayer.Name == PlayerName(message) ? "Вы уже зарегистрированы" : "Вы уже были зарегистрированы. Имя обновлено.";
                existPlayer.Name = PlayerName(message);
                await playerRepository.UpdateAsync(existPlayer);

                return(messageForUser);
            }
            catch (UserNotFoundException)
            {
                await playerRepository.AddAsync(new Player(message.From.Id, PlayerName(message), message.Chat.Id));

                return("Регистрация прошла успешно");
            }
        }
Esempio n. 13
0
        private async Task <Player> CreatePlayerInternalAsync(string username, CancellationToken cancellationToken)
        {
            using (await padlock.WriterLockAsync(cancellationToken).ConfigureAwait(true))
            {
                if (await _players.ExistsPlayerWithUsernameAsync(username, cancellationToken).ConfigureAwait(false))
                {
                    throw new DuplicateEntityException($"Duplicate exception. Username '{username}' already exists.");
                }

                var player = await _players
                             .AddAsync(new Player { Username = username }, cancellationToken)
                             .ConfigureAwait(false);

                await _wallets
                .AddAsync(new Wallet { PlayerId = player.Id, Balance = 0 }, cancellationToken)
                .ConfigureAwait(false);

                await _unitOfWork.CommitAsync(cancellationToken).ConfigureAwait(false);

                _logger.LogDebug("{method} finished. Player with {playerId} id created.", nameof(CreatePlayerAsync), player.Id);
                return(player);
            }
        }
Esempio n. 14
0
        public async Task <PlayerResponse> SaveAsync(Player player)
        {
            var existingWallet = await _playerRepository.FindByIdAsync(player.Id);

            if (existingWallet != null)
            {
                return(new PlayerResponse("Player already exists."));
            }

            try
            {
                await _playerRepository.AddAsync(player);

                await _unitOfWork.CompleteAsync();

                return(new PlayerResponse(player));
            }
            catch (Exception ex)
            {
                // Do some logging stuff
                return(new PlayerResponse($"An error occurred when saving the player: {ex.Message}"));
            }
        }
Esempio n. 15
0
        public async Task <IActionResult> Create([FromBody] PlayerCreateDto player)
        {
            var team = await _teamRepository.GetByIdAsync(player.TeamId);

            if (team == null)
            {
                return(BadRequest($"Invalid country Id { player.TeamId }"));
            }

            if (await _playerRepository.ExistAsync(p => p.Email == player.Email))
            {
                return(BadRequest($"Invalid email - It is already registered in the system"));
            }

            var completeNameResult = CompleteName.Create(player.FirstName, player.LastName);

            if (completeNameResult.IsFailure)
            {
                return(BadRequest(completeNameResult.Error));
            }

            var emailResult = Email.Create(player.Email);

            if (emailResult.IsFailure)
            {
                return(BadRequest(emailResult.Error));
            }

            var newPlayer = new Player(completeNameResult.Value, player.BirthDate, emailResult.Value, player.Phone, team);

            await _playerRepository.AddAsync(newPlayer);

            await _unitOfWork.Commit();

            return(Ok());
        }