No, not yet solved. I'm temporarily recording the selected id in a field within the Users entity which I've extended, but this is costly in terms of performance to the database.
I'll send parts of my source, I think it's easier. MySession Class
public class MySession : IAbpSession, ITransientDependency
{
public IAbpSession _AbpSession;
public MySession(IAbpSession AbpSession)
{
_AbpSession=AbpSession;
}
public int? ImpersonatorTenantId
{
get { return _AbpSession.ImpersonatorTenantId; }
}
public long? ImpersonatorUserId
{
get { return _AbpSession.ImpersonatorUserId; }
}
public Abp.MultiTenancy.MultiTenancySides MultiTenancySide
{
get { return _AbpSession.MultiTenancySide; }
}
public int? TenantId
{
get { return _AbpSession.TenantId; }
}
public long? UserId
{
get { return _AbpSession.UserId; }
}
public string FormaturaSelecionada
{
get
{
var claimsPrincipal = Thread.CurrentPrincipal as ClaimsPrincipal;
if (claimsPrincipal == null)
{
return null;
}
var formaturaClaim = claimsPrincipal.Claims.FirstOrDefault(c => c.Type == "FormaturaAtual");
if (formaturaClaim == null || string.IsNullOrEmpty(formaturaClaim.Value))
{
return null;
}
return formaturaClaim.Value;
}
set
{
var claimsPrincipal = Thread.CurrentPrincipal as ClaimsPrincipal;
if (claimsPrincipal == null)
{
throw new Exception("erro");
}
claimsPrincipal.Identities.First().AddClaim(new Claim("FormaturaAtual", value));
}
}
}
The user when selecting the Graduation, through the screen below, calls the controler FormaturaSelect, sending the new ID which must be set in the session variable.
public async Task<JsonResult> FormaturaSelect(int id, string returnUrl = "")
{
Debug.WriteLine(string.Format("----Check selected value ----"));
Debug.WriteLine(string.Format("Step 1: Current Value in _mySession = [{0}]", _mySession.FormaturaSelecionada));
Debug.WriteLine(string.Format("Step 2: Add value id= [{0}]", id));
_mySession.FormaturaSelecionada = id.ToString();
Debug.WriteLine(string.Format("Step 3: Current Value in _mySession = [{0}]", _mySession.FormaturaSelecionada));
//continue...
}
I put several debugs in the code, below the results. First execution: ----Check selected value ---- Step 1: Current Value in _mySession = [] Step 2: Add value id= [1] Step 3: Current Value in _mySession = [1]
Second executionL ----Check selected value ---- Step 1: Current Value in _mySession = [] Step 2: Add value id= [2] Step 3: Current Value in _mySession = [2]
The value between the two requests is lost. But it can be seen that it adds to the current Claim
When I use the property after a Login, everything happens perfectly.
LoginResult.Identity.AddClaim (new Claim ("Company", CompanyId.ToString ()));
I tried to use _userManager.AddClaim, in another part of the code, where the user can select another company related to it, it starts to add the values in the table AbpUserClaims, but recording the wrong information.
Claim myClaim = new Claim ("type", "value");
_userManager.AddClaim (_AbpSession.GetUserId (), myClaim);
ClainType receives the value, and the ClaimValue is null, generating problems for the next user login.
What is the correct way to do this operation?
Thank you, that's exactly what I needed!
I'll try to explain my problem in more detail, it may be that Abp can help me using some already existing structure that, I'm not seeing.
I have 3 types of users that will use the platform:
The use of the tenant was limited to the use by the accountants, since they must see 1 or more companies, but without being able to see all, that is, they can not be admin, just me.
For this, I created a structure Companies vs. Users, thus controlling who has access to a particular company.
The user, when entering the system, selects which company wants to see the data, this way I force the filter and I only bring the data referring to the company that he selected during that session.
This is the question in relation to the above question, how to know and filter the data of which company the user selected.
I managed to run, implementing Api version of swagger without using ABPWebApi (). Now I have the error Not supported by Swagger 2.0: Multiple operations with path 'api / AbpServiceProxies' and method 'GET'.
Already tried removing the .WithConventionalVerbs () of Configuration.Modules.AbpWebApi (). DynamicApiControllerBuilder, but still without success.
Guys, solved! Connection string is integratedSecurity, the IIS User cant have permission to access database.