Exemplo n.º 1
0
        public async Task CreateNewPlayer(CancellationToken cancellationToken)
        {
            var authId = GetAuthId();

            if (!string.IsNullOrEmpty(authId) && !_context.Player.Any(x => x.AuthString == authId))
            {
                var player = new Player()
                {
                    DisplayName = _currentUser.GetName(),
                    AuthString  = authId,
                    Email       = _currentUser.GetEmail(),
                    Firstname   = _currentUser.GetFirstname(),
                    Surname     = _currentUser.GetSurname()
                };

                if (!_context.Player.Any())
                {
                    foreach (var role in _context.PlayerRole)
                    {
                        player.Roles.Add(new PlayerRolePlayer()
                        {
                            PlayerRoleId = role.Id
                        });
                    }
                }
                await _context.Player.AddAsync(player, cancellationToken);

                await _context.SaveChangesAsync(cancellationToken);
            }

            //return _context.Player.Include(p => p.Roles).ThenInclude(role => role.PlayerRole).First<Player>(x => x.AuthString == authId);
        }