diff --git a/app/controllers/CategoriesController.asp b/app/controllers/CategoriesController.asp
index bf76a36..f27c178 100644
--- a/app/controllers/CategoriesController.asp
+++ b/app/controllers/CategoriesController.asp
@@ -34,71 +34,137 @@ Class CategoriesController_Class
m_title = v
End Property
- '---------------------------------------------------------------
- ' Action: Index
- '---------------------------------------------------------------
- Public Sub Index()
- ' TODO: Implement Index action
- Response.Write "Index action called"
- End Sub
-
- '---------------------------------------------------------------
- ' Action: Show
- '---------------------------------------------------------------
- Public Sub Show(id)
- ' TODO: Implement Show action
- Response.Write "Show called
"
- Response.Write "Parameters:
"
- Response.Write "id = " & Server.HTMLEncode(CStr(id)) & "
"
- End Sub
-
- '---------------------------------------------------------------
- ' Action: New
- '---------------------------------------------------------------
- Public Sub NewForm()
- ' TODO: Implement NewForm action
- Response.Write "NewForm action called"
- End Sub
-
- '---------------------------------------------------------------
- ' Action: Create
- '---------------------------------------------------------------
- Public Sub Create()
- ' TODO: Implement Create action
- Response.Write "Create action called"
- End Sub
-
- '---------------------------------------------------------------
- ' Action: Edit
- '---------------------------------------------------------------
- Public Sub Edit(id)
- ' TODO: Implement Edit action
- Response.Write "Edit called
"
- Response.Write "Parameters:
"
- Response.Write "id = " & Server.HTMLEncode(CStr(id)) & "
"
- End Sub
-
- '---------------------------------------------------------------
- ' Action: Update
- '---------------------------------------------------------------
- Public Sub Update(id)
- ' TODO: Implement Update action
- Response.Write "Update called
"
- Response.Write "Parameters:
"
- Response.Write "id = " & Server.HTMLEncode(CStr(id)) & "
"
- End Sub
-
- '---------------------------------------------------------------
- ' Action: Delete
- '---------------------------------------------------------------
- Public Sub Delete(id)
- ' TODO: Implement Delete action
- Response.Write "Delete called
"
- Response.Write "Parameters:
"
- Response.Write "id = " & Server.HTMLEncode(CStr(id)) & "
"
- End Sub
-
-End Class
+ '---------------------------------------------------------------
+ ' Action: Index
+ '---------------------------------------------------------------
+ Public Sub Index()
+ Dim categories
+ Set categories = CategoriesRepository().FindAll
+ %>
+
+ <%
+ End Sub
+
+ '---------------------------------------------------------------
+ ' Action: Show
+ '---------------------------------------------------------------
+ Public Sub Show(ByVal id)
+ Dim category
+ On Error Resume Next
+ Set category = CategoriesRepository().FindByID(id)
+ If Err.Number <> 0 Then
+ Err.Clear
+ On Error GoTo 0
+ Response.Status = "404 Not Found"
+ %>
+
+ <%
+ Exit Sub
+ End If
+ On Error GoTo 0
+ %>
+
+ <%
+ End Sub
+
+ '---------------------------------------------------------------
+ ' Action: New
+ '---------------------------------------------------------------
+ Public Sub NewForm()
+ %>
+
+ <%
+ End Sub
+
+ '---------------------------------------------------------------
+ ' Action: Create
+ '---------------------------------------------------------------
+ Public Sub Create()
+ Dim name : name = Trim(Request.Form("Name"))
+ If Len(name) = 0 Then
+ Flash().AddError "Name is required."
+ Response.Redirect "/categories/new"
+ Exit Sub
+ End If
+
+ Dim category
+ Set category = New POBO_Categories
+
+ category.Name = name
+ category.Slug = Request.Form("Slug")
+ category.Description = Request.Form("Description")
+
+ CategoriesRepository().AddNew category
+ Flash().Success = "Category created."
+ Response.Redirect "/categories"
+ End Sub
+
+ '---------------------------------------------------------------
+ ' Action: Edit
+ '---------------------------------------------------------------
+ Public Sub Edit(ByVal id)
+ Dim category
+ On Error Resume Next
+ Set category = CategoriesRepository().FindByID(id)
+ If Err.Number <> 0 Then
+ Err.Clear
+ On Error GoTo 0
+ Response.Status = "404 Not Found"
+ %>
+
+ <%
+ Exit Sub
+ End If
+ On Error GoTo 0
+ %>
+
+ <%
+ End Sub
+
+ '---------------------------------------------------------------
+ ' Action: Update
+ '---------------------------------------------------------------
+ Public Sub Update(ByVal id)
+ Dim category
+ On Error Resume Next
+ Set category = CategoriesRepository().FindByID(id)
+ If Err.Number <> 0 Then
+ Err.Clear
+ On Error GoTo 0
+ Response.Status = "404 Not Found"
+ %>
+
+ <%
+ Exit Sub
+ End If
+ On Error GoTo 0
+
+ Dim name : name = Trim(Request.Form("Name"))
+ If Len(name) = 0 Then
+ Flash().AddError "Name is required."
+ Response.Redirect "/categories/" & Server.URLEncode(CStr(id)) & "/edit"
+ Exit Sub
+ End If
+
+ category.Name = name
+ category.Slug = Request.Form("Slug")
+ category.Description = Request.Form("Description")
+
+ CategoriesRepository().Update category
+ Flash().Success = "Category updated."
+ Response.Redirect "/categories"
+ End Sub
+
+ '---------------------------------------------------------------
+ ' Action: Delete
+ '---------------------------------------------------------------
+ Public Sub Delete(ByVal id)
+ CategoriesRepository().Delete id
+ Flash().Success = "Category deleted."
+ Response.Redirect "/categories"
+ End Sub
+
+End Class
' Singleton instance
Dim CategoriesController_Class__Singleton
diff --git a/app/controllers/CommentsController.asp b/app/controllers/CommentsController.asp
index 9ee675e..5712243 100644
--- a/app/controllers/CommentsController.asp
+++ b/app/controllers/CommentsController.asp
@@ -34,25 +34,68 @@ Class CommentsController_Class
m_title = v
End Property
- '---------------------------------------------------------------
- ' Action: Create
- '---------------------------------------------------------------
- Public Sub Create()
- ' TODO: Implement Create action
- Response.Write "Create action called"
- End Sub
-
- '---------------------------------------------------------------
- ' Action: Delete
- '---------------------------------------------------------------
- Public Sub Delete(id)
- ' TODO: Implement Delete action
- Response.Write "Delete called
"
- Response.Write "Parameters:
"
- Response.Write "id = " & Server.HTMLEncode(CStr(id)) & "
"
- End Sub
-
-End Class
+ '---------------------------------------------------------------
+ ' Action: Create
+ '---------------------------------------------------------------
+ Public Sub Create()
+ Dim comment
+ Set comment = New POBO_Comments
+
+ comment.PostID = FormNumberOrZero(Request.Form("PostID"))
+ comment.AuthorName = Request.Form("AuthorName")
+ comment.AuthorEmail = Request.Form("AuthorEmail")
+ comment.Body = Request.Form("Body")
+ comment.CreatedDate = Now()
+ comment.IsApproved = 0
+
+ CommentsRepository().AddNew comment
+ Flash().Success = "Comment submitted for approval."
+
+ Dim slug : slug = ResolvePostSlug(comment.PostID)
+ If Len(slug) > 0 Then
+ Response.Redirect "/posts/" & Server.URLEncode(slug)
+ Else
+ Response.Redirect "/posts"
+ End If
+ End Sub
+
+ '---------------------------------------------------------------
+ ' Action: Delete
+ '---------------------------------------------------------------
+ Public Sub Delete(ByVal id)
+ CommentsRepository().Delete id
+ Flash().Success = "Comment deleted."
+
+ Dim returnUrl : returnUrl = Request.ServerVariables("HTTP_REFERER")
+ If Len(returnUrl) = 0 Then returnUrl = "/posts"
+ Response.Redirect returnUrl
+ End Sub
+
+ Private Function FormNumberOrZero(ByVal value)
+ If IsNumeric(value) Then
+ FormNumberOrZero = CLng(value)
+ Else
+ FormNumberOrZero = 0
+ End If
+ End Function
+
+ Private Function ResolvePostSlug(ByVal postID)
+ Dim slug : slug = Trim(Request.Form("Slug"))
+ If Len(slug) = 0 Then slug = Trim(Request.Form("PostSlug"))
+
+ If Len(slug) = 0 And CLng(postID) > 0 Then
+ Dim post
+ On Error Resume Next
+ Set post = PostsRepository().FindByID(postID)
+ If Err.Number = 0 Then slug = CStr(post.Slug)
+ Err.Clear
+ On Error GoTo 0
+ End If
+
+ ResolvePostSlug = slug
+ End Function
+
+End Class
' Singleton instance
Dim CommentsController_Class__Singleton
diff --git a/app/repositories/CategoriesRepository.asp b/app/repositories/CategoriesRepository.asp
index c7a831f..e8eb20e 100644
--- a/app/repositories/CategoriesRepository.asp
+++ b/app/repositories/CategoriesRepository.asp
@@ -23,11 +23,15 @@ Class CategoriesRepository_Class
Destroy rs
End Function
- Public Function GetAll(orderBy)
- Set GetAll = Find(Empty, orderBy)
- End Function
-
- Public Function Find(where_kvarray, order_string_or_array)
+ Public Function GetAll(orderBy)
+ Set GetAll = Find(Empty, orderBy)
+ End Function
+
+ Public Function FindAll()
+ Set FindAll = Find(Empty, "Name")
+ End Function
+
+ Public Function Find(where_kvarray, order_string_or_array)
Dim sql : sql = "Select [CategoryID], [Description], [Name], [Slug] FROM [Categories]"
Dim where_keys, where_values, i
If Not IsEmpty(where_kvarray) Then
diff --git a/app/views/Categories/edit.asp b/app/views/Categories/edit.asp
new file mode 100644
index 0000000..a81b018
--- /dev/null
+++ b/app/views/Categories/edit.asp
@@ -0,0 +1,35 @@
+
Browse post categories from ASPBlogBrainOrdure.
+