I have the following class with static properties and methods which helps manage users on a website. I want to be able to re-use this class among other projects by overriding some properties.
public class Account {
public static string sessionName = "Account";
public static string tableName = "Accounts";
public static bool isLoggedIn(){
return HttpContext.Current.Session[sessionName] != null;
}
public static bool login(string email, string password){
//connect to database and return user details from specified table
DataTable t = Database.login(tableName, email, password);
DataRow r = t.Rows[0];
HttpContext.Current.Session[sessionName] = r;
return true;
}
public static object val(string name){
return ((DataRow)HttpContext.Current.Session[sessionName])[name];
}
}
This basically logs a user in and stores their details in a DataRow in the session, using a session name defined in the properties.
Is it possible to do something like below to use this class with multiple types of user?
public class WebsiteUser : Account {
public override string sessionName = "WebsiteUser";
public override string tableName = "WebsiteUsers";
}
public class TradeUser : Account {
public override string sessionName = "TradeUser";
public override string tableName = "TradeUsers";
}
Then call the following code to use each derived class.
if (WebsiteUser.isLoggedIn()){
//manage website user
}
if (TradeUser.isLoggedIn()){
//manage trade user
}