Base solution for your next web application
Starts in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

organization unit duplicate title in same level #5383


User avatar
0
carelearning created

Hello,

We have a business need to have duplicate Display Names in OrganizationUnits under the same parent. We have association metadata tables to differentiate between them. Is there a way to disable the check on save when using the IRepository<OrganizationUnit>? Currently we get the following error: "There is already an organization unit with name [name]. Two units with same name can not be created in same level." The documentation here does not mention this as a requirement.

Thank you for your time and effort.


3 Answer(s)
  • User Avatar
    0
    aaron created
    Support Team

    You can subclass OrganizationUnitManager to override ValidateOrganizationUnitAsync method, and then inject your subclass in OrganizationAppService.

  • User Avatar
    0
    carelearning created

    @aaron Thanks! This worked. Our code for those interested:

    public class CustomOrganizationUnitManager : OrganizationUnitManager
        {
            public CustomOrganizationUnitManager(IRepository<OrganizationUnit, long> organizationUnitRepository) : base(organizationUnitRepository)
            {
            }
    
            protected override Task ValidateOrganizationUnitAsync(OrganizationUnit organizationUnit)
            {
                return Task.CompletedTask;
            }
        }
    

    usage

    public OuManager(IRepository<OrganizationUnit, long> organizationUnitRepository,
                             IRepository<UserOrganizationUnit, long> userOrganizationUnitRepository)
            {
              _organizationUnitManager = new CustomOrganizationUnitManager(organizationUnitRepository);    
             _organizationUnitRepository = organizationUnitRepository;
             _userOrganizationUnitRepository = userOrganizationUnitRepository;
            }
    
  • User Avatar
    0
    aaron created
    Support Team

    That's great :)