/**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     try {
         $data = $request->all();
         $codigoAnt = DB::select('select CODIGO from empleados order by CAST(codigo AS SIGNED) desc LIMIT 1');
         $censador = new Censador();
         $censador->noDocumento = $data["noDocumento"];
         $censador->nombres = $data["nombres"];
         $censador->apellidos = $data["apellidos"];
         $censador->estado = 'Activo';
         $censador->Cargos_id = '7';
         $censador->TipoDocumentos_id = '1';
         $censador->direccion = $data["direccion"];
         $censador->telefono = $data["telefono"];
         $censador->codigo = $codigoAnt[0]->CODIGO + 1;
         $censador->save();
         $usuarios = new Usuarios();
         $usuarios->correo = $data["correo"];
         $usuarios->clave = "123456";
         $usuarios->Empleados_id = $censador->id;
         $usuarios->estado = 'A';
         $usuarios->save();
         return JsonResponse::create(array('message' => "Censador Guardado Correctamente", "request" => $censador), 200);
     } catch (Exception $exc) {
         return JsonResponse::create(array('message' => "No se pudo guardar el Censo", "exception" => $exc->getMessage(), "request" => json_encode($data)), 401);
     }
 }
 /**
  * Creates a new Usuarios model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Usuarios();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
示例#3
0
 /**
  * Creates a new Usuarios model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Usuarios();
     $model->scenario = 'create';
     if ($model->load(Yii::$app->request->post())) {
         // process uploaded image file instance
         $image = $model->uploadImage();
         $model->criado_por = Yii::$app->user->getId();
         if ($model->save()) {
             // upload only if valid uploaded file instance found
             if ($image !== false) {
                 $path = $model->getImageFile();
                 $image->saveAs($path);
             }
             return $this->redirect(['view', 'id' => $model->id_usuario]);
         }
         //error saving model
         return $this->render('create', ['model' => $model]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }