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

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

  before_action :admin_space
  
  def admin_space
    @admin_space = "stocks"
  end
  
  def index
    @m_events = MEvent.all

    @m_events = sort_by_sorting(@m_events, "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 
        @m_events = @m_events.page(page).per(per_page)
      
      }
    end
  end

  def show
    @m_event = MEvent.find(params[:id])

  end

  def new
    @m_event = MEvent.new
  
  end

  def edit
    @m_event = MEvent.find(params[:id])
    
  end

  def create
    @m_event = MEvent.new(params.require(:m_event).permit!)

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

  end


  def update
    @m_event = MEvent.find(params[:id])


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


  def destroy
    @m_event = MEvent.find(params[:id])
    @m_event.destroy
    
  end
end
