If the viewer is subscribe then unsubscribe, if not subscribe then subscribe.

@param AnCommandContext $context Context parameter
548449
protected function _actionTogglesubscription($context)
    {
        if ($this->getItem()->subscribed(get_viewer())) {
            $ret = $this->_mixer->execute('unsubscribe', $context);
        } else {
            $ret = $this->_mixer->execute('subscribe', $context);
        }

        return $ret;
    }
47404
protected function _actionAdd(AnCommandContext $context)
    {
        $payload = $this->_order->getPayload();

        if (!$this->_gateway->process($payload)) {
            throw new ComSubscriptionsDomainPaymentException('Payment error. Check the log');
        }

        $this->getService('repos:people.person')
        ->addBehavior('com:subscriptions.domain.behavior.subscriber');
        $person = $this->_order->getSubscriber();
        $package = $this->_order->getPackage();

        if (!$person->persisted()) {
            $person->getRepository()->getSpace()
            ->setEntityState($person, AnDomain::STATE_NEW);
            $person->enable()->saveEntity();

            $this->_order->setSubscriber($person);
        }

        if ($person->hasSubscription() && !$package->recurring) {
            $subscription = $person->changeSubscriptionTo($package);
        } else {
            $subscription = $person->subscribeTo($package);
        }

        if ($payload->getRecurring()) {
            $subscription->setValue('profileId', $payload->getRecurring()->profile_id);
            $subscription->setValue('profileStatus', $payload->getRecurring()->profile_status);
        }

        if (!$this->commit()) {
            throw new RuntimeException("Subscription can not be added");
        }

        $this->getResponse()->status = AnHttpResponse::CREATED;
        dispatch_plugin('subscriptions.onAfterSubscribe', array('subscription' => $subscription));
        $this->setItem($subscription);

        return $subscription;
    }
65575
public function redirect(AnCommandContext $context)
    {
        $url = null;

        if ($context->action === 'delete') {
            $viewer = $this->getService('com:people.viewer');

            if ($viewer->id == $this->getItem()->id) {
                $url = 'index.php?';
            } else {
                $url = 'option=com_people&view=people';
            }
        }

        if ($url) {
            $context->response->setRedirect(route($url));
        }
    }
512103
protected function _afterEntityInsert(AnCommandContext $context)
    {
        $actorIds = $this->package->getActorIds();

        if (count($actorIds)) {
            $actors = $this->getService('repos:actors.actor')
                           ->getQuery(true)
                           ->where('id', 'IN', $actorIds)
                           ->fetchSet();

            foreach ($actors as $actor) {
                $actor->addFollower($this->person);
            }
        }
    }
434384
protected function _beforeRepositoryFetch(AnCommandContext $context)
    {
        if (AnService::has('viewer')) {
            $query = $context->query;
            $repository = $query->getRepository();
            $viewer = get_viewer();

            if ($viewer->id) {
                $query->where("IF( FIND_IN_SET({$viewer->id}, @col(blockedIds)), 0, 1)");
            }
        }
    }
934408
protected function _afterEntityDelete(AnCommandContext $context)
    {
        $this->subscribee->getRepository()
                         ->getBehavior('subscribable')
                         ->resetStats(array($this->subscribee));
    }
72644
protected function _actionOptions(AnCommandContext $context)
    {
        $context->response->status = AnHttpResponse::OK;
        $context->response->set('Content-Length', 0);
    }
1137733
protected function _afterEntityUpdate(AnCommandContext $context)
    {
        $this->getSpace()->setEntityState($context->entity, AnDomain::STATE_UPDATED);
    }
1329310
protected function _actionUnvoteComment(AnCommandContext $context)
    {
        $this->getCommentController()->id($this->cid)->execute('unvote', $context);
    }
253487
protected function _actionGet(AnCommandContext $context)
    {
        $this->_request->append(array(
            'layout' => 'default',
        ));

        $this->getCommandChain()->run('layout.'.$this->getRequest()->get('layout'), $context);

        if ($this->getRequest()->get('layout') == 'login' && !$this->viewer->guest()) {
            $url = route('option=com_subscriptions&view=signup&layout=payment&id='.$this->getItem()->id);
            $context->response->setRedirect($url);
            return false;
        }

        return parent::_actionGet($context);
    }
571836
protected function _afterEntityInsert(AnCommandContext $context)
    {
        $this->ownable->getRepository()->getBehavior('sharable')->resetStats(array($this->ownable));
    }
341318
protected function _afterEntityDelete(AnCommandContext $context)
    {
        $this->votee->getRepository()
                    ->getBehavior('votable')
                    ->resetStats(array($this->votee));
    }
817558
public function authorizeUpgradePackage(AnCommandContext $context)
    {
        $viewer = $context->viewer;

        if (!$viewer->hasSubscription()) {
            return false;
        }

        $package = $viewer->subscription->package;

        return !$this->eql($package) &&
        (
            $package->duration < $this->duration ||
            $package->price < $this->price
        );
    }
911674
protected function _actionDelete(AnCommandContext $context)
    {
        $context->response->status = AnHttpResponse::NO_CONTENT;
        $entity = $this->getItem()->delete();

        return $entity;
    }
695319
protected function _actionDelete(AnCommandContext $context)
    {
        dispatch_plugin('user.onBeforeDeletePerson', array('data' => $context->data));

        $person = parent::_actionDelete($context);
        $person_id = $person->id;

        $this->getService('repos:sessions.session')->destroy(array('nodeId' => $person->id));

        dispatch_plugin('user.onAfterDeletePerson', array('id' => $person_id));

        return $person;
    }
589565
protected function _actionException(AnCommandContext $context)
    {
        if (
            $context->data instanceof LibBaseControllerExceptionUnauthorized &&
            $this->getController() instanceof ComPeopleControllerSession
        ) {
            $context->response->send();
            exit(0);
        } else {
            parent::_actionException($context);
        }
    }
652699
protected function _actionGetcount(AnCommandContext $context)
    {
        $count = $this->actor->numOfNewNotifications();
        return $this->getView()->newNotifications($count)->display();
    }