Skip to content
This repository has been archived by the owner on Nov 19, 2020. It is now read-only.

Commit

Permalink
UmbracoVirtualNodeById
Browse files Browse the repository at this point in the history
Custom route handling with MapUmbracoRoute and UmbracoVirtualNodeByIdHandler
  • Loading branch information
Mantus667 committed Jul 30, 2017
1 parent a0ecf5a commit b703f0c
Show file tree
Hide file tree
Showing 10 changed files with 150 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/UmbracoUrlHandling/App_Data/Models/all.dll.path
Original file line number Diff line number Diff line change
@@ -1 +1 @@
C:\Users\mantu\AppData\Local\Temp\Temporary ASP.NET Files\vs\027ab051\822a0174\App_Web_all.generated.cs.8f9494c4.cnvmy50x.dll
C:\Users\mantu\AppData\Local\Temp\Temporary ASP.NET Files\vs\027ab051\822a0174\App_Web_all.generated.cs.8f9494c4.oibqrept.dll
28 changes: 27 additions & 1 deletion src/UmbracoUrlHandling/App_Data/Models/all.generated.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
using Umbraco.ModelsBuilder;
using Umbraco.ModelsBuilder.Umbraco;
[assembly: PureLiveAssembly]
[assembly:ModelsBuilderAssembly(PureLive = true, SourceHash = "d75e4cafcf09787f")]
[assembly:ModelsBuilderAssembly(PureLive = true, SourceHash = "e4d2aa0bdb7a3315")]
[assembly:System.Reflection.AssemblyVersion("0.0.0.1")]


Expand Down Expand Up @@ -313,6 +313,32 @@ public string Type
}
}

/// <summary>ProductDetails</summary>
[PublishedContentModel("ProductDetails")]
public partial class ProductDetails : PublishedContentModel
{
#pragma warning disable 0109 // new is redundant
public new const string ModelTypeAlias = "ProductDetails";
public new const PublishedItemType ModelItemType = PublishedItemType.Content;
#pragma warning restore 0109

public ProductDetails(IPublishedContent content)
: base(content)
{ }

#pragma warning disable 0109 // new is redundant
public new static PublishedContentType GetModelContentType()
{
return PublishedContentType.Get(ModelItemType, ModelTypeAlias);
}
#pragma warning restore 0109

public static PublishedPropertyType GetModelPropertyType<TValue>(Expression<Func<ProductDetails, TValue>> selector)
{
return PublishedContentModelUtility.GetModelPropertyType(GetModelContentType(), selector);
}
}

/// <summary>Folder</summary>
[PublishedContentModel("Folder")]
public partial class Folder : PublishedContentModel
Expand Down
30 changes: 28 additions & 2 deletions src/UmbracoUrlHandling/App_Data/Models/models.generated.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
using Umbraco.ModelsBuilder.Umbraco;

[assembly: PureLiveAssembly]
[assembly:ModelsBuilderAssembly(PureLive = true, SourceHash = "d75e4cafcf09787f")]
[assembly:System.Reflection.AssemblyVersion("0.0.0.3")]
[assembly:ModelsBuilderAssembly(PureLive = true, SourceHash = "e4d2aa0bdb7a3315")]
[assembly:System.Reflection.AssemblyVersion("0.0.0.2")]

namespace Umbraco.Web.PublishedContentModels
{
Expand Down Expand Up @@ -297,6 +297,32 @@ public string Type
}
}

/// <summary>ProductDetails</summary>
[PublishedContentModel("ProductDetails")]
public partial class ProductDetails : PublishedContentModel
{
#pragma warning disable 0109 // new is redundant
public new const string ModelTypeAlias = "ProductDetails";
public new const PublishedItemType ModelItemType = PublishedItemType.Content;
#pragma warning restore 0109

public ProductDetails(IPublishedContent content)
: base(content)
{ }

#pragma warning disable 0109 // new is redundant
public new static PublishedContentType GetModelContentType()
{
return PublishedContentType.Get(ModelItemType, ModelTypeAlias);
}
#pragma warning restore 0109

public static PublishedPropertyType GetModelPropertyType<TValue>(Expression<Func<ProductDetails, TValue>> selector)
{
return PublishedContentModelUtility.GetModelPropertyType(GetModelContentType(), selector);
}
}

/// <summary>Folder</summary>
[PublishedContentModel("Folder")]
public partial class Folder : PublishedContentModel
Expand Down
2 changes: 1 addition & 1 deletion src/UmbracoUrlHandling/App_Data/Models/models.hash
Original file line number Diff line number Diff line change
@@ -1 +1 @@
d75e4cafcf09787f
e4d2aa0bdb7a3315
Binary file modified src/UmbracoUrlHandling/App_Data/Umbraco.sdf
Binary file not shown.
36 changes: 36 additions & 0 deletions src/UmbracoUrlHandling/Controller/ProductDetailsController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Web.Mvc;
using Umbraco.Web.Models;
using Umbraco.Web.Mvc;

namespace UmbracoUrlHandling.Controller
{
/// <summary>
/// Controller for Product page
/// </summary>
/// <seealso cref="Umbraco.Web.Mvc.RenderMvcController" />
public class ProductDetailsController : RenderMvcController
{
/// <summary>
/// The default action to render the front-end view
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
[NonAction]
public override ActionResult Index(RenderModel model)
{
return base.Index(model);
}

/// <summary>
/// Indexes the specified model.
/// </summary>
/// <param name="model">The model.</param>
/// <param name="sku">The sku.</param>
/// <returns></returns>
public ActionResult ProductDetails(RenderModel model, string sku)
{
ViewData["sku"] = sku;
return View("ProductDetails", model);
}
}
}
19 changes: 19 additions & 0 deletions src/UmbracoUrlHandling/RouteHandler/ProductRouteHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using Umbraco.Web.Mvc;

namespace UmbracoUrlHandling.RouteHandler
{
/// <summary>
/// Product Route Handler for Product Page
/// </summary>
/// <seealso cref="Umbraco.Web.Mvc.UmbracoVirtualNodeByIdRouteHandler" />
public class ProductRouteHandler : UmbracoVirtualNodeByIdRouteHandler
{
/// <summary>
/// Initializes a new instance of the <see cref="ProductRouteHandler"/> class.
/// </summary>
/// <param name="realNodeId">The real node identifier.</param>
public ProductRouteHandler(int realNodeId) : base(realNodeId)
{
}
}
}
18 changes: 17 additions & 1 deletion src/UmbracoUrlHandling/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using Umbraco.Core;
using Umbraco.Core.Services;
using Umbraco.Core.Strings;
using Umbraco.Web;
using Umbraco.Web.Routing;
using UmbracoUrlHandling.ContentFinder;
using UmbracoUrlHandling.RouteHandler;
using UmbracoUrlHandling.SegmentProvider;
using UmbracoUrlHandling.UrlProvider;

Expand All @@ -22,7 +26,19 @@ public void OnApplicationStarting(UmbracoApplicationBase umbracoApplication, App
UrlProviderResolver.Current.InsertTypeBefore<DefaultUrlProvider, BlogPostUrlProvider>();

ContentFinderResolver.Current.InsertTypeBefore<ContentFinderByNotFoundHandlers, BlogPostContentFinder>();
}

RouteTable.Routes.MapUmbracoRoute(
"ProductRoute",
"Products/{sku}",
new
{
controller = "ProductDetails",
action = "ProductDetails",
sku = UrlParameter.Optional
},
new ProductRouteHandler(1100)
);
}

public void OnApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
{
Expand Down
14 changes: 14 additions & 0 deletions src/UmbracoUrlHandling/UmbracoUrlHandling.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,15 @@
<Content Include="config\BaseRestExtensions.config" />
<Content Include="config\applications.config" />
<Content Include="config\404handlers.config" />
<Content Include="Views\Partials\BottomNavigation.cshtml" />
<Content Include="Views\Partials\MainNavigation.cshtml" />
<Content Include="Views\BlogOverview.cshtml" />
<Content Include="Views\BlogPost.cshtml" />
<Content Include="Views\Home.cshtml" />
<Content Include="Views\Master.cshtml" />
<Content Include="Views\ProductDetails.cshtml" />
<Content Include="Views\RealEstate.cshtml" />
<Content Include="Views\TextPage.cshtml" />
<None Include="Web.Debug.config">
<DependentUpon>Web.config</DependentUpon>
</None>
Expand Down Expand Up @@ -322,6 +331,8 @@
<ItemGroup>
<Compile Include="ContentFinder\BlogPostContentFinder.cs" />
<Compile Include="ContentFinder\ContentFinderItem.cs" />
<Compile Include="Controller\ProductDetailsController.cs" />
<Compile Include="RouteHandler\ProductRouteHandler.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SegmentProvider\ImmoUrlSegmentProvider.cs" />
<Compile Include="Startup.cs" />
Expand All @@ -331,6 +342,9 @@
<Analyzer Include="..\packages\Microsoft.CodeAnalysis.Analyzers.1.0.0\analyzers\dotnet\cs\Microsoft.CodeAnalysis.Analyzers.dll" />
<Analyzer Include="..\packages\Microsoft.CodeAnalysis.Analyzers.1.0.0\analyzers\dotnet\cs\Microsoft.CodeAnalysis.CSharp.Analyzers.dll" />
</ItemGroup>
<ItemGroup>
<Folder Include="Views\MacroPartials\" />
</ItemGroup>
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
Expand Down
7 changes: 7 additions & 0 deletions src/UmbracoUrlHandling/Views/ProductDetails.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage<ContentModels.ProductDetails>
@using ContentModels = Umbraco.Web.PublishedContentModels;
@{
Layout = "Master.cshtml";
}

<h1>The sku is: @ViewData["sku"]</h1>

0 comments on commit b703f0c

Please sign in to comment.