summaryrefslogtreecommitdiff
path: root/app/controllers/bazaar_controller.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/controllers/bazaar_controller.rb')
-rw-r--r--app/controllers/bazaar_controller.rb18
1 files changed, 14 insertions, 4 deletions
diff --git a/app/controllers/bazaar_controller.rb b/app/controllers/bazaar_controller.rb
index d51a419..4ba858a 100644
--- a/app/controllers/bazaar_controller.rb
+++ b/app/controllers/bazaar_controller.rb
@@ -11,15 +11,25 @@ class BazaarController < ApplicationController
if params[:buy_order] == "1"
BazaarOrder.transaction do
current_char.shift_item("vestige", (-price_each * quantity))
- current_char.bazaar_orders.create!(item: item, quantity: quantity,
- price_each: price_each, buy_order: true)
+ order = current_char.bazaar_orders.find_or_initialize_by(item: item, price_each: price_each, buy_order: true)
+ if order.new_record?
+ order.quantity = quantity
+ else
+ order.quantity += quantity
+ end
+ order.save!
flash[:notice] = "Posted buy order for #{item.name} at #{price_each} vg each."
end
else
BazaarOrder.transaction do
current_char.shift_item(item, -quantity)
- current_char.bazaar_orders.create!(item: item, quantity: quantity,
- price_each: price_each, buy_order: false)
+ order = current_char.bazaar_orders.find_or_initialize_by(item: item, price_each: price_each, buy_order: false)
+ if order.new_record?
+ order.quantity = quantity
+ else
+ order.quantity += quantity
+ end
+ order.save!
flash[:notice] = "Posted sell order for #{item.name} at #{price_each} vg each."
end
end