其他操作按照http://www.ideliverable.com/blog?page=3博客中步骤操作就可以
下面说说需要注意的几点:
widget的创建
在Models下添加一个继承自ContentPart的空类;
创建一个包含Display的Driver;
Placement.info添加Place;
Migration.cs中定义内容类型,.WithPart("新创建的类”)
.WithPart("CommonPart")
.WithPart("WidgetPart")
WithSetting("Stereotype","Widget");
在Views中创建显示网页;
这样就可以添加widget到zone了。
形状候补
通过DisplayType的不同显示不同的页面
前台详细默认Detail,列表默认Summary
后台列表默认SummaryAdmin
通过Driver的Display方法或placement.info可实现
if (displayType != "SummaryAdmin")
{
driverResults.Add
(
ContentShape("Parts_Product_AddButton", () =>
shapeHelper.Parts_Product_AddButton(ProductId: part.Id))
);
}
<Match DisplayType="SummaryAdmin">
<Place Parts_Product_AddButton="-" />
</Match>
protected override DriverResult Display(ProductPart part, string displayType, dynamic shapeHelper)
{
return Combined(
ContentShape("Parts_Product_SummaryAdmin", () => shapeHelper.Parts_Product_SummaryAdmin(
Price: part.Price,
Sku: part.Sku
)),
ContentShape("Parts_Product", () => shapeHelper.Parts_Product(
Price: part.Price,
Sku: part.Sku
)),
ContentShape("Parts_Product_AddButton", () => shapeHelper.Parts_Product_AddButton(
ProductId: part.Id
))
);
}
Placement.info:
<Placement>
...
<Match DisplayType="SummaryAdmin">
<Place Parts_Product_AddButton="-" />
<Place Parts_Product="-" />
<Place Parts_Product_SummaryAdmin="Content:0" />
</Match>
</Placement>
添加管理菜单
AdminMenu.cs:
using Orchard.Localization;
using Orchard.UI.Navigation;
namespace Orchard.Webshop {
public class AdminMenu : INavigationProvider
{
public string MenuName {
get { return "admin"; }
}
public AdminMenu() {
T = NullLocalizer.Instance;
}
private Localizer T { get; set; }
public void GetNavigation(NavigationBuilder builder) {
builder
// Image set
.AddImageSet("webshop")
// "Webshop"
.Add(item => item
.Caption(T("Webshop"))
.Position("2")
.LinkToFirstChild(true)
// "Customers"
.Add(subItem => subItem
.Caption(T("Customers"))
.Position("2.1")
.Action("Index", "CustomerAdmin", new { area ="Orchard.Webshop" })
)
// "Orders"
.Add(subItem => subItem
.Caption(T("Orders"))
.Position("2.2")
.Action("Index", "OrderAdmin", new { area ="Orchard.Webshop" })
)
);
}
}
}
Styles/menu.webshop-admin.css:
.navicon-webshop {
background-image:url('../images/menu.webshop.png')!important;
}
.navicon-webshop:hover {
background-position:0 -30px !important;
}
Controllers/CustomerAdminController.cs:
using System;
using System.Linq;
using System.Web.Mvc;
using Orchard.ContentManagement;
using Orchard.DisplayManagement;
using Orchard.Settings;
using Orchard.UI.Admin;
using Orchard.UI.Navigation;
using Orchard.Users.Models;
using Orchard.Webshop.Helpers;
using Orchard.Webshop.Services;
using Orchard.Webshop.ViewModels;
namespace Orchard.Webshop.Controllers {
[Admin]
public class CustomerAdminController : Controller {
private dynamic Shape { get; set; }
private readonly ICustomerService _customerService;
private readonly ISiteService _siteService;
public CustomerAdminController(ICustomerService customerService,IShapeFactory shapeFactory, ISiteService siteService) {
Shape = shapeFactory;
_customerService = customerService;
_siteService = siteService;
}
public ActionResult Index(PagerParameters pagerParameters,CustomersSearchVM search) {
// Create a basic query that selects all customer content items, joinedwith the UserPartRecord table
var customerQuery =_customerService.GetCustomers().Join<UserPartRecord>().List();
// If the user specified a search expression, update the query with afilter
if (!string.IsNullOrWhiteSpace(search.Expression)) {
var expression =search.Expression.Trim();
customerQuery = from customerin customerQuery
where
customer.FirstName.Contains(expression,StringComparison.InvariantCultureIgnoreCase) ||
customer.LastName.Contains(expression,StringComparison.InvariantCultureIgnoreCase) ||
customer.As<UserPart>().Email.Contains(expression)
select customer;
}
// Project the query into a list of customer shapes
var customersProjection = from customer in customerQuery
selectShape.Customer
(
Id:customer.Id,
FirstName: customer.FirstName,
LastName:customer.LastName,
Email:customer.As<UserPart>().Email,
CreatedAt: customer.CreatedAt
);
// The pager is used to apply paging on the query and to create aPagerShape
var pager = new Pager(_siteService.GetSiteSettings(),pagerParameters.Page, pagerParameters.PageSize);
// Apply paging
var customers =customersProjection.Skip(pager.GetStartIndex()).Take(pager.PageSize);
// Construct a Pager shape
var pagerShape =Shape.Pager(pager).TotalItemCount(customerQuery.Count());
// Create the viewmodel
var model = new CustomersIndexVM(customers, search, pagerShape);
return View(model);
}
}
}