Base solution for your next web application
Open Closed

Power Tools and UserId #12259


User avatar
0
qquestel created

I am creating an entity using Power Tools. How do i capture the current Logged In user 'Id' and 'TennentId' to update the fields the the database for that table


6 Answer(s)
  • User Avatar
    0
    oguzhanagir created
    Support Team

    Hi

    You can use the AbpSession extension to get the information of the logged in user. You can get it by calling AbpSession.GetTenantId(), AbpSession.GetUserId() methods. If you want to get UserIdentifier as well. You can use it as AbpSession.ToUserIdentifier().

  • User Avatar
    0
    qquestel created

    Hi

    You can use the AbpSession extension to get the information of the logged in user. You can get it by calling AbpSession.GetTenantId(), AbpSession.GetUserId() methods. If you want to get UserIdentifier as well. You can use it as AbpSession.ToUserIdentifier().

    So you cant get it from Add New Navigation Property in Power Tools?

    Select Your Entity Like User (x.x.Authorization.Users.long ?

    I would have to create the Property in PowerTool and then update it in code to use AbpSession.GetUserId()

  • User Avatar
    0
    oguzhanagir created
    Support Team

    Hi

    Yes, when creating the relevant entity, you can filter by user by associating the User in the Navigation Property with the user you selected, as you said, you will need to update it manually. Here, you can condition it by taking the logged in user instead of the user information in the input.

  • User Avatar
    0
    qquestel created

    Having problems with Tenantid

    AbpSession.GetTenantId()

    Do i need to add the TS file and the DTO as well?

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @qquestel

    This is not possible with the current version of Power Tools. When you create an entity, if you select one of the 3 options below, AspNet Zero will add CreationUserId field to your entity and will set it with the currently logged in user's Id.

    If your entity is multi-tenant (see screenshot below), the Power Tools will add a TenantId field to your entity and will generate a code block to set it automatically to logged in user's TenantId

    If you want to add a custom field for example, BuyerUserId and then set it to currently logged in user's Id, you need to modify generated app service code and set it as shown below;

    yourEntity.BuyerUserId = AbpSession.GetTenantId()
    

    You don't have to add it to creation DTO classes.

  • User Avatar
    0
    qquestel created

    Thank you