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

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

  before_action :admin_space
  
  def admin_space
    @admin_space = "default"
  end
  
  def index
    @stock_lines = StockLine.order(:name).all

  end

  def show
    @stock_line = StockLine.find(params[:id])

  end

  def new
    @stock_line = StockLine.new
  
  end

  def edit
    @stock_line = StockLine.find(params[:id])
    
  end

  def create
    @stock_line = StockLine.new(params.require(:stock_line).permit!)

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

  end


  def update
    @stock_line = StockLine.find(params[:id])


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


  def destroy
    @stock_line = StockLine.find(params[:id])
    @stock_line.destroy
    
  end
end
