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

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

  before_action :admin_space
  
  def admin_space
    @admin_space = "default"
  end
  
  def index
    @line_stock_usages = LineStockUsage.all

    @line_stock_usages = sort_by_sorting(@line_stock_usages, "id DESC")
    respond_to do |format|
      format.html{
      
        params[:search][:per_page] = params[:search][:per_page] || 100
        per_page = params[:search][:per_page]
        page = (params[:page] and params[:page] != "") ? params[:page] : 1 
        @line_stock_usages = @line_stock_usages.page(page).per(per_page)
      
      }
    end
  end

  def show
    @line_stock_usage = LineStockUsage.find(params[:id])

  end

  def new
    @line_stock_usage = LineStockUsage.new
  
  end

  def edit
    @line_stock_usage = LineStockUsage.find(params[:id])
    
  end

  def create
    @line_stock_usage = LineStockUsage.new(params.require(:line_stock_usage).permit!)

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

  end


  def update
    @line_stock_usage = LineStockUsage.find(params[:id])


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


  def destroy
    @line_stock_usage = LineStockUsage.find(params[:id])
    @line_stock_usage.destroy
    
  end
end
