Friday, July 25, 2008

Business Logic Layer

Free Open Source Church Management System Business Logic Layer

Much of the basic logic for my BLL's comes from the following tutorials. ASP.NET Data Access Tutorials

Here is the updated code for the Families BLL

Imports Microsoft.VisualBasic
Imports FamiliesTableAdapters

_
Public Class FamiliesBLL

Private _theAdapter As tblFamiliesTableAdapter = Nothing

Protected ReadOnly Property Adapter() As tblFamiliesTableAdapter
Get
If _theAdapter Is Nothing Then
_theAdapter = New tblFamiliesTableAdapter()
End If

Return _theAdapter
End Get
End Property

(System.ComponentModel.DataObjectMethodType.Select, True)> _
Public Function GetFamilies() As Families.tblFamiliesDataTable
Return Adapter.GetFamilies
End Function

(System.ComponentModel.DataObjectMethodType.Select, False)> _
Public Function GetFamilyByID(ByVal FamilyID As Integer) _
As Families.tblFamiliesDataTable
Return Adapter.GetFamilyByID(FamilyID)
End Function

(System.ComponentModel.DataObjectMethodType.Insert, True)> _
Public Function NewFamily( _
ByVal FamilyName As String, ByVal FamilyDescription As String, _
ByVal SalutationID As Integer, ByVal Salutation As String, _
ByVal Address As String, ByVal City As String, ByVal StateID As Integer, ByVal StateName As String, ByVal ZIP As String, _
ByVal HomePhone As String, ByVal FamilyCellPhone As String, ByVal FamilyEmail As String, ByVal ShelbyFamilyID As Integer, _
ByVal ImageID As Integer _
) As Boolean

Dim SiteID As Integer = 1


Dim TBL As New Families.tblFamiliesDataTable
Dim ARow As Families.tblFamiliesRow = TBL.NewtblFamiliesRow()

ARow.FamilyName = FamilyName
ARow.FamilyDescription = FamilyDescription

ARow.SalutationID = SalutationID
ARow.Salutation = Salutation

ARow.Address = Address
ARow.City = City
ARow.StateID = StateID
ARow.StateName = StateName
ARow.ZIP = ZIP

ARow.HomePhone = HomePhone
ARow.FamilyCellPhone = FamilyCellPhone
ARow.FamilyEmail = FamilyEmail

ARow.ShelbyFamilyID = ShelbyFamilyID

ARow.SiteID = SiteID

ARow.Created = Now()
ARow.CreatedBy = HttpContext.Current.User.Identity.Name
ARow.LastEdited = Now()
ARow.EditedBy = HttpContext.Current.User.Identity.Name

TBL.AddtblFamiliesRow(ARow)
Dim rowsAffected As Integer = Adapter.Update(TBL)

Return rowsAffected = 1
End Function

(System.ComponentModel.DataObjectMethodType.Update, True)> _
Public Function UpdateFamily(ByVal FamilyID As Integer, _
ByVal FamilyName As String, ByVal FamilyDescription As String, _
ByVal SalutationID As Integer, ByVal Salutation As String, _
ByVal Address As String, ByVal City As String, ByVal StateID As Integer, ByVal StateName As String, ByVal ZIP As String, _
ByVal HomePhone As String, ByVal FamilyCellPhone As String, ByVal FamilyEmail As String, _
ByVal ImageID As Integer _
) As Boolean

Dim TBL As Families.tblFamiliesDataTable = _
Adapter.GetFamilyByID(FamilyID)

If TBL.Count = 0 Then
Return False
End If

Dim ARow As Families.tblFamiliesRow = TBL(0)

ARow.FamilyName = FamilyName
ARow.FamilyDescription = FamilyDescription

ARow.SalutationID = SalutationID
ARow.Salutation = Salutation

ARow.Address = Address
ARow.City = City
ARow.StateID = StateID
ARow.StateName = StateName
ARow.ZIP = ZIP

ARow.HomePhone = HomePhone
ARow.FamilyCellPhone = FamilyCellPhone
ARow.FamilyEmail = FamilyEmail

ARow.LastEdited = Now()
ARow.EditedBy = HttpContext.Current.User.Identity.Name

Dim rowsAffected As Integer = Adapter.Update(ARow)

Return rowsAffected = 1
End Function

(System.ComponentModel.DataObjectMethodType.Delete, True)> _
Public Function DeleteFamily(ByVal FamilyID As Integer) As Boolean

Dim TBL As Families.tblFamiliesDataTable = _
Adapter.GetFamilyByID(FamilyID)

If TBL.Count = 0 Then
Return False
End If

Dim ARow As Families.tblFamiliesRow = TBL(0)

ARow.LastEdited = Now()
ARow.EditedBy = HttpContext.Current.User.Identity.Name

ARow.Deleted = True
ARow.DateDeleted = Now()
ARow.DeletedBy = HttpContext.Current.User.Identity.Name

Dim rowsAffected As Integer = Adapter.Update(ARow)

Return rowsAffected = 1
End Function

(System.ComponentModel.DataObjectMethodType.Delete, False)> _
Public Function DeleteCompletly(ByVal FamilyID As Integer) As Boolean
Dim rowsAffected As Integer = Adapter.Delete(FamilyID)

Return rowsAffected = 1
End Function

End Class

No comments: