예제 #1
0
        public async Task <IActionResult> Register([FromBody] PlayerRegisterDto playerRegisterDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var response = await playerLogic.CreatePlayer(playerRegisterDto.Username, playerRegisterDto.Password);

            if (response != null)
            {
                return(Ok(response));
            }

            return(BadRequest());
        }
예제 #2
0
        public async Task <IHttpActionResult> Register(PlayerRegisterDto newPlayer)
        {
            if (newPlayer == null || !ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            if (!service.CheckUsernameAvailability(newPlayer.UserName))
            {
                return(BadRequest("This username has been already taken. Try another one."));
            }
            var player = mapper.Map <Player>(newPlayer);

            var result = await service.AddPlayer(player, newPlayer.UserName, newPlayer.Password, newPlayer.Email);

            _achievementsService.AssignAchievementToUser(newPlayer.UserName, "AccountCreated");
            return(!result.Succeeded ? GetErrorResult(result) : Ok());
        }