- ABP Framework version: v4.2.0
- UI type: MVC
How do I want to add attributes to these two entities?
Volo.Abp.Account.RegisterDto Volo.Abp.Account.Public.Web.Pages.Account.RegisterModel.PostInput
The following method cannot be used. ObjectExtensionManager.Instance.AddOrUpdateProperty<RegisterDto, string>("Title");
14 Answer(s)
-
0
you can add extra property to the current
Tenant
object. OpenYourProjectModuleExtensionConfigurator.cs
and replace theConfigureExtraProperties()
method with below:private static void ConfigureExtraProperties() { OneTimeRunner.Run(() => { ObjectExtensionManager.Instance.Modules() .ConfigureSaas(x => { x.ConfigureTenant(tenant => { tenant.AddOrUpdateProperty<string>( "MyExtraProperty", property => { //validation rules property.Attributes.Add(new RequiredAttribute()); property.Attributes.Add( new StringLengthAttribute(64) { MinimumLength = 4 } ); //...other configurations for this property } ); }); }); }); }
Ref: https://docs.abp.io/en/abp/latest/Module-Entity-Extensions
-
0
you can add extra property to the current
Tenant
object. OpenYourProjectModuleExtensionConfigurator.cs
and replace theConfigureExtraProperties()
method with below:private static void ConfigureExtraProperties() { OneTimeRunner.Run(() => { ObjectExtensionManager.Instance.Modules() .ConfigureSaas(x => { x.ConfigureTenant(tenant => { tenant.AddOrUpdateProperty<string>( "MyExtraProperty", property => { //validation rules property.Attributes.Add(new RequiredAttribute()); property.Attributes.Add( new StringLengthAttribute(64) { MinimumLength = 4 } ); //...other configurations for this property } ); }); }); }); }
Ref: https://docs.abp.io/en/abp/latest/Module-Entity-Extensions
I still don't understand. I need to add properties to registerdto. Why configure tent object?
-
0
because it will also be shown on the register page and I guess you want that.
-
0
Can you give me an example of how to access this new property? I don't understand. thank you.
I've read the document carefully for many times, and I don't know how to access it so that it can be displayed on the UI, and set and get values.
https://docs.abp.io/en/abp/latest/Module-Entity-Extensions
I have written how to add a new property, but I don't know how to set the referenced property.
How do I set and get it? registerDto.SetProperty("PhoneNumber", "0123456789"); Methods like this are not available. Can you give me some examples?
https://docs.abp.io/en/abp/latest/Module-Entity-Extensions#create-update-forms https://docs.abp.io/en/abp/latest/Module-Entity-Extensions#data-table
-
0
Can someone help me with this problem? thank you.
-
0
this is how you can get and set an extra property
//SET AN EXTRA PROPERTY var user = await _identityUserRepository.GetAsync(userId); user.SetProperty("Title", "My custom title value!"); await _identityUserRepository.UpdateAsync(user); //GET AN EXTRA PROPERTY var user = await _identityUserRepository.GetAsync(userId); return user.GetProperty<string>("Title");
see https://docs.abp.io/en/abp/latest/Customizing-Application-Modules-Extending-Entities
-
0
-
0
hi @lataing
You are right, The
RegisterDto
doesn't inheritExtensibleEntityDto
. I will handle it in next version.You can create a new
RegisterAsync
method to temporarily solve the problem.Volo.Abp.Account.Public.Web.Pages.Account.RegisterModel.PostInput
Please refer to https://docs.abp.io/en/abp/latest/UI/AspNetCore/Customization-User-Interface
-
0
Hello, @maliming. I see that every module has an extension method like this.
The attribute is extended as follows, but I don't know how to set the value for the SocialSecurityNumber attribute or how to get the value.
No unit test, case or document was found. Can you explain it for me?
Another problem is that if I can't add properties to RegisterDto, I need to rewrite AccountAppService instead of just the RegisterAsync method.
-
0
hi
https://docs.abp.io/en/abp/latest/Object-Extensions https://docs.abp.io/en/abp/latest/Module-Entity-Extensions
Another problem is that if I can't add properties to RegisterDto, I need to rewrite AccountAppService instead of just the RegisterAsync method.
You can add new method and new Dto.
-
0
This question has been automatically marked as stale because it has not had recent activity.
-
0
Hi,
I'm bringing this one back up because after going through ABP's extensive Extra Properties feature, I still don't see how we can use it to map some obvious properties like
Name
andSurname
during registration without modifying module code. In providedAccountAppService.RegisterAsync
the extra properties are mapped like this:input.MapExtraPropertiesTo(user);
So even after adding
Name
andSurname
as extra properties toRegisterDto
those properties will not get mapped to theIdentityUser
object.Only option to avoid modifying source code seems to be to override the
AccountAppService
by calling the base method, map add'l properties after create, and do a follow upUserManager.UpdateAsync
.public override async Task<IdentityUserDto> RegisterAsync(RegisterDto input) { var baseResult = await base.RegisterAsync(input); // Handle extra properties var user = await UserManager.GetByIdAsync(baseResult.Id); user.Surname = input.GetSurname(); user.Name = input.GetName(); await UserManager.UpdateAsync(user); var result = ObjectMapper.Map<IdentityUser, IdentityUserDto>(user); return result; }
It would be nice if there was a way to make
MapExtraPropertiesTo
extension method also map to regular properties. After checking the source, it seems that this is only possible using AutoMapperMapExtraProperties
which would still require modifying module source code.Thoughts?
-
0
hi @rahul.patel
Please create a new question. Thanks.