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

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

  before_action :admin_space
  
  def admin_space
    @admin_space = "preferences"
  end
  
  def index
    @accounting_zones = AccountingZone.order(:name).all

  end

  def show
    @accounting_zone = AccountingZone.find(params[:id])

  end

  def new
    @accounting_zone = AccountingZone.new
  
  end

  def edit
    @accounting_zone = AccountingZone.find(params[:id])
    
  end

  def create
    @accounting_zone = AccountingZone.new(params.require(:accounting_zone).permit!)

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

  end


  def update
    @accounting_zone = AccountingZone.find(params[:id])


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


  def destroy
    @accounting_zone = AccountingZone.find(params[:id])
    @accounting_zone.destroy
    
  end
end