<% Class boards_Repository_Class Public Function FindByID(id) Dim sql : sql = "SELECT [id],[name],[slug],[created_at],[created_by],[updated_at],[updated_by] FROM [boards] WHERE [id] = ?" Dim rs : Set rs = DAL.Query(sql, Array(id)) If rs.EOF Then Err.Raise 1, "boards_Repository_Class", "Board not found with id = " & id Else Set FindByID = Automapper.AutoMap(rs, "POBO_boards") End If Destroy rs End Function Public Function FindBySlug(slug) Dim sql : sql = "SELECT [id],[name],[slug],[created_at],[created_by],[updated_at],[updated_by] FROM [boards] WHERE [slug] = ?" Dim rs : Set rs = DAL.Query(sql, Array(slug)) If rs.EOF Then Set FindBySlug = Nothing Else Set FindBySlug = Automapper.AutoMap(rs, "POBO_boards") End If Destroy rs End Function Public Function GetAll() Dim sql : sql = "SELECT [id],[name],[slug],[created_at],[created_by],[updated_at],[updated_by] FROM [boards] ORDER BY [name] ASC" Dim rs : Set rs = DAL.Query(sql, Empty) Dim list : Set list = New LinkedList_Class Do Until rs.EOF list.Push Automapper.AutoMap(rs, "POBO_boards") rs.MoveNext Loop Set GetAll = list Destroy rs End Function Public Function SlugExists(slug, excludeId) Dim sql, rs If CLng(excludeId) > 0 Then sql = "SELECT COUNT(*) FROM [boards] WHERE [slug] = ? AND [id] <> ?" Set rs = DAL.Query(sql, Array(slug, excludeId)) Else sql = "SELECT COUNT(*) FROM [boards] WHERE [slug] = ?" Set rs = DAL.Query(sql, Array(slug)) End If SlugExists = (rs(0) > 0) Destroy rs End Function Public Function UniqueSlug(baseSlug, excludeId) Dim candidate, suffix candidate = baseSlug suffix = 2 Do While SlugExists(candidate, excludeId) candidate = baseSlug & "-" & suffix suffix = suffix + 1 Loop UniqueSlug = candidate End Function Public Sub AddNew(ByRef model) Dim sql : sql = "INSERT INTO [boards] ([name],[slug],[created_at],[created_by],[updated_at],[updated_by]) VALUES (?,?,?,?,?,?)" DAL.Execute sql, Array(model.name, model.slug, model.created_at, model.created_by, model.updated_at, model.updated_by) Dim rsId : Set rsId = DAL.Query("SELECT @@IDENTITY AS NewID", Empty) If Not rsId.EOF Then If Not IsNull(rsId(0)) Then model.id = rsId(0) End If Destroy rsId End Sub Public Sub Update(model) Dim sql : sql = "UPDATE [boards] SET [name]=?,[slug]=?,[updated_at]=?,[updated_by]=? WHERE [id]=?" DAL.Execute sql, Array(model.name, model.slug, model.updated_at, model.updated_by, model.id) End Sub Public Sub Delete(id) DAL.Execute "DELETE FROM [boards] WHERE [id]=?", Array(id) End Sub End Class Dim boards_Repository__Singleton Function boards_Repository() If IsEmpty(boards_Repository__Singleton) Then Set boards_Repository__Singleton = New boards_Repository_Class End If Set boards_Repository = boards_Repository__Singleton End Function %>