如何将某些字段映射到特定用户? [英] How do I map certain fields to specific users?

查看:67
本文介绍了如何将某些字段映射到特定用户?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在vb.net中创建一个mvc应用程序,我试图将某些字段映射到某些用户,以便它特定于各个用户。我有四个连接映射的SQL表。它们是UserTable,ClientTable,ProjectTypeTable和IssueTable。



我想要做的是:ID为1的用户将登录,我得到这个ID并将其与ClientTable中的userID匹配,以获取该客户端的正确用户。一旦我得到它,我将获得ClientID并将其与ProjectTypeTable匹配以获得多个正确的projectTypes,例如客户端可以有1-8个项目可用。 IssueTable将具有所选的projectType。



我创建了一个ViewModel,如下所示:



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





我打算做的是在用户登录时检索userID并将其传递给会话状态中的其他视图,以便在p中保留正确的userID直到他们退出为止。以下是我的尝试:





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 = "")
'the speech marks will be the userID retrieved from the session state
userModel.proTable = dbServer.ProjectTypes.Where(Function(x) x.client = "").ToList()
'the speech marks will be the clientID retrieved from the session state





问题我我有的是我实际上没有获得ID,这是将用户映射到特定字段的好方法吗? ID不必通过会话状态发送,这是我尝试的最后一件事。我怎么能正确地做到这一点?



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?

推荐答案

如果我正确理解了这个问题,我就不会为不同的用户使用不同的表。在我看来,表格应该是相同的,但您可以在每个表格中添加一列,您可以将用户ID放在不同用户的不同行中。这些列应该是指向用户表的外键。



代码的一些注释。



  • 您获取getUserID变量的值,但您获取的值是用户名。这应该是其他领域吗?
  • 我希望密码不会保存为纯文本,但处理得当,即使在数据库中也无法看到,
  • 当你获取ctable,你在条件中使用空字符串,而不是会话中的用户ID
If I understand the question correctly, I wouldn't use different tables for different users. In my opinion the tables should be the same but you can add a column into each table where you place the user id to separate rows for different users. These columns should be foreign keys pointing to user table.

Some notes for the code.

  • You fetch a value to getUserID variable but the value you fetch is the username. Should this be some other field?
  • I hope that the password isn't saved as plain text but handled properly and cannot be seen in any case, even in the database
  • When you fetch the ctable you use an empty string in the condition, not the userid from the session


这篇关于如何将某些字段映射到特定用户?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆