class CinnostiZamsController < ApplicationController
  # GET /cinnosti_zams
  # GET /cinnosti_zams.json
  def index
    @zamestnanci = Zamestnanci.all

    respond_to do |format|
      format.html # index.html.erb
      format.json { render json: @cinnosti_zamestnanci}
    end
  end

  # GET /cinnosti_zams/1
  # GET /cinnosti_zams/1.json
  def show
    @cinnosti_zam = CinnostiZam.find(params[:id])

    respond_to do |format|
      format.html # show.html.erb
      format.json { render json: @cinnosti_zam }
    end
  end

  # GET /cinnosti_zams/new
  # GET /cinnosti_zams/new.json
  def new
    @zamestnanci = Zamestnanci.find(params[:id])

    respond_to do |format|
      format.html # new.html.erb
      format.json { render json: @cinnosti_zamestnanci}
    end
  end

  # GET /cinnosti_zams/1/edit
  def edit
    @cinnosti_zam = CinnostiZam.find(params[:id])
  end

  # POST /cinnosti_zams
  # POST /cinnosti_zams.json
  def create
    @zamestnanci = Zamestnanci.find(params[:id])
    @cinnosti = Cinnosti.find(params[:zamestnanci][:cinnosti])
    
    @zamestnanci.cinnosti << @cinnosti
    
    redirect_to  cinnosti_zams_path
  end

  # PUT /cinnosti_zams/1
  # PUT /cinnosti_zams/1.json
  def update
    @cinnosti_zam = CinnostiZam.find(params[:id])

    respond_to do |format|
      if @cinnosti_zam.update_attributes(params[:cinnosti_zam])
        format.html { redirect_to @cinnosti_zam, notice: 'Cinnosti zam was successfully updated.' }
        format.json { head :no_content }
      else
        format.html { render action: "edit" }
        format.json { render json: @cinnosti_zam.errors, status: :unprocessable_entity }
      end
    end
  end

  # DELETE /cinnosti_zams/1
  # DELETE /cinnosti_zams/1.json
  def destroy
    @cinnosti_zam = CinnostiZam.find(params[:id])
    @cinnosti_zam.destroy

    respond_to do |format|
      format.html { redirect_to cinnosti_zams_url }
      format.json { head :no_content }
    end
  end
end
