or
@model IEnumerable<Application.ServiceProxy.CustomerDTO>@(Html.Kendo().Grid(Model) .Name("grid") .Columns(columns => { columns.Bound(c => c.customerID).Width(100); columns.Bound(c => c.name1).Width(100); columns.Bound(c => c.matchcode).Width(100); columns.Bound(c => c.city).Width(100); columns.Bound(c => c.postalCode).Width(100); }) .Pageable() .Sortable() .Scrollable() .Filterable() //.HtmlAttributes(new { style = "height:430px;" }) .DataSource(dataSource => dataSource .Ajax() .PageSize(20) .Read(read => read.Action("Get", "Customer") )using System;using System.Collections.Generic;using System.Net.Http;using System.Web.Mvc;using Kendo.Mvc.UI;using Kendo.Mvc.Extensions;using BusinessLogic.Models;using System.Web;using System.Linq;using Newtonsoft.Json;using Application.ServiceProxy;using System.Web.Http;using System.Web.Http.OData.Query;using System.Web.Http.OData;namespace Application.Controllers{ public class CustomerController : Controller { [Queryable(AllowedQueryOptions = AllowedQueryOptions.All)] public IEnumerable<ServiceProxy.CustomerDTO> Get() { var customer = odataService.Customer.Take(10); return customer.AsEnumerable(); } public ActionResult Index() { return View() ; } }}using System;using System.Collections.Generic;using System.Linq;using System.Net;using System.Web;using System.Net.Http;using System.Web.Http;using BusinessLogic.Models;using System.Web.Http.OData.Query;using System.Web.Http.OData;namespace BusinessLogic.Controllers{ //public class CustomerController : CPSGlobalAPIController public class CustomerController : EntitySetController<CustomerDTO, int> { protected cpsGlobalEntities entity = new cpsGlobalEntities(); #region mapper private IQueryable<CustomerDTO> mapCustomer() { return from c in entity.customer select new CustomerDTO() { customerID = c.customerID, matchcode = c.matchcode, salesOrganizationCompanyCode = c.salesOrganization.companyCode, salesOrganizationID = c.salesOrganizationID, salesOrganizationName = c.salesOrganization.name, statusID = c.statusID, statusPrefix = c.status.prefix, statusTranslationKey = c.status.translationKey, serviceLevelStatusID = c.serviceLevelStatusID, serviceLevelPrefix = c.status1.prefix, serviceLevelTranslationKey = c.status1.translationKey, systemID = c.systemID, dunsNumber = c.dunsNumber, mediaIDLogo = c.mediaIDLogo, salesOrganization = c.salesOrganization.companyCode, inventoryManagerID = c.inventoryManager.inventoryManagerID, inventoryManagerAddressID = c.inventoryManager.addressID, customerExternalSystemID = c.customerExternalSystemID, internationalGroup = c.internationalGroup, division = c.division, corporateID = c.corporateID, #region duplicated items for improved list view name1 = c.customerExternalSystem.address.name1, postalCode = c.customerExternalSystem.address.postalCode, city = c.customerExternalSystem.address.city, stateCode = c.customerExternalSystem.address.state.stateCode, countryCode = c.customerExternalSystem.address.country.countryCode #endregion }; } #endregion #region GET #region GET all [Queryable] public override IQueryable<CustomerDTO> Get() { return mapCustomer().AsQueryable(); } #endregion #region GET by ID protected override CustomerDTO GetEntityByKey(int key) { //return mapCustomer().FirstOrDefault(p => p.customerID == key); var cust = (from c in mapCustomer() where c.customerID == key select c).FirstOrDefault(); if (cust.inventoryManagerAddressID != null) { AddressController adC = new AddressController(); cust.inventoryManagerAddressDTO = adC.Get((int)cust.inventoryManagerAddressID); } if (cust.customerExternalSystemID != null) { CustomerExternalSystemController cesC = new CustomerExternalSystemController(); cust.customerExternalSystemDTO = cesC.Get((int)cust.customerExternalSystemID); } if (cust == null) throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotFound)); return cust; } #endregion #region POST protected override CustomerDTO CreateEntity(CustomerDTO customerDTO) { var customer = new customer() { matchcode = customerDTO.matchcode, salesOrganizationID = customerDTO.salesOrganizationID, statusID = customerDTO.statusID, serviceLevelStatusID = customerDTO.serviceLevelStatusID, mediaIDLogo = customerDTO.mediaIDLogo, systemID = customerDTO.systemID, customerExternalSystemID = customerDTO.customerExternalSystemID, internationalGroup = customerDTO.internationalGroup, division = customerDTO.division, corporateID = customerDTO.corporateID, inventoryManagerID = customerDTO.inventoryManagerID, dunsNumber = customerDTO.dunsNumber }; entity.customer.Add(customer); entity.SaveChanges(); return GetEntityByKey(customer.customerID); } protected override int GetKey(CustomerDTO customer) { return customer.customerID; } #endregion #region Put protected override CustomerDTO UpdateEntity(int key, CustomerDTO customerDTO) { var originalCustomer = entity.customer.Find(key); originalCustomer.matchcode = customerDTO.matchcode; originalCustomer.salesOrganizationID = customerDTO.salesOrganizationID; originalCustomer.statusID = customerDTO.statusID; originalCustomer.serviceLevelStatusID = customerDTO.serviceLevelStatusID; originalCustomer.mediaIDLogo = customerDTO.mediaIDLogo; originalCustomer.systemID = customerDTO.systemID; originalCustomer.customerExternalSystemID = customerDTO.customerExternalSystemID; originalCustomer.inventoryManagerID = customerDTO.inventoryManagerID; originalCustomer.dunsNumber = customerDTO.dunsNumber; originalCustomer.internationalGroup = customerDTO.internationalGroup; originalCustomer.division = customerDTO.division; originalCustomer.corporateID = customerDTO.corporateID; entity.SaveChanges(); return GetEntityByKey(key); } #endregion #region PATCH #endregion #region DELETE public override void Delete([FromODataUri] int key) { var customer = entity.customer.Find(key); if (customer == null) { throw new HttpResponseException(HttpStatusCode.NotFound); } entity.customer.Remove(customer); entity.SaveChanges(); } #endregion }}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>