public Player CreatePlayer(CreatePlayerRequest createPlayerRequest, ApplicationUser applicationUser, bool linkCurrentUserToThisPlayer = false)
{
if (createPlayerRequest == null)
{
throw new ArgumentNullException(nameof(createPlayerRequest));
}
ValidatePlayerNameIsNotNullOrWhiteSpace(createPlayerRequest.Name);
int gamingGroupId = createPlayerRequest.GamingGroupId ?? applicationUser.CurrentGamingGroupId;
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;
}