or
public
class
BeamlineViewModel
{
public
decimal
ID {
get
;
set
; }
public
string
Description {
get
;
set
; }
public
Nullable<
decimal
> SortOrder {
get
;
set
; }
public
string
InsertionDevice {
get
;
set
; }
public
Nullable<
decimal
> AllocationPanelID {
get
;
set
; }
public
string
Status {
get
;
set
; }
public
IEnumerable<SelectListItem> AllocationPanels {
get
;
set
; }
public
IEnumerable<SelectListItem> StatusTypes =
new
List<SelectListItem>
{
new
SelectListItem {Value =
"A"
, Text =
"Available"
},
new
SelectListItem {Value =
"C"
, Text =
"Construction and Commissioning"
},
new
SelectListItem {Value =
"D"
, Text =
"Diagnostic and Instrumentation"
},
new
SelectListItem {Value =
"O"
, Text =
"Operational"
},
new
SelectListItem {Value =
"U"
, Text =
"Unused Port"
}
};
}
public
ActionResult Index()
{
return
View(GetBeamlines());
}
public
ActionResult Edit(
int
id)
{
using
(MyEntities context =
new
MyEntities())
{
return
View(context.Beamlines.Find(id));
}
}
private
static
IEnumerable<BeamlineViewModel> GetBeamlines()
{
var context =
new
MyEntities();
return
context.Beamlines.Select(b =>
new
BeamlineViewModel
{
ID = b.ID,
Description = b.Description,
SortOrder = b.Sort_Order,
InsertionDevice = b.Insertion_Device,
AllocationPanelID = b.Allocation_Panel_ID,
Status = b.Status
});
}
public
ActionResult GetAllocationPanels()
{
using
(MyEntities context =
new
MyEntities())
{
var allocationPanels = context.Allocation_Panels.ToList();
var model =
new
BeamlineViewModel
{
AllocationPanels = allocationPanels.Select(m =>
new
SelectListItem { Value = m.ID.ToString(), Text = m.Description })
};
return
View(model);
}
}
@model IEnumerable<MyProject.ViewModels.BeamlineViewModel>
@{
ViewBag.Title =
"Beamlines"
;
}
<h2>Beamlines</h2>
@(Html.Kendo().Grid(Model)
.Name(
"gvBeamlines"
)
.Columns(columns =>
{
columns.Command(command => { command.Edit(); }).Width(50);
columns.Bound(o => o.Description).Width(100);
columns.Bound(o => o.InsertionDevice).Title(
"Insertion Device"
);
columns.Bound(o => o.Status);
columns.Bound(o => o.EnergyRange).Title(
"Energy Range"
);
columns.Command(command => { command.Destroy(); }).Width(50);
})
.ToolBar(toolbar => toolbar.Create())
.Editable(editable => editable.Mode(GridEditMode.PopUp).TemplateName(
"Beamline"
).Window(window => window.HtmlAttributes(
new
{ @style =
"width:700px;"
})))
.Pageable()
.Sortable()
.DataSource(dataSource => dataSource
.Server()
.Model(model => model.Id(o => o.ID))
.Create(create => create.Action(
"Create"
,
"Beamlines"
))
.Read(read => read.Action(
"Index"
,
"Beamlines"
))
.Update(update => update.Action(
"Edit"
,
"Beamlines"
))
.Destroy(destroy => destroy.Action(
"Delete"
,
"Beamlines"
))
)
)
@model MyProject.ViewModels.BeamlineViewModel
@Html.HiddenFor(model => model.ID)
<div
class
=
"editor-label"
>
@Html.Label(
"Beamline"
)
</div>
<div
class
=
"editor-field"
>
@Html.EditorFor(model => model.Description)
@Html.ValidationMessageFor(model => model.Description)
</div>
<div
class
=
"editor-label"
>
@Html.Label(
"Status"
)
</div>
<div
class
=
"editor-field"
>
@Html.DropDownListFor(model => model.Status,
new
SelectList(Model.StatusTypes,
"Value"
,
"Text"
),
"(Select One)"
)
@Html.ValidationMessageFor(model => model.Status)
</div>
<div
class
=
"editor-label"
>
@Html.Label(
"Sort Order"
)
</div>
<div
class
=
"editor-field"
>
@Html.EditorFor(model => model.SortOrder)
@Html.ValidationMessageFor(model => model.SortOrder)
</div>
<div
class
=
"editor-label"
>
@Html.Label(
"Insertion Device Beamline"
)
</div>
<div
class
=
"editor-field"
>
@Html.RadioButtonFor(model => model.InsertionDevice,
"Y"
)
@Html.Label(
"Yes"
)
@Html.RadioButtonFor(model => model.InsertionDevice,
"N"
)
@Html.Label(
"No"
)
@Html.ValidationMessageFor(model => model.InsertionDevice)
</div>
<div
class
=
"editor-label"
>
@Html.Label(
"Allocation Panel"
)
</div>
<div
class
=
"editor-field"
>
@Html.DropDownListFor(model => model.AllocationPanelID,
new
SelectList(Model.AllocationPanels,
"Value"
,
"Text"
),
"(Select One)"
)
@Html.ValidationMessageFor(model => model.AllocationPanelID)
</div>