src/Money/Module/Category/Controller/Category.php
public function ajaxCreate()
    {
        if (!Server::getInstance()->isAjax()) {
            throw new \RuntimeException();
        }

        $response = new Api();
        $response->setHttpCode(200);
        $response->setIsSuccess(true);

        try {
            $post = Post::getInstance();

            $accountId  = (int) $post->get('accountId');

            //~ Retrieve user account / account
            $mapper = new AccountUserMapper(Database::get('money'));
            $accountUser = $mapper->findByKeys(array(
                'user_id'    => Session::getInstance()->get('id'),
                'account_id' => $accountId
            ));
            $account = $accountUser->getAccount();

            //~ Retrieve category
            $categoryMapper = new CategoryMapper(Database::get('money'));
            $category       = $categoryMapper->newDataInstance();

            $category->setAccountId($account->getId());
            $category->setName($post->get('categoryName'));
            $category->setParentId((int) $post->get('categoryParentId'));

            $categoryMapper->insert($category);

        } catch (\Exception $exception) {
            $response->setIsSuccess(false)
                ->setHttpCode(500)
                ->setErrorCode($exception->getCode())
                ->setErrorMessage($exception->getMessage())
                ->setContent(true);
        }

        return $response;
    }
public function ajaxCreate()
    {
        if (!Server::getInstance()->isAjax()) {
            throw new \RuntimeException();
        }

        $response = new Api();
        $response->setHttpCode(200);
        $response->setIsSuccess(true);

        try {
            $post = Post::getInstance();

            $accountId  = (int) $post->get('accountId');

            //~ Retrieve user account / account
            $mapper = new AccountUserMapper(Database::get('money'));
            $accountUser = $mapper->findByKeys(array(
                'user_id'    => Session::getInstance()->get('id'),
                'account_id' => $accountId
            ));
            $account = $accountUser->getAccount();

            //~ Retrieve category
            $categoryMapper = new CategoryMapper(Database::get('money'));
            $category       = $categoryMapper->newDataInstance();

            $category->setAccountId($account->getId());
            $category->setName($post->get('categoryName'));
            $category->setParentId((int) $post->get('categoryParentId'));

            $categoryMapper->insert($category);

        } catch (\Exception $exception) {
            $response->setIsSuccess(false)
                ->setHttpCode(500)
                ->setErrorCode($exception->getCode())
                ->setErrorMessage($exception->getMessage())
                ->setContent(true);
        }

        return $response;
    }
Ajax edit category.

@return ResponseInterface