You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

138 lines
4.5KB

  1. <% Option Explicit %>
  2. <!--#include file="../../include_all.asp"-->
  3. <!--#include file="../../ViewModels/KitViewModels.asp"-->
  4. <%
  5. Class KitController
  6. Public Model
  7. Public Sub Index
  8. dim page_size : page_size = 10
  9. dim page_num : page_num = Choice(Len(Request.Querystring("page_num")) > 0, Request.Querystring("page_num"), 1)
  10. dim page_count, record_count
  11. set Model = new PagedIndex_ViewModel_Class
  12. Model.Title = "Kit"
  13. set Model.Kit = KitRepository.FindPaged(empty, "ID", page_size, page_num, page_count, record_count)
  14. Model.CurrentPageNumber = page_num
  15. Model.PageSize = page_size
  16. Model.PageCount = page_count
  17. Model.RecordCount = record_count
  18. %> <!--#include file="../../Views/Kit/Index.asp"--> <%
  19. End Sub
  20. Public Sub Search
  21. dim searchValue:searchValue = Choice(Request.Form.Count = 0,Request.QueryString("q"),Request.Form("q"))
  22. dim page_size : page_size = 10
  23. dim page_num : page_num = Choice(Len(Request.Querystring("page_num")) > 0, Request.Querystring("page_num"), 1)
  24. dim page_count, record_count
  25. set Model = new PagedIndex_ViewModel_Class
  26. Model.Title = "Kit"
  27. set Model.Kit = KitRepository.SearchTablePaged(Array("ID","%" & searchValue & "%","JobNumber","%" & searchValue & "%","Jcode","%" & searchValue & "%"),"ID", page_size, page_num, page_count, record_count)
  28. Model.CurrentPageNumber = page_num
  29. Model.PageSize = page_size
  30. Model.PageCount = page_count
  31. Model.RecordCount = record_count
  32. %> <!--#include file="../../Views/Kit/Index.asp"--> <%
  33. End Sub
  34. Public Sub Edit
  35. dim id : id = Request.QueryString("Id")
  36. set Model = new Edit_ViewModel_Class
  37. set Model.Kit = KitRepository.FindByID(id)
  38. Model.Title = "Edit Kit"
  39. HTMLSecurity.SetAntiCSRFToken "KitEditForm"
  40. %> <!--#include file="../../Views/Kit/Edit.asp"--> <%
  41. Flash.Success = "Kit Updated."
  42. End Sub
  43. Public Sub EditPost
  44. MVC.RequirePost
  45. HTMLSecurity.OnInvalidAntiCsrfTokenRedirectToActionExt "KitEditForm", Request.Form("nonce"), "Edit", Array("Id", Request.Form("Id"))
  46. dim ID : ID = Request.Form("Id")
  47. dim model : set model = KitRepository.FindByID(ID)
  48. set model = Automapper.AutoMap(Request.Form, model)
  49. 'model.Validate
  50. 'If model.Validator.HasErrors then
  51. FormCache.SerializeForm "EditKit", Request.Form
  52. ' Flash.Errors = model.Validator.Errors
  53. ' MVC.RedirectToActionExt "Edit", Array("Id",ID)
  54. 'Else
  55. KitRepository.Update model
  56. FormCache.ClearForm "EditKit"
  57. Flash.Success = "Kit updated."
  58. MVC.RedirectToAction "Index"
  59. 'End If
  60. End Sub
  61. Public Sub Create
  62. dim form_params : set form_params = FormCache.DeserializeForm("NewKit")
  63. dim ID : ID = Request.QueryString("Id")
  64. dim model : set model = new Create_ViewModel_Class
  65. model.Title = "Create Kit "
  66. model.JCode = ID
  67. dim ugh : set ugh = JurisdictionRepository.Find(Array("[JCode] = ?",ID),empty)
  68. set model.Jurisdiction = ugh.pop()
  69. 'If Not form_params Is Nothing then
  70. ' set Model = Automapper.AutoMap(form_params, New Create_ViewModel_Class)
  71. 'Else
  72. ' set Model = new Create_ViewModel_Class
  73. 'End If
  74. HTMLSecurity.SetAntiCSRFToken "KitCreateForm"
  75. %> <!--#include file="../../Views/Kit/Create.asp"--> <%
  76. End Sub
  77. Public Sub CreatePost
  78. MVC.RequirePost
  79. HtmlSecurity.OnInvalidAntiCSRFTokenRedirectToAction "KitCreateForm", Request.Form("nonce"), "Create"
  80. dim new_Kit_model : set new_Kit_model = Automapper.AutoMap(Request.Form, new KitModel_Class)
  81. 'new_Kit_model.Validator.Validate
  82. 'If new_Kit_model.Validator.HasErrors then
  83. ' FormCache.SerializeForm "NewKit", Request.Form
  84. ' Flash.Errors = new_Kit_model.Validator.Errors
  85. ' MVC.RedirectToAction "Create"
  86. 'Else
  87. KitRepository.AddNew new_Kit_model
  88. ' FormCache.ClearForm "NewKit"
  89. Flash.Success = "Kit added."
  90. MVC.RedirectToAction "Index"
  91. 'End If
  92. End Sub
  93. Public Sub Delete
  94. dim id : id = Request.QueryString("Id")
  95. set Model = new Delete_ViewModel_Class
  96. set Model.Kit = KitRepository.FindByID(id)
  97. Model.Title = "Delete Kit"
  98. HTMLSecurity.SetAntiCSRFToken "KitDeleteForm"
  99. %> <!--#include file="../../Views/Kit/Delete.asp"--> <%
  100. End Sub
  101. Public Sub DeletePost
  102. MVC.RequirePost
  103. HtmlSecurity.OnInvalidAntiCSRFTokenRedirectToAction "KitDeleteForm", Request.Form("nonce"), "Create"
  104. dim id : id = Request.Form("Id")
  105. KitRepository.Delete id
  106. Flash.Success = "Kit deleted."
  107. MVC.RedirectToAction "Index"
  108. End Sub
  109. End Class
  110. MVC.Dispatch
  111. %>

Powered by TurnKey Linux.