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

class Public::ParticularsController < ApplicationController
  layout "public"
  before_filter :order_params
  def index
    @particulars = current_p_customer.particulars.order(:name).all

   
  end

  def show
    @particular = current_p_customer.particulars.find(params[:id])

  end

  def new
    
    
		@particular = current_p_customer.particulars.new
    @particular.force_validation = true

  end

 

  def edit
  
    
    @particular = current_p_customer.particulars.find(params[:id])
    @particular.force_validation = true
  end

  def create
    @particular = current_p_customer.particulars.new(params.require(:particular).permit!)


    if @particular.save
      if params[:order]
        redirect_to particulars_public_p_orders_path
      else
        redirect_to public_particulars_path
      end
    else
      render action: "new"
 
    end

  end


  def update
    @particular = current_p_customer.particulars.find(params[:id])


    if @particular.update_attributes(params.require(:particular).permit!)
      
      if params[:order]
        redirect_to particulars_public_p_orders_path
      else
        redirect_to public_particulars_path
      end
      
       
    else
     render action: "edit" 
      
    end
      
  end


  def destroy
    @particular = Particular.find(params[:id])
    @particular.destroy
    
    redirect_to public_particulars_path
    
    
  end
  
  private
  def order_params
    if params[:order] == "true"
      params[:order] = true
    else
      params[:order] = nil
    end
    
  end
end
