<?php
namespace App\Controller;

use App\Controller\AppController;

/**
 * Usdates Controller
 *
 * @property \App\Model\Table\UsdatesTable $Usdates
 */
class UsdatesController extends AppController
{

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

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

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

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

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

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

    /**
     * Edit method
     *
     * @param string|null $id Usdate 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)
    {
        $usdate = $this->Usdates->get($id, [
            'contain' => []
        ]);
        if ($this->request->is(['patch', 'post', 'put'])) {
            $usdate = $this->Usdates->patchEntity($usdate, $this->request->data);
            if ($this->Usdates->save($usdate)) {
                $this->Flash->success(__('The usdate has been saved.'));

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

    /**
     * Delete method
     *
     * @param string|null $id Usdate 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']);
        $usdate = $this->Usdates->get($id);
        if ($this->Usdates->delete($usdate)) {
            $this->Flash->success(__('The usdate has been deleted.'));
        } else {
            $this->Flash->error(__('The usdate could not be deleted. Please, try again.'));
        }

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