<?php
namespace App\Controller;

use App\Controller\AppController;

/**
 * Apimports Controller
 *
 * @property \App\Model\Table\ApimportsTable $Apimports
 */
class ApimportsController extends AppController
{

    /**
     * Index method
     *
     * @return \Cake\Network\Response|null
     */
    public function index()
    {
        $apimports = $this->paginate($this->Apimports);

        $this->set(compact('apimports'));
        $this->set('_serialize', ['apimports']);
    }

    /**
     * View method
     *
     * @param string|null $id Apimport id.
     * @return \Cake\Network\Response|null
     * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
     */
    public function view($id = null)
    {
        $apimport = $this->Apimports->get($id, [
            'contain' => []
        ]);

        $this->set('apimport', $apimport);
        $this->set('_serialize', ['apimport']);
    }

    /**
     * Add method
     *
     * @return \Cake\Network\Response|null Redirects on successful add, renders view otherwise.
     */
    public function add()
    {
        $apimport = $this->Apimports->newEntity();
        if ($this->request->is('post')) {
            $apimport = $this->Apimports->patchEntity($apimport, $this->request->data);
            if ($this->Apimports->save($apimport)) {
                $this->Flash->success(__('The apimport has been saved.'));

                return $this->redirect(['action' => 'index']);
            }
            $this->Flash->error(__('The apimport could not be saved. Please, try again.'));
        }
        $this->set(compact('apimport'));
        $this->set('_serialize', ['apimport']);
    }

    /**
     * Edit method
     *
     * @param string|null $id Apimport id.
     * @return \Cake\Network\Response|null Redirects on successful edit, renders view otherwise.
     * @throws \Cake\Network\Exception\NotFoundException When record not found.
     */
    public function edit($id = null)
    {
        $apimport = $this->Apimports->get($id, [
            'contain' => []
        ]);
        if ($this->request->is(['patch', 'post', 'put'])) {
            $apimport = $this->Apimports->patchEntity($apimport, $this->request->data);
            if ($this->Apimports->save($apimport)) {
                $this->Flash->success(__('The apimport has been saved.'));

                return $this->redirect(['action' => 'index']);
            }
            $this->Flash->error(__('The apimport could not be saved. Please, try again.'));
        }
        $this->set(compact('apimport'));
        $this->set('_serialize', ['apimport']);
    }

    /**
     * Delete method
     *
     * @param string|null $id Apimport id.
     * @return \Cake\Network\Response|null Redirects to index.
     * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
     */
    public function delete($id = null)
    {
        $this->request->allowMethod(['post', 'delete']);
        $apimport = $this->Apimports->get($id);
        if ($this->Apimports->delete($apimport)) {
            $this->Flash->success(__('The apimport has been deleted.'));
        } else {
            $this->Flash->error(__('The apimport could not be deleted. Please, try again.'));
        }

        return $this->redirect(['action' => 'index']);
    }
}
