class Admin::AdminsController < ApplicationController
  layout "admin"
  
  before_filter :auth_admin
  
  def index
    
    @admins = Admin.all
  end


  def show
    @admin = Admin.find(params[:id])

  end


  def new
    @admin = Admin.new(:contact_role => true)
  
  end

  def edit
    @admin = Admin.find(params[:id])
  
  end

  def create
    @admin = Admin.new(admin_params)
    
    if @admin.save
      @admins = Admin.all
      @admin.generate_mdp_now if @admin.generate_mdp and @admin.generate_mdp != "0"
          
    else
      render :action => "new" 
    end
  end

  def update
    @admin = Admin.find(params[:id])
    
    if @admin.update_attributes(admin_params)
      @admin.generate_mdp_now if @admin.generate_mdp and @admin.generate_mdp != "0"
          
    else
      render :action => "edit" 
    end
    
  end
      


  def destroy
    @admin = Admin.find(params[:id])
    
    @admin.destroy if @admin != @current_admin
  
  end
  
  private
      def admin_params
        params.require(:admin).permit!
      end



end
