Orchard custom module does not save all items

Creating my first module in Orchard, and everything except saving (on some fields) works. I do not get errors when saving, the fields just show their default value, while no values ​​are inserted / updated in the database table.

At first I built a module with only one property, and then added more to the record as soon as I confirmed that everything was updated from the administrator. Now the new fields are displayed in the editor, but only the original property (SoldOut) saves on updating or creating. I saw another message that recommended deleting the mappings.bin file, but that didn't change anything. Thanks for any help!

Here are the main classes:

public class ConferencePartRecord : ContentPartRecord { public virtual bool OnlyShowTeaser { get; set; } public virtual int TheYear { get; set; } public virtual DateTime StartDate { get; set; } public virtual DateTime EndDate { get; set; } public virtual DateTime EarlyReg { get; set; } public virtual DateTime RegularReg { get; set; } public virtual DateTime LateReg { get; set; } public virtual DateTime ConfirmDate { get; set; } public virtual bool SoldOut { get; set; } public virtual bool ConferenceSpace { get; set; } public virtual int EarlyBirdException { get; set; } public virtual string NextConf { get; set; } } public class ConferencePart : ContentPart<ConferencePartRecord> { public bool OnlyShowTeaser { get { return Record.OnlyShowTeaser; } set { Record.OnlyShowTeaser = value; } } public int TheYear { get { return Record.TheYear; } set { Record.TheYear = value; } } public DateTime StartDate { get { return Record.StartDate; } set { Record.StartDate = value; } } public DateTime EndDate { get { return Record.EndDate; } set { Record.EndDate = value; } } public DateTime EarlyReg { get { return Record.EarlyReg; } set { Record.EarlyReg = value; } } public DateTime RegularReg { get { return Record.RegularReg; } set { Record.RegularReg = value; } } public DateTime LateReg { get { return Record.LateReg; } set { Record.LateReg = value; } } public DateTime ConfirmDate { get { return Record.ConfirmDate; } set { Record.ConfirmDate = value; } } public bool ConferenceSpace { get { return Record.ConferenceSpace; } set { Record.ConferenceSpace = value; } } public int EarlyBirdException { get { return Record.EarlyBirdException; } set { Record.EarlyBirdException = value; } } public String NextConf { get { return Record.NextConf; } set { Record.NextConf = value; } } public bool SoldOut { get { return Record.SoldOut; } set { Record.SoldOut = value; } } } 

Here is my driver class:

 public class ConferenceDriver : ContentPartDriver<AeriesConference.Models.ConferencePart> { protected override DriverResult Display(ConferencePart part, string displayType, dynamic shapeHelper) { return ContentShape("Parts_Conference", () => shapeHelper.Parts_Conference(SoldOut: part.SoldOut)); } //GET protected override DriverResult Editor(ConferencePart part, dynamic shapeHelper) { return ContentShape("Parts_Conference_Edit", () => shapeHelper.EditorTemplate( TemplateName: "Parts/Conference", Model: part, Prefix: Prefix)); } //POST protected override DriverResult Editor(ConferencePart part, IUpdateModel updater, dynamic shapeHelper) { updater.TryUpdateModel(part, Prefix, null, null); return Editor(part, shapeHelper); } } 

... class migrations.cs (so you can see my updates - they are all reflected in the database)

  public int Create() { // Creating table ConferenceRecord SchemaBuilder.CreateTable("ConferencePartRecord", table => table .ContentPartRecord() .Column("SoldOut", DbType.Boolean) ); return 1; } public int UpdateFrom1() { // Create (or alter) a part called "ConferencePart" and configure it to be "attachable". ContentDefinitionManager.AlterPartDefinition("ConferencePart", part => part .Attachable()); return 2; } public int UpdateFrom2() { SchemaBuilder.AlterTable("ConferencePartRecord", table => table.AddColumn("OnlyShowTeaser", DbType.Boolean)); SchemaBuilder.AlterTable("ConferencePartRecord", table => table.AddColumn("TheYear", DbType.Int16)); SchemaBuilder.AlterTable("ConferencePartRecord", table => table.AddColumn("StartDate", DbType.DateTime)); SchemaBuilder.AlterTable("ConferencePartRecord", table => table.AddColumn("EndDate", DbType.DateTime)); SchemaBuilder.AlterTable("ConferencePartRecord", table => table.AddColumn("EarlyReg", DbType.DateTime)); SchemaBuilder.AlterTable("ConferencePartRecord", table => table.AddColumn("RegularReg", DbType.DateTime)); SchemaBuilder.AlterTable("ConferencePartRecord", table => table.AddColumn("LateReg", DbType.DateTime)); SchemaBuilder.AlterTable("ConferencePartRecord", table => table.AddColumn("ConfirmDate", DbType.DateTime)); SchemaBuilder.AlterTable("ConferencePartRecord", table => table.AddColumn("ConferenceSpace", DbType.Boolean)); SchemaBuilder.AlterTable("ConferencePartRecord", table => table.AddColumn("EarlyBirdException", DbType.Int16)); SchemaBuilder.AlterTable("ConferencePartRecord", table => table.AddColumn("NextConf", DbType.String)); return 3; } } 

and finally my handler class:

 public class ConferencePartHandler : ContentHandler { public ConferencePartHandler(IRepository<ConferencePartRecord> repository) { Filters.Add(StorageFilter.For(repository)); } } 
+4
source share
1 answer

Of course, I found the problem 5 minutes after posting the question. I missed one of the datetime fields in the cshtml file for the editor, and when it was stored in the database, it was dying from updating because the date column is not zero.

0
source

Source: https://habr.com/ru/post/1437692/


All Articles