これは初心者の質問です。ユーザーの詳細を保持するクラスを設計しています。私が頭を悩ませているのは「許可」です
これがシナリオです。各ユーザーは複数の都市に属しています。そして、さまざまな権限を持つことができるその都市で。
たとえば、John は NY と DC にいて、NY では 1、2、3 の権限を持ち、DC では 3、4 の権限を持っています。
これを考慮してクラスを設計する方法がわかりません。
私が設計しなかった私のテーブルは、次のようになります(いくつかのサンプルデータを含む):
userID City permission
John NY 1
John NY 2
John NY 3
John DC 3
John DC 4
Jane DC 1
Jane DC 2
Jane NY 6
私のC#クラスでは、もともと次のように別々に書き出しました:
public class User
{
public string userid { get; set; }
public string name{ get; set; } //from main user table
public string address{ get; set; } //from main user table
public List<string> Citites{ get; set; } //from usercitypermission table
public List<string> userRole { get; set; }//from usercitypermission table
public User(string username)
{
this.userid = username;
DataSet ds = new DataSet();
SqlConnection conn = new SqlConnection(cCon.getConn());
SqlCommand cmd = new SqlCommand("sp_getUserDetails", conn);
// 2. set the command object so it knows
// to execute a stored procedure
cmd.CommandType = CommandType.StoredProcedure;
// 3. add parameter to command, which
// will be passed to the stored procedure
cmd.Parameters.Add(
new SqlParameter("@userName", username));
try
{
// Open the connection and execute the Command
conn.Open();
SqlDataAdapter sqlDA = new SqlDataAdapter();
sqlDA.SelectCommand = cmd;
sqlDA.Fill(ds);
}
catch (Exception ex)
{
throw (ex);
}
finally
{
conn.Close();
}
this.userRole = new List<string>();
foreach (DataTable DT in ds.Tables)
{
foreach (DataRow dr in DT.Rows)
{
this.userRole.Add(dr["permission"].ToString());
}
}
}
これらを設定すると、 my で個別に実行するだけなtblUserCityPermission
ので、私の Cities にCities
はユーザーの個別のリストが保持されます (このコードは投稿しませんでしたが、これは実行されるストアド プロシージャにすぎません。はそのユーザーのすべての権限 (1-10)をuserRole
保持しますが (上記を参照)、その権限が適用される都市は考慮されません。
これが理にかなっていることを願っています。:-/
私の質問は、ユーザーがいる特定の都市 (または都市) にアクセス許可が関連付けられるようにクラスを設計するにはどうすればよいかということだと思いList
ます。私はここから離れていますか?