My current site uses two databases, one that stores the users directly and another one that stores additional data using the user email. I need to extract data (an identification number) from this other table, so I have created a model that operates like this:
ZivoyAccount.cs
namespace ZivoyPublicaciones.Models
{
public class ZivoyAccount
{
//Database for additional data
private PPublicEntities db = new PPublicEntities();
//Database with user roles
private zivoypostEntities userdb = new zivoypostEntities();
public Int64 UserIdentification {
get {
//Get the User Identity
String UserIdentity = HttpContext.Current.User.Identity.GetUserId();
var UserData = userdb.AspNetUsers.Find(UserIdentity);
//Get the User Email
var UserEmail = UserData.Email;
//Get the Data from Other Database
var ZivoyUserData = db.Users.Find(UserEmail);
return ZivoyUserData.user_gkey;
}
}
}
}
But I have been reading that this isn't the right behaviour since this variables get set for all users, and I need them to be set for each user. How could I accomplish this?
I'm calling my model on a father controller so that I can use this variable on all my child controller
AuthorizationController.cs
namespace ZivoyPublicaciones.Controllers
{
[Authorize]
public class AuthorizationController : Controller
{
protected ZivoyAccount UserProfiler = new ZivoyAccount();
}
}