2012-03-30 12 views
1

オーチャード・モジュールではすべて正常に動作しますが、残念ながらデータベースは更新されません。オーチャードCMS - ハンドラがデータベースを更新しません

私はEditorTemplates \パーツ\ Course.cshtmlが怒鳴るよう \ Orchard.Web \モジュール\コース\ビューで管理パネルのビューを定義しています

@model Course.Models.CoursePart 

<fieldset> 
    <legend>Course Fields</legend> 

    <div class="editor-label"> 
    @Html.LabelFor(model => model.Title) 
    </div> 
    <div class="editor-field"> 
    @Html.TextBoxFor(model => model.Title) 
    @Html.ValidationMessageFor(model => model.Title) 
    </div> 

    <div class="editor-label"> 
    @Html.LabelFor(model => model.Description) 
    </div> 
    <div class="editor-field"> 
    @Html.TextBoxFor(model => model.Description) 
    @Html.ValidationMessageFor(model => model.Description) 
    </div> 


    <div class="editor-label"> 
    @Html.LabelFor(model => model.ImagePath) 
    </div> 
    <div class="editor-field"> 
    @Html.TextBoxFor(model => model.ImagePath) 
    @Html.ValidationMessageFor(model => model.ImagePath) 
    </div> 


</fieldset> 

として怒鳴るドライバ:

public class CourseDriver : ContentPartDriver<CoursePart> 
    { 
     protected override DriverResult Display(CoursePart part, 
             string displayType, 
             dynamic shapeHelper) 
     { 

      return ContentShape("Parts_Course", 
       () => shapeHelper.Parts_Course(
       Description: part.Description, 
       Title: part.Title, 
       ImagePath: part.ImagePath, 
       Area: part.Area 
       )); 
     } 

     //GET 
     protected override DriverResult Editor(CoursePart part, 
               dynamic shapeHelper) 
     { 

      return ContentShape("Parts_Course_Edit", 
       () => shapeHelper.EditorTemplate(
        TemplateName: "Parts/Course", 
        Model: part, 
        Prefix: Prefix)); 
     } 

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

ハンドラ:

namespace Course.Handlers 
{ 
    public class CourseHandler: ContentHandler 
    { 
      public CourseHandler(IRepository<CourseRecord> repository) 
      { 
       Filters.Add(StorageFilter.For(repository)); 
      } 

    } 
} 

以下に説明する移行クラスはOrchard.Web \ Modules \ Course \ Migrations.csファイルです。

namespace Course { 
    public class Migrations : DataMigrationImpl { 

     public int Create() { 
      // Creating table CoursePartRecord 
      SchemaBuilder.CreateTable("CourseRecord", table => table 
       .ContentPartRecord() 
       .Column("Area", DbType.String) 
       .Column("Description", DbType.String) 
       .Column("Title", DbType.String) 
       .Column("ImagePath", DbType.String) 
      ); 

      //Add the AlterPartDefinition lines to the migration in order to make the part 
      //attachable to any content type. 
      ContentDefinitionManager.AlterPartDefinition(
       typeof(CoursePart).Name, cfg => cfg.Attachable()); 

      return 1; 
     } 

     public int UpdateFrom1() 
     { 
      ContentDefinitionManager.AlterTypeDefinition("CourseContent", cfg => cfg 
       .WithPart("CommonPart") 
       .WithPart("RoutePart") 
       .WithPart("BodyPart") 
       .WithPart("CoursePart") 
       .WithPart("CommentsPart") 
       .WithPart("TagsPart") 
       .WithPart("LocalizationPart") 
       .Creatable() 
       .Indexed()); 
      return 2; 
     } 
    } 
} 

モデルが蛇腹記載されている:私は手順に従ってし

namespace Course.Models 
{ 
    public class CourseRecord : ContentPartRecord 
    { 
     public virtual String Area { get; set; } 

     public virtual String Description { get; set; } 
     public virtual String Title { get; set; } 

     public virtual String ImagePath { get; set; } 

    } 


    public class CoursePart : ContentPart<CourseRecord> 
    { 
     public String Area { get; set; } 
     [Required] 
     public String Description { get; set; } 
     [Required] 
     public String Title { get; set; } 
     public String ImagePath { get; set; } 
    } 
} 

果樹園ドキュメントにおける例を記載:http://docs.orchardproject.net/Documentation/Writing-a-content-part

問題:データベースが作成または更新されていない、レコードからすべてのプロパティがnull値で更新され、repository.TableCourseHandlerのメソッドは常にリストを返しています。

敬具、 ティト私にヒントを与えた、と私は私のコードの移行コードで再び見ていた@mdmコメントへ

+0

あなたは私たちあなたの移行クラスとあなたのCourseRecordクラスを表示することができます:それは正常に働いて怒鳴る私はコードに変更

? – mdm

+0

@mdm、今私はすでにそれを追加しました。気づいてくれてありがとう。 – Tito

答えて

1

感謝。 そして、クラスCoursePartは、レコードからの書き込みまたは読み取りではないので、間違って定義されました。

public class CoursePart : ContentPart<CourseRecord> 

{ 
    public String Area 
    { 
     get { return Record.Area; } 
     set { Record.Area = value; } 
    } 

    [Required] 
    public String Description 
    { 
     get { return Record.Description; } 
     set { Record.Description = value; } 
    } 

    [Required] 
    public String Title 
    { 
     get { return Record.Title; } 
     set { Record.Title = value; } 
    } 

    public String ImagePath 
    { 
     get { return Record.ImagePath; } 
     set { Record.ImagePath = value; } 
    } 
} 
関連する問題