public async Task AddPlayerAsync(Player player)
        {
            player.Id = Guid.NewGuid();
            await repository.CreateAsync(player);

            await repository.SaveChangesAsync();
        }
示例#2
0
        public async Task <int> AddNewPlayerAsync(PlayerDTO newPlayer)
        {
            var createdPlayer = await _playerRepository.CreateAsync(Mapper.Map <EntityPlayer>(newPlayer));

            if (createdPlayer != null)
            {
                return(createdPlayer.Id);
            }
            return(0);
        }
 public async Task CreateAsync(Player player)
 {
     try
     {
         await _playerRepository.CreateAsync(player);
     }
     catch (Exception ex)
     {
         _logger.LogError(ex, "There was an error creating a player");
         throw;
     }
 }
        public async Task <Player> GetOrCreateAsync(Player player)
        {
            var exists = await _playerRepository.ExistsAsync(player.AuthProviderId);

            if (exists)
            {
                var p = await _playerRepository.GetByAuthProviderIdAsync(player.AuthProviderId);

                p.IsReturning = true;
                return(p);
            }
            return(await _playerRepository.CreateAsync(player));
        }
示例#5
0
        public async Task <IActionResult> Post([FromBody] Player item)
        {
            if (item == null)
            {
                return(StatusCode(422, "Відсутні данні."));
            }
            //if (string.IsNullOrEmpty(item.Name)) return StatusCode(422, "Відсутня назва.");

            var result = await _playerRepository.CreateAsync(item);

            if (result.Result == OperationResult.Ok)
            {
                return(StatusCode(201, result.Value));
            }
            return(StatusCode(422, result.Message));
        }
示例#6
0
        public async Task <AuthResultModel> RegisterAsync(RegisterModel registerModel)
        {
            try
            {
                using (IPlayerRepository playerRepository = RepositoriesFactory.PlayerRepository)
                {
                    Player player = await playerRepository.FindAsync(registerModel.Login);

                    if (player != null)
                    {
                        return(new AuthResultModel
                        {
                            Success = false,
                            Field = nameof(registerModel.Login),
                            ErrorMessage = $"Игрок с логином \"{registerModel.Login}\" уже есть"
                        });
                    }

                    player = new Player
                    {
                        Login          = registerModel.Login,
                        HashedPassword = _CreatePasswordHash(registerModel.Password)
                    };

                    await playerRepository.CreateAsync(player);

                    return(new AuthResultModel {
                        PlayerId = player.Id
                    });
                }
            }
            catch (Exception)
            {
                return(new AuthResultModel
                {
                    Success = false,
                    Field = nameof(registerModel.PasswordConfirm),
                    ErrorMessage = $"Произошла неизвестная ошибка при регистрации, попробуйте позже."
                });
            }
        }
示例#7
0
 public async Task CreatePlayerAsync(Player player)
 {
     await playerRepository.CreateAsync(player);
 }
示例#8
0
 public async Task CreateAsync(Player player)
 {
     await _playerRepository.CreateAsync(_mapper.Map <Data.Contracts.Entities.Player>(player));
 }