I am creating an mvc application in vb.net in which I am trying to map certain fields to certain users so that it is specific to individual users. I have four SQL tables connected that are involved in the mapping. They are UserTable, ClientTable, ProjectTypeTable and IssueTable.
What I am trying to do is this: A user with the ID of one will log on, I get this ID and match it with the userID in the ClientTable to get the correct user for that client. Once I get that I will get the ClientID and match it with the ProjectTypeTable to get the multiple correct projectTypes, eg a client can have 1-8 projects available to them. The IssueTable will have the selected projectType.
I have created a ViewModel which looks like this:
Public Class ClientViewModel
Public proTable As List(Of ProjectType)
Public cTable As ClientTable
Public uTable As UserTable
Public iTable As IssueTable
End Class
What I planned to do is retrieve the userID when the user logs on and pass it to other views in session state so that the correct userID is kept through out the project until they log out. Here is what I have tried:
Dim uTable As SQLDatabase = New SQLDatabase()
Dim getUserID = (From data In uTable.UserTables Where data.username = user.username AndAlso data.userPassword = user.userPassword Select data.userID)
If (userdetailLocal.Count() > 0) Then
Session("userIDData") = getUserID.ToString()
Then in the submit controller I have this:
Dim getuserID = Session("userIDData")
Dim userModel = New IssueTracker.ClientViewModel()
userModel.cTable = dbServer.ClientTables.Where(Function(x) x.userID = "")
userModel.proTable = dbServer.ProjectTypes.Where(Function(x) x.client = "").ToList()
The problem I am having is that I am not actually getting the ID, is this a good way to map the users to specific fields? The ID's do not have to be sent across via session state that was the last thing I tried. How can I do this correctly?