require_dependency "phcmemberspro/application_controller" module Phcmemberspro class Members::MainsController < ApplicationController # Security & Action Filters before_action :require_user before_action :set_paper_trail_whodunnit before_action :set_members_main, only: [:show, :edit, :update, :destroy] layout :phcmemberspro_membersmain_layouts_resolver # Member Profile List def index @members_mains = Members::Main.where(oganization_id: membership_info.org_id) end # Detailed Member Profile def show @versions = PaperTrail::Version.where(item_id: params[:id]) @members_contacts = Members::Contact.where(main_id: params[:id]) @members_businesses = Members::Business.where(main_id: params[:id]) @members_listings = Directory::Catlist.where(main_id: params[:id]) @members_main = Members::Main.find(params[:id]) end # New Member Profile def new @members_main = Members::Main.new end # Edit Member Profile def edit end # Create Member Profile Action def create @members_main = Members::Main.new(members_main_params) @members_main.user_id = current_user.id @members_main.membership_id = membership_info.id @members_main.oganization_id = membership_info.org_id if @members_main.save redirect_to members_mains_path, notice: 'Member profile has been successfully created.' else render :new end end # Update Member Profile Action def update @members_main.user_id = current_user.id @members_main.membership_id = membership_info.id @members_main.oganization_id = membership_info.org_id if @members_main.update(members_main_params) redirect_to members_mains_path, notice: 'Member profile has been successfully updated.' else render :edit end end # Delete Member Profile Action def destroy @members_main.destroy redirect_to members_mains_path, notice: 'Member profile and all businesses was successfully destroyed.' end private # Grab User Session Key (For ID) def current_user @_current_user ||= AuthRocket::Session.from_token(session[:ar_token]).try(:user) end # Get Current User from Above and Get Membership Info def membership_info AuthRocket::Membership.all(user_id: current_user.id).first end # Common Callbacks def set_members_main @members_main = Members::Main.find(params[:id]) end # White List def members_main_params params.require(:members_main).permit(:mfirstname, :mlastname, :mtitle, :memail, :mphone, :mnotes, :smfacebook, :smtwitter, :smlinkedin, :user_id, :membership_id, :oganization_id) end end end