Base solution for your next web application
Starts in:
01 DAYS
01 HRS
01 MIN
01 SEC

Activities of "maharatha"

Also I was trying to get the TenantID inside my DBContext constructor and it was coming as Null. But as far as I know you should be able to get AbpSession.TenantID values if you are using AspnetZero which I am currently using.

Any help is really appreciated.

I was going through the below post :

#488@8b17fa78-f26f-44a4-bd4f-1ea5b00d5f75

But couldn't find an answer. But my requirement is more or less similar.

I want to use all inbuild functionality of ASPNET ZERO but I would like to save all tenant related information other than implemented by AspnetZero to be stored in it's own DB.

To be more specific I want all transnational data (like vendor,customer,etc) to be stored in a separate database for each Tenant.

<a class="postlink" href="https://github.com/aspnetboilerplate/aspnetboilerplate-samples/tree/master/MultipleDbContextDemo">https://github.com/aspnetboilerplate/as ... ontextDemo</a> : This is a solution which enables me to seggregate the data.

The problem is I want to programatically change the DBContext connection string based on TenantID. I am unable to access ASPNetZero Sessions outside DBcontext contructor , so I am not sure how to use this to pass the correct connection string. Moreover I am also unable to access Session in my DbContext class. So the hwole question revolves around how to access the TenantID so that I can get the connection string and pass on to the database.

public class TesTrans : AbpDbContext { /* Setting "Default" to base class helps us when working migration commands on Package Manager Console. * But it may cause problems when working Migrate.exe of EF. ABP works either way. * */ public virtual IDbSet<COAUnit> COAUnit { get; set; }

    // public virtual IDbSet&lt;AddressUnit&gt; AddressUnit { get; set; }
    
   

<span style="color:#BF00BF">// nameOrConnectionString - How to set this connection string as I am unable to access ABPSession or any session </span> public TesTrans (string nameOrConnectionString) : base(nameOrConnectionString) {

    }

    /* This constructor is used by ABP to pass connection string defined in CORPACCOUNTINGDataModule.PreInitialize.
     * Notice that, actually you will not directly create an instance of TesTrans since ABP automatically handles it.
     */
    

}

My project has the requirement where one single user can be associated with multiple companies. This is taken care by AspnetZero. I think it would be useful if we have the following items implemented as well :

  1. Setting a default Organization to an user
  2. Associating that Organization when the user logs in. Presently a user when logs in is not associated with any organization
  3. Allowing an user to switch organization

When we add or do any activity the system automatically updates the TenantID in DB , but I don't see any such provision for Organization, probably for the lack of above implementation.

Awesome !! Worked for me.

I am currently starting a new project so such quick response is very much appreciated.

Thank You Again .

This is how I am adding claims :

var identity = await UserManager.CreateIdentityAsync(GetCurrentUser(), DefaultAuthenticationTypes.ApplicationCookie);

identity.AddClaim(new Claim("OrganizationId", "2"));

This is how I am trying to get the claim :

public class MyAppSession : IdentityFrameworkClaimsAbpSession {

    // Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType
    private readonly UserManager _userManager;

    public MyAppSession(UserManager userManager, IMultiTenancyConfig multiTenancy) : base(multiTenancy)
    {
        
        _userManager = userManager;
    }

   
    public static long? OrganizationId
    {
        get
        {

            
            var claimsPrincipal = Thread.CurrentPrincipal as ClaimsPrincipal;
            if (claimsPrincipal == null)
            {
                return null;
            }

            var claimsIdentity = claimsPrincipal.Identity as ClaimsIdentity;
            if (claimsIdentity == null)
            {
                return null;
            }
            
            var OrgIdClaim = claimsIdentity.Claims.FirstOrDefault(c => c.Type == "OrganizationId");
            if (OrgIdClaim == null || string.IsNullOrEmpty(OrgIdClaim.Value))
            {
                return null;
            }

            long orgId;
            if (!long.TryParse(OrgIdClaim.Value, out orgId))
            {
                return null;
            }

            return orgId;
        }
      
    }



    
}

I am unable to get the claim :

Am I doing anything wrong ?

To start with I am in love with Abp and AbpZero. Awesome Job @hikalkan.

I have read the previous article of extending the session ields :

#584@1182f777-3cd5-40b6-82d9-19e91497527f

I found the easiest way to do is to add claims directly but I don't think that's the smartest way to do it.

Could you provide an example with implementation as I am sure this is going to help a lot of people ? I am actually planning to store the organization ID for a user.

Showing 321 to 326 of 326 entries