From 6aa520678345f1d583cc638744e489ee888e265e Mon Sep 17 00:00:00 2001
From: Jess Chadwick
Date: Mon, 11 Jun 2018 22:49:05 -0400
Subject: [PATCH] Re-recording 03_03
---
.../Website/Helpers/ProductHelpers.cs | 22 ++++++++++++++++
.../Website/Views/Products/ProductList.cshtml | 2 +-
.../Website/Views/Products/_Rating.cshtml | 25 ++++++++++++-------
Ch03/03_03_End/Website/Website.csproj | 2 +-
4 files changed, 40 insertions(+), 11 deletions(-)
create mode 100644 Ch03/03_03_End/Website/Helpers/ProductHelpers.cs
diff --git a/Ch03/03_03_End/Website/Helpers/ProductHelpers.cs b/Ch03/03_03_End/Website/Helpers/ProductHelpers.cs
new file mode 100644
index 0000000..8e18620
--- /dev/null
+++ b/Ch03/03_03_End/Website/Helpers/ProductHelpers.cs
@@ -0,0 +1,22 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Web;
+using System.Web.Mvc;
+using System.Web.Mvc.Html;
+using HPlusSports.Models;
+
+namespace HPlusSports
+{
+ public static class ProductHelpers
+ {
+ public static IHtmlString Rating(this System.Web.Mvc.HtmlHelper html, ProductRating rating)
+ {
+ if (rating == null || rating.ReviewCount == 0)
+ {
+ return new MvcHtmlString("No Rating");
+ }
+ return html.Partial("_Rating", rating);
+ }
+ }
+}
\ No newline at end of file
diff --git a/Ch03/03_03_End/Website/Views/Products/ProductList.cshtml b/Ch03/03_03_End/Website/Views/Products/ProductList.cshtml
index 6d20a19..6e7b26f 100644
--- a/Ch03/03_03_End/Website/Views/Products/ProductList.cshtml
+++ b/Ch03/03_03_End/Website/Views/Products/ProductList.cshtml
@@ -34,7 +34,7 @@
}
- @Html.Rating(rating)
+ @Html.Rating(rating)
diff --git a/Ch03/03_03_End/Website/Views/Products/_Rating.cshtml b/Ch03/03_03_End/Website/Views/Products/_Rating.cshtml
index 915582a..ea59c76 100644
--- a/Ch03/03_03_End/Website/Views/Products/_Rating.cshtml
+++ b/Ch03/03_03_End/Website/Views/Products/_Rating.cshtml
@@ -1,10 +1,17 @@
-@model ProductRating
+@model HPlusSports.Models.ProductRating
-
- @for (var i = 1; i <= 5; i++)
- {
- var starClass = (Model.Rating >= i) ? "star" : "star-empty";
-
- }
-
-(@Model.ReviewCount)
\ No newline at end of file
+@if (Model == null || Model.ReviewCount == 0)
+{
+ No Rating
+}
+else
+{
+
+ @for (var i = 1; i <= 5; i++)
+ {
+ var starClass = (Model.Rating >= i) ? "star" : "star-empty";
+
+ }
+
+ (@Model.ReviewCount)
+}
\ No newline at end of file
diff --git a/Ch03/03_03_End/Website/Website.csproj b/Ch03/03_03_End/Website/Website.csproj
index b33b89f..7a2e65d 100644
--- a/Ch03/03_03_End/Website/Website.csproj
+++ b/Ch03/03_03_End/Website/Website.csproj
@@ -197,12 +197,12 @@
-
Global.asax
+