class Public::ContactsController < ApplicationController  
  layout :get_public_layout
  
  def index
    
  end
  
  def new
    @contact = Contact.new(:raison_id => params[:raison_id], :survey_set_id => params[:id])
    
    if @contact.raison_id == 3 and session[:order_document_ids] and session[:order_document_ids].size > 0
      session[:order_document_ids].each do |token|
        @contact.document_orders << DocumentOrder.new(:data_file => DataFile.find_by_token(token))
      end
    end
    
    
  end
	def create
		@contact = Contact.new(params.require(:contact).permit!)
    
    
	
		if @contact.save
      if @contact.raison_id == 3
        @contact.notes = session[:order_document_ids].join(",")
        session[:order_document_ids] = []
      end
      @contact.save
			QuestionMailer.send_contact(@contact).deliver
      
      render :action => :create
    else
      
      render :action => :new
		end

	end

end
