2

I have been posting data to a Full Audited Entity via the API. As it is FullAuditedEntity, it should automatically be created with creatorId, creationTime and a couple other column values. But when I checked in the database, CreatorUserID is null even though CreationTime is there. It should be 1 cos I posted with the default admin. Furthermore, when I delete the rows, the same happens: I can only see DeletionTime but not DeleterUserId.

Below is the data captured by the API Endpoints that I can see using breakpoints:

enter image description here

I experimented with two Object Mapping Methods creating output and output2 but both of them gives the same null value for CreatorUserId. By right, both CreatorUserId and CreationTime should have values by this stage.

        [AbpAuthorize]
        public async Task<Rule> CreateAsync(CreateRuleInput input)
        {
            Rule output = Mapper.Map<CreateRuleInput, Rule>(input);
            Rule output2 = ObjectMapper.Map< Rule>(input);
            return await _ruleManager.Create(output);
        }

Is there anything wrong with my object mapping functions?

Wei Minn
  • 179
  • 1
  • 2
  • 15

2 Answers2

2

There is nothing wrong with your object mapping functions.

I experimented with two Object Mapping Methods... By right, both CreatorUserId and CreationTime should have values by this stage.

CreatorUserId and CreationTime only have values after SaveChanges() is called.

I have to put [TenantId] manually in the JSON post object, and it shows in the database.

You should not do that. CreatorUserId is only set if the entity belongs to the current tenant.

I can see UserId which is 1 in breakpoint. Somehow it gets ignored during mapping.

The proper way to create an entity as "Default" tenant admin, is to log in as the tenant admin.

UserId = 1 means you are logged in as host admin. "Default" tenant admin has UserId = 2.

If I don't specify tenantId or put 0, it gives Server Internal Error: 500.

If you want host to create Rule, make sure it implements IMayHaveTenant not IMustHaveTenant.

aaron
  • 39,695
  • 6
  • 46
  • 102
  • Thank you for the answer! In fact, i just found out about it and posted the answer just now. I don't know if it's a feature or a bug but the default host admin should also be able to create entity. Cos right now, it's caused a lot of confusions in me – Wei Minn Jan 05 '18 at 09:35
  • 1
    If you want host to create `Rule`, make sure it implements `IMayHaveTenant` not `IMustHaveTenant`. – aaron Jan 05 '18 at 09:38
0

The problem is with the default Admin because it has no tenant.

From another tenant, I created a new user and post data using the new user's credentials. Then I post the data by leaving out tenantId in the post body. And it works just fine.

I used to specify tenantId in the post data object for the default Admin (Host tenant). If I don't specify tenantId or put 0, it gives Server Internal Error: 500. So, I have to specify tenantId in the post body object. I think because of that it somehow messes with the mappings inside the API because default Admin has no tenant.

Wei Minn
  • 179
  • 1
  • 2
  • 15