public void GivenIAlreadyHaveSomePlayersExistingInTheSystem()
        {
            var player1 = new ScrabblePlayer
                {
                    Email = "*****@*****.**",
                    Name = "a"
                };
            player1.GenerateNewIdentity();

            var player2 = new ScrabblePlayer
                {
                    Email = "*****@*****.**",
                    Name = "b"
                };
            player2.GenerateNewIdentity();

            ScenarioContext.Current["plr1"] = player1;
            ScenarioContext.Current["plr2"] = player2;

            using (var context = new ScrabbleClubContext(TestDbConStrName))
            {
                context.ScrabblePlayers.Add(player1);
                context.ScrabblePlayers.Add(player2);
                context.SaveChanges();
            }
        }
        public IOperationResult SavePlayer(PlayerDto playerDto)
        {
            //1. this method handles both add and update but as very well could have been 2 separate methods
            //2. the transaction in this case is for demo purposes (as to where transactions go)

            var validationErrors = _validationBus.Validate(playerDto);
            var validationResults = validationErrors as IList<Notification> ?? validationErrors.ToList();
            if (validationErrors != null && validationResults.Any())
                return new OperationResult(false, validationResults);

            var currentPlayer = new ScrabblePlayer
                {
                    ContactPhoneNumber = playerDto.ContactPhoneNumber,
                    Email = playerDto.Email,
                    JoinDate = playerDto.JoinDate,
                    Name = playerDto.Name,
                    StreetAddress = playerDto.StreetAddress
                };

            using (var scope = new TransactionScope())
            {
                if (playerDto.Id == Guid.Empty)
                {
                    currentPlayer.GenerateNewIdentity();
                    _scrabblePlayerRepository.Add(currentPlayer);
                }
                else
                {
                    currentPlayer.ChangeCurrentIdentity(playerDto.Id);
                    var persistedPlayer =_scrabblePlayerRepository.Get(playerDto.Id);
                    if (persistedPlayer != null)
                    {
                        _scrabblePlayerRepository.Merge(persistedPlayer, currentPlayer);
                    }
                    else
                    {
                        //log the problem or do something else
                    }
                }

                _scrabblePlayerRepository.UnitOfWork.Commit();
                scope.Complete();
            }

            return new OperationResult(true, null);
        }