How to get Media Picker Field via proxy record of many-to-many in orchard
Posted
by
Sergey Schipanov
on Stack Overflow
See other posts from Stack Overflow
or by Sergey Schipanov
Published on 2012-11-12T22:31:16Z
Indexed on
2012/11/12
23:00 UTC
Read the original article
Hit count: 243
I need to access mediapickerfield in Widget view. This field is relative to 'ActionPart'.
I have a problem, when I create many-to-many relationships to display my 'ActionPart' in the widget.
When I mapped many-to-many I take an 'ActionPart' and but cannot access the mediapickerfield.
Records classes
public class ActionPartRecord : ContentPartRecord
{
public virtual string Text { get; set; }
public virtual double Price { get; set; }
public virtual int TextPosX { get; set; }
public virtual int TextPosY { get; set; }
public virtual String TextSale { get; set; }
public virtual int Color { get; set; }
}
public class ActionListRecord
{
public virtual int Id { get; set; }
public virtual ActionPartRecord ActionPartRecord { get; set; }
public virtual ActionWidgetPartRecord ActionWidgetPartRecord { get; set; }
}
public class ActionWidgetPartRecord : ContentPartRecord
{
public ActionWidgetPartRecord()
{
ActionList = new List<ActionListRecord>();
}
public virtual IList<ActionListRecord> ActionList { get; set; }
}
public class ActionWidgetPart : ContentPart<ActionWidgetPartRecord>
{
public IEnumerable<ActionPartRecord> ActionList
{
get
{
return Record.ActionList.Select(x => x.ActionPartRecord);
}
}
}
ActionPart class
public class ActionPart : ContentPart<ActionPartRecord>
{
public String Text
{
get { return Record.Text; }
set { Record.Text = value; }
}
/*other field*/
}
Migrations
public int Create()
{
SchemaBuilder.CreateTable("ActionPartRecord", table => table
.ContentPartRecord()
.Column<string>("Text")
.Column<double>("Price")
.Column<int>("TextPosX")
.Column<int>("TextPosY")
.Column<string>("TextSale")
.Column<int>("Color")
);
ContentDefinitionManager.AlterPartDefinition("ActionPart",
builder => builder
.WithField("BaseImage", fieldBuilder => fieldBuilder.OfType("MediaPickerField").WithDisplayName("Action Image"))
.WithField("PatternImage", fieldBuilder => fieldBuilder.OfType("MediaPickerField").WithDisplayName("Pattern Image"))
.WithField("TimeExp", fieldBuilder => fieldBuilder.OfType("DateTimeField").WithDisplayName("Expecting date"))
.Attachable());
ContentDefinitionManager.AlterTypeDefinition("Action", cfg => cfg
.WithPart("CommonPart")
.WithPart("TitlePart")
.WithPart("RoutePart")
.WithPart("BodyPart")
.WithPart("ActionPart")
.Creatable()
.Indexed());
SchemaBuilder.CreateTable("ActionListRecord",
table => table
.Column<int>("Id", column => column.PrimaryKey().Identity())
.Column<int>("ActionPartRecord_Id")
.Column<int>("ActionWidgetPartRecord_Id")
);
SchemaBuilder.CreateTable("ActionWidgetPartRecord", table => table
.ContentPartRecord()
);
ContentDefinitionManager.AlterPartDefinition(
"ActionWidgetPart",
builder => builder.Attachable());
ContentDefinitionManager.AlterTypeDefinition("ActionWidget", cfg => cfg
.WithPart("ActionWidgetPart")
.WithPart("WidgetPart")
.WithPart("CommonPart")
.WithSetting("Stereotype", "Widget"));
return 1;
}
Driver Display method
protected override DriverResult Display(
ActionWidgetPart part,
string displayType,
dynamic shapeHelper)
{
return ContentShape("Parts_ActionWidget",
() => shapeHelper.Parts_ActionWidget(
ContentPart: part,
ActionList: part.ActionList));
}
Widget View
@foreach (var action in Model.ActionList)
{
<div class="item">
*How to access BaseImage Field in this row*
<div class="sale-pattern"></div>
<div class="container">
<div class="carousel-caption">
<h1>@action.Text</h1>
<h1 class="price">@action.Price</h1>
</div>
</div>
</div>
}
© Stack Overflow or respective owner