ASP Classic blog framework - BrainOrdure
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.

181 lines
5.2KB

  1. <%
  2. ' Auto-generated Controller: Categories
  3. ' Generated on 5/2/2026 9:47:37 PM
  4. ' Generator: generateController.vbs v1.0
  5. '
  6. ' Remember to:
  7. ' 1. Add to app/controllers/autoload_controllers.asp
  8. ' 2. Register in core/lib.ControllerRegistry.asp
  9. ' 3. Add routes in public/Default.asp
  10. Class CategoriesController_Class
  11. Private m_useLayout
  12. Private m_title
  13. Private Sub Class_Initialize()
  14. m_useLayout = True
  15. m_title = "Categories"
  16. End Sub
  17. Public Property Get useLayout
  18. useLayout = m_useLayout
  19. End Property
  20. Public Property Let useLayout(v)
  21. m_useLayout = v
  22. End Property
  23. Public Property Get Title
  24. Title = m_title
  25. End Property
  26. Public Property Let Title(v)
  27. m_title = v
  28. End Property
  29. '---------------------------------------------------------------
  30. ' Action: Index
  31. '---------------------------------------------------------------
  32. Public Sub Index()
  33. Dim categories
  34. Set categories = CategoriesRepository().FindAll
  35. %>
  36. <!--#include file="../views/Categories/index.asp" -->
  37. <%
  38. End Sub
  39. '---------------------------------------------------------------
  40. ' Action: Show
  41. '---------------------------------------------------------------
  42. Public Sub Show(ByVal id)
  43. Dim category
  44. On Error Resume Next
  45. Set category = CategoriesRepository().FindByID(id)
  46. If Err.Number <> 0 Then
  47. Err.Clear
  48. On Error GoTo 0
  49. Response.Status = "404 Not Found"
  50. %>
  51. <!--#include file="../views/Error/NotFound.asp" -->
  52. <%
  53. Exit Sub
  54. End If
  55. On Error GoTo 0
  56. Dim categoryPosts
  57. Set categoryPosts = PostsRepository().Find(Array("CategoryID", id, "IsPublished", 1), "PublishedDate DESC")
  58. %>
  59. <!--#include file="../views/Categories/show.asp" -->
  60. <%
  61. End Sub
  62. '---------------------------------------------------------------
  63. ' Action: New
  64. '---------------------------------------------------------------
  65. Public Sub NewForm()
  66. %>
  67. <!--#include file="../views/Categories/new.asp" -->
  68. <%
  69. End Sub
  70. '---------------------------------------------------------------
  71. ' Action: Create
  72. '---------------------------------------------------------------
  73. Public Sub Create()
  74. Dim name : name = Trim(Request.Form("Name"))
  75. If Len(name) = 0 Then
  76. Flash().AddError "Name is required."
  77. Response.Redirect "/categories/new"
  78. Exit Sub
  79. End If
  80. Dim category
  81. Set category = New POBO_Categories
  82. category.Name = name
  83. category.Slug = Request.Form("Slug")
  84. category.Description = Request.Form("Description")
  85. CategoriesRepository().AddNew category
  86. Flash().Success = "Category created."
  87. Response.Redirect "/categories"
  88. End Sub
  89. '---------------------------------------------------------------
  90. ' Action: Edit
  91. '---------------------------------------------------------------
  92. Public Sub Edit(ByVal id)
  93. Dim category
  94. On Error Resume Next
  95. Set category = CategoriesRepository().FindByID(id)
  96. If Err.Number <> 0 Then
  97. Err.Clear
  98. On Error GoTo 0
  99. Response.Status = "404 Not Found"
  100. %>
  101. <!--#include file="../views/Error/NotFound.asp" -->
  102. <%
  103. Exit Sub
  104. End If
  105. On Error GoTo 0
  106. %>
  107. <!--#include file="../views/Categories/edit.asp" -->
  108. <%
  109. End Sub
  110. '---------------------------------------------------------------
  111. ' Action: Update
  112. '---------------------------------------------------------------
  113. Public Sub Update(ByVal id)
  114. Dim category
  115. On Error Resume Next
  116. Set category = CategoriesRepository().FindByID(id)
  117. If Err.Number <> 0 Then
  118. Err.Clear
  119. On Error GoTo 0
  120. Response.Status = "404 Not Found"
  121. %>
  122. <!--#include file="../views/Error/NotFound.asp" -->
  123. <%
  124. Exit Sub
  125. End If
  126. On Error GoTo 0
  127. Dim name : name = Trim(Request.Form("Name"))
  128. If Len(name) = 0 Then
  129. Flash().AddError "Name is required."
  130. Response.Redirect "/categories/" & Server.URLEncode(CStr(id)) & "/edit"
  131. Exit Sub
  132. End If
  133. category.Name = name
  134. category.Slug = Request.Form("Slug")
  135. category.Description = Request.Form("Description")
  136. CategoriesRepository().Update category
  137. Flash().Success = "Category updated."
  138. Response.Redirect "/categories"
  139. End Sub
  140. '---------------------------------------------------------------
  141. ' Action: Delete
  142. '---------------------------------------------------------------
  143. Public Sub Delete(ByVal id)
  144. CategoriesRepository().Delete id
  145. Flash().Success = "Category deleted."
  146. Response.Redirect "/categories"
  147. End Sub
  148. End Class
  149. ' Singleton instance
  150. Dim CategoriesController_Class__Singleton
  151. Function CategoriesController()
  152. If IsEmpty(CategoriesController_Class__Singleton) Then
  153. Set CategoriesController_Class__Singleton = New CategoriesController_Class
  154. End If
  155. Set CategoriesController = CategoriesController_Class__Singleton
  156. End Function
  157. %>

Powered by TurnKey Linux.