Describe the class relationships among Product, SubProduct and a Customer(or Lead) in VB.net

Rajnilari2015
Posted by Rajnilari2015 under VB.NET category on | Points: 40 | Views : 266
A Product can have multiple SubProducts. And multiple Customers/Leads can subscribe to multiple SubProducts

It is described as under

Class NProduct
Public Property ProductID() As String
Get
Return m_ProductID
End Get
Set
m_ProductID = Value
End Set
End Property
Private m_ProductID As String
Public Property SubProducts() As List(Of NSubProduct)
Get
Return m_SubProducts
End Get
Set
m_SubProducts = Value
End Set
End Property
Private m_SubProducts As List(Of NSubProduct)
End Class

Class NSubProduct
Public Property NSubProductID() As String
Get
Return m_NSubProductID
End Get
Set
m_NSubProductID = Value
End Set
End Property
Private m_NSubProductID As String
Public Property Color() As String
Get
Return m_Color
End Get
Set
m_Color = Value
End Set
End Property
Private m_Color As String
Public Property NSubProductName() As String
Get
Return m_NSubProductName
End Get
Set
m_NSubProductName = Value
End Set
End Property
Private m_NSubProductName As String
Public Property NLeads() As List(Of NLead)
Get
Return m_NLeads
End Get
Set
m_NLeads = Value
End Set
End Property
Private m_NLeads As List(Of NLead)
End Class

Class NLead
Public Property NLeadID() As String
Get
Return m_NLeadID
End Get
Set
m_NLeadID = Value
End Set
End Property
Private m_NLeadID As String
Public Property NCreatedDate() As DateTime
Get
Return m_NCreatedDate
End Get
Set
m_NCreatedDate = Value
End Set
End Property
Private m_NCreatedDate As DateTime
End Class


Sample data for population of the above data structure

Imports System.Collections.Generic
Imports System.Linq

Namespace ConsoleApplication1
Class Program
Private Shared Sub Main(args As String())
Dim dataSRC = SourceData()
End Sub

Private Shared Function SourceData() As NProduct
Dim objNProduct As New NProduct()
objNProduct.ProductID = "1"
objNProduct.SubProducts = GetSubProducts()
Return objNProduct
End Function

Private Shared Function GetSubProducts() As List(Of NSubProduct)
Dim lstSubProds As New List(Of NSubProduct)()
Enumerable.Range(1, 4).ToList().ForEach(Function(i) lstSubProds.Add(New NSubProduct() With { _
Key .NSubProductID = "NSubProductID" + i.ToString(), _
Key .NSubProductName = "SubProduct" + i.ToString(), _
Key .NLeads = GetLeads(i) _
}))
Return lstSubProds
End Function

Private Shared Function GetLeads(j As Integer) As List(Of NLead)
Dim lstLeads As New List(Of NLead)()

For i As Integer = 0 To 4




lstLeads.Add(New NLead() With { _
Key .NLeadID = "NLeadID" + (If((i Mod 2 = 0), i.ToString(), j.ToString())), _
Key .NCreatedDate = DateTime.Now.AddDays(j) _
})
Next
Return lstLeads
End Function
End Class

Class NProduct
Public Property ProductID() As String
Get
Return m_ProductID
End Get
Set
m_ProductID = Value
End Set
End Property
Private m_ProductID As String
Public Property SubProducts() As List(Of NSubProduct)
Get
Return m_SubProducts
End Get
Set
m_SubProducts = Value
End Set
End Property
Private m_SubProducts As List(Of NSubProduct)
End Class

Class NSubProduct
Public Property NSubProductID() As String
Get
Return m_NSubProductID
End Get
Set
m_NSubProductID = Value
End Set
End Property
Private m_NSubProductID As String
Public Property NSubProductName() As String
Get
Return m_NSubProductName
End Get
Set
m_NSubProductName = Value
End Set
End Property
Private m_NSubProductName As String
Public Property NLeads() As List(Of NLead)
Get
Return m_NLeads
End Get
Set
m_NLeads = Value
End Set
End Property
Private m_NLeads As List(Of NLead)
End Class

Class NLead
Public Property NLeadID() As String
Get
Return m_NLeadID
End Get
Set
m_NLeadID = Value
End Set
End Property
Private m_NLeadID As String
Public Property NCreatedDate() As DateTime
Get
Return m_NCreatedDate
End Get
Set
m_NCreatedDate = Value
End Set
End Property
Private m_NCreatedDate As DateTime
End Class
End Namespace

Comments or Responses

Login to post response