module Logistics module Core class ChargeableServiceIncrementsController < ApplicationController # GET /chargeable_service_increments # GET /chargeable_service_increments.json def index @chargeable_service_increments = ChargeableServiceIncrement.all @response = {:success => true, :message => '', :data => @chargeable_service_increments} render json: @response end # POST /chargeable_service_increments # POST /chargeable_service_increments.json def create uoc_list = params[:increments] cs_uoc = nil if uoc_list.count > 0 cs_uoc = ChargeableServiceUnitOfCharge.find(uoc_list[0][:chargeable_service_unit_of_charge_id]) end uoc_list.each do |uoc| increment = ServiceIncrement.find(uoc[:service_increment_id]) cs_uoc.service_increments << increment end begin cs_uoc.save response = {:success => true, :message => 'Service Increment successfully'} rescue => e response = {:success => false, :message => e.message} end render json: response end private # Never trust parameters from the scary internet, only allow the white list through. def chargeable_service_increment_params params.permit(:increments => [:chargeable_service_unit_of_charge_id, :service_increment_id]) end end end end