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

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

  before_action :admin_space
  
  def admin_space
    @admin_space = "default"
  end
  
  def index
    @departement_frances = DepartementFrance.all

    @departement_frances = sort_by_sorting(@departement_frances, "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 
        @departement_frances = @departement_frances.page(page).per(per_page)
      
      }
    end
  end

  def show
    @departement_france = DepartementFrance.find(params[:id])

  end

  def new
    @departement_france = DepartementFrance.new
  
  end

  def edit
    @departement_france = DepartementFrance.find(params[:id])
    
  end

  def create
    @departement_france = DepartementFrance.new(params.require(:departement_france).permit!)

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

  end


  def update
    @departement_france = DepartementFrance.find(params[:id])


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


  def destroy
    @departement_france = DepartementFrance.find(params[:id])
    @departement_france.destroy
    
  end
end
