/**
     * Save Company INfO
     * 3 Models Inserted in Dealer Save
     * User,Company,UserCompany Table Inserted
     * @note User is inserted with company role
     */
    public function SaveCompany(){

        if($this->validate()) {
            $transaction = Auction::$app->db->beginTransaction();
            try {
                $user=$this->SaveUser();
                $company=$this->SaveUserCompany();

                if(!$user || !$company) {
                    return null;
                }

                $companyUser=new CompanyUsers();
                $companyUser->company=$company;
                $companyUser->user=$user;

                if (!$companyUser->save(false)) {
                    return null;
                }

                $transaction->commit();
                //$this->trigger(self::AFTER_SAVE);
                Auction::info('Company Registration Success');
                return true;

            } catch (Exception $ex) {
                $transaction->rollBack();
                $_message = Auction::loggerMessageFormat('Company Registration Failed with Following Errors',$this->getErrors());
                Auction::error($_message);
            }
        }

        return null;
    }
Esempio n. 2
0
    public function SaveCompanyUser(){
        $this->user_role = DatabaseHelper::COMPANY_USER;

        if($this->save()){
            $model = new CompanyUsers();
            $model->user = $this->id;
            $model->company = Auction::$app->session->get('user.company');

            $model->save();
            return true;
        }

        return false;
    }