# -*- encoding : utf-8 -*-

class Admin::PCommercialCatsController < ApplicationController
  layout "admin"
  before_action :auth_admin

  before_action :admin_space
  
  def admin_space
    @admin_space = "clients"
  end
  
  def index
    @p_commercial_cats = PCommercialCat.order(:name).all

  end

  def show
    @p_commercial_cat = PCommercialCat.find(params[:id])

  end

  def new
    @p_commercial_cat = PCommercialCat.new
  
  end

  def edit
    @p_commercial_cat = PCommercialCat.find(params[:id])
    
  end

  def create
    @p_commercial_cat = PCommercialCat.new(params.require(:p_commercial_cat).permit!)

    if @p_commercial_cat.save
      
    else
      render action: "new"
 
    end

  end


  def update
    @p_commercial_cat = PCommercialCat.find(params[:id])


    if @p_commercial_cat.update_attributes(params.require(:p_commercial_cat).permit!)
      
    else
     render action: "edit" 
      
    end
      
  end


  def destroy
    @p_commercial_cat = PCommercialCat.find(params[:id])
    @p_commercial_cat.destroy
    
  end
end
