<?php

namespace api\modules\prolab\controllers;

use Yii;
use common\models\LabPriceCt;
use backend\modules\prolab\models\LabPriceCtSearch;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;

/**
 * LabPriceCtController implements the CRUD actions for LabPriceCt model.
 */
class LabPriceCtController extends Controller
{
    /**
     * {@inheritdoc}
     */
    public function behaviors()
    {
        return [
            'verbs' => [
                'class' => VerbFilter::className(),
                'actions' => [
                    'delete' => ['POST'],
                ],
            ],
        ];
    }

    /**
     * Lists all LabPriceCt models.
     * @return mixed
     */
    public function actionIndex()
    {
        $searchModel = new LabPriceCtSearch();
        $dataProvider = $searchModel->search(Yii::$app->request->queryParams);

        return $this->render('index', [
            'searchModel' => $searchModel,
            'dataProvider' => $dataProvider,
        ]);
    }

    /**
     * Displays a single LabPriceCt model.
     * @param string $CustID
     * @param string $LabID
     * @return mixed
     * @throws NotFoundHttpException if the model cannot be found
     */
    public function actionView($CustID, $LabID)
    {
        return $this->render('view', [
            'model' => $this->findModel($CustID, $LabID),
        ]);
    }

    /**
     * Creates a new LabPriceCt model.
     * If creation is successful, the browser will be redirected to the 'view' page.
     * @return mixed
     */
    public function actionCreate()
    {
        $model = new LabPriceCt();

        if ($model->load(Yii::$app->request->post()) && $model->save()) {
            return $this->redirect(['view', 'CustID' => $model->CustID, 'LabID' => $model->LabID]);
        }

        return $this->render('create', [
            'model' => $model,
        ]);
    }

    /**
     * Updates an existing LabPriceCt model.
     * If update is successful, the browser will be redirected to the 'view' page.
     * @param string $CustID
     * @param string $LabID
     * @return mixed
     * @throws NotFoundHttpException if the model cannot be found
     */
    public function actionUpdate($CustID, $LabID)
    {
        $model = $this->findModel($CustID, $LabID);

        if ($model->load(Yii::$app->request->post()) && $model->save()) {
            return $this->redirect(['view', 'CustID' => $model->CustID, 'LabID' => $model->LabID]);
        }

        return $this->render('update', [
            'model' => $model,
        ]);
    }

    /**
     * Deletes an existing LabPriceCt model.
     * If deletion is successful, the browser will be redirected to the 'index' page.
     * @param string $CustID
     * @param string $LabID
     * @return mixed
     * @throws NotFoundHttpException if the model cannot be found
     */
    public function actionDelete($CustID, $LabID)
    {
        $this->findModel($CustID, $LabID)->delete();

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

    /**
     * Finds the LabPriceCt model based on its primary key value.
     * If the model is not found, a 404 HTTP exception will be thrown.
     * @param string $CustID
     * @param string $LabID
     * @return LabPriceCt the loaded model
     * @throws NotFoundHttpException if the model cannot be found
     */
    protected function findModel($CustID, $LabID)
    {
        if (($model = LabPriceCt::findOne(['CustID' => $CustID, 'LabID' => $LabID])) !== null) {
            return $model;
        }

        throw new NotFoundHttpException('The requested page does not exist.');
    }
}
