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()); }
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()); }