Exercise Files
This commit is contained in:
23
Ch04/04_03_End/Website/Extensions/HtmlHelperExtensions.cs
Normal file
23
Ch04/04_03_End/Website/Extensions/HtmlHelperExtensions.cs
Normal file
@ -0,0 +1,23 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.Mvc.Html;
|
||||
|
||||
namespace HPlusSports
|
||||
{
|
||||
public static class HtmlHelperExtensions
|
||||
{
|
||||
|
||||
public static IHtmlString Rating(this System.Web.Mvc.HtmlHelper html, Models.ProductRating rating)
|
||||
{
|
||||
if (rating == null || rating.ReviewCount == 0)
|
||||
{
|
||||
return new System.Web.Mvc.MvcHtmlString("<span><em>No Rating</em></span>");
|
||||
}
|
||||
|
||||
return html.Partial("_Rating", rating);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
22
Ch04/04_03_End/Website/Extensions/TempDataExtensions.cs
Normal file
22
Ch04/04_03_End/Website/Extensions/TempDataExtensions.cs
Normal file
@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
|
||||
namespace HPlusSports
|
||||
{
|
||||
public static class TempDataExtensions
|
||||
{
|
||||
const string SuccessMessageKey = "SuccessMessage";
|
||||
|
||||
public static string SuccessMessage(this System.Web.Mvc.TempDataDictionary tempData)
|
||||
{
|
||||
return tempData[SuccessMessageKey] as string;
|
||||
}
|
||||
|
||||
public static void SuccessMessage(this System.Web.Mvc.TempDataDictionary tempData, string successMessage)
|
||||
{
|
||||
tempData[SuccessMessageKey] = successMessage;
|
||||
}
|
||||
}
|
||||
}
|
||||
21
Ch04/04_03_End/Website/Extensions/UrlHelperExtensions.cs
Normal file
21
Ch04/04_03_End/Website/Extensions/UrlHelperExtensions.cs
Normal file
@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using HPlusSports.Models;
|
||||
|
||||
namespace HPlusSports
|
||||
{
|
||||
public static class UrlHelperExtensions
|
||||
{
|
||||
public static string Product(this System.Web.Mvc.UrlHelper urlHelper, Product product)
|
||||
{
|
||||
return Product(urlHelper, product?.SKU);
|
||||
}
|
||||
|
||||
public static string Product(this System.Web.Mvc.UrlHelper urlHelper, string sku)
|
||||
{
|
||||
return urlHelper.Action("Product", "Products", new { id = sku });
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user