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
Public Function GetFamilies() As Families.tblFamiliesDataTable
Return Adapter.GetFamilies
End Function
Public Function GetFamilyByID(ByVal FamilyID As Integer) _
As Families.tblFamiliesDataTable
Return Adapter.GetFamilyByID(FamilyID)
End Function
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
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
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
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:
Post a Comment