Re-recording 03_03
This commit is contained in:
22
Ch03/03_03_End/Website/Helpers/ProductHelpers.cs
Normal file
22
Ch03/03_03_End/Website/Helpers/ProductHelpers.cs
Normal file
@ -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("<span><em>No Rating</em></span>");
|
||||
}
|
||||
return html.Partial("_Rating", rating);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,10 +1,17 @@
|
||||
@model ProductRating
|
||||
@model HPlusSports.Models.ProductRating
|
||||
|
||||
@if (Model == null || Model.ReviewCount == 0)
|
||||
{
|
||||
<span><em>No Rating</em></span>
|
||||
}
|
||||
else
|
||||
{
|
||||
<span title="@Model.Rating.GetValueOrDefault().ToString("N1")">
|
||||
@for (var i = 1; i <= 5; i++)
|
||||
{
|
||||
var starClass = (Model.Rating >= i) ? "star" : "star-empty";
|
||||
<span class="rating-star glyphicon glyphicon-@starClass"></span>
|
||||
<span class="Model-star glyphicon glyphicon-@starClass"></span>
|
||||
}
|
||||
</span>
|
||||
<span>(@Model.ReviewCount)</span>
|
||||
}
|
||||
@ -197,12 +197,12 @@
|
||||
<Compile Include="Controllers\ImagesController.cs" />
|
||||
<Compile Include="Controllers\InventoryController.cs" />
|
||||
<Compile Include="Controllers\ProductsController.cs" />
|
||||
<Compile Include="Extensions\HtmlHelperExtensions.cs" />
|
||||
<Compile Include="Extensions\TempDataExtensions.cs" />
|
||||
<Compile Include="Extensions\UrlHelperExtensions.cs" />
|
||||
<Compile Include="Global.asax.cs">
|
||||
<DependentUpon>Global.asax</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Helpers\ProductHelpers.cs" />
|
||||
<Compile Include="Models\Identity\AccountViewModels.cs" />
|
||||
<Compile Include="Models\Identity\IdentityModels.cs" />
|
||||
<Compile Include="Models\Identity\ManageViewModels.cs" />
|
||||
|
||||
Reference in New Issue
Block a user