At my orchard module, everything works fine, but unfortunately the database is not updated.
I have defined the view for the admin panel at Orchard.Web\Modules\Course\Views\EditorTemplates\Parts\Course.cshtml as bellow:
@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>
And the driver as bellow:
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);
}
}
And the Handler:
namespace Course.Handlers
{
public class CourseHandler: ContentHandler
{
public CourseHandler(IRepository<CourseRecord> repository)
{
Filters.Add(StorageFilter.For(repository));
}
}
}
The migration class described bellow is at the Orchard.Web\Modules\Course\Migrations.cs file.
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;
}
}
}
The models are described bellow:
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; }
}
}
I was following the steps according with the example at the orchard documentation: http://docs.orchardproject.net/Documentation/Writing-a-content-part.
Problem: The database is not created or updated, every property from the record is updated with null values, the repository.Table
in CourseHandler
method is always returning a list.
Best regards, Tito