Add RentablePolicy for MaxOverdueVideos and MaxOverdueGames
[cs356-p2-videostore.git] / app / controllers / purchase_controller.rb
index a3b61bb..ebb08cd 100644 (file)
@@ -73,6 +73,20 @@ class PurchaseController < ApplicationController
       return
     end
 
+    @maxoverduevideos = RentablePolicy.find_by_name("MaxOverdueVideos")
+    if @rentable.class == Video and @customer.overdue_videos >= @maxoverduevideos.value
+      flash[:error] = "#{@maxoverduevideos.description} LIMIT REACHED"
+      redirect_to :action => :rent_begin
+      return
+    end
+
+    @maxoverduegames = RentablePolicy.find_by_name("MaxOverdueGames")
+    if @rentable.class == Game and @customer.overdue_games >= @maxoverduegames.value
+      flash[:error] = "#{@maxoverduegames.description} LIMIT REACHED"
+      redirect_to :action => :rent_begin
+      return
+    end
+
     # Check out the item
     checkout = Coitem.new
     checkout.customer = @customer