abp-framework

ABP Extended User Entity, CreateUser api error


I am using the latest version of ABP.Framework community edition (8.0.2).

I created a Blazor project and have followed the guide here to extend the User Entity: https://community.abp.io/posts/how-to-add-custom-properties-to-the-user-entity-rixchoha

The entity was created in the AbpUsers table.

This works when using the UI to add a new user, but I want to be able to call the API and create a user.

After I authorize myself in swagger, I attempt to create a user with the api/identity/users

The error I get is:

{
  "error": {
    "code": null,
    "message": "Your request is not valid!",
    "details": "The following errors were detected during validation.\r\n - The EmployeeNo field is required.\r\n",
    "data": {},
    "validationErrors": [
      {
        "message": "The EmployeeNo field is required.",
        "members": [
          "employeeNo"
        ]
      }
    ]
  }
}

I am posting the following (left blank for this post):

{
  "userName": "string",
  "name": "string",
  "surname": "string",
  "email": "user@example.com",
  "phoneNumber": "string",
  "isActive": true,
  "lockoutEnabled": true,
  "roleNames": [
    "string"
  ],
  "employeeNo":"string",
  "password": "string"
}

I have also tried this but get the same error:

{
  "userName": "string",
  "name": "string",
  "surname": "string",
  "email": "user@example.com",
  "phoneNumber": "string",
  "isActive": true,
  "lockoutEnabled": true,
  "roleNames": [
    "string"
  ],
  "extraProperties":{
    "employeeNo":"string"
  }
  "password": "string"
}

Do I need to override the controller for this to take?

EfCoreEntityExtensionMapping.cs:

ObjectExtensionManager.Instance
    .MapEfCoreProperty<IdentityUser, string>(UserConsts.EmployeeNo,
        (_, propertyBuilder) =>
        {
            propertyBuilder.HasDefaultValue("");
            propertyBuilder.HasMaxLength(UserConsts.MaxEmployeeNoLength);
        });

ModuleExtensionConfigurator.cs

ObjectExtensionManager.Instance.Modules()
   .ConfigureIdentity(identity =>
   {
       identity.ConfigureUser(user =>
       {
           user.AddOrUpdateProperty<string>( //property type: string
               UserConsts.EmployeeNo, //property name
               property =>
               {
                   //validation rules
                   property.Attributes.Add(new RequiredAttribute());
                   property.Attributes.Add(new StringLengthAttribute(UserConsts.MaxEmployeeNoLength) 
                       {MinimumLength = UserConsts.MinEmployeeNoLength});
                   
                   property.Configuration[IdentityModuleExtensionConsts.ConfigurationNames.AllowUserToEdit] = true;

                   //...other configurations for this property
               }
           );
       });
   });

Solution

  • In my case, I found that through inspecting the payload in Chromes developer tools, the E in EmployeeNo needed to be capitalized.

    {
      "userName": "string",
      "name": "string",
      "surname": "string",
      "email": "user@example.com",
      "phoneNumber": "string",
      "isActive": true,
      "lockoutEnabled": true,
      "roleNames": [
        "string"
      ],
      "extraProperties":{
        "EmployeeNo":"string"
      },
      "password": "string"
    }