Advertisement
Guest User

Untitled

a guest
May 1st, 2016
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.55 KB | None | 0 0
  1. @model IEnumerable<SAReds.UI.Web.Models.DepartmentModel>
  2.  
  3. @(Html.Telerik().Grid<SAReds.UI.Web.Models.DepartmentModel>(Model)
  4. .Name("Grid")
  5. .DataKeys(keys =>
  6. {
  7. keys.Add(o => o.Id);
  8. })
  9. .Columns(columns =>
  10. {
  11. columns.Bound(o => o.CompanyName).Title("Company Name").Width(150);
  12. columns.Bound(o => o.Name).Title("Department Name").Width(150);
  13. columns.Bound(o => o.Active).Width(100).Title("Active");
  14. columns.Template(o => Html.ActionLink("Edit", "EditDepartment", new { o.Id })).Width(35)
  15. .ClientTemplate("<a href=" " + Url.Action("EditDepartment", "Task") + "/<#= Id#>">Edit</a>")
  16. .Title("Edit");
  17. })
  18. .DataBinding(dataBinding =>
  19. {
  20. dataBinding.Server().Select("CompanyDepartment", "Task", new
  21. {
  22. ajax =
  23. ViewData["ajax"]
  24. });
  25. dataBinding.Ajax().Select("_CompanyDepartment",
  26. "Task").Enabled((bool)ViewData["ajax"]);
  27. })
  28. .Scrollable(scrolling => scrolling.Enabled((bool)ViewData["scrolling"]))
  29. .Sortable(sorting => sorting.Enabled((bool)ViewData["sorting"]))
  30. .Pageable(paging => paging.Enabled((bool)ViewData["paging"]))
  31. .Filterable(filtering => filtering.Enabled((bool)ViewData["filtering"]))
  32. .Groupable(grouping => grouping.Enabled((bool)ViewData["grouping"]))
  33. .Footer((bool)ViewData["showFooter"]) )
  34.  
  35. public ActionResult CompanyDepartment(bool? ajax, bool? scrolling, bool? paging, bool? filtering, bool? sorting,bool? grouping, bool? showFooter)
  36. {
  37. ViewData["ajax"] = ajax ?? true;
  38. ViewData["scrolling"] = scrolling ?? true;
  39. ViewData["paging"] = paging ?? true;
  40. ViewData["filtering"] = filtering ?? true;
  41. ViewData["grouping"] = grouping ?? true;
  42. ViewData["sorting"] = sorting ?? true;
  43. ViewData["showFooter"] = showFooter ?? true;
  44.  
  45.  
  46. IDataOperations ops = DataSession.GetDataOperations(null);
  47. List<Department> Depts = new List<Department>();
  48. List<Employee> employeeList = new List<Employee>();
  49. ops.Load(Depts).Select("*").From("Department");
  50. ops.Commit();
  51. //Employee employee = new Employee();
  52. Company company = new Company();
  53. ops.Load(employeeList);
  54. ops.Commit();
  55.  
  56. List<DepartmentModel> deptModel = new List<DepartmentModel>();
  57. foreach(Department dp in Depts)
  58. {
  59. ops.Load(company).FilterColumns("Id").Values(new { Id = dp.CompanyId });
  60. ops.Commit();
  61.  
  62. deptModel.Add(new DepartmentModel()
  63. {
  64. Id = dp.Id,
  65. CompanyId = dp.CompanyId,
  66. Active = dp.Active,
  67. Name = dp.Name,
  68. CompanyName = company.Name
  69. });
  70. }
  71.  
  72. return View(deptModel);
  73. }
  74.  
  75. [GridAction]
  76. public ActionResult _CompanyDepartment()
  77. {
  78.  
  79. IDataOperations ops = DataSession.GetDataOperations(null);
  80. List<Department> Depts = new List<Department>();
  81. ops.Load(Depts).Select("*").From("Department");
  82.  
  83. List<DepartmentModel> deptModel = new List<DepartmentModel>();
  84. foreach (Department dp in Depts)
  85. {
  86. deptModel.Add(new DepartmentModel()
  87. {
  88. Id = dp.Id,
  89. CompanyId = dp.CompanyId,
  90. Active = dp.Active,
  91. Name = dp.Name
  92. });
  93. }
  94.  
  95. return View(new GridModel<<SAReds.UI.Web.Models.DepartmentModel>>
  96. {
  97. Data = deptModel
  98. });
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement