2012-03-30 5 views
1

과수원 모듈에서는 모든 것이 잘 작동하지만 불행히도 데이터베이스는 업데이트되지 않습니다.과수원 CMS - 처리기가 데이터베이스를 업데이트하지 않습니다.

내가 Orchard.Web \ 모듈 \ 코스 \ 조회수 \ EditorTemplates 벨으로 부품 \ Course.cshtml \에있는 관리자 패널에 대한 뷰를 정의

:

@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; 
     } 
    } 
} 

모델은 노호 설명된다 : I이 단계를 수행 하였다

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의 방법은 항상 목록을 반환합니다.

안부, 티토

+0

당신은 우리에게 당신의 마이그레이션 클래스와 CourseRecord 클래스를 보여줄 수 : 정상적으로 작동 노호

나는 코드로 변경하면? – mdm

+0

@mdm, 이제 이미 추가했습니다. 그것을주의 해 주셔서 감사합니다. – Tito

답변

1

덕분에 나에게 힌트를 준 코멘트를 @mdm하고, 나는 내 코드 마이그레이션 코드를 다시 살펴 보았다. 그리고 클래스 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; } 
    } 
} 
관련 문제