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

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

  before_action :admin_space
  
  def admin_space
    @admin_space = "default"
  end
  
  def index
    @p_commercial_object_brands = PCommercialObjectBrand.all

    @p_commercial_object_brands = sort_by_sorting(@p_commercial_object_brands, "id DESC")
    respond_to do |format|
      format.html{
      
        params[:search][:per_page] = params[:search][:per_page] || 100
        per_page = params[:search][:per_page]
        page = (params[:page] and params[:page] != "") ? params[:page] : 1 
        @p_commercial_object_brands = @p_commercial_object_brands.page(page).per(per_page)
      
      }
    end
  end

  def show
    @p_commercial_object_brand = PCommercialObjectBrand.find(params[:id])

  end

  def new
    @p_commercial_object_brand = PCommercialObjectBrand.new
  
  end

  def edit
    @p_commercial_object_brand = PCommercialObjectBrand.find(params[:id])
    
  end

  def create
    @p_commercial_object_brand = PCommercialObjectBrand.new(params.require(:p_commercial_object_brand).permit!)

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

  end


  def update
    @p_commercial_object_brand = PCommercialObjectBrand.find(params[:id])


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


  def destroy
    @p_commercial_object_brand = PCommercialObjectBrand.find(params[:id])
    @p_commercial_object_brand.destroy
    
  end
end
