Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

130 lines
4.4KB

  1. <% Option Explicit %>
  2. <!--#include file="../../include_all.asp"-->
  3. <!--#include file="../../ViewModels/SettingsViewModels.asp"-->
  4. <%
  5. Class SettingsController
  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 = "Settings"
  13. set Model.Settings = SettingsRepository.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/Settings/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 = "Settings"
  27. set Model.Settings = SettingsRepository.SearchTablePaged(Array("ID","%" & searchValue & "%","Name","%" & searchValue & "%","Value","%" & 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/Settings/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.Settings = SettingsRepository.FindByID(id)
  38. Model.Title = "Edit Settings"
  39. HTMLSecurity.SetAntiCSRFToken "SettingsEditForm"
  40. %> <!--#include file="../../Views/Settings/Edit.asp"--> <%
  41. Flash.Success = "Settings Updated."
  42. End Sub
  43. Public Sub EditPost
  44. MVC.RequirePost
  45. HTMLSecurity.OnInvalidAntiCsrfTokenRedirectToActionExt "SettingsEditForm", Request.Form("nonce"), "Edit", Array("Id", Request.Form("Id"))
  46. dim ID : ID = Request.Form("Id")
  47. dim model : set model = SettingsRepository.FindByID(ID)
  48. set model = Automapper.AutoMap(Request.Form, model)
  49. 'model.Validate
  50. 'If model.Validator.HasErrors then
  51. FormCache.SerializeForm "EditSettings", Request.Form
  52. ' Flash.Errors = model.Validator.Errors
  53. ' MVC.RedirectToActionExt "Edit", Array("Id",ID)
  54. 'Else
  55. SettingsRepository.Update model
  56. FormCache.ClearForm "EditSettings"
  57. Flash.Success = "Settings updated."
  58. MVC.RedirectToAction "Index"
  59. 'End If
  60. End Sub
  61. Public Sub Create
  62. dim form_params : set form_params = FormCache.DeserializeForm("NewSettings")
  63. If Not form_params Is Nothing then
  64. set Model = Automapper.AutoMap(form_params, New Create_ViewModel_Class)
  65. Else
  66. set Model = new Create_ViewModel_Class
  67. End If
  68. HTMLSecurity.SetAntiCSRFToken "SettingsCreateForm"
  69. %> <!--#include file="../../Views/Settings/Create.asp"--> <%
  70. End Sub
  71. Public Sub CreatePost
  72. MVC.RequirePost
  73. HtmlSecurity.OnInvalidAntiCSRFTokenRedirectToAction "SettingsCreateForm", Request.Form("nonce"), "Create"
  74. dim new_Settings_model : set new_Settings_model = Automapper.AutoMap(Request.Form, new SettingsModel_Class)
  75. 'new_Settings_model.Validator.Validate
  76. 'If new_Settings_model.Validator.HasErrors then
  77. ' FormCache.SerializeForm "NewSettings", Request.Form
  78. ' Flash.Errors = new_Settings_model.Validator.Errors
  79. ' MVC.RedirectToAction "Create"
  80. 'Else
  81. SettingsRepository.AddNew new_Settings_model
  82. ' FormCache.ClearForm "NewSettings"
  83. Flash.Success = "Settings added."
  84. MVC.RedirectToAction "Index"
  85. 'End If
  86. End Sub
  87. Public Sub Delete
  88. dim id : id = Request.QueryString("Id")
  89. set Model = new Delete_ViewModel_Class
  90. set Model.Settings = SettingsRepository.FindByID(id)
  91. Model.Title = "Delete Settings"
  92. HTMLSecurity.SetAntiCSRFToken "SettingsDeleteForm"
  93. %> <!--#include file="../../Views/Settings/Delete.asp"--> <%
  94. End Sub
  95. Public Sub DeletePost
  96. MVC.RequirePost
  97. HtmlSecurity.OnInvalidAntiCSRFTokenRedirectToAction "SettingsDeleteForm", Request.Form("nonce"), "Create"
  98. dim id : id = Request.Form("Id")
  99. SettingsRepository.Delete id
  100. Flash.Success = "Settings deleted."
  101. MVC.RedirectToAction "Index"
  102. End Sub
  103. End Class
  104. MVC.Dispatch
  105. %>

Powered by TurnKey Linux.