国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

Orchard模塊開發全接觸6:自定義用戶注冊

2019-11-17 01:39:18
字體:
來源:轉載
供稿:網友

Orchard模塊開發全接觸6:自定義用戶注冊

我們都知道 Orchard 的用戶注冊相當簡單,現在,我們需要一個自定義的用戶注冊,現在,開始吧。

一:定義實體

Models/CustomerPartRecord.cs:

public class CustomerPartRecord : ContentPartRecord{ public virtual string FirstName { get; set; } public virtual string LastName { get; set; } public virtual string Title { get; set; } public virtual DateTime CreatedUtc { get; set; }}

Models/CustomerPart.cs:

public class CustomerPart : ContentPart<CustomerPartRecord>{

public string FirstName { get { return Record.FirstName; } set { Record.FirstName = value; } }

public string LastName { get { return Record.LastName; } set { Record.LastName = value; } }

public string Title { get { return Record.Title; } set { Record.Title = value; } }

public DateTime CreatedUtc { get { return Record.CreatedUtc; } set { Record.CreatedUtc = value; } }}

Models/AddressPartRecord.cs:

public class AddressPartRecord : ContentPartRecord{ public virtual int CustomerId { get; set; } public virtual string Type { get; set; }}

Models/AddressPart.cs:

public class AddressPart : ContentPart<AddressPartRecord>{

public int CustomerId { get { return Record.CustomerId; } set { Record.CustomerId = value; } }

public string Type { get { return Record.Type; } set { Record.Type = value; } }}

修改Migrations.cs

public int UpdateFrom4(){ SchemaBuilder.CreateTable("CustomerPartRecord", table => table .ContentPartRecord() .Column<string>("FirstName", c => c.WithLength(50)) .Column<string>("LastName", c => c.WithLength(50)) .Column<string>("Title", c => c.WithLength(10)) .Column<DateTime>("CreatedUtc") );

SchemaBuilder.CreateTable("AddressPartRecord", table => table .ContentPartRecord() .Column<int>("CustomerId") .Column<string>("Type", c => c.WithLength(50)) );

ContentDefinitionManager.AlterPartDefinition("CustomerPart", part => part .Attachable(false) );

ContentDefinitionManager.AlterTypeDefinition("Customer", type => type .WithPart("CustomerPart") .WithPart("UserPart") );

ContentDefinitionManager.AlterPartDefinition("AddressPart", part => part .Attachable(false) .WithField("Name", f => f.OfType("TextField")) .WithField("AddressLine1", f => f.OfType("TextField")) .WithField("AddressLine2", f => f.OfType("TextField")) .WithField("Z ContentDefinitionManager.AlterTypeDefinition("Address", type => type .WithPart("CommonPart") .WithPart("AddressPart") );

return 5;}

Handlers/CustomerPartHandler.cs:

public class CustomerPartHandler : ContentHandler{ public CustomerPartHandler(IRepository<CustomerPartRecord> repository) { Filters.Add(StorageFilter.For(repository)); Filters.Add(new ActivatingFilter<UserPart>("Customer")); }}

注意哦,使用 UsrerPart,必須引用 Orchard.Users,于是乎,我們修改 Dependencies:

name: tminji.shopantiforgery: enabledauthor: tminji.comwebsite: http://www.tminji.comversion: 1.0.0orchardversion: 1.0.0description: The tminji.com module is a shopping module. Dependencies: Orchard.PRojections, Orchard.Forms, Orchard.jQuery, Orchard.jQuery, AIM.LinqJs, Orchard.Knockout, Orchard.Usersfeatures: shop: Description: shopping module. Category: ASample

注意哦,如果我們使用 UserPart,那么,我們就不能再 attach CommonPart,否則會導致 StackOverflowException

Handlers/AddressPartHandler.cs:

public class AddressPartHandler : ContentHandler{ public AddressPartHandler(IRepository<AddressPartRecord> repository) { Filters.Add(StorageFilter.For(repository)); }}

然后,Drivers/CustomerPartDriver.cs:

public class CustomerPartDriver : ContentPartDriver<CustomerPart>{

protected override string Prefix { get { return "Customer"; } }

protected override DriverResult Editor(CustomerPart part, dynamic shapeHelper) { return ContentShape("Parts_Customer_Edit", () => shapeHelper.EditorTemplate(TemplateName: "Parts/Customer", Model: part, Prefix: Prefix)); }

protected override DriverResult Editor(CustomerPart part, IUpdateModel updater, dynamic shapeHelper) { updater.TryUpdateModel(part, Prefix, null, null); return Editor(part, shapeHelper); }}

然后,Drivers/AddressPartDriver.cs:

public class AddressPartDriver : ContentPartDriver<AddressPart>{

protected override string Prefix { get { return "Address"; } }

protected override DriverResult Editor(AddressPart part, dynamic shapeHelper) { return ContentShape("Parts_Address_Edit", () => shapeHelper.EditorTemplate(TemplateName: "Parts/Address", Model: part, Prefix: Prefix)); }

protected override DriverResult Editor(AddressPart part, IUpdateModel updater, dynamic shapeHelper) { updater.TryUpdateModel(part, Prefix, null, null); return Editor(part, shapeHelper); }}

Views/EditorTemplates/Parts/Customer.cshtml:

@using System.Web.Mvc.Html@model TMinji.Shop.Models.CustomerPart<fieldset> <div class="editor-label">@Html.LabelFor(x => x.Title)</div> <div class="editor-field">@Html.EditorFor(x => x.Title)</div>

<div class="editor-label">@Html.LabelFor(x => x.FirstName)</div> <div class="editor-field"> @Html.EditorFor(x => x.FirstName) @Html.ValidationMessageFor(x => x.FirstName) </div>

<div class="editor-label">@Html.LabelFor(x => x.LastName)</div> <div class="editor-field"> @Html.EditorFor(x => x.LastName) @Html.ValidationMessageFor(x => x.LastName) </div></fieldset>

Views/EditorTemplates/Parts/Address.cshtml:

@using System.Web.Mvc.Html@model TMinji.Shop.Models.AddressPart<fieldset> <div class="editor-label">@Html.LabelFor(x => x.Type)</div> <div class="editor-field">@Html.EditorFor(x => x.Type)</div>

<div class="editor-label">@Html.LabelFor(x => x.CustomerId)</div> <div class="editor-field"> @Html.EditorFor(x => x.CustomerId) @Html.ValidationMessageFor(x => x.CustomerId) </div></fieldset>

Placement.info:

<Placement> <Place Parts_Product_Edit="Content:1" /> <Place Parts_Product="Content:0" /> <Place Parts_Product_AddButton="Content:after" /> <Place Parts_ShoppingCartWidget="Content:0" /> <Place Parts_Customer_Edit="Content:0" /> <Place Parts_Address_Edit="Content:0" /></Placement>

運行之,可以看到創建了數據庫表:

image

二:前臺準備

控制器 CheckoutController.cs:

using Orchard;using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Web.Mvc;using Orchard.Mvc;using Orchard.Themes;

namespace TMinji.Shop.Controllers{ public class CheckoutController : Controller { private readonly IOrchardServices _services; private Localizer T { get; set; }

public CheckoutController(IOrchardServices services) { _services = services; }

[Themed] public ActionResult SignupOrLogin() {

return new ShapeResult(this, _services.New.Checkout_SignupOrLogin()); } }

}

創建視圖 Checkout.SignupOrLogin.cshtml:

@using Orchard.ContentManagement@using Orchard.Core.Title.Models@using TMinji.Shop.Models

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 泰宁县| 南京市| 萨迦县| 苗栗县| 靖边县| 绵竹市| 梨树县| 晋中市| 美姑县| 安新县| 新泰市| 舒城县| 江川县| 桃江县| 犍为县| 太白县| 甘肃省| 旬阳县| 嘉鱼县| 新蔡县| 嘉兴市| 张北县| 枝江市| 静乐县| 英吉沙县| 镇雄县| 报价| 辰溪县| 漾濞| 定南县| 临夏县| 洮南市| 原阳县| 平罗县| 沙田区| 如皋市| 和硕县| 渑池县| 达孜县| 富锦市| 梁平县|