public Domain.Entities.Player CreatePlayerWithFacebookID(string username, string facebook_id, string device_id = null)
        {
            bool created_player = false;
            bool created_player_fb_link = false;

            Domain.Entities.Player player = null;
            Domain.Entities.FacebookPlayer player_facebook = null;
            TableServiceContext service_context = _client.GetDataServiceContext();

            username = username.ToLower();
            facebook_id = facebook_id.ToLower();
            try{
                if (IsUsernameAvailable(username) && IsFacebookIDAvailable(facebook_id))
                {
                    player = new Domain.Entities.Player(username, facebook_id);
                    player.DeviceID = device_id;
                    service_context.AddObject(_table_name, player);
                    service_context.SaveChanges();
                    created_player = true;

                    player_facebook = new Domain.Entities.FacebookPlayer(facebook_id, username);
                    service_context.AddObject(_facebook_player_table_name, player_facebook);
                    service_context.SaveChanges();

                    created_player_fb_link = true;
                    return player;
                }
                else
                {
                    throw new ArgumentException("Username or FB ID already registered.", "username or facebook_id");
                }
               }
            catch{
                try
                {
                    if (service_context != null)
                    {
                        //revert on any error if possible
                        if (created_player)
                        {
                            service_context.DeleteObject(player);
                            service_context.SaveChanges();
                        }

                        if (created_player_fb_link && player_facebook != null)
                        {
                            service_context.DeleteObject(player_facebook);
                            service_context.SaveChanges();
                        }
                    }
                }
                catch
                {
                }

                throw;
            }
        }
Ejemplo n.º 2
0
        public async Task Handle(PlayerConnectedEvent notification, CancellationToken cancellationToken)
        {
            var player = new Domain.Entities.Player
            {
                Connected  = true,
                Identifier = notification.Identifier,
                Name       = notification.Player
            };

            _onitamaDbContext.Player.Add(player);
            await _onitamaDbContext.SaveChangesAsync();

            await _mediator.Publish(new LobbyJoinedEvent { Player = player });
        }
Ejemplo n.º 3
0
        protected override async Task Handle(CreatePlayerCommand request, CancellationToken cancellationToken)
        {
            var alreadyExists = await _playerReadOnlyRepository.PlayerWithEmailExist(request.Email);

            if (alreadyExists)
            {
                throw new PlayerWithSuchEmailAlreadyExistsException(request.Email);
            }

            var player = new Domain.Entities.Player()
            {
                Email    = request.Email,
                Password = request.Password
            };

            await _playerWriteOnlyRepository.CreatePlayer(player);
        }
        public Domain.Entities.Player CreatePlayerWithPassword(string username, string password, string device_id = null)
        {
            bool created_player = false;
            bool created_player_pass_link = false;

            Domain.Entities.Player player = null;
            Domain.Entities.PlayerPassword player_password = null;
            TableServiceContext service_context = _client.GetDataServiceContext();

            username = username.ToLower();

            try
            {
                if (IsUsernameAvailable(username))
                {
                    player = new Domain.Entities.Player(username);
                    player.DeviceID = device_id;
                    service_context.AddObject(_table_name, player);
                    service_context.SaveChanges();
                    created_player = true;

                    player_password = new Domain.Entities.PlayerPassword(username, password);
                    service_context.AddObject(_player_password_table_name, player_password);
                    service_context.SaveChanges();

                    created_player_pass_link = true;
                    return player;
                }
                else
                {
                    throw new ArgumentException("Username already registered.", "username");
                }
            }
            catch
            {
                try
                {
                    if (service_context != null)
                    {
                        //revert on any error if possible
                        if (created_player)
                        {
                            service_context.DeleteObject(player);
                            service_context.SaveChanges();
                        }

                        if (created_player_pass_link && player_password != null)
                        {
                            service_context.DeleteObject(player_password);
                            service_context.SaveChanges();
                        }
                    }
                }
                catch
                {
                }

                throw;
            }
        }