How to Get Start With Orchard to Create Module

2014/8/12 min read
bookmark this
Responsive image

This blog shows how to create a HelloWorld module to Orchard, ASP.NET MVC open source application, also how to add the module as role at create role page.

 

First you need to download Orchard, following is the greate blog get you start, it has more detail information of how to create HelloWorld then this blog.

HelloWorld Orchard

After you download the source code, you can just build and start web application as Orchard.Web, then that's it you can start your web application now. 

Base on the above Orchard Hello document, you can create the scafold project by type following command.

Orchard.Web\bin>orchard.exe
orchard> codegen module HelloWorld
orchard> feature enable HelloWorld

If you add controller and view like following, then your first HelloWorld is finished.

To enable permission, you need to create Permissions file imprement, IPermissionProvider, then Orchard framework is going to inject that IPermissionProvider to generate the actual logic.


using Orchard.Environment.Extensions.Models;
using Orchard.Security.Permissions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace HelloWorld
{
    public class Permissions : IPermissionProvider
    {
        public static readonly Permission SetHomePage = new Permission { Description = "Set Accounting Page", Name = "SetHomePage" };

        public virtual Feature Feature { get; set; }

        public IEnumerable GetPermissions()
        {
            return new[] {
                SetHomePage
            };
        }

        public IEnumerable GetDefaultStereotypes()
        {
            return new[] {
                new PermissionStereotype {
                    Name = "Administrator",
                    Permissions = new[] {SetHomePage}
                },
                new PermissionStereotype {
                    Name = "Editor",
                    Permissions = new[] {SetHomePage}
                }
            };
        }

    }
}

You also need to add new module to database


After everything is finished, you will notice at the Add ROle view, your HelloWorld module been added.


Simple, isn't it!?