<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>

<channel>
	<title>Patrick's Bytes</title>
	<atom:link href="http://patrickyong.net/feed/" rel="self" type="application/rss+xml" />
	<link>http://patrickyong.net</link>
	<description>Techie for the past 30 years...</description>
	<pubDate>Wed, 04 Aug 2010 11:39:26 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.2</generator>
	<language>en</language>
			<item>
		<title>Orchard Alpha released</title>
		<link>http://patrickyong.net/2010/08/03/orchard-alpha-released/</link>
		<comments>http://patrickyong.net/2010/08/03/orchard-alpha-released/#comments</comments>
		<pubDate>Tue, 03 Aug 2010 08:16:20 +0000</pubDate>
		<dc:creator>Patrick</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<category><![CDATA[asp.net mvc]]></category>

		<category><![CDATA[orchard]]></category>

		<guid isPermaLink="false">http://patrickyong.net/2010/08/03/orchard-alpha-released/</guid>
		<description><![CDATA[As promised, Project Orchard reached with Alpha milestone just now with the downloads available at http://orchard.codeplex.com
Among the features included in this release

The core module API is mostly baked 
Data migrations for updating database schema on module activation and upgrade between versions of modules 
Basic command-line scaffolding of modules and data migrations 
Dynamic compilation of module [...]]]></description>
			<content:encoded><![CDATA[<p>As promised, Project Orchard reached with Alpha milestone just now with the downloads available at <a href="http://orchard.codeplex.com">http://orchard.codeplex.com</a></p>
<p>Among the features included in this release</p>
<ul>
<li>The core module API is mostly baked </li>
<li>Data migrations for updating database schema on module activation and upgrade between versions of modules </li>
<li>Basic command-line scaffolding of modules and data migrations </li>
<li>Dynamic compilation of module source, for notepad-style development
<ul>
<li>Defining custom content types, parts, and fields </li>
<li>Define new content types (admin panel or code) </li>
<li>Add fields to content types (admin panel or code) </li>
<li>Associate content parts to types (admin panel or code) </li>
<li>Add fields or parts to existing content types (admin panel or code)</li>
</ul>
</li>
<li>Packaging and installing modules (as zip files) – can include source, binaries, or both </li>
<li>Sharing modules via an ATOM feed (to be exposed on OrchardProject.net), and installing from the feed using a new “Gallery” module </li>
<li>Enabling, disabling, and upgrading module features and their dependencies (admin panel or command-line) </li>
<li>Search </li>
<li>Localization support for both the Orchard application and database-driven content items </li>
<li>Azure support </li>
<li>Multi-tenancy support </li>
<li>Interactive command-line support for many administrative tasks </li>
<li>Some basic reporting/logging functionality </li>
<li>Everything from previous Mix release: pages, blogs, comments, tags, users/roles, media, menu navigation, and basic theme support</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://patrickyong.net/2010/08/03/orchard-alpha-released/feed/</wfw:commentRss>
		</item>
		<item>
		<title>A 7 part tutorial on project Orchard based on the latest change set</title>
		<link>http://patrickyong.net/2010/07/26/a-7-part-tutorial-on-project-orchard-based-on-the-latest-change-set/</link>
		<comments>http://patrickyong.net/2010/07/26/a-7-part-tutorial-on-project-orchard-based-on-the-latest-change-set/#comments</comments>
		<pubDate>Mon, 26 Jul 2010 14:42:01 +0000</pubDate>
		<dc:creator>Patrick</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<category><![CDATA[asp.net mvc]]></category>

		<category><![CDATA[orchard]]></category>

		<guid isPermaLink="false">http://patrickyong.net/2010/07/26/a-7-part-tutorial-on-project-orchard-based-on-the-latest-change-set/</guid>
		<description><![CDATA[&#160;

Over the weekend I created a tutorial to create a module inside project Orchard. I referred to the original walkthrough found inside project Orchard’s website. The original walkthrough was created for the March 2010 release of project orchard and I have modified the codes and steps so that it will work with the latest change [...]]]></description>
			<content:encoded><![CDATA[<p>&#160;</p>
<p><img src="http://download.codeplex.com/Project/Download/FileDownload.aspx?ProjectName=orchard&amp;DownloadId=91632&amp;Build=16983" /></p>
<p>Over the weekend I created a tutorial to create a module inside project Orchard. I referred to the original walkthrough found inside project Orchard’s website. The original walkthrough was created for the March 2010 release of project orchard and I have modified the codes and steps so that it will work with the <a href="http://orchard.codeplex.com/SourceControl/changeset/changes/b446fbbf328e">latest change set</a>.</p>
<p>Below is the Table of Content</p>
<p><a href="http://patrickyong.net/2010/07/25/hello-orchard-creating-a-orchard-module-using-latest-source-code/">What is project Orchard and a Hello World sample</a></p>
<p><a href="http://patrickyong.net/2010/07/25/hello-orchard-part-2/">Hooking into Admin panel</a></p>
<p><a href="http://patrickyong.net/2010/07/26/hello-orchard-part-3working-with-data/">Working with Data</a></p>
<p><a href="http://patrickyong.net/2010/07/26/orchard-content-type/">Orchard Content Type</a></p>
<p><a href="http://patrickyong.net/2010/07/26/hello-orchard-part-5attaching-a-part-to-content-type/">Attaching a part to content type</a></p>
<p><a href="http://patrickyong.net/2010/07/26/hello-orchard-6composing-view-using-different-content-parts/">Composing view using different content parts</a></p>
<p><a href="http://patrickyong.net/2010/07/26/hello-orchard-final-partbuilding-the-module-front-end/">Finishing touch on the front end listing and shopping cart</a></p>
<p>For the complete project source code, download from my Windows Live SkyDrive here.</p>
<p> <iframe title="Preview" scrolling="no" marginheight="0" marginwidth="0" frameborder="0" style="width:98px;height:115px;padding:0;background-color:#fcfcfc;" src="http://cid-732d1d42507315a3.office.live.com/embedicon.aspx/Project%20Orchard/Orchard.Commerce.zip"></iframe>
<p>&#160;</p>
<p>&#160;</p>
<p>It is best if you check out the <a href="http://orchard.codeplex.com/releases/view/42040">Mar 2010 build</a> and the <a href="http://orchardproject.net/privatedrops/orchardmodulewalkthrough.doc">original tutorial</a> as well for more info on Orchard. </p>
<p>&#160;</p>
<p>Cheers.</p>
]]></content:encoded>
			<wfw:commentRss>http://patrickyong.net/2010/07/26/a-7-part-tutorial-on-project-orchard-based-on-the-latest-change-set/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Hello Orchard Final Part&#8211;Building the module front end</title>
		<link>http://patrickyong.net/2010/07/26/hello-orchard-final-partbuilding-the-module-front-end/</link>
		<comments>http://patrickyong.net/2010/07/26/hello-orchard-final-partbuilding-the-module-front-end/#comments</comments>
		<pubDate>Mon, 26 Jul 2010 14:31:59 +0000</pubDate>
		<dc:creator>Patrick</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<category><![CDATA[asp.net mvc]]></category>

		<category><![CDATA[orchard]]></category>

		<guid isPermaLink="false">http://patrickyong.net/2010/07/26/hello-orchard-final-partbuilding-the-module-front-end/</guid>
		<description><![CDATA[With the backend Product administration page done, now we can build the front end to list the products and a simple shopping cart
Following are copy-pastes from the walkthrough at orchardproject.net with my modifications
1. Let’s first update our HomeController query the ContentManager for the list of products, passing the model to the View:
using Orchard.Commerce.Models;using Orchard.ContentManagement;
…
[Themed]&#160;&#160;&#160; public [...]]]></description>
			<content:encoded><![CDATA[<p>With the backend Product administration page done, now we can build the front end to list the products and a simple shopping cart</p>
<p><font color="#555555"><strong>Following are copy-pastes from the walkthrough at orchardproject.net with my modifications</strong></font></p>
<p>1. Let’s first update our HomeController query the ContentManager for the list of products, passing the model to the View:</p>
<pre>using Orchard.Commerce.Models;using Orchard.ContentManagement;</pre>
<p>…</p>
<pre>[Themed]&#160;&#160;&#160; public class HomeController : Controller&#160;&#160;&#160; {

&#160;&#160;&#160;&#160;&#160;&#160;&#160; private readonly IContentManager _contentManager;

&#160;&#160;&#160;&#160;&#160;&#160;&#160; public HomeController(IContentManager contentManager)&#160;&#160;&#160;&#160;&#160;&#160;&#160; {&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; _contentManager = contentManager;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }

&#160;&#160;&#160;&#160;&#160;&#160;&#160; public ActionResult Index()&#160;&#160;&#160;&#160;&#160;&#160;&#160; {&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; return View(_contentManager.Query&lt;Product&gt;().List());&#160;&#160;&#160;&#160;&#160;&#160;&#160; }&#160;&#160;&#160; }</pre>
<p>2. Now let’s update the Home/Index.ascx view page to render the list of products. To make this easier, delete the existing Index.ascx page and right-click the Index() action to “Add &gt; View” in Visual Studio. This time, we’ll add a strongly-typed view that takes the Product type, and choose “List” for the View content type:</p>
<p><a href="http://patrickyong.net/wp-content/uploads/2010/07/image36.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" class="wlDisabledImage" title="image" border="0" alt="image" src="http://patrickyong.net/wp-content/uploads/2010/07/image-thumb35.png" width="428" height="412" /></a></p>
<p>3. In Index.ascx, add this at the top of the file:</p>
<pre>&lt;%@ Control Language=&quot;C#&quot; Inherits=&quot;System.Web.Mvc.ViewUserControl&lt;IEnumerable&lt;Orchard.Commerce.Models.Product&gt;&gt;&quot; %&gt;<font style="background-color: #ffff00">&lt;div class=&quot;page-title&quot;&gt;&lt;%=Html.TitleForPage(&quot;Product list&quot;)%&gt;&lt;/div&gt;</font>&#160;&#160;&#160; &lt;table&gt;</pre>
<p>4. Type Ctrl-F5 to build and run the site. Click the “Shop” menu item on the front-end to reveal your list of products.</p>
<p><a href="http://patrickyong.net/wp-content/uploads/2010/07/image37.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" class="wlDisabledImage" title="image" border="0" alt="image" src="http://patrickyong.net/wp-content/uploads/2010/07/image-thumb36.png" width="563" height="214" /></a></p>
<p>5. Let’s now create a “Details” view so we can verify we can see tags and add comments (recall the UI composition section above). In the HomeController, add this:</p>
<pre>using Orchard.Mvc.Results;</pre>
<p>…</p>
<pre>public ActionResult Details(int id)&#160;&#160;&#160;&#160;&#160;&#160;&#160; {&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; var product = _contentManager.Get&lt;Product&gt;(id);&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; if (product == null)&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; return new NotFoundResult();

&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; var viewModel = _contentManager.BuildDisplayModel&lt;Product&gt;(product,&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &quot;Details&quot;);

&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; return View(viewModel);&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</pre>
<p>6. Let’s then create the “Details.ascx” view under Views &gt; Home:</p>
<p><a href="http://patrickyong.net/wp-content/uploads/2010/07/image38.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" class="wlDisabledImage" title="image" border="0" alt="image" src="http://patrickyong.net/wp-content/uploads/2010/07/image-thumb37.png" width="579" height="124" /></a></p>
<pre>&lt;%@ Control Language=&quot;C#&quot; Inherits=&quot;System.Web.Mvc.ViewUserControl&lt;Orchard.Mvc.ViewModels.ContentItemViewModel&lt;Orchard.Commerce.Models.Product&gt;&gt;&quot; %&gt;&lt;div class=&quot;page-title&quot;&gt;&#160;&#160;&#160; &lt;%=Html.TitleForPage(&quot;Product details&quot;)%&gt;&lt;/div&gt;&lt;%= Html.DisplayForItem(Model) %&gt;&lt;div&gt;&#160;&#160;&#160; &lt;%=Html.ActionLink(&quot;Back to List&quot;, &quot;Index&quot;) %&gt;&lt;/div&gt;</pre>
<p><b><br />
    <br /></b>Note the “Details” string. It a convention for the type of display (other include summary, list, etc.). Let’s update the ProductDriver to handle the composition:</p>
<pre>protected override DriverResult Display(Product product, string displayType){   return ContentPartTemplate(product, &quot;Product.Fields&quot;).Location(&quot;primary&quot;, &quot;1&quot;);}</pre>
<p>This is very similar to the “Editor” method. Product.Fields is the template used to render the fields. Let’s create Product.Fields.ascx in the “DisplayTemplates” folder.</p>
<p><a href="http://patrickyong.net/wp-content/uploads/2010/07/image39.png"><img style="border-right-width: 0px; margin: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" class="wlDisabledImage" title="image" border="0" alt="image" src="http://patrickyong.net/wp-content/uploads/2010/07/image-thumb38.png" width="227" height="150" /></a></p>
<p>7. Add Product.Fields.ascx under the “Views &gt; DisplayTemplates” folder:</p>
<pre>&lt;%@ Control Language=&quot;C#&quot; Inherits=&quot;System.Web.Mvc.ViewUserControl&lt;Orchard.Commerce.Models.Product&gt;&quot; %&gt;&lt;fieldset&gt;&#160;&#160;&#160; &lt;legend&gt;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;%= Html.Encode(Model.Sku)%&gt;&lt;/legend&gt;&#160;&#160;&#160; &lt;p&gt;&#160;&#160;&#160; &lt;/p&gt;&#160;&#160;&#160; &lt;h3&gt;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;%= Html.Encode(Model.Description)%&gt;&lt;/h3&gt;&#160;&#160;&#160; &lt;p&gt;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Price:&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;%= Html.Encode(String.Format(&quot;{0:F}&quot;, Model.Price))%&gt;&lt;/p&gt;&lt;/fieldset&gt;</pre>
<p>8. And finally update the Index view to link the “sku” field to the product details page:</p>
<p>Replace this:</p>
<pre>&lt;td&gt;   &lt;%: item.Sku %&gt;&lt;/td&gt;</pre>
<p>With this:</p>
<pre>&lt;td&gt;&#160; &lt;%= Html.ActionLink(item.Sku ?? &quot;sku&quot;, &quot;Details&quot;, new { id = item.Id })%&gt;&lt;/td&gt;</pre>
<p>9. Type Ctrl-F5 to build and run the site. Now, when clicking on a “sku” in the index view, we get to the product details page (with comments and tags).</p>
<p><a href="http://patrickyong.net/wp-content/uploads/2010/07/clip-image0062.jpg"><img style="border-right-width: 0px; margin: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="clip_image006" border="0" alt="clip_image006" src="http://patrickyong.net/wp-content/uploads/2010/07/clip-image006-thumb2.jpg" width="202" height="244" /></a></p>
<h3>Implementing a basic shopping cart</h3>
<p>To give another take on UI composition, we are going to implement a simple shopping cart, and we will display it in the “sidebar” zone using the MVC 2 RenderAction method. </p>
<p>1. Let’s first define the data model we are going to use to store the shopping cart data (we are using simple records, not content items for this simple example). Add a ShoppingCartRecord class in the Models folder:</p>
<pre>using Orchard.Data.Conventions;using System.Collections.Generic;

namespace Orchard.Commerce.Models{&#160;&#160;&#160; public class ShoppingCartRecord&#160;&#160;&#160; {&#160;&#160;&#160;&#160;&#160;&#160;&#160; public ShoppingCartRecord()&#160;&#160;&#160;&#160;&#160;&#160;&#160; {&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Entries = new List&lt;ShoppingCartEntryRecord&gt;();&#160;&#160;&#160;&#160;&#160;&#160;&#160; }

&#160;&#160;&#160;&#160;&#160;&#160;&#160; public virtual int Id { get; set; }

&#160;&#160;&#160;&#160;&#160;&#160;&#160; public virtual int UserId { get; set; }

&#160;&#160;&#160;&#160;&#160;&#160;&#160; [CascadeAllDeleteOrphan]&#160;&#160;&#160;&#160;&#160;&#160;&#160; public virtual IList&lt;ShoppingCartEntryRecord&gt; Entries { get; set; }

&#160;&#160;&#160; }

&#160;&#160;&#160; public class ShoppingCartEntryRecord&#160;&#160;&#160; {&#160;&#160;&#160;&#160;&#160;&#160;&#160; public virtual int Id { get; set; }&#160;&#160;&#160;&#160;&#160;&#160;&#160; public virtual ProductRecord Product { get; set; }&#160;&#160;&#160;&#160;&#160;&#160;&#160; public virtual int Quantity { get; set; }&#160;&#160;&#160; }}
</pre>
<p>2. Next, let’s update the HomeController class to use more services we are going to need:</p>
<pre>using Orchard.Data;using Orchard.UI.Notify;using Orchard.Security;using Orchard.Localization;</pre>
<p>…</p>
<pre>[Themed]&#160;&#160;&#160; public class HomeController : Controller&#160;&#160;&#160; {&#160;&#160;&#160;&#160;&#160;&#160;&#160; private readonly IContentManager _contentManager;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font style="background-color: #ffff00">private readonly IRepository&lt;ShoppingCartRecord&gt; _repository;&#160;&#160;&#160;&#160;&#160;&#160;&#160; private readonly INotifier _notifier;&#160;&#160;&#160;&#160;&#160;&#160;&#160; public virtual IUser CurrentUser { get; set; }&#160;&#160;&#160;&#160;&#160;&#160;&#160; public Localizer T { get; set; }

&#160;&#160;&#160;&#160;&#160;&#160;&#160; public HomeController(IContentManager contentManager, IRepository&lt;ShoppingCartRecord&gt; repository, INotifier notifier)&#160;&#160;&#160;&#160;&#160;&#160;&#160; {&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; _contentManager = contentManager;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; _repository = repository;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; _notifier = notifier;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</font></pre>
<p>Some things to note about this code:</p>
<p>§ “IRespository&lt;ShoppingCartRecord&gt; gives access to the database</p>
<p>§ “CurrentUser” gives access to the logged-in user</p>
<p>§ “T” gives access to the localization service</p>
<p>§ “INotifier” gives access to the notification area of the application</p>
<p><b><i>Now, let’s implement the “AddToCart” action… </i></b></p>
<p>We’ll create the cart for the user if needed, add 1 product to the list, and display a “Product added” message to the notification area of the site.</p>
<p>Note that in this simple example, we don’t handle anonymous users very well – there is a single shopping cart for the whole site. We also don’t support “merging” the shopping cart content when an anonymous user decides to log in after creating his shopping cart. These are more advanced applications of a shopping cart implementation that we will skip for now.</p>
<p>3. In HomeController, add the AddToCart action method:</p>
<pre>public ActionResult AddToCart(int id)&#160;&#160;&#160;&#160;&#160;&#160;&#160; {&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; // Retrieve shopping cart for current user

&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; ShoppingCartRecord cart;

&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; if (CurrentUser == null)&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; {&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; cart = _repository.Fetch(c =&gt; c.UserId == 0).SingleOrDefault();&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }

&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; else&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; {&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; cart = _repository.Fetch(c =&gt; c.UserId ==&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; CurrentUser.Id).SingleOrDefault();&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }

&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; // Create cart if none found

&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; if (cart == null)&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; {&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; cart = new ShoppingCartRecord();&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; _repository.Create(cart);&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; cart.UserId = (CurrentUser == null ? 0 : CurrentUser.Id);&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }

&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; // Add product to cart entry&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; var product = _contentManager.Get&lt;Product&gt;(id).Record;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; var entry = cart.Entries.Where(e =&gt; e.Product == product).SingleOrDefault();

&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; if (entry == null)&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; {&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; entry = new ShoppingCartEntryRecord&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; {&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Product = product,&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Quantity = 0&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; };&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; cart.Entries.Add(entry);&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }

&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; entry.Quantity++;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; _notifier.Add(NotifyType.Information, T(&quot;Added {1} to shopping cart&quot;,&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; entry.Quantity, product.Sku));&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; // Back to product list&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; return RedirectToAction(&quot;Index&quot;);&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</pre>
<p>4. Finally, update the “Index.ascx” view (under Views &gt; Home) to include a “Add to cart” column:</p>
<p>a. Add a “Buy” column…</p>
<pre>&lt;th&gt;Buy&lt;/th&gt;</pre>
<p>b. And add an “Add To Cart” link…</p>
<pre>&lt;td&gt;&lt;%= Html.ActionLink(&quot;Add to cart&quot;, &quot;AddToCart&quot;, new { id= item.Id })%&gt;&lt;/td&gt;</pre>
<p>5. Type Ctrl-F5 to build and run the site.</p>
<p><font color="#ff0000">NOTE: Since we created a new record class, there is a need to update the database. Go into the admin page and trigger Database Update under Site Configuration –&gt; Dev Tools menu.</font></p>
<p><a href="http://patrickyong.net/wp-content/uploads/2010/07/image40.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" class="wlDisabledImage" title="image" border="0" alt="image" src="http://patrickyong.net/wp-content/uploads/2010/07/image-thumb39.png" width="405" height="218" /></a></p>
<p>We now have a working “Add to cart” link next to each product in the list</p>
<p>We also get notification that a product has been added to the cart</p>
<p><a href="http://patrickyong.net/wp-content/uploads/2010/07/image41.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" class="wlDisabledImage" title="image" border="0" alt="image" src="http://patrickyong.net/wp-content/uploads/2010/07/image-thumb40.png" width="540" height="207" /></a></p>
<p>Well that’s it! There is another section about rendering the shopping cart content on the sidebar which I will update with another post later due to some issue with the Controller rendering.</p>
<p>If you want to revisit back the previous past, you can go to the <a href="http://patrickyong.net/2010/07/26/a-7-part-tutorial-on-project-orchard-based-on-the-latest-change-set/">TOC page</a> I created here.</p>
]]></content:encoded>
			<wfw:commentRss>http://patrickyong.net/2010/07/26/hello-orchard-final-partbuilding-the-module-front-end/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Hello Orchard 6&#8211;Composing view using different content parts</title>
		<link>http://patrickyong.net/2010/07/26/hello-orchard-6composing-view-using-different-content-parts/</link>
		<comments>http://patrickyong.net/2010/07/26/hello-orchard-6composing-view-using-different-content-parts/#comments</comments>
		<pubDate>Mon, 26 Jul 2010 13:23:11 +0000</pubDate>
		<dc:creator>Patrick</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<category><![CDATA[asp.net mvc]]></category>

		<category><![CDATA[orchard]]></category>

		<guid isPermaLink="false">http://patrickyong.net/2010/07/26/hello-orchard-6composing-view-using-different-content-parts/</guid>
		<description><![CDATA[This is the 6th part of my Orchard introduction. As of today I updated my source code to reflect today’s build and also because I need it for certain bug fixes. For more info about my previous posting, check out
Part 1
Part 2
Part 3
Part 4
Part 5
In part 5, we talk about composing content type with parts [...]]]></description>
			<content:encoded><![CDATA[<p>This is the 6th part of my Orchard introduction. As of today I updated my source code to reflect today’s build and also because I need it for certain bug fixes. For more info about my previous posting, check out</p>
<p><a href="http://patrickyong.net/2010/07/25/hello-orchard-creating-a-orchard-module-using-latest-source-code/">Part 1</a></p>
<p><a href="http://patrickyong.net/2010/07/25/hello-orchard-part-2/">Part 2</a></p>
<p><a href="http://patrickyong.net/2010/07/26/hello-orchard-part-3working-with-data/">Part 3</a></p>
<p><a href="http://patrickyong.net/2010/07/26/orchard-content-type/">Part 4</a></p>
<p><a href="http://patrickyong.net/2010/07/26/hello-orchard-part-5attaching-a-part-to-content-type/">Part 5</a></p>
<p>In part 5, we talk about composing content type with parts to import commonly used properties such as Owner and Published Date. Now we want to reused UI in our view composition. According to the original walkthrough document on how UI composition works:-</p>
<p><a href="http://patrickyong.net/wp-content/uploads/2010/07/image34.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" class="wlDisabledImage" title="image" border="0" alt="image" src="http://patrickyong.net/wp-content/uploads/2010/07/image-thumb33.png" width="536" height="257" /></a></p>
<p><em>The idea behind UI composition is that the view of a product (in our example, the editor view in the admin panel) should be assembled from the constituent views from all the attached parts. Each part defines its own view templates that expect a specific view model type to be passed to it. The obtain these view models, the Controller action calls the BuildXxxModel methods on ContentManager. The ContentManager delegates to ContentDriver types (one for each part) to retrieve the appropriate view models for each part. The ContentManager then aggregates those into a single view model that is handed back to the Controller. What is actually passed back from the ContentDriver is a ContentPartTemplate object – the view, the model for that view, and the zone and location/position within the zone to render the part (note that the zone/position information will eventually be driven from metadata/templates instead of code).</em></p>
<p> 
<p>Let’s get started</p>
<p>1. First of all, add reference to Orchard.Tags and Orchard.Comments</p>
<p><a href="http://patrickyong.net/wp-content/uploads/2010/07/image35.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" class="wlDisabledImage" title="image" border="0" alt="image" src="http://patrickyong.net/wp-content/uploads/2010/07/image-thumb34.png" width="302" height="474" /></a></p>
<p>2. Then let’s enable the “Comments” and “Tags” part for our ProductHandler:</p>
<pre>using Orchard.Tags.Models;using Orchard.Comments.Models;</pre>
<pre>public ProductHandler(IRepository&lt;ProductRecord&gt; repository)&#160;&#160;&#160;&#160;&#160;&#160;&#160; {&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Filters.Add(new ActivatingFilter&lt;Product&gt;(ProductHandler.ContentType.Name));&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Filters.Add(new ActivatingFilter&lt;Orchard.Core.Common.Models.CommonPart&gt;(ProductHandler.ContentType.Name));&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font style="background-color: #ffff00">Filters.Add(new ActivatingFilter&lt;CommentsPart&gt;(ProductHandler.ContentType.Name));&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Filters.Add(new ActivatingFilter&lt;TagsPart&gt;(ProductHandler.ContentType.Name));</font>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Filters.Add(StorageFilter.For(repository));&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</pre>
<p>&#160;</p>
<p>For now, the association of content parts is done in code. However, eventually this will move to a metadata system that enables association of parts to items on-the-fly, using the Orchard admin panel instead of writing code to do this. This would enable our Product type to be completely independent, with no compile-time dependency on specific parts.</p>
<p>2. Now let’s update the “Create” method of our AdminController to create the ContentItemViewModel for the product:</p>
<pre>public ActionResult Create(){&#160; var product = _contentManager.New&lt;Product&gt;(&quot;product&quot;);   var model = _contentManager.BuildEditorModel(product);   return View(model);}</pre>
<p>3. We also need to update the “Create.ascx” view to use the “ContentItemViewModel” and dispatch the form composition to the Orchard HtmlHelper.</p>
<pre>&lt;%@ Control Language=&quot;C#&quot; Inherits=&quot;Orchard.Mvc.ViewUserControl&lt;Orchard.Mvc.ViewModels.ContentItemViewModel&lt;Orchard.Commerce.Models.Product&gt;&gt;&quot; %&gt;&lt;h1&gt;&#160;&#160;&#160; &lt;%=Html.TitleForPage(T(&quot;Create Product&quot;).ToString()) %&gt;&lt;/h1&gt;&lt;% using (Html.BeginFormAntiForgeryPost())&#160;&#160; { %&gt;&lt;%=Html.ValidationSummary() %&gt;&lt;%=Html.EditorForModel(Model)%&gt;&lt;fieldset&gt;&#160;&#160;&#160; &lt;input type=&quot;submit&quot; value=&quot;Create&quot; /&gt;&lt;/fieldset&gt;&lt;% } %&gt;&lt;div&gt;&#160;&#160;&#160; &lt;p&gt;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;%=Html.ActionLink(&quot;Back to List&quot;, &quot;Index&quot;) %&gt;&lt;/p&gt;&lt;/div&gt;</pre>
<p>4. Next, we will define a driver and template for the Product type that participates in this UI composition process. </p>
<p>Create a new Drivers folder and then add a new ProductDriver class (that derives from ContentItemDriver). This class is responsible for returning the appropriate view model, template, and location for the various views of a Product (in our example, the editor view):</p>
<pre>using System;using System.Collections.Generic;using System.Linq;using System.Web;using Orchard.ContentManagement.Drivers;using Orchard.Commerce.Models;using Orchard.ContentManagement;

namespace Orchard.Commerce.Drivers{&#160;&#160;&#160; public class ProductDriver : ContentItemDriver&lt;Product&gt;&#160;&#160;&#160; {

&#160;&#160;&#160;&#160;&#160;&#160;&#160; protected override bool UseDefaultTemplate { get { return true; } }

&#160;&#160;&#160;&#160;&#160;&#160;&#160; protected override DriverResult Display(Product product, string displayType)&#160;&#160;&#160;&#160;&#160;&#160;&#160; {&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; return ContentPartTemplate(product, &quot;Product.Fields&quot;).Location(&quot;primary&quot;, &quot;1&quot;);&#160;&#160;&#160;&#160;&#160;&#160;&#160; }

&#160;&#160;&#160;&#160;&#160;&#160;&#160; //GET&#160;&#160;&#160;&#160;&#160;&#160;&#160; protected override DriverResult Editor(Product product)&#160;&#160;&#160;&#160;&#160;&#160;&#160; {&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; return ContentPartTemplate(product, &quot;Product.Fields&quot;).Location(&quot;primary&quot;, &quot;3&quot;);&#160;&#160;&#160;&#160;&#160;&#160;&#160; }

&#160;&#160;&#160;&#160;&#160;&#160;&#160; //POST&#160;&#160;&#160;&#160;&#160;&#160;&#160; protected override DriverResult Editor(Product part, IUpdateModel updater)&#160;&#160;&#160;&#160;&#160;&#160;&#160; {&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; updater.TryUpdateModel(part, Prefix, null, null);&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; return Editor(part);&#160;&#160;&#160;&#160;&#160;&#160;&#160; }&#160;&#160;&#160; }}</pre>
<p>This code says that the template to use for displaying the product is “Product.Fields”. Notice how we pass the “products” instance as the view model for that template. We also mention it’s going to be displayed in the “primary” zone, at the top of the zone (position=”1”).</p>
<p>5. Let’s now create “Product.Fields.ascx” under the Commerce &gt; Views &gt; EditorTemplates folder. This is essentially the same as our former “Create” view, which displayed the editors for properties for the Product type.<br />
  <br /><a href="http://patrickyong.net/wp-content/uploads/2010/07/clip-image0022.jpg"><img style="border-right-width: 0px; margin: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="clip_image002" border="0" alt="clip_image002" src="http://patrickyong.net/wp-content/uploads/2010/07/clip-image002-thumb2.jpg" width="224" height="162" /></a></p>
<pre>&lt;%@ Control Language=&quot;C#&quot; Inherits=&quot;System.Web.Mvc.ViewUserControl&lt;Orchard.Commerce.Models.Product&gt;&quot; %&gt;&lt;fieldset&gt;&#160;&#160;&#160; &lt;legend&gt;Fields&lt;/legend&gt;&#160;&#160;&#160; &lt;%=Html.HiddenFor(model=&gt;model.Id) %&gt;&#160;&#160;&#160; &lt;div class=&quot;editor-label&quot;&gt;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;%= Html.LabelFor(model =&gt; model.Sku) %&gt;&#160;&#160;&#160; &lt;/div&gt;&#160;&#160;&#160; &lt;div class=&quot;editor-field&quot;&gt;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;%= Html.TextBoxFor(model =&gt; model.Sku)%&gt;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;%= Html.ValidationMessageFor(model =&gt; model.Sku)%&gt;&#160;&#160;&#160; &lt;/div&gt;&#160;&#160;&#160; &lt;div class=&quot;editor-label&quot;&gt;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;%= Html.LabelFor(model =&gt; model.Description)%&gt;&#160;&#160;&#160; &lt;/div&gt;&#160;&#160;&#160; &lt;div class=&quot;editor-field&quot;&gt;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;%= Html.TextBoxFor(model =&gt; model.Description)%&gt;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;%= Html.ValidationMessageFor(model =&gt; model.Description)%&gt;&#160;&#160;&#160; &lt;/div&gt;&#160;&#160;&#160; &lt;div class=&quot;editor-label&quot;&gt;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;%= Html.LabelFor(model =&gt; model.Price) %&gt;&#160;&#160;&#160; &lt;/div&gt;&#160;&#160;&#160; &lt;div class=&quot;editor-field&quot;&gt;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;%= Html.TextBoxFor(model =&gt; model.Price) %&gt;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;%= Html.ValidationMessageFor(model =&gt; model.Price) %&gt;&#160;&#160;&#160; &lt;/div&gt;&lt;/fieldset&gt;</pre>
<p>6. Type Ctrl-F5 to build and run the site.</p>
<p>Now when we click on “Create new Product” link, we see a form which contains the fields of the products, but also tags, comments and owner fields.</p>
<p><a href="http://patrickyong.net/wp-content/uploads/2010/07/clip-image0043.jpg"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="clip_image004" border="0" alt="clip_image004" src="http://patrickyong.net/wp-content/uploads/2010/07/clip-image004-thumb3.jpg" width="580" height="462" /></a></p>
<p>7. The last thing we need to do is re-implement the “Create” “Post” action in AdminController.cs:</p>
<pre>[HttpPost]&#160;&#160;&#160;&#160;&#160;&#160;&#160; public ActionResult Create(FormCollection input)&#160;&#160;&#160;&#160;&#160;&#160;&#160; {&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; var product = _contentManager.New&lt;Product&gt;(&quot;product&quot;);&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; var model = _contentManager.UpdateEditorModel(product, this);

&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; if (!ModelState.IsValid)&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; {&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; return View(model);&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }

&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; _contentManager.Create(product);&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; return RedirectToAction(&quot;Index&quot;);&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</pre>
<p>Note the “this” parameter, passed to UpdateEditorModel. To enable validation of the model, we need an interface between the MVC controller and the content drivers. We are going to implement this interface in the “AdminController” itself, by simply delegating the default MVC base class.</p>
<pre>using Orchard.Localization;

namespace Orchard.Commerce.Controllers{&#160;&#160;&#160; [Admin]&#160;&#160;&#160; [Themed]&#160;&#160;&#160; public class AdminController : Controller, IUpdateModel&#160;&#160;&#160; {&#160;&#160;&#160;&#160;&#160;&#160;&#160; bool IUpdateModel.TryUpdateModel&lt;TModel&gt;(TModel model, string prefix, string[] includeProperties, string[] excludeProperties)&#160;&#160;&#160;&#160;&#160;&#160;&#160; {&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; return TryUpdateModel(model, prefix, includeProperties, excludeProperties);&#160;&#160;&#160;&#160;&#160;&#160;&#160; }

&#160;&#160;&#160;&#160;&#160;&#160;&#160; void IUpdateModel.AddModelError(string key, LocalizedString errorMessage)&#160;&#160;&#160;&#160;&#160;&#160;&#160; {&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; ModelState.AddModelError(key, errorMessage.ToString());&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</pre>
<p>The update/validation of the model is going through the ContentManager, to all the content drivers, and then back to our AdminController. The last thing we need to do is implement the model update/validation for the “Product” part. We do that in the ProductDriver:</p>
<pre>protected override DriverResult Editor(Product part, IUpdateModel updater){&#160;&#160;&#160; updater.TryUpdateModel(part, Prefix, null, null);&#160;&#160;&#160; return Editor(part);}</pre>
<p>8. Type Ctrl-F5 to build and run the site.</p>
<p>We can now create a new product, including model validation!</p>
<p><a href="http://patrickyong.net/wp-content/uploads/2010/07/clip-image0061.jpg"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image006" border="0" alt="clip_image006" src="http://patrickyong.net/wp-content/uploads/2010/07/clip-image006-thumb1.jpg" width="557" height="396" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://patrickyong.net/2010/07/26/hello-orchard-6composing-view-using-different-content-parts/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Hello Orchard Part 5&#8211;Attaching a part to content type</title>
		<link>http://patrickyong.net/2010/07/26/hello-orchard-part-5attaching-a-part-to-content-type/</link>
		<comments>http://patrickyong.net/2010/07/26/hello-orchard-part-5attaching-a-part-to-content-type/#comments</comments>
		<pubDate>Mon, 26 Jul 2010 07:48:45 +0000</pubDate>
		<dc:creator>Patrick</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<category><![CDATA[asp.net mvc]]></category>

		<category><![CDATA[orchard]]></category>

		<guid isPermaLink="false">http://patrickyong.net/2010/07/26/hello-orchard-part-5attaching-a-part-to-content-type/</guid>
		<description><![CDATA[One of the coolest feature in Orchard is the ability to compose different content part together to make a complete content type. This promotes composite applications e.g. the comment content part with its logic and UI can be reused in different part of the application.
Part 5 of this tutorial will shows you how to attach [...]]]></description>
			<content:encoded><![CDATA[<p>One of the coolest feature in Orchard is the ability to compose different content part together to make a complete content type. This promotes composite applications e.g. the comment content part with its logic and UI can be reused in different part of the application.</p>
<p>Part 5 of this tutorial will shows you how to attach a Common part to the Product content type where this Common part contains properties like Published Data and Owner.</p>
<p>1. Add a reference to Orchard.Core</p>
<p><a href="http://patrickyong.net/wp-content/uploads/2010/07/image33.png"><img style="border-bottom: 0px; border-left: 0px; margin: 0px; display: inline; border-top: 0px; border-right: 0px" class="wlDisabledImage" title="image" border="0" alt="image" src="http://patrickyong.net/wp-content/uploads/2010/07/image-thumb32.png" width="244" height="94" /></a></p>
<p>2. Go to the ProductRecord.cs file and update it to include these namespaces:</p>
<pre>using System.ComponentModel.DataAnnotations;using Orchard.Core.Common.Models;</pre>
<p>Now, let’s illustrate the power of the data composition story… We are going to add a “Common” part to the “Product” content type. The “Common” part is an Orchard extension which automatically keeps track of Owner, Container, CreationDate, etc. for content items.</p>
<p>Here is the definition of the ICommonAspect interface (no need to type this – it’s already defined by Orchard in the Orchard.Core.Common.Models namespace). Once we add this part to our Product type, the CommonAspect data will be saved (as a “Content Part”) with each instance of “Product”.</p>
<p>public interface ICommonAspect : IContent {</p>
<p>IUser Owner { get; set; }</p>
<p>IContent Container { get; set; }</p>
<p>DateTime? CreatedUtc { get; set; }</p>
<p>DateTime? PublishedUtc { get; set; }</p>
<p>DateTime? ModifiedUtc { get; set; }</p>
<p>DateTime? VersionCreatedUtc { get; set; }</p>
<p>DateTime? VersionPublishedUtc { get; set; }</p>
<p>DateTime? VersionModifiedUtc { get; set; }</p>
<p>}</p>
<p>3. Change the ProductHandler class to add a “CommonPart” (was called CommonAspect) part to the “Product” content type:</p>
<pre>using Orchard.ContentManagement.Handlers;using Orchard.ContentManagement;using Orchard.Commerce.Models;using Orchard.Data;using Orchard.Core.Common.Models;

namespace Orchard.Commerce.Handlers{&#160;&#160;&#160; public class ProductHandler : ContentHandler&#160;&#160;&#160; {&#160;&#160;&#160;&#160;&#160;&#160;&#160; public readonly static ContentType ContentType = new ContentType&#160;&#160;&#160;&#160;&#160;&#160;&#160; {&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Name = &quot;product&quot;,&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; DisplayName = &quot;Product&quot;&#160;&#160;&#160;&#160;&#160;&#160;&#160; };

&#160;&#160;&#160;&#160;&#160;&#160;&#160; public ProductHandler(IRepository&lt;ProductRecord&gt; repository)&#160;&#160;&#160;&#160;&#160;&#160;&#160; {&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Filters.Add(new ActivatingFilter&lt;Product&gt;(ProductHandler.ContentType.Name));&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font style="background-color: #ffff00"> Filters.Add(new ActivatingFilter&lt;Orchard.Core.Common.Models.CommonPart&gt;(ProductHandler.ContentType.Name));</font>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Filters.Add(StorageFilter.For(repository));&#160;&#160;&#160;&#160;&#160;&#160;&#160; }

&#160;&#160;&#160; }}</pre>
<p>That’s it! Now, whenever a “Product” is going to be manipulated by the application, a “CommonAspect” will go with it. Under the hood, the content manager will activate the “CommonAspect” part when “Products” are activated. The “CommonAspect” implementation will keep track of creation date, modification date and publication dates automatically for us.</p>
<p>3. Let’s illustrate that by displaying the “Created”, “Published” date for each product in the Index.ascx view. Add these 2 lines at the beginning of the file:</p>
<pre>&lt;%@ Import Namespace=&quot;Orchard.Core.Common.Models&quot;%&gt;&lt;%@ Import Namespace=&quot;Orchard.ContentManagement&quot;%&gt;</pre>
<p>a. Add “Created” and “Published” columns:</p>
<pre>&lt;th&gt;   Created&lt;/th&gt;&lt;th&gt;&#160;&#160; Published&lt;/th&gt;</pre>
<p>b. Access to the “Created” and “Published” dates as follows:</p>
<pre>&lt;td&gt;   &lt;%= Html.Encode(String.Format(&quot;{0}&quot;, item.As&lt;CommonPart&gt;().CreatedUtc))%&gt;&lt;/td&gt;&lt;td&gt;   &lt;%= Html.Encode(String.Format(&quot;{0}&quot;, item.As&lt;CommonPart&gt;().PublishedUtc)) %&gt;&lt;/td&gt;</pre>
<p>4. Type Ctrl-F5 to build and run in Visual Studio. </p>
<p><strike>Note: If you don’t empty the database at this point, the product created until now will have no “Common” data value. Orchard doesn’t have a story for database upgrade for now. To reset the database (destroy all data for the site), delete the App_Data/Sites folder in your project. You may need to “Show All Files” in Visual Studio’s Solution Explorer before you can see this folder. After deleting the database, you’ll need to walk through the Orchard setup screen again.</strike></p>
<p>Previously the tutorial would ask you to empty the database and recreate the website again. But with the latest data migration facility you need not do so. Just go to Site Configuration –&gt; Dev Tools and trigger the Update Database command.</p>
<p>Notice how the table now shows created and published dates (they have been setup automatically by the content manager, stored in a “Common” aspect table).</p>
<p><a href="http://patrickyong.net/wp-content/uploads/2010/07/clip-image0021.jpg"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image002" border="0" alt="clip_image002" src="http://patrickyong.net/wp-content/uploads/2010/07/clip-image002-thumb1.jpg" width="574" height="175" /></a></p>
<p>Let’s look at what happens when a product instance is created. Set a debug breakpoint in “AdminController.Create” action, on the line of code that invokes _contentManager.Create(product). Type F5 in Visual Studio to begin debugging, and then create a new product using the admin panel in order to hit the breakpoint:</p>
<p><a href="http://patrickyong.net/wp-content/uploads/2010/07/clip-image0042.jpg"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image004" border="0" alt="clip_image004" src="http://patrickyong.net/wp-content/uploads/2010/07/clip-image004-thumb2.jpg" width="572" height="366" /></a></p>
<p>The “Product” content item has 2 parts: the Product part and the “CommonPart” part. If we look at the data maintained by the “CommonPart”, we see that everything is taken care of internally. Here is the “Product” instance after the call to “Create” of content manager:</p>
<p><a href="http://patrickyong.net/wp-content/uploads/2010/07/clip-image006.jpg"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image006" border="0" alt="clip_image006" src="http://patrickyong.net/wp-content/uploads/2010/07/clip-image006-thumb.jpg" width="569" height="270" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://patrickyong.net/2010/07/26/hello-orchard-part-5attaching-a-part-to-content-type/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Orchard Content Type</title>
		<link>http://patrickyong.net/2010/07/26/orchard-content-type/</link>
		<comments>http://patrickyong.net/2010/07/26/orchard-content-type/#comments</comments>
		<pubDate>Sun, 25 Jul 2010 18:02:46 +0000</pubDate>
		<dc:creator>Patrick</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<category><![CDATA[asp.net mvc]]></category>

		<category><![CDATA[orchard]]></category>

		<guid isPermaLink="false">http://patrickyong.net/2010/07/26/orchard-content-type/</guid>
		<description><![CDATA[This is part 4 of my walkthrough document for project Orchard based on the document released in March 2010. Check out here for previous posts – Part 1 Hello World, Part 2 Hocking up admin page, Part 3 Working with data
What is Content Type
Orchard Content Type maybe somewhat similar to SharePoint content type conceptually but [...]]]></description>
			<content:encoded><![CDATA[<p>This is part 4 of my walkthrough document for project Orchard based on the document released in March 2010. Check out here for previous posts – <a href="http://patrickyong.net/2010/07/25/hello-orchard-creating-a-orchard-module-using-latest-source-code/">Part 1 Hello World</a>, Part <a href="http://patrickyong.net/2010/07/25/hello-orchard-part-2/">2 Hocking up admin page</a>, <a href="http://patrickyong.net/2010/07/26/hello-orchard-part-3working-with-data/">Part 3 Working with data</a></p>
<h3>What is Content Type</h3>
<p>Orchard Content Type maybe somewhat similar to SharePoint content type conceptually but architecturally its apple and orange. According to the walkthrough document, an Orchard Content Type is:-</p>
<p><em>Rather than work with database records directly, let’s start using some of the higher-level abstractions that Orchard CMS offers. Fundamental to the Orchard CMS is the idea of multiple content types – the built-in pages and posts types are examples….</em></p>
<p>Most importantly:</p>
<p><em>…we will take advantage of it in the next section, when we explore composition of additional “parts” on the content types (the way that comments and tags are parts applied to pages and posts). Assembling the data and UI of the application from multiple types and parts allows the system to remain loosely coupled and allows installed modules to extend each others types in interesting ways.</em></p>
<p><b><i>Objectives:</i></b></p>
<p>1. Create a Product content type</p>
<p>2. Add a ProductHandler for Product type</p>
<p>a. Associate repository and ProductRecord type</p>
<p>b. Associate Product type to content type name</p>
<p><b><i>Follow These Steps:</i></b></p>
<p>1. Go to the ProductRecord.cs file and update it to inherites ContentPartRecord &lt;Note that I removed the ID property because the base class already has one&gt;:</p>
<pre>using System.ComponentModel.DataAnnotations;using System.Web.Mvc;using Orchard.Data;using Orchard.ContentManagement;using Orchard.ContentManagement.Records;using Orchard.ContentManagement.Handlers;

namespace Orchard.Commerce.Models{

&#160;&#160;&#160; public class ProductRecord: ContentPartRecord&#160; &#160;&#160;&#160; {

&#160;&#160;&#160;&#160;&#160;&#160;&#160; [Required]&#160;&#160;&#160;&#160;&#160;&#160;&#160; public virtual string Sku { get; set; }

&#160;&#160;&#160;&#160;&#160;&#160;&#160; [Required]&#160;&#160;&#160;&#160;&#160;&#160;&#160; public virtual string Description { get; set; }

&#160;&#160;&#160;&#160;&#160;&#160;&#160; [Required]&#160;&#160;&#160;&#160;&#160;&#160;&#160; public virtual decimal Price { get; set; }

&#160;&#160;&#160; }

}
</pre>
<p>2. Add a Product.cs file in the Model folder.</p>
<pre>using System;using System.Collections.Generic;using System.Linq;using System.Web;using Orchard.ContentManagement;using System.ComponentModel.DataAnnotations;

namespace Orchard.Commerce.Models{&#160;&#160;&#160; public class Product : ContentPart&lt;ProductRecord&gt;&#160;&#160;&#160; {&#160;&#160;&#160;&#160;&#160;&#160;&#160; public int Id&#160;&#160;&#160;&#160;&#160;&#160;&#160; {&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; get { return Record.Id; }&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; set { Record.Id = value; }&#160;&#160;&#160;&#160;&#160;&#160;&#160; }

&#160;&#160;&#160;&#160;&#160;&#160;&#160; [Required]&#160;&#160;&#160;&#160;&#160;&#160;&#160; public string Sku&#160;&#160;&#160;&#160;&#160;&#160;&#160; {&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; get { return Record.Sku; }&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; set { Record.Sku = value; }&#160;&#160;&#160;&#160;&#160;&#160;&#160; }

&#160;&#160;&#160;&#160;&#160;&#160;&#160; [Required]&#160;&#160;&#160;&#160;&#160;&#160;&#160; public string Description&#160;&#160;&#160;&#160;&#160;&#160;&#160; {&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; get { return Record.Description; }&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; set { Record.Description = value; }&#160;&#160;&#160;&#160;&#160;&#160;&#160; }

&#160;&#160;&#160;&#160;&#160;&#160;&#160; [Required]&#160;&#160;&#160;&#160;&#160;&#160;&#160; public decimal Price&#160;&#160;&#160;&#160;&#160;&#160;&#160; {&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; get { return Record.Price; }&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; set { Record.Price = value; }&#160;&#160;&#160;&#160;&#160;&#160;&#160; }&#160;&#160;&#160; } }</pre>
<p>Then create a Handlers folder and add a&#160; ProductHandler class</p>
<p><a href="http://patrickyong.net/wp-content/uploads/2010/07/image27.png"><img style="border-right-width: 0px; margin: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" class="wlDisabledImage" title="image" border="0" alt="image" src="http://patrickyong.net/wp-content/uploads/2010/07/image-thumb26.png" width="228" height="244" /></a></p>
<pre>using Orchard.ContentManagement.Handlers;using Orchard.ContentManagement;using Orchard.Commerce.Models;using Orchard.Data;

namespace Orchard.Commerce.Handlers{&#160;&#160;&#160; public class ProductHandler : ContentHandler&#160;&#160;&#160; {&#160;&#160;&#160;&#160;&#160;&#160;&#160; public readonly static ContentType ContentType = new ContentType&#160;&#160;&#160;&#160;&#160;&#160;&#160; {&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Name = &quot;product&quot;,&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; DisplayName = &quot;Product&quot;&#160;&#160;&#160;&#160;&#160;&#160;&#160; };

&#160;&#160;&#160;&#160;&#160;&#160;&#160; public ProductHandler(IRepository&lt;ProductRecord&gt; repository)&#160;&#160;&#160;&#160;&#160;&#160;&#160; {&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Filters.Add(new ActivatingFilter&lt;Product&gt;(ProductHandler.ContentType.Name));&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Filters.Add(StorageFilter.For(repository));&#160;&#160;&#160;&#160;&#160;&#160;&#160; }

&#160;&#160;&#160; }}</pre>
<p>The Product type is an Orchard content type, using ProductRecord for storage. For convenience, we’ve wrapped the properties of the record on the Product type, but this is optional, as the Product type also exposes these properties directly from its Record property, for example Product.Record.SKU. The ProductHandler is responsible for registering the content type with the system, ensuring the the Product type is activated whenever a new “Product” content item is created, and associating the IRepository&lt;ProductRecord&gt; for storage.</p>
<p>We also need to update our Commerce admin pages to use the new content type instead of the record. To do this, we will go through the IContentManager interface to query for products instead of talking to the repository directly. The ContentManager is responsible for resolving the requested content type to a handler (in this case, ProductHandler) and instantiating the type for us.</p>
<p>3. In AdminController.cs…</p>
<p>a. Change all references from “ProductRecord” to “Product”…</p>
<p>b. Change all references to “IRepository&lt;ProductRecord&gt;” to “IContentManager”…</p>
<pre>using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.Mvc;

using Orchard.Themes;using Orchard.UI.Admin;using Orchard.ContentManagement;using Orchard.Data;using Orchard.Commerce.Models;

namespace Orchard.Commerce.Controllers{&#160;&#160;&#160; [Admin]&#160;&#160;&#160; [Themed]&#160;&#160;&#160; public class AdminController : Controller&#160;&#160;&#160; {

&#160;&#160;&#160;&#160;&#160;&#160;&#160; private readonly IContentManager _contentManager;

&#160;&#160;&#160;&#160;&#160;&#160;&#160; public AdminController(IContentManager contentManager)&#160;&#160;&#160;&#160;&#160;&#160;&#160; {&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; _contentManager = contentManager;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }

&#160;&#160;&#160;&#160;&#160;&#160;&#160; public ActionResult Index()&#160;&#160;&#160;&#160;&#160;&#160;&#160; {&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; return View(_contentManager.Query&lt;Product&gt;().List());&#160;&#160;&#160;&#160;&#160;&#160;&#160; }

&#160;&#160;&#160;&#160;&#160;&#160;&#160; public ActionResult Create()&#160;&#160;&#160;&#160;&#160;&#160;&#160; {&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; return View(_contentManager.New&lt;Product&gt;(&quot;product&quot;));&#160;&#160;&#160;&#160;&#160;&#160;&#160; }

&#160;&#160;&#160;&#160;&#160;&#160;&#160; [HttpPost]&#160;&#160;&#160;&#160;&#160;&#160;&#160; public ActionResult Create(FormCollection input)&#160;&#160;&#160;&#160;&#160;&#160;&#160; {&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; var product = _contentManager.New&lt;Product&gt;(&quot;product&quot;);

&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; if (!TryUpdateModel(product))&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; {&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; return View(product);&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }

&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; _contentManager.Create(product);

&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; return RedirectToAction(&quot;Index&quot;);&#160;&#160;&#160;&#160;&#160;&#160;&#160; }&#160;&#160;&#160; }}</pre>
<p>4. Change the “Create.ascx” view to use “Product” instead of “ProductRecord” in the first line (the view model):</p>
<pre>&lt;%@ Control Language=&quot;C#&quot; Inherits=&quot;System.Web.Mvc.ViewUserControl&lt;Orchard.Commerce.Models.Product&gt;&quot; %&gt;</pre>
<p>5. Change the “Index.ascx” view to use “Product” instead of “ProductRecord” in the first line (the view model):</p>
<pre>&lt;%@ Control Language=&quot;C#&quot; Inherits=&quot;System.Web.Mvc.ViewUserControl&lt;IEnumerable&lt;Orchard.Commerce.Models.Product&gt;&gt;&quot; %&gt;</pre>
<p>6. Type Ctrl-F5 to build and run in Visual Studio. And when you try to add a new product you will be hit by exception. This is because the database table schema has not been updated.</p>
<p><a href="http://patrickyong.net/wp-content/uploads/2010/07/image28.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" class="wlDisabledImage" title="image" border="0" alt="image" src="http://patrickyong.net/wp-content/uploads/2010/07/image-thumb27.png" width="600" height="160" /></a></p>
<p>7. Orchard introduces a concept of data migration so that whenever an ContentType is created user will be prompted to update the database via the administration page.</p>
<p>Now create a DataMigrations folder and add a ProductDataMigration class</p>
<pre>using Orchard.Data.Migration;

namespace Orchard.Commerce.DataMigrations{&#160;&#160;&#160; public class ProductDataMigration : DataMigrationImpl&#160;&#160;&#160; {&#160;&#160;&#160;&#160;&#160;&#160;&#160; public int Create()&#160;&#160;&#160;&#160;&#160;&#160;&#160; {&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; SchemaBuilder.CreateTable(&quot;ProductRecord&quot;, table =&gt; table&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; .ContentPartRecord()&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; .Column&lt;string&gt;(&quot;Sku&quot;)&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; .Column&lt;string&gt;(&quot;Description&quot;)&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; .Column&lt;string&gt;(&quot;Price&quot;)&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; );

&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; return 0010;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }&#160;&#160;&#160; }

}</pre>
<p>8. Hit Ctrl-F5 and go back to the admin page, you will notice a message on top of the dashboard.</p>
<p><a href="http://patrickyong.net/wp-content/uploads/2010/07/image29.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" class="wlDisabledImage" title="image" border="0" alt="image" src="http://patrickyong.net/wp-content/uploads/2010/07/image-thumb28.png" width="600" height="133" /></a> </p>
<p></p>
<p>9. Click on Site Configuration –&gt; Features. Notice that Orchard.Commerce is in red. Click on the Update command</p>
<p><a href="http://patrickyong.net/wp-content/uploads/2010/07/image30.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" class="wlDisabledImage" title="image" border="0" alt="image" src="http://patrickyong.net/wp-content/uploads/2010/07/image-thumb29.png" width="391" height="228" /></a></p>
<p>10. Surprisingly I am hit with a transaction error. </p>
<p><a href="http://patrickyong.net/wp-content/uploads/2010/07/image31.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" class="wlDisabledImage" title="image" border="0" alt="image" src="http://patrickyong.net/wp-content/uploads/2010/07/image-thumb30.png" width="598" height="343" /></a> </p>
<p></p>
<p>11. So I found a workaround by renaming the table first from Orchard_Commerce_Product to Orchard_Commerce_Product_bck</p>
<p>12. And I went back to click on Upgrade again. The table migrated successful. </p>
<p><a href="http://patrickyong.net/wp-content/uploads/2010/07/image32.png"><img style="border-bottom: 0px; border-left: 0px; margin: 0px; display: inline; border-top: 0px; border-right: 0px" class="wlDisabledImage" title="image" border="0" alt="image" src="http://patrickyong.net/wp-content/uploads/2010/07/image-thumb31.png" width="244" height="185" /></a></p>
<p>13. And I can start data entry for Products.</p>
<p><a href="http://patrickyong.net/wp-content/uploads/2010/07/image81.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" class="wlDisabledImage" title="image[8]" border="0" alt="image[8]" src="http://patrickyong.net/wp-content/uploads/2010/07/image8-thumb.png" width="596" height="88" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://patrickyong.net/2010/07/26/orchard-content-type/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Hello Orchard, Part 3&#8211;Working with Data</title>
		<link>http://patrickyong.net/2010/07/26/hello-orchard-part-3working-with-data/</link>
		<comments>http://patrickyong.net/2010/07/26/hello-orchard-part-3working-with-data/#comments</comments>
		<pubDate>Sun, 25 Jul 2010 16:33:06 +0000</pubDate>
		<dc:creator>Patrick</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<category><![CDATA[asp.net mvc]]></category>

		<category><![CDATA[orchard]]></category>

		<guid isPermaLink="false">http://patrickyong.net/2010/07/26/hello-orchard-part-3working-with-data/</guid>
		<description><![CDATA[This is the 3rd instalment of my attempts to modify and complete the original walkthrough of Orchard using the latest change set of the Orchard Framework. Check out part 1 and part 2 here.
Working with Data 
     Let’s now look at how to work with data. The objective for this section [...]]]></description>
			<content:encoded><![CDATA[<p>This is the 3rd instalment of my attempts to modify and complete the original <a href="http://orchardproject.net/privatedrops/orchardmodulewalkthrough.doc">walkthrough</a> of Orchard using the latest change set of the Orchard Framework. Check out <a href="http://patrickyong.net/2010/07/25/hello-orchard-creating-a-orchard-module-using-latest-source-code/">part 1</a> and <a href="http://patrickyong.net/2010/07/25/hello-orchard-part-2/">part 2</a> here.</p>
<h2>Working with Data </h2>
<p><b>     <br /></b>Let’s now look at how to work with data. The objective for this section is to create a ProductRecord type that is persisted to the database. We’ll then update the Commerce area admin pages to be able to list and create new products.</p>
<p><b><i>Objectives:</i></b></p>
<p>1. Create a ProductRecord type that is persisted to the database</p>
<p>2. Add admin pages for creating and listing products</p>
<p><b><i>Follow These Steps:</i></b></p>
<p>1. Create “ProductRecord.cs” in “Models” folder</p>
<p>
<pre class="csharpcode"><span class="kwrd">using</span> System.ComponentModel.DataAnnotations;
<span class="kwrd">using</span> System.Web.Mvc; 

<span class="kwrd">namespace</span> Orchard.Commerce.Models
{
     <span class="kwrd">public</span> <span class="kwrd">class</span> ProductRecord
    {
         <span class="kwrd">public</span> <span class="kwrd">virtual</span> <span class="kwrd">int</span> Id { get; set; }

         [Required]
        <span class="kwrd">public</span> <span class="kwrd">virtual</span> <span class="kwrd">string</span> Sku { get; set; }

         [Required]
        <span class="kwrd">public</span> <span class="kwrd">virtual</span> <span class="kwrd">string</span> Description { get; set; }

         [Required]
        <span class="kwrd">public</span> <span class="kwrd">virtual</span> <span class="kwrd">decimal</span> Price { get; set; }
     }
 }</pre>
<style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<p></p>
<p>&#160; </p>
<p>Orchard generally favors convention over configuration, and in the example above, there are a few conventions at work. First, the *Record suffix on the class, coupled with the fact that the class lives under the *.Models namespace, tells Orchard this is a persistent class that should be backed by a database table. Second, the property named “Id” is conventionally used as the primary key for the record.</p>
<p>2. Add the “IRepository&lt;ProductRecord&gt;” to the AdminController. This is another example of using dependency injection to receive access to services (in this case, the database). </p>
<pre class="csharpcode"><span class="kwrd">using</span> Orchard.Data;

<span class="kwrd">using</span> Orchard.Commerce.Models;</pre>
<pre class="csharpcode">    [Admin]
    [Themed]
    <span class="kwrd">public</span> <span class="kwrd">class</span> AdminController : Controller
    {
        <span class="kwrd">private</span> <span class="kwrd">readonly</span> IRepository&lt;ProductRecord&gt; _repository;

         <span class="kwrd">public</span> AdminController(IRepository&lt;ProductRecord&gt; repository)
        {
            _repository = repository;
        }

         <span class="rem">//</span>
        <span class="rem">// GET: /Admin/</span>
         <span class="kwrd">public</span> ActionResult Index()
        {
            <span class="kwrd">return</span> View();
        }
     }</pre>
<style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<p>3. Create the 2 “Admin/Create” actions (typical MVC pattern for entity creation)</p>
<pre class="csharpcode"><span class="kwrd">public</span> ActionResult Create()
        {
            <span class="kwrd">return</span> View(<span class="kwrd">new</span> ProductRecord());
        }

         [HttpPost]
        <span class="kwrd">public</span> ActionResult Create(ProductRecord product)
        {
            <span class="kwrd">if</span> (!ModelState.IsValid)
            {
                <span class="kwrd">return</span> View(product);
            }

            _repository.Create(product);
            <span class="kwrd">return</span> RedirectToAction(<span class="str">&quot;Index&quot;</span>);
        }</pre>
<style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<p><b><i>Now, we are going to add the corresponding “Create” view… </i></b></p>
<p>4. Build the project first, so the ProductRecord type is available in the Add View dialog.</p>
<p>5. Right-click the Create action and choose “Add View…”</p>
<p>6. Select the “Create a partial view (.ascx)” option</p>
<p>7. Select the “Create a strongly-typed view” option and type “Orchard.Web.Areas.Commerce.Models.ProductRecord” for the View data class. Select “Create” as the View content.</p>
<p><a href="http://patrickyong.net/wp-content/uploads/2010/07/image21.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" class="wlDisabledImage" title="image" border="0" alt="image" src="http://patrickyong.net/wp-content/uploads/2010/07/image-thumb20.png" width="442" height="426" /></a></p>
<p>8. In the view markup/code, change the ID field to be hidden:</p>
<pre class="csharpcode"><span class="kwrd">&lt;</span><span class="html">div</span> <span class="attr">class</span><span class="kwrd">=&quot;editor-label&quot;</span><span class="kwrd">&gt;</span>
        <span class="asp">&lt;%</span>= Html.HiddenFor(model =&gt; model.Id) <span class="asp">%&gt;</span>
    <span class="kwrd">&lt;/</span><span class="html">div</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">div</span> <span class="attr">class</span><span class="kwrd">=&quot;editor-field&quot;</span><span class="kwrd">&gt;</span>
        <span class="asp">&lt;%</span>= Html.HiddenFor(model =&gt; model.Id) <span class="asp">%&gt;</span>
        <span class="asp">&lt;%</span>= Html.ValidationMessageFor(model =&gt; model.Id) <span class="asp">%&gt;</span>
    <span class="kwrd">&lt;/</span><span class="html">div</span><span class="kwrd">&gt;</span></pre>
<style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<p>9. Change Html.BeginForm to Html.BeginFormAntiForgeryPost<br />
  </p>
<pre class="csharpcode"><span class="asp">&lt;%@ Control Language=&quot;C#&quot; Inherits=&quot;System.Web.Mvc.ViewUserControl&lt;Orchard.Commerce.Models.ProductRecord&gt;&quot; %&gt;</span>
<span class="asp">&lt;%</span> <span class="kwrd">using</span> (Html.BeginFormAntiForgeryPost())   {<span class="asp">%&gt;</span>
<span class="asp">&lt;%</span>: Html.ValidationSummary(<span class="kwrd">true</span>) <span class="asp">%&gt;</span></pre>
<style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
</p>
<p>10. In AdminController.cs, update the Index() method to pass the list of Products from the repository:</p>
<pre class="csharpcode"><span class="kwrd">public</span> ActionResult Index()
{
     <span class="kwrd">return</span> View(_repository.Table);
}</pre>
<style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<p>11. Delete “Views\Admin\index.ascx” file (we are going to re-create it as a “List” view).</p>
<p>12. In AdminController.cs, right-click the “Index()” action and chose “Add View…” to recreate the “Index” view.</p>
<p>a. Choose the partial view option</p>
<p>b. Select the strongly-typed view option, typing “Orchard.Web.Areas.Commerce.Models.ProductRecord” for the View data class.</p>
<p>c. Select “List” as the View content.</p>
<p><a href="http://patrickyong.net/wp-content/uploads/2010/07/image22.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" class="wlDisabledImage" title="image" border="0" alt="image" src="http://patrickyong.net/wp-content/uploads/2010/07/image-thumb21.png" width="359" height="360" /></a></p>
<p>13. Open Index.ascx</p>
<p>d. Update the table class: &lt;table class=&quot;items&quot;&gt; (so it looks nice)</p>
<p>14. Type Ctrl-F5 to build and run the site in Visual Studio.</p>
<p>15. Go to the “Manage Products” admin page</p>
<p>NOTE: So far we have been following the steps in the original document, which should be OK. However with Devtools module added in recent change set, the database table for Product records does not get built automatically. In fact you will get an error message if you click on Manage Products. </p>
<p><a href="http://patrickyong.net/wp-content/uploads/2010/07/image23.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" class="wlDisabledImage" title="image" border="0" alt="image" src="http://patrickyong.net/wp-content/uploads/2010/07/image-thumb22.png" width="556" height="193" /></a></p>
<p>16. Login to admin module. Click on Site Configuration –&gt; Features and enable Orchard.DevTools module</p>
<p><a href="http://patrickyong.net/wp-content/uploads/2010/07/image24.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" class="wlDisabledImage" title="image" border="0" alt="image" src="http://patrickyong.net/wp-content/uploads/2010/07/image-thumb23.png" width="549" height="122" /></a></p>
<p>17. After the refresh you shall see Developer Tools under the Site Configuration menu, click on it. Then in the Dev Tools page, click on Database Migration</p>
<p>18. Then you are presented with only 1 menu item which is Update Database option. Click on it to start the table creation.</p>
<p><a href="http://patrickyong.net/wp-content/uploads/2010/07/image25.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" class="wlDisabledImage" title="image" border="0" alt="image" src="http://patrickyong.net/wp-content/uploads/2010/07/image-thumb24.png" width="378" height="264" /></a></p>
<p>19. Once you see the “Database Updated successfully” option, go back to the Admin page.</p>
<p>Then click on Manage Products under the Commerce menu. And Boo Yah! You will see the manage products page rendered nicely.</p>
<p><a href="http://patrickyong.net/wp-content/uploads/2010/07/image26.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" class="wlDisabledImage" title="image" border="0" alt="image" src="http://patrickyong.net/wp-content/uploads/2010/07/image-thumb25.png" width="562" height="116" /></a></p>
<p>20. You can create a product (with validation)</p>
<p>21. The “Index” view shows the list of product from the db:</p>
<p><b><a href="http://patrickyong.net/wp-content/uploads/2010/07/clip-image0041.jpg"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="clip_image004" border="0" alt="clip_image004" src="http://patrickyong.net/wp-content/uploads/2010/07/clip-image004-thumb1.jpg" width="547" height="194" /></a></b><b></b></p>
<p>22. Enter a few products to use as sample data…</p>
]]></content:encoded>
			<wfw:commentRss>http://patrickyong.net/2010/07/26/hello-orchard-part-3working-with-data/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Hello Orchard Part 2</title>
		<link>http://patrickyong.net/2010/07/25/hello-orchard-part-2/</link>
		<comments>http://patrickyong.net/2010/07/25/hello-orchard-part-2/#comments</comments>
		<pubDate>Sun, 25 Jul 2010 12:05:12 +0000</pubDate>
		<dc:creator>Patrick</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<category><![CDATA[asp.net mvc]]></category>

		<category><![CDATA[orchard]]></category>

		<guid isPermaLink="false">http://patrickyong.net/2010/07/25/hello-orchard-part-2/</guid>
		<description><![CDATA[Find out more about Orchard and how to create a simple Hello World module using latest change set from Codeplex from my first post here.
In my 1st port, I build a very simple module that displays “Hello World” on the front-end using the applied Orchard theme. We’ll also wire up the navigation menu to our [...]]]></description>
			<content:encoded><![CDATA[<p>Find out more about Orchard and how to create a simple Hello World module using latest change set from Codeplex from my first post <a href="http://patrickyong.net/2010/07/25/hello-orchard-creating-a-orchard-module-using-latest-source-code/">here</a>.</p>
<p>In my 1st port, I build a very simple module that displays “Hello World” on the front-end using the applied Orchard theme. We’ll also wire up the navigation menu to our module’s routes.</p>
<h2>Hooking into the Admin Panel</h2>
<p>The next thing we want to do is wire up our custom module to the admin panel, so we have a way to perform administration tasks on the back-end.</p>
<p><b><i>Objectives:</i></b></p>
<p>1. Add an admin panel page for the custom area</p>
<p>2. Add a menu item to the admin panel for the custom area</p>
<p><b><i>Follow These Steps:</i></b></p>
<p>1. Open up Orchard.Commerce project and right-click the “Controllers” folder and choose “Add &gt; Controller…”</p>
<p>2. Type “AdminController” for the controller name and click [OK].</p>
<p>3. Add the following namespaces and attributes on the controller class:</p>
<pre class="csharpcode"><span class="kwrd">using</span> Orchard.Themes;
<span class="kwrd">using</span> Orchard.UI.Admin; 

<span class="kwrd">namespace</span> Orchard.Commerce.Controllers{
    [Admin]
    [Themed]
    <span class="kwrd">public</span> <span class="kwrd">class</span> AdminController : Controller</pre>
<style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<p>4. Right-click on the “Index()” method name and choose “Add View…”</p>
<p>5. Selected the “Create a partial view” option and click [Add]</p>
<p>6. Add the following HTML to the View page: &lt;p&gt;Commerce Area Admin&lt;/p&gt;</p>
<p>7. Type Ctrl-F5 to build and run in VS.</p>
<p>8. Navigate to this URL in the browser: http://localhost:&lt;port&gt;/Admin/Commerce </p>
<p><a href="http://patrickyong.net/wp-content/uploads/2010/07/clip-image002.jpg"><img style="border-right-width: 0px; margin: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="clip_image002" border="0" alt="clip_image002" src="http://patrickyong.net/wp-content/uploads/2010/07/clip-image002-thumb.jpg" width="244" height="119" /></a></p>
<p>ð Note that you will need to log in as admin before you can view this page. By convention, controllers named “Admin*” are protected from access by anonymous site visitors.</p>
<p><b><i>Hooking into the admin menu…</i></b></p>
<p>1. Add a reference to Orchard.Pages project</p>
<p><a href="http://patrickyong.net/wp-content/uploads/2010/07/image20.png"><img style="border-right-width: 0px; margin: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" class="wlDisabledImage" title="image" border="0" alt="image" src="http://patrickyong.net/wp-content/uploads/2010/07/image-thumb19.png" width="244" height="137" /></a></p>
<p>1. Add an AdminMenu.cs file to the root of the “OrchardCommerce” project. For convenience, you may copy this from another module folder (and change the namespace and area name appropriately).</p>
<p><pre class="csharpcode"><span class="kwrd">using</span> Orchard.Pages.Services;
<span class="kwrd">using</span> Orchard.UI.Navigation;
<span class="kwrd">using</span> Orchard.Localization; 

<span class="kwrd">namespace</span> Orchard.Web.Areas.Commerce{
    <span class="kwrd">public</span> <span class="kwrd">class</span> AdminMenu : INavigationProvider
    {
         <span class="kwrd">public</span> Localizer T { get; set; }
         <span class="kwrd">private</span> <span class="kwrd">readonly</span> IPageService _pageService;
         <span class="kwrd">public</span> AdminMenu(IPageService pageService)
        {
            _pageService = pageService;
        }

         <span class="kwrd">public</span> <span class="kwrd">string</span> MenuName { get { <span class="kwrd">return</span> <span class="str">&quot;admin&quot;</span>; } }

         <span class="kwrd">public</span> <span class="kwrd">void</span> GetNavigation(NavigationBuilder builder)
        {
            builder.Add(T(<span class="str">&quot;Commerce&quot;</span>), <span class="str">&quot;20&quot;</span>,
                menu =&gt; menu
                        .Add(T(<span class="str">&quot;Manage Products&quot;</span>), <span class="str">&quot;1.0&quot;</span>,
                            item =&gt; item
                                .Action(<span class="str">&quot;Index&quot;</span>, <span class="str">&quot;Admin&quot;</span>, <span class="kwrd">new</span> { area = <span class="str">&quot;Orchard.Commerce&quot;</span> })));
        }
    }
 }</pre>
<style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<p></p>
<p>2. Type Ctrl-F5 to build and run in VS.</p>
<p>3. Navigate to this URL in the browser: http://localhost:&lt;port&gt;/Admin </p>
<p><a href="http://patrickyong.net/wp-content/uploads/2010/07/clip-image004.jpg"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="clip_image004" border="0" alt="clip_image004" src="http://patrickyong.net/wp-content/uploads/2010/07/clip-image004-thumb.jpg" width="152" height="244" /></a></p>
<p>Orchard uses dependency injection to provide services to the application. In the example above, the INavigationProvider interface derives from IDependency. Simply by including a constructor that accepts INavigationProvider as a parameter, an implementation of this interface will be provided by the application framework to this class when it is constructed. We use this interface to define a main menu item for our Commerce &gt; Manage Products screen. In the next section, we will see dependency injection again when we use the IRepository interface to access the database.</p>
]]></content:encoded>
			<wfw:commentRss>http://patrickyong.net/2010/07/25/hello-orchard-part-2/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Hello Orchard - Creating a Orchard module using latest source code</title>
		<link>http://patrickyong.net/2010/07/25/hello-orchard-creating-a-orchard-module-using-latest-source-code/</link>
		<comments>http://patrickyong.net/2010/07/25/hello-orchard-creating-a-orchard-module-using-latest-source-code/#comments</comments>
		<pubDate>Sun, 25 Jul 2010 09:35:07 +0000</pubDate>
		<dc:creator>Patrick</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<category><![CDATA[asp.net mvc]]></category>

		<category><![CDATA[azure]]></category>

		<category><![CDATA[orchard]]></category>

		<guid isPermaLink="false">http://patrickyong.net/2010/07/25/hello-orchard-creating-a-orchard-module-using-latest-source-code/</guid>
		<description><![CDATA[What is Orchard?

Project Orchard is the latest open source CMS project by folks in Microsoft based on ASP.NET MVC platform. It has some relationship with project Oxite which is another CMS used by the MIX event website. You can read more about Orchard from the official website here. And you can also check out the [...]]]></description>
			<content:encoded><![CDATA[<h2>What is Orchard?</h2>
<p><img src="http://download.codeplex.com/Project/Download/FileDownload.aspx?ProjectName=orchard&amp;DownloadId=91632&amp;Build=16983" /></p>
<p>Project Orchard is the latest open source CMS project by folks in Microsoft based on ASP.NET MVC platform. It has some relationship with project Oxite which is another CMS used by the MIX event website. You can read more about Orchard from the official website <a href="http://www.orchardproject.net/">here</a>. And you can also check out the official download as well as the latest build from <a href="http://orchard.codeplex.com/">Codeplex</a>. It is light weight where you can do copy-paste deployment onto shared webhosting, doesn’t require SQL Server to run yet at the same time you can add functionalities as a Orchard Module.</p>
<p>&#160;</p>
<h3><strong>Official Download</strong></h3>
<p>The official download dates back to March 2010 at the time of MIX 2010. The feature sets are primitive and less composite than what’s in the <a href="http://www.orchardproject.net/docs/feature-roadmap.ashx">roadmap</a>. It has been 4 months since the release and the team will release a official Alpha release by end of July 2010.</p>
<p>Having said that, the March release comes with a walkthrough which you can follow to build a customized module for Orchard. You can check out the walkthrough here.</p>
<p><a href="http://orchard.codeplex.com/releases/view/42040">March 2010 release</a></p>
<p><a href="http://orchardproject.net/privatedrops/orchardmodulewalkthrough.doc">Walkthrough Document</a></p>
<p><a href="http://www.msteched.com/2010/NorthAmerica/WEB202">Video walkthrough</a></p>
<p><strong></strong></p>
<h3><strong>Latest Build</strong></h3>
<p>In the true spirit of open source, the Orchard team chose Mercurial instead of Team Foundation Server to be the source code host of the project. Codeplex supports both source control systems maybe because of some non-.NET or non-Windows hosted there. </p>
<p>In the March 2010 release Modules are actually ASP.NET MVC 2 Area where else in the latest build, they are individual ASP.NET MVC Web App. The new module design makes Orchard more suitable for composition and multi tenancy, in a way like SharePoint features.</p>
<p>Because of this architecture change, the walkthrough mentioned above does not work with the latest build. So in this and subsequent blog post, I will share more about creating a customized module for latest build of Orchard</p>
<h3><strong>Downloading latest build</strong></h3>
<p>To get the latest build, you either download from the source tree using TortoiseHG which is a Windows based Mercurial client (<a href="http://codeplex.codeplex.com/Wikipage?title=Source%20Control%20Clients">instructions here</a>) or you can download the latest changeset from the source code page at <a href="http://orchard.codeplex.com/SourceControl/list/changesets">Codeplex</a>. </p>
<p><a href="http://patrickyong.net/wp-content/uploads/2010/07/image.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" class="wlDisabledImage" title="image" border="0" alt="image" src="http://patrickyong.net/wp-content/uploads/2010/07/image-thumb.png" width="368" height="447" /></a></p>
<p>Whenever you download source code packages as a zip file from the Web, remember to ‘unblock’ it from the file property page else Visual Studio will give you a not trusted source warning message which can be annoying at times.</p>
<p><a href="http://patrickyong.net/wp-content/uploads/2010/07/image1.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" class="wlDisabledImage" title="image" border="0" alt="image" src="http://patrickyong.net/wp-content/uploads/2010/07/image-thumb1.png" width="502" height="178" /></a></p>
<p>&#160;</p>
<h3><strong>Understand the Orchard architecture</strong></h3>
<p>I won’t dwell too deep into this as <a href="http://weblogs.asp.net/bleroy/archive/2010/06/15/how-orchard-works.aspx">Bertrand Le Roy</a> wrote an extensive document titled How Orchard Works <a href="http://orchardproject.net/docs/Default.aspx?Page=How-Orchard-works&amp;NS=&amp;AspxAutoDetectCookieSupport=1">here</a>. Architects should read this document first to understand how things work.</p>
<h3><strong>Accessing the latest change set</strong></h3>
<p><a href="http://patrickyong.net/wp-content/uploads/2010/07/image2.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" class="wlDisabledImage" title="image" border="0" alt="image" src="http://patrickyong.net/wp-content/uploads/2010/07/image-thumb2.png" width="534" height="298" /></a></p>
<p>I downloaded the latest change set as of today and from Windows Explorer you will notice there are 2 Visual Studio solution file. Note also that it has been updated to support Visual Studio 2010 solution. You also note that there is a Windows Azure solution file here but let’s check this out in my future post.</p>
<p>The whole Orchard application framework is inside the Orchard folder while Orchard.Web is the ASP.NET project which can be hosted inside IIS. Let’s open up Orcahrd.sln using VS2010.</p>
<p><a href="http://patrickyong.net/wp-content/uploads/2010/07/image15.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" class="wlDisabledImage" title="image[15]" border="0" alt="image[15]" src="http://patrickyong.net/wp-content/uploads/2010/07/image15-thumb1.png" width="251" height="464" /></a></p>
<p>All in all there are more than 30 projects in project Orchard with Orchard.Core, Orchard.Framework and Orchard.Web at the center of this CMS. On top of that there are some core modules which Orchard needs such as the User, Pages, and Setup modules. </p>
<h3>Build and setup a sample site</h3>
<p>Orchard supports both SQL Server and SQLite database but for sake of debugging and troubleshooting I will choose SQL Server. Let’s create an empty database inside SQL Server called OrchardTutorialDB in the local SQL Express instance.</p>
<p><a href="http://patrickyong.net/wp-content/uploads/2010/07/image3.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" class="wlDisabledImage" title="image" border="0" alt="image" src="http://patrickyong.net/wp-content/uploads/2010/07/image-thumb3.png" width="544" height="240" /></a></p>
<p>Back to Visual Studio 2010 with the project opened, press Ctrl-F5. IE will be opened and you will see the Orchard setup page</p>
<p><a href="http://patrickyong.net/wp-content/uploads/2010/07/image4.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" class="wlDisabledImage" title="image" border="0" alt="image" src="http://patrickyong.net/wp-content/uploads/2010/07/image-thumb4.png" width="524" height="448" /></a></p>
<p>At this page, you need to give a name for the website and assign a website admin account. Then click on ‘Use an existing SQL Server database’ to setup SQL Server. Key in the connection string in the following format</p>
<p><em>Data Source=.\sqlexpress;Initial Catalog=OrchardTutorialDB ;User Id=myUsername;Password=myPassword;</em></p>
<p>Note: Skip and leave the Database Table Prefix empty at the moment because of a <a href="http://orchard.codeplex.com/workitem/16488">known bug</a> with using the prefix</p>
<p><a href="http://patrickyong.net/wp-content/uploads/2010/07/image5.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" class="wlDisabledImage" title="image" border="0" alt="image" src="http://patrickyong.net/wp-content/uploads/2010/07/image-thumb5.png" width="393" height="476" /></a></p>
<p>Click ‘Finish Setup’ and a few minutes later you will see the website up and running!</p>
<p><a href="http://patrickyong.net/wp-content/uploads/2010/07/image6.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" class="wlDisabledImage" title="image" border="0" alt="image" src="http://patrickyong.net/wp-content/uploads/2010/07/image-thumb6.png" width="527" height="279" /></a></p>
<p>I will normally change my theme to a more presentable one.</p>
<p><a href="http://patrickyong.net/wp-content/uploads/2010/07/image7.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" class="wlDisabledImage" title="image" border="0" alt="image" src="http://patrickyong.net/wp-content/uploads/2010/07/image-thumb7.png" width="527" height="292" /></a></p>
<h3><strong>Hello Orchard - Adding a new Module</strong></h3>
<p>Note: from this point onwards I will reuse some of the text in the Orchard <a href="http://orchardproject.net/privatedrops/orchardmodulewalkthrough.doc">Walkthrough</a> document.</p>
<p><font color="#ff0000"><strong><em>NOTE: Step 2 to 4 and 15 to 17 are very additional steps to make the walkthrough works in the new change set.</em></strong></font></p>
<p>The objective here is to build a very simply Hello World style webpage themed by Orchard with a menu item on top.</p>
<p><b><i>Objectives:</i></b></p>
<p>1. A simple custom area that renders “Hello World” on the app’s front-end</p>
<p>2. Views in the custom area that take advantage of the currently applied Orchard theme</p>
<p>3. A menu item on the front-end for navigating to the custom area’s view</p>
<p><b><i>Follow These Steps:</i></b></p>
<p>1. Right-click the Modules node in VS Solution Explorer, and choose “Add &gt; New Project…”</p>
<p><a href="http://patrickyong.net/wp-content/uploads/2010/07/image8.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" class="wlDisabledImage" title="image" border="0" alt="image" src="http://patrickyong.net/wp-content/uploads/2010/07/image-thumb8.png" width="507" height="170" /></a></p>
<p>2. In the project creation screen, choose “ASP.NET MVC 2.0 Empty Web Application” </p>
<p><strong><font color="#ff0000">&lt;Very Important&gt;</font></strong> On the path text box, it is default to &lt;Orchard location&gt;\src folder. Change it to &lt;Orchard location&gt;\src\Orchard.Web\Modules\ folder (Screenshot below). Else Orchard will not recognize the new module.</p>
<p>Finally Type “Orchard.Commerce” for the area name and click [OK].</p>
<p><a href="http://patrickyong.net/wp-content/uploads/2010/07/image9.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" class="wlDisabledImage" title="image" border="0" alt="image" src="http://patrickyong.net/wp-content/uploads/2010/07/image-thumb9.png" width="515" height="321" /></a></p>
<p>3. For Orchard to discover this module, you need to add a module.txt file at the project root folder and insert the following content. </p>
<pre class="csharpcode">name: Commerce
antiforgery: enabled
author: Patrick Yong
website: http:<span class="rem">//patrickyong.net</span>
version: 0.1
orchardversion: 0.1.2010.0312
description: Commerce
features:    Orchard.Commerce:
Description: Commerce.
Category: Commerce</pre>
<style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<p>4. Modify the web.config file accordingly. Basically I added &lt;httphandlers&gt; and &lt;handlers&gt; in &lt;System.WebServer&gt; for MVC routing.</p>
<pre class="csharpcode"><span class="kwrd">&lt;?</span><span class="html">xml</span> <span class="attr">version</span><span class="kwrd">=&quot;1.0&quot;</span>?<span class="kwrd">&gt;</span>
<span class="rem">&lt;!--  For more information on how to configure your ASP.NET application, please visit  http://go.microsoft.com/fwlink/?LinkId=152368  --&gt;</span>
<span class="kwrd">&lt;</span><span class="html">configuration</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;</span><span class="html">system.web</span><span class="kwrd">&gt;</span>
   <span class="rem">&lt;!--             Set compilation debug=&quot;true&quot; to insert debugging             symbols into the compiled page. Because this             affects performance, set this value to true only             during development.    --&gt;</span>
   <span class="kwrd">&lt;</span><span class="html">compilation</span> <span class="attr">debug</span><span class="kwrd">=&quot;true&quot;</span> <span class="attr">targetFramework</span><span class="kwrd">=&quot;4.0&quot;</span><span class="kwrd">&gt;</span>
   <span class="kwrd">&lt;</span><span class="html">assemblies</span><span class="kwrd">&gt;</span>
      <span class="kwrd">&lt;</span><span class="html">add</span> <span class="attr">assembly</span><span class="kwrd">=&quot;System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35&quot;</span><span class="kwrd">/&gt;</span>
      <span class="kwrd">&lt;</span><span class="html">add</span> <span class="attr">assembly</span><span class="kwrd">=&quot;System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35&quot;</span><span class="kwrd">/&gt;</span>
      <span class="kwrd">&lt;</span><span class="html">add</span> <span class="attr">assembly</span><span class="kwrd">=&quot;System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35&quot;</span><span class="kwrd">/&gt;</span>
      <span class="kwrd">&lt;</span><span class="html">add</span> <span class="attr">assembly</span><span class="kwrd">=&quot;System.Data.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089&quot;</span><span class="kwrd">/&gt;</span>
   <span class="kwrd">&lt;/</span><span class="html">assemblies</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;/</span><span class="html">compilation</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;</span><span class="html">customErrors</span><span class="kwrd">&gt;</span>
   <span class="kwrd">&lt;</span><span class="html">error</span> <span class="attr">statusCode</span><span class="kwrd">=&quot;404&quot;</span> <span class="attr">redirect</span><span class="kwrd">=&quot;FileNotFound.htm&quot;</span> <span class="kwrd">/&gt;</span>
<span class="kwrd">&lt;/</span><span class="html">customErrors</span><span class="kwrd">&gt;</span>    --<span class="kwrd">&gt;</span>    <span class="kwrd">&lt;</span><span class="html">pages</span> <span class="attr">controlRenderingCompatibilityVersion</span><span class="kwrd">=&quot;3.5&quot;</span> <span class="attr">clientIDMode</span><span class="kwrd">=&quot;AutoID&quot;</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;</span><span class="html">namespaces</span><span class="kwrd">&gt;</span>
   <span class="kwrd">&lt;</span><span class="html">add</span> <span class="attr">namespace</span><span class="kwrd">=&quot;System.Web.Mvc&quot;</span><span class="kwrd">/&gt;</span>
   <span class="kwrd">&lt;</span><span class="html">add</span> <span class="attr">namespace</span><span class="kwrd">=&quot;System.Web.Mvc.Ajax&quot;</span><span class="kwrd">/&gt;</span>
   <span class="kwrd">&lt;</span><span class="html">add</span> <span class="attr">namespace</span><span class="kwrd">=&quot;System.Web.Mvc.Html&quot;</span><span class="kwrd">/&gt;</span>
   <span class="kwrd">&lt;</span><span class="html">add</span> <span class="attr">namespace</span><span class="kwrd">=&quot;System.Web.Routing&quot;</span><span class="kwrd">/&gt;</span>
   <span class="kwrd">&lt;</span><span class="html">add</span> <span class="attr">namespace</span><span class="kwrd">=&quot;System.Linq&quot;</span><span class="kwrd">/&gt;</span>
   <span class="kwrd">&lt;</span><span class="html">add</span> <span class="attr">namespace</span><span class="kwrd">=&quot;System.Collections.Generic&quot;</span><span class="kwrd">/&gt;</span>
   <span class="kwrd">&lt;</span><span class="html">add</span> <span class="attr">namespace</span><span class="kwrd">=&quot;Orchard.Mvc.Html&quot;</span><span class="kwrd">/&gt;</span>
   <span class="kwrd">&lt;/</span><span class="html">namespaces</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;/</span><span class="html">pages</span><span class="kwrd">&gt;</span>
   <span class="kwrd">&lt;</span><span class="html">httpHandlers</span><span class="kwrd">&gt;</span>
      <span class="kwrd">&lt;</span><span class="html">add</span> <span class="attr">verb</span><span class="kwrd">=&quot;*&quot;</span> <span class="attr">path</span><span class="kwrd">=&quot;*.mvc&quot;</span> <span class="attr">validate</span><span class="kwrd">=&quot;false&quot;</span> <span class="attr">type</span><span class="kwrd">=&quot;System.Web.Mvc.MvcHttpHandler, System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35&quot;</span><span class="kwrd">/&gt;</span>
   <span class="kwrd">&lt;/</span><span class="html">httpHandlers</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;/</span><span class="html">system.web</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;</span><span class="html">system.web.extensions</span><span class="kwrd">/&gt;</span>
<span class="rem">&lt;!--         The system.webServer section is required for running ASP.NET AJAX under Internet        Information Services 7.0.  It is not necessary for previous version of IIS.  --&gt;</span>
<span class="kwrd">&lt;</span><span class="html">system.webServer</span><span class="kwrd">&gt;</span>
   <span class="kwrd">&lt;</span><span class="html">validation</span> <span class="attr">validateIntegratedModeConfiguration</span><span class="kwrd">=&quot;false&quot;</span><span class="kwrd">/&gt;</span>
   <span class="kwrd">&lt;</span><span class="html">modules</span> <span class="attr">runAllManagedModulesForAllRequests</span><span class="kwrd">=&quot;true&quot;</span><span class="kwrd">&gt;&lt;/</span><span class="html">modules</span><span class="kwrd">&gt;</span>
   <span class="kwrd">&lt;</span><span class="html">handlers</span><span class="kwrd">&gt;</span>
      <span class="kwrd">&lt;</span><span class="html">remove</span> <span class="attr">name</span><span class="kwrd">=&quot;MvcHttpHandler&quot;</span><span class="kwrd">/&gt;</span>
      <span class="kwrd">&lt;</span><span class="html">remove</span> <span class="attr">name</span><span class="kwrd">=&quot;UrlRoutingHandler&quot;</span><span class="kwrd">/&gt;</span>
      <span class="kwrd">&lt;</span><span class="html">add</span> <span class="attr">name</span><span class="kwrd">=&quot;MvcHttpHandler&quot;</span> <span class="attr">preCondition</span><span class="kwrd">=&quot;integratedMode&quot;</span> <span class="attr">verb</span><span class="kwrd">=&quot;*&quot;</span> <span class="attr">path</span><span class="kwrd">=&quot;*.mvc&quot;</span> <span class="attr">type</span><span class="kwrd">=&quot;System.Web.Mvc.MvcHttpHandler, System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35&quot;</span><span class="kwrd">/&gt;</span>
   <span class="kwrd">&lt;/</span><span class="html">handlers</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;/</span><span class="html">system.webServer</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;</span><span class="html">runtime</span><span class="kwrd">&gt;</span>
   <span class="kwrd">&lt;</span><span class="html">assemblyBinding</span> <span class="attr">xmlns</span><span class="kwrd">=&quot;urn:schemas-microsoft-com:asm.v1&quot;</span><span class="kwrd">&gt;</span>
      <span class="kwrd">&lt;</span><span class="html">dependentAssembly</span><span class="kwrd">&gt;</span>
         <span class="kwrd">&lt;</span><span class="html">assemblyIdentity</span> <span class="attr">name</span><span class="kwrd">=&quot;System.Web.Mvc&quot;</span> <span class="attr">publicKeyToken</span><span class="kwrd">=&quot;31bf3856ad364e35&quot;</span> <span class="kwrd">/&gt;</span>
         <span class="kwrd">&lt;</span><span class="html">bindingRedirect</span> <span class="attr">oldVersion</span><span class="kwrd">=&quot;1.0.0.0&quot;</span> <span class="attr">newVersion</span><span class="kwrd">=&quot;2.0.0.0&quot;</span> <span class="kwrd">/&gt;</span>
      <span class="kwrd">&lt;/</span><span class="html">dependentAssembly</span><span class="kwrd">&gt;</span>
   <span class="kwrd">&lt;/</span><span class="html">assemblyBinding</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;/</span><span class="html">runtime</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;/</span><span class="html">configuration</span><span class="kwrd">&gt;</span></pre>
<style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<p>5. Right-click the newly created “Ocrhard.Commerce &gt; Controllers” folder, and choose “Add &gt; Controller…”</p>
<p>6. Name the Controller “HomeController”</p>
<p>7. Right-click on the “Index()” method name and choose “Add View…”</p>
<p><a href="http://patrickyong.net/wp-content/uploads/2010/07/image10.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" class="wlDisabledImage" title="image" border="0" alt="image" src="http://patrickyong.net/wp-content/uploads/2010/07/image-thumb10.png" width="513" height="114" /></a></p>
<p>8. Selected the “Create a partial view” option and click [Add]</p>
<p><a href="http://patrickyong.net/wp-content/uploads/2010/07/image11.png"><img style="border-right-width: 0px; margin: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" class="wlDisabledImage" title="image" border="0" alt="image" src="http://patrickyong.net/wp-content/uploads/2010/07/image-thumb11.png" width="244" height="166" /></a></p>
<p>9. Add the following HTML to the View page: &lt;p&gt;Hello World&lt;/p&gt;</p>
<p>10. Add Orchard.Framework and Orchard.Themes to the project reference</p>
<p><a href="http://patrickyong.net/wp-content/uploads/2010/07/image12.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" class="wlDisabledImage" title="image" border="0" alt="image" src="http://patrickyong.net/wp-content/uploads/2010/07/image-thumb12.png" width="454" height="278" /></a></p>
<p>11. Add the following namespace imports to the HelloController.cs file:</p>
<pre class="csharpcode"><span class="kwrd">using</span> Orchard.Themes;
<span class="kwrd">using</span> Orchard.UI.Navigation;</pre>
<style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<p>12. Add an [Themed] attribute to the HelloController class:</p>
<pre class="csharpcode">[Themed]
<span class="kwrd">public</span> <span class="kwrd">class</span> HomeController : Controller</pre>
<style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<p>13. Add another class to create a new Menu item, you can create a new .cs file in the project root folder or add it inside the controller class<br />
  </p>
<pre class="csharpcode"><span class="kwrd">public</span> <span class="kwrd">class</span> MainMenu : INavigationProvider
 {
        <span class="kwrd">public</span> Localizer T { get; set; }
         <span class="kwrd">public</span> String MenuName
        {
            get { <span class="kwrd">return</span> <span class="str">&quot;main&quot;</span>; }
        }

         <span class="kwrd">public</span> <span class="kwrd">void</span> GetNavigation(NavigationBuilder builder)
        {
            builder.Add(menu =&gt; menu.Add(T(<span class="str">&quot;Shop&quot;</span>), <span class="str">&quot;4&quot;</span>, item =&gt; item.Action(<span class="str">&quot;Index&quot;</span>, <span class="str">&quot;Home&quot;</span>, <span class="kwrd">new</span> { area = <span class="str">&quot;Orchard.Commerce&quot;</span> })));
        }
}</pre>
<style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
</p>
<p>14. Type Ctrl-F5 to build and run in VS.</p>
<p>15. Login as admin (using the admin account you created during setup) and navigate to the admin page</p>
<p><a href="http://patrickyong.net/wp-content/uploads/2010/07/image13.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" class="wlDisabledImage" title="image" border="0" alt="image" src="http://patrickyong.net/wp-content/uploads/2010/07/image-thumb13.png" width="464" height="234" /></a></p>
<p>16. Scroll down to look for Site Configuration menu and click on Features</p>
<p><a href="http://patrickyong.net/wp-content/uploads/2010/07/image14.png"><img style="border-right-width: 0px; margin: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" class="wlDisabledImage" title="image" border="0" alt="image" src="http://patrickyong.net/wp-content/uploads/2010/07/image-thumb14.png" width="174" height="244" /></a></p>
<p>17. Voila! If you had done everything right, you will see Orchard.Commerce as a module under the Commerce category. Now click on the ‘Enable’ button.</p>
<p><a href="http://patrickyong.net/wp-content/uploads/2010/07/image16.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" class="wlDisabledImage" title="image" border="0" alt="image" src="http://patrickyong.net/wp-content/uploads/2010/07/image-thumb15.png" width="543" height="276" /></a></p>
<p>18. After a moment, message(s) will appear and to try out the feature, click on Your Site on top.</p>
<p><a href="http://patrickyong.net/wp-content/uploads/2010/07/image17.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" class="wlDisabledImage" title="image" border="0" alt="image" src="http://patrickyong.net/wp-content/uploads/2010/07/image-thumb16.png" width="541" height="163" /></a></p>
<p>19. Now you notice an additional item on the top menu</p>
<p><a href="http://patrickyong.net/wp-content/uploads/2010/07/image18.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" class="wlDisabledImage" title="image" border="0" alt="image" src="http://patrickyong.net/wp-content/uploads/2010/07/image-thumb17.png" width="528" height="179" /></a></p>
<p>&#160;</p>
<p>10. Finally click on ‘Shop’ to Navigate to this URL in the browser: <a href="http://localhost:%3cport%3e/Commerce">http://localhost:&lt;port&gt;/Commerce</a></p>
<p><a href="http://patrickyong.net/wp-content/uploads/2010/07/image19.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" class="wlDisabledImage" title="image" border="0" alt="image" src="http://patrickyong.net/wp-content/uploads/2010/07/image-thumb18.png" width="507" height="243" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://patrickyong.net/2010/07/25/hello-orchard-creating-a-orchard-module-using-latest-source-code/feed/</wfw:commentRss>
		</item>
		<item>
		<title>SharePoint Foundation 2010 RTM Available for Download!</title>
		<link>http://patrickyong.net/2010/04/29/sharepoint-foundation-2010-rtm-available-for-download/</link>
		<comments>http://patrickyong.net/2010/04/29/sharepoint-foundation-2010-rtm-available-for-download/#comments</comments>
		<pubDate>Wed, 28 Apr 2010 17:02:40 +0000</pubDate>
		<dc:creator>Patrick</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<category><![CDATA[sharepoint 2010]]></category>

		<category><![CDATA[sharepoint foundation]]></category>

		<guid isPermaLink="false">http://patrickyong.net/2010/04/29/sharepoint-foundation-2010-rtm-available-for-download/</guid>
		<description><![CDATA[At last! If you have downloaded Visual Studio 2010 RTM and want to start developing for SharePoint Foundation 2010 , it is available here on Microsoft download site. I have not seen it in my MSDN account, which allows me to have faster download with the File Transfer Manager.
]]></description>
			<content:encoded><![CDATA[<p>At last! If you have downloaded Visual Studio 2010 RTM and want to start developing for SharePoint Foundation 2010 , it is available <a href="http://www.microsoft.com/downloads/details.aspx?displaylang=en&amp;FamilyID=49c79a8a-4612-4e7d-a0b4-3bb429b46595">here</a> on Microsoft download site. I have not seen it in my MSDN account, which allows me to have faster download with the File Transfer Manager.</p>
]]></content:encoded>
			<wfw:commentRss>http://patrickyong.net/2010/04/29/sharepoint-foundation-2010-rtm-available-for-download/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
