this a newbie question, I am designing a class that is going to hold user details. One part tha thas me scratching my head is "permission"
here is the scenario. each user belong to multiple cities. and in that city that could have various permissions.
for example, John is in NY and DC, in NY he has permissions 1,2,3 and in DC 3,4
i dont know how to design my class to take this into account.
my table, which i did not design) looks like this(with some sample data):
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
in my C# class, i have originally written them out separately like so:
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());
}
}
}
when i set these, i just run a distinct on my tblUserCityPermission, so my Cities holds a distinct list of Cities the user is in (i didn't post the code for this, but it's just a stored procedure tha ti run, similar to the one above)
and the userRole holds all permissions for that user (1-10) (shown above), but it does not take into account what City that permission applies to.
i hope this makes sense. :-/
i guess my question is, how do i design the class to make sure my permissions are tied to each specific City(or Cities) the user is in. should i be using a type other than List? Am i way off here?