예제 #1
0
        public Player CreatePlayer(CreatePlayerRequest createPlayerRequest, ApplicationUser applicationUser, bool linkCurrentUserToThisPlayer = false)
        {
            if (createPlayerRequest == null)
            {
                throw new ArgumentNullException(nameof(createPlayerRequest));
            }
            ValidatePlayerNameIsNotNullOrWhiteSpace(createPlayerRequest.Name);
            if (!applicationUser.CurrentGamingGroupId.HasValue)
            {
                throw new UserHasNoGamingGroupException(applicationUser.Id);
            }
            int gamingGroupId = createPlayerRequest.GamingGroupId ?? applicationUser.CurrentGamingGroupId.Value;

            ThrowPlayerAlreadyExistsExceptionIfPlayerExistsWithThisName(createPlayerRequest.Name, gamingGroupId);

            var newPlayer = new Player
            {
                Name              = createPlayerRequest.Name,
                Active            = true,
                ApplicationUserId = linkCurrentUserToThisPlayer ? applicationUser.Id : null,
                GamingGroupId     = gamingGroupId
            };

            newPlayer = _dataContext.Save(newPlayer, applicationUser);
            _dataContext.CommitAllChanges();

            new Task(() => _eventTracker.TrackPlayerCreation(applicationUser)).Start();

            return(newPlayer);
        }
예제 #2
0
 private void ValidateRequestIsNotNull(CreatePlayerRequest createPlayerRequest)
 {
     if (createPlayerRequest == null)
     {
         throw new ArgumentNullException(nameof(createPlayerRequest));
     }
 }
예제 #3
0
    /// <summary>
    /// 创建实例
    /// </summary>
    public static CreatePlayerRequest create(CreatePlayerData data)
    {
        CreatePlayerRequest re = (CreatePlayerRequest)BytesControl.createRequest(dataID);

        re.data = data;
        return(re);
    }
예제 #4
0
 public void SetUp()
 {
     _createPlayerRequest = new CreatePlayerRequest
     {
         Name = "player name"
     };
 }
예제 #5
0
        public virtual HttpResponseMessage SaveNewPlayer([FromBody] NewPlayerMessage newPlayerMessage, [FromUri] int gamingGroupId)
        {
            var requestedPlayer = new CreatePlayerRequest
            {
                Name               = newPlayerMessage.PlayerName,
                GamingGroupId      = newPlayerMessage.GamingGroupId,
                PlayerEmailAddress = newPlayerMessage.PlayerEmailAddress
            };

            Player newPlayer;

            try
            {
                newPlayer = _playerSaver.CreatePlayer(requestedPlayer, CurrentUser);
            }
            catch (PlayerAlreadyExistsException exception)
            {
                exception.ErrorSubCode = 1;
                throw;
            }
            catch (PlayerWithThisEmailAlreadyExistsException exception)
            {
                exception.ErrorSubCode = 2;
                throw;
            }

            var newlyCreatedPlayerMessage = new NewlyCreatedPlayerMessage
            {
                PlayerId      = newPlayer.Id,
                GamingGroupId = newPlayer.GamingGroupId,
                NemeStatsUrl  = AbsoluteUrlBuilder.GetPlayerDetailsUrl(newPlayer.Id)
            };

            return(Request.CreateResponse(HttpStatusCode.OK, newlyCreatedPlayerMessage));
        }
예제 #6
0
        public async Task AddPlayer( )
        {
            CreatePlayerRequest playerToAdd = new CreatePlayerRequest(View.PlayerName, View.FirstName, View.LastName, View.Colour);

            Either <int, ErrorResponse> response = await RequestAsync(true, () => _playerRepository.AddPlayer(playerToAdd));

            response.OnError(error => View.Error.Show(error.GetErrorMessage( )));
        }
예제 #7
0
        private Player AddUserToGamingGroupAsPlayer(ApplicationUser currentUser)
        {
            var createPlayerRequest = new CreatePlayerRequest
            {
                Name = currentUser.UserName
            };

            return(this.playerSaver.CreatePlayer(createPlayerRequest, currentUser, true));
        }
예제 #8
0
 public void CreatePlayer(Player player)
 {
     Log("Calling CreatePlayer with player {0}", player.Id);
     var request = new CreatePlayerRequest
     {
         Player = player
     };
     var response = client.CreatePlayer(request);
 }
예제 #9
0
    public void CreateNewCharacterRequest(string nickName, byte roleID, ServerCallbackDelegate OnCreateNewCharacter)
    {
        CreatePlayerRequest request = new CreatePlayerRequest();

        request.job      = roleID;
        request.serverId = _serverID;
        request.nickName = nickName;
        SendCommand(request, OnCreateNewCharacter);
    }
        public async Task <PlayerModel> CreatePlayer(CreatePlayerCommand command)
        {
            var rating = await ratingApiClient.GetDefaultPlayerRating();

            CreatePlayerRequest createPlayerRequest = new CreatePlayerRequest(command.Name, rating.Rating, rating.Deviation, rating.Volatility);

            Player createdPlayer = await playersApiClient.CreatePlayer(createPlayerRequest);

            return(PlayerMapper.Map(createdPlayer));
        }
        public async Task <IActionResult> PostPlayerAsync([FromBody] CreatePlayerRequest playerRequest)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }
            await _playerService.CreatePlayerAsync(playerRequest);

            return(Ok("Record has been added successfully."));
        }
    /// Called when player creation has completed allowing us to log the
    /// player in
    ///
    /// @param request
    ///     Info on request made to create player
    /// @param response
    ///     Holds the id and secret to log the player in
    ///
    private void OnPlayerCreated(CreatePlayerRequest request, CreatePlayerResponse response)
    {
        Debug.Log("Player created. Logging in");

        //Save the credentials so we don't create a new player next time we launch the app
        PlayerPrefs.SetString("CCId", response.ChilliConnectId);
        PlayerPrefs.SetString("CCSecret", response.ChilliConnectSecret);
        PlayerPrefs.Save();
        m_chilliConnect.PlayerAccounts.LogInUsingChilliConnect(response.ChilliConnectId, response.ChilliConnectSecret, (loginRequest) => OnLoggedIn(), (loginRequest, error) => Debug.LogError(error.ErrorDescription));
    }
예제 #13
0
        public IActionResult Create([FromBody] CreatePlayerRequest request)
        {
            if (!IsPlayerNameValid(ModelState, nameof(request.PlayerName), request.PlayerName))
            {
                return(BadRequest(ModelState));
            }

            var playerId = _playerService.Create(Mapper.Map <Player>(request));

            return(Ok(playerId));
        }
예제 #14
0
        public void ItReturnsANotModifiedStatusIfValidationFails()
        {
            var player = new CreatePlayerRequest();

            autoMocker.ClassUnderTest.ModelState.AddModelError("key", "message");

            var result = autoMocker.ClassUnderTest.Save(player, currentUser) as HttpStatusCodeResult;

            Assert.IsNotNull(result);
            Assert.AreEqual((int)HttpStatusCode.NotModified, result.StatusCode);
        }
예제 #15
0
        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));
        }
예제 #16
0
        public void ItReturnsAConflictHttpStatusCodeWhenThePlayerExists()
        {
            var player = new CreatePlayerRequest
            {
                Name = "player name"
            };

            autoMocker.Get <IPlayerSaver>().Expect(x => x.CreatePlayer(player, currentUser))
            .Repeat.Once()
            .Throw(new PlayerAlreadyExistsException(player.Name, 1));

            var result = autoMocker.ClassUnderTest.Save(player, currentUser) as HttpStatusCodeResult;

            Assert.IsNotNull(result);
            Assert.AreEqual((int)HttpStatusCode.Conflict, result.StatusCode);
        }
예제 #17
0
        public void ItSavesThePlayer()
        {
            var player = new CreatePlayerRequest
            {
                Name = "player name"
            };

            autoMocker.ClassUnderTest.Save(player, currentUser);

            autoMocker.Get <IPlayerSaver>().AssertWasCalled(mock => mock.CreatePlayer(
                                                                Arg <CreatePlayerRequest> .Matches(
                                                                    x => x.Name == player.Name &&
                                                                    x.GamingGroupId == currentUser.CurrentGamingGroupId),
                                                                Arg <ApplicationUser> .Is.Equal(currentUser),
                                                                Arg <bool> .Is.Equal(false)));
        }
예제 #18
0
        public async Task <IActionResult> PostPlayer([FromBody] CreatePlayerRequest request)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            PlayerDataModel player = new PlayerDataModel
            {
                Name         = request.Name,
                CreationDate = DateTime.Now
            };

            _context.Players.Add(player);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetPlayer", new { id = player.Id }, ViewModelFactory.CreatePlayerViewModel(player)));
        }
예제 #19
0
        public virtual HttpResponseMessage SaveNewPlayer([FromBody] NewPlayerMessage newPlayerMessage, [FromUri] int gamingGroupId)
        {
            var requestedPlayer = new CreatePlayerRequest
            {
                Name          = newPlayerMessage.PlayerName,
                GamingGroupId = newPlayerMessage.GamingGroupId
            };

            var actualNewlyCreatedPlayer = playerSaver.CreatePlayer(requestedPlayer, CurrentUser);

            var newlyCreatedPlayerMessage = new NewlyCreatedPlayerMessage
            {
                PlayerId      = actualNewlyCreatedPlayer.Id,
                GamingGroupId = actualNewlyCreatedPlayer.GamingGroupId
            };

            return(Request.CreateResponse(HttpStatusCode.OK, newlyCreatedPlayerMessage));
        }
        public void SetUp()
        {
            _createPlayerRequest = new CreatePlayerRequest
            {
                Name          = "player name",
                GamingGroupId = _currentUser.CurrentGamingGroupId.Value
            };

            _expectedSavedPlayer = new Player
            {
                Name          = _createPlayerRequest.Name,
                Id            = 89,
                GamingGroupId = _currentUser.CurrentGamingGroupId.Value
            };
            _autoMocker.Get <IDataContext>()
            .Expect(mock => mock.Save(Arg <Player> .Is.Anything, Arg <ApplicationUser> .Is.Anything))
            .Return(_expectedSavedPlayer);
        }
예제 #21
0
        public async Task <IActionResult> AddPlayer([FromBody] CreatePlayerRequest request)
        {
            PlayerServerSide player = new PlayerServerSide(request.Name, request.AvatarUrl, request.Id);

            playerRegistry.AddPlayer(request.Id, player);

            await lobbyHubContext.Clients.All.NewPlayer(new ServerSidePlayerOverview
            {
                AvatarUrl = request.AvatarUrl,
                Id        = request.Id,
                Name      = request.Name,
            });

            Guid lobbyId = playerRegistry.GetLobbyIdByPlayerId(request.Id);

            return(base.Ok(new AddPlayerResponse {
                LobbyId = lobbyId
            }));
        }
        public async Task CreatePlayerAsync(CreatePlayerRequest playerRequest)
        {
            using var transaction = await _dbContext.Database.BeginTransactionAsync();

            try
            {
                var player = new Player
                {
                    NickName   = playerRequest.NickName,
                    JoinedDate = DateTime.Now
                };

                await _dbContext.Players.AddAsync(player);

                await _dbContext.SaveChangesAsync();

                var playerId = player.PlayerId;

                var playerInstruments = new List <PlayerInstrument>();
                foreach (var instrument in playerRequest.PlayerInstruments)
                {
                    playerInstruments.Add(new PlayerInstrument
                    {
                        PlayerId         = playerId,
                        InstrumentTypeId = instrument.InstrumentTypeId,
                        ModelName        = instrument.ModelName,
                        Level            = instrument.Level
                    });
                }

                _dbContext.PlayerInstruments.AddRange(playerInstruments);
                await _dbContext.SaveChangesAsync();

                await transaction.CommitAsync();
            }
            catch
            {
                // Log exceptions here
                await transaction.RollbackAsync();

                throw;
            }
        }
예제 #23
0
        public ActionResult <CreatePlayerResponse> CreatePlayer(CreatePlayerRequest request)
        {
            var response = new CreatePlayerResponse()
            {
                ResponseMessage = Models.ResponseMessage.Failure
            };

            int?teamId = request.Player.TeamId == 0 ? null : request.Player.TeamId;

            _context.Players.Add(new Player(request.Player.FirstName, request.Player.LastName, request.Player.Height, request.Player.Weight, request.Player.Position, request.Player.DateOfBirth, teamId));

            var success = _context.SaveChanges();

            if (success > 0)
            {
                response.ResponseMessage = Models.ResponseMessage.Success;
            }

            return(Ok(response));
        }
예제 #24
0
        public CreatePlayerResponse CreatePlayer(CreatePlayerRequest request)
        {
            if (request == null)
            {
                AddNotification("CreatePlayerRequest", Message.X0_IS_REQUIRED.ToFormat("CreatePlayerRequest"));
            }

            var email  = new Email(request.Email);
            var name   = new Name(request.FirstName, request.LastName);
            var player = new Player(name, email, request.Password);

            AddNotifications(player);

            if (IsInvalid())
            {
                return(null);
            }

            return((CreatePlayerResponse)_playerRepository.CreatePlayer(player));
        }
예제 #25
0
        public Player CreatePlayer(CreatePlayerRequest createPlayerRequest, ApplicationUser applicationUser, bool linkCurrentUserToThisPlayer = false)
        {
            ValidateRequestIsNotNull(createPlayerRequest);
            ValidatePlayerNameIsNotNullOrWhiteSpace(createPlayerRequest.Name);
            ValidateRequestedEmailIsntSetAtTheSameTimeAsAttemptingToLinktoCurrentPlayer(createPlayerRequest,
                                                                                        linkCurrentUserToThisPlayer);
            var gamingGroupId = ValidateAndGetGamingGroupId(createPlayerRequest.GamingGroupId, applicationUser);

            ValidatePlayerDoesntExistWithThisName(createPlayerRequest.Name, gamingGroupId);

            ValidateUserNotAlreadyRegisteredWithThisEmail(
                gamingGroupId, createPlayerRequest.PlayerEmailAddress);

            var newPlayer = new Player
            {
                Name              = createPlayerRequest.Name,
                Active            = true,
                ApplicationUserId = linkCurrentUserToThisPlayer ? applicationUser.Id : null,
                GamingGroupId     = gamingGroupId
            };

            newPlayer = _dataContext.Save(newPlayer, applicationUser);

            if (!string.IsNullOrWhiteSpace(createPlayerRequest.PlayerEmailAddress))
            {
                var playerInvitation = new PlayerInvitation
                {
                    EmailSubject       = $"NemeStats Invitation from {applicationUser.UserName}",
                    InvitedPlayerEmail = createPlayerRequest.PlayerEmailAddress,
                    InvitedPlayerId    = newPlayer.Id,
                    GamingGroupId      = gamingGroupId
                };
                _playerInviter.InvitePlayer(playerInvitation, applicationUser);
            }

            _dataContext.CommitAllChanges();

            new Task(() => _eventTracker.TrackPlayerCreation(applicationUser)).Start();

            return(newPlayer);
        }
예제 #26
0
        private void Handle(CreatePlayerRequest request)
        {
            //throw new Exception();
            //Thread.Sleep(TimeSpan.FromSeconds(30)); //- test aby sprawdzić, czy zrobi się dziecko aktora
            //tzn. że wiele osob będzie mogło w tym samym czasie korzystać z aplikacji

            try
            {
                if (CheckInputs(firstName: request.FirstName, lastName: request.LastName, nickName: request.NickName,
                                age: request.Age, sex: request.Sex))
                {
                    _playerRepo.Insert(new Player
                    {
                        FirstName = request.FirstName,
                        LastName  = request.LastName,
                        NickName  = request.NickName,
                        Age       = request.Age,
                        Sex       = request.Sex,
                        IsDeleted = false
                    });

                    var response = new CreatePlayerResponse(true);
                    Sender.Tell(response);

                    _logger.Info("Create Player successfull: {0} {1}", request.FirstName, request.LastName);
                }
                else
                {
                    var response = new CreatePlayerResponse(false);
                    Sender.Tell(response);
                    _logger.Error("Couldn't create Player: {0} {1}: Are fields are required", request.FirstName, request.LastName);
                }
            }
            catch (Exception ex)
            {
                var response = new CreatePlayerResponse(false);
                Sender.Tell(response);
                _logger.Error("Couldn't create Player: {0} {1}: {2}", request.FirstName, request.LastName, ex.Message);
            }
        }
예제 #27
0
    protected virtual void stepCheckCreatePlayer()
    {
        if (_playerList.Count == 0)
        {
            Ctrl.log("列表为空需要创建");

            CreatePlayerRequest.create(getCreatePlayerData()).send();
        }
        else
        {
            Ctrl.print("有角色直接登录");

            if (ShineSetting.openCheck)
            {
                if (_stepTool.isComplete(PlayerLogin))
                {
                    Ctrl.errorLog("step不该已完成:PlayerLogin");
                }
            }

            _stepTool.completeStep(CheckCreatePlayer);
        }
    }
예제 #28
0
        public virtual ActionResult Save(CreatePlayerRequest createPlayerRequest, ApplicationUser currentUser)
        {
            if (!Request.IsAjaxRequest())
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            if (ModelState.IsValid)
            {
                try
                {
                    createPlayerRequest.Name          = createPlayerRequest.Name.Trim();
                    createPlayerRequest.GamingGroupId = currentUser.CurrentGamingGroupId;
                    var player = playerSaver.CreatePlayer(createPlayerRequest, currentUser);
                    return(Json(player, JsonRequestBehavior.AllowGet));
                }
                catch (PlayerAlreadyExistsException playerAlreadyExistsException)
                {
                    return(new HttpStatusCodeResult(HttpStatusCode.Conflict, playerAlreadyExistsException.Message));
                }
            }

            return(new HttpStatusCodeResult(HttpStatusCode.NotModified));
        }
 private CreatePlayerResponse OnCreatePlayer(CreatePlayerRequest request, ICommandCallerInfo callerinfo)
 {
     CreatePlayerWithReservedId(callerinfo.CallerWorkerId, request.playerType);
     return(new CreatePlayerResponse());
 }
예제 #30
0
        public async Task <PlayerDto> CreatePlayer([FromBody] CreatePlayerRequest request, CancellationToken cancellationToken)
        {
            var player = await _playerService.CreatePlayerAsync(request.Username, cancellationToken).ConfigureAwait(false);

            return(PlayerDto.Create(player));
        }