public function sellProduct($id, $quantity, $upid)
 {
     $this->user->startTran();
     if ($this->user->changeProductQuantity(Auth::getUserId(), $id, $quantity, $upid) !== 1) {
         Session::setError('not enough products');
         $this->user->rollback();
         Redirect::back();
     }
     $userProduct = $this->user->getProduct(Auth::getUserId(), $id, $upid);
     if ($userProduct['quantity'] < 1) {
         if ($this->user->deleteProduct(Auth::getUserId(), $id, $upid) !== 1) {
             Session::setError('something went wrong');
             $this->user->rollback();
             Redirect::back();
         }
     }
     $soldProducts = $this->product->getProduct($id);
     if ($this->product->addQuantity($soldProducts['id'], $quantity) !== 1) {
         Session::setError('something went wrong');
         $this->user->rollback();
         Redirect::back();
     }
     if ($this->user->addCash(Auth::getUserId(), $soldProducts['price'] * $quantity) !== 1) {
         Session::setError('something went wrong');
         $this->user->rollback();
         Redirect::back();
     }
     $this->user->commit();
     Session::setMessage('You sold ' . $quantity . ' of ' . $userProduct['name']);
     Redirect::to('/user/' . Auth::getUserId() . '/products');
 }