Scenario: An employee can belong to multiple departments. Using the Power Tool, I can pick a FK relationship, but it's only one to one.
Per this post: https://support.aspnetzero.com/QA/Questions/6933/How-to-generate-relational-entities-using-abp-Power-tool One to Many is supported.
How do we do this?
If this is no longer the case? How do we accomplish this in the asp.net zero / aspboilerplate way?
Ok - the Rad tool only does one-to-one.
Examining the MS documents - I see I can add, for example List<Department> Departments to my Employee entity.
However, I think this will break migrations.
Thus, I'm looking at the User and Roles - it seems the netZero / ABP way is to:
- Have a role table
- Have a UserRoles Table
- Have a Users table
On the GetUserForEditOutput class has an Array of UserRoleDto.
When GetUserForEdit is call - it goes to the RoleManager which gets all roles, then it selects those into a UserRoleDto.
Then it adds that to the GetUserForEditOutput class and returns it.
On Update or Save - it uses CreateOrUpdateUserInput, which has role names as an array of Strings.
On update, it sets the roles via the UserManager, which leans on the RoleManager - and it does all this by the role name.
Internally, this takes this array string, finds each role by normalized name, finds the role, then deletes it from UserRoleDto by the Role.Id, or adds it to the UserRoleDto table.
In the modal create or edit js - on save, it goes through the list of checked roles, and builds a string by name, assigns the model, and that's posted back.
This list are the checkboxes under the wrapper div of class user-role-checkbox-list.
The view model is CreateOrEditUserModalViewModel, which is inheriting from GetUserForEditOutput, which has the UserRoleDto array (as mentioned above.
The User inherits from AbpUser which is based on AbpUserBase, which has ICollection<UserRole> Roles.
For mapping, in the customDtoMapper - there's configuration.CreateMap<Role, OrganizationUnitRoleListDto>(); Under the User object, which seems to have more to do the OUs than the actual Roles' ICollection<UserRole>.
The object mapper does not handle roles, instead it leans on the UserManager. It goes through each role, and calls IsInRoleAsync from the userManager, which then goes to our UserRole table and queries it, returning a bool if the list of roles the user has contains the passed name.
It does this each time (inefficient, IMHO, but irrelevant).
So, based on this - to accomplish what I would need to do the following:
I create an Entity for Employee Department membership I modify the DTOs for my employee to have an Arrays / Lists for the EmployeeDepartment entity. Then, in my Employee App Service, I populate the EmployeeDepartment list / array on the Employee DTOs. In the view model, I add this array of EmployeeEntityDTOs, rendering it however I wish (perhaps a modal). Then, on post back, when saving the employee, I also have to update my EmployeeDepartment entity, adding new entries and removing the old ones.
So, in summary, my requirements are:
- A relationship entity
- Modify DTOs
- Modify View Models
- Modify client side scripts to populate Models
- Modify App service to handle the Lists/Arrays of the primary Entity.
Am I missing anything?