/**
  * Method that adds a client and returns the result of operation
  * 
  * @param \Library\HttpRequest $rq
  * @return JSON
  */
 public function executeAdd(\Library\HttpRequest $rq)
 {
     $result = $this->InitResponseWS();
     $client = \Applications\PMTool\Helpers\CommonHelper::PrepareUserObject($this->dataPost(), new \Applications\PMTool\Models\Dao\Client());
     $result["data"] = $client;
     //Load interface to query the database
     $manager = $this->managers->getManagerOf($this->module());
     $result["dataId"] = $manager->add($client);
     $client->setClient_id($result["dataId"]);
     $sessionProject = \Applications\PMTool\Helpers\ProjectHelper::GetUserSessionProject($this->app()->user(), $client->project_id());
     $sessionProject[\Library\Enums\SessionKeys::ClientObject] = $client;
     \Applications\PMTool\Helpers\ProjectHelper::UpdateUserSessionProject($this->app()->user(), $sessionProject);
     if (intval($result["dataId"]) > 0) {
         $this->dataPost['user_email'] = $this->dataPost['client_contact_email'];
         if (is_bool($this->app->config()->get(\Library\Enums\AppSettingKeys::AddUserForProjectClient))) {
             $userId = \Applications\PMTool\Helpers\UserHelper::AddUser($this, $result["dataId"], \Library\Enums\UserRole::Visitor, "client_id");
         } else {
             $userId = 1;
         }
     }
     //Process DB result and send result
     if ($result["dataId"] > 0) {
         $result = $this->SendResponseWS($result, array("resx_file" => \Applications\PMTool\Resources\Enums\ResxFileNameKeys::Client, "resx_key" => $this->action(), "step" => $result["dataId"] > 0 && $userId > 0 ? "success" : "error"));
     }
 }
 public function executeAdd(\Library\HttpRequest $rq)
 {
     // Init result sent to client (e.g. browser)
     $result = $this->InitResponseWS();
     //Get the current PM Session
     $pm = \Applications\PMTool\Helpers\PmHelper::GetCurrentSessionPm($this->app()->user());
     $dataPost = $this->dataPost();
     $dataPost["pm_id"] = $pm === NULL ? NULL : $pm[\Library\Enums\SessionKeys::PmObject]->pm_id();
     $origin = $originId = "";
     if (array_key_exists("origin", $dataPost)) {
         $postUserData = (array) $dataPost["userData"];
         $postUserData["pm_id"] = $dataPost["pm_id"];
         $origin = $dataPost["origin"];
         $originId = $dataPost["originid"];
     } else {
         $postUserData = $dataPost;
     }
     //Store the pm_id in the dataPost...
     //.. and build the object to query the DB
     $technician = \Applications\PMTool\Helpers\CommonHelper::PrepareUserObject($postUserData, new \Applications\PMTool\Models\Dao\Technician());
     $technician->setTechnician_document("");
     $result["dataIn"] = $technician;
     //Load interface to query the database
     $manager = $this->managers->getManagerOf($this->module);
     $result["dataId"] = $manager->add($technician);
     if ($pm !== NULL) {
         //Update the object with last inserted Id
         $technician->setTechnician_id($result["dataId"]);
         if ($technician->technician_id() > 0 && \Library\Utility\StringHelper::Equals($origin, "task") && !\Library\Utility\StringHelper::IsNullOrEmpty($originId)) {
             \Applications\PMTool\Helpers\TechnicianHelper::AddTaskTechnician($this, $originId, $technician->technician_id());
         }
         //Update the PM Session
         array_push($pm[\Library\Enums\SessionKeys::PmTechnicians], $technician);
         //And update the Sessiom
         \Applications\PMTool\Helpers\PmHelper::SetSessionPm($this->app()->user(), $pm);
     }
     //add user record for FT
     if (intval($result["dataId"]) > 0) {
         $this->dataPost['user_email'] = $postUserData['technician_email'];
         $userId = \Applications\PMTool\Helpers\UserHelper::AddUser($this, $result["dataId"], \Library\Enums\UserRole::Technician);
     }
     //Send the response to browser
     $this->SendResponseWS($result, array("resx_file" => \Applications\PMTool\Resources\Enums\ResxFileNameKeys::Technician, "resx_key" => $this->action(), "step" => intval($result["dataId"]) > 0 && $userId > 0 ? "success" : "error"));
 }