Add MaxVideos and MaxGames RentablePolicies
[cs356-p2-videostore.git] / app / controllers / purchase_controller.rb
index 704e38b..a3b61bb 100644 (file)
@@ -58,6 +58,21 @@ class PurchaseController < ApplicationController
       return
     end
 
+    # Check Rentable Policies
+    @maxvideos = RentablePolicy.find_by_name("MaxVideos")
+    if @rentable.class == Video and @customer.checked_out_videos >= @maxvideos.value
+      flash[:error] = "#{@maxvideos.description} LIMIT REACHED"
+      redirect_to :action => :rent_begin
+      return
+    end
+
+    @maxgames = RentablePolicy.find_by_name("MaxGames")
+    if @rentable.class == Game and @customer.checked_out_games >= @maxgames.value
+      flash[:error] = "#{@maxgames.description} LIMIT REACHED"
+      redirect_to :action => :rent_begin
+      return
+    end
+
     # Check out the item
     checkout = Coitem.new
     checkout.customer = @customer