Base solution for your next web application
Open Closed

Extending OrganizationUnit does not work when updating #11835


User avatar
0
Hammer created

Hello, I'm using version 11.3, Angular .Net Core.

I tried extending the OrganizationUnit class by following documentation, but came to a bizarre behaviour in OrganizationUnitAppService's UpdateOrganizationUnit method.

Here is my new class:

public class OrganizationUnitExtended: OrganizationUnit
{    
    [Range(OrganizationUnitExtendedConsts.MinDDDefaultDay, OrganizationUnitExtendedConsts.MinDDDefaultDay)]
    public int DirectDebitPreferedDay { get; set; }
}

I ran the Migrations and thus added the column in DB.

Then, I created a DBSet for my new class in DBContext class:

public virtual DbSet<OrganizationUnitExtended> OrganizationUnitsExtended { get; set; }

In OrganizationUnitAppService, I replaced

private readonly IRepository<OrganizationUnit, long> _organizationUnitRepository;

with 

private readonly IRepository<OrganizationUnitExtended, long> _organizationUnitRepository;

I also changed OrganizationUnitDto to include my new property, and created a new UpdateOrganizationUnitExtendedInput.

public class UpdateOrganizationUnitExtendedInput
    {
        [Range(1, long.MaxValue)]
        public long Id { get; set; }

        [Required]
        [StringLength(OrganizationUnit.MaxDisplayNameLength)]
        public string DisplayName { get; set; }

        [Range(OrganizationUnitExtendedConsts.MaxDDDefaultDay, OrganizationUnitExtendedConsts.MinDDDefaultDay)]
        public int DirectDebitPreferedDay { get; set; }

    }

I then changed UpdateOrganizationUnit method to this:

 [AbpAuthorize(AppPermissions.Pages_Administration_OrganizationUnits_ManageOrganizationTree)]
        public async Task<OrganizationUnitDto> UpdateOrganizationUnit(UpdateOrganizationUnitExtendedInput input)
        {
            var organizationUnit = await _organizationUnitRepository.GetAsync(input.Id);

            organizationUnit.DisplayName = input.DisplayName;

            await _organizationUnitRepository.UpdateAsync(organizationUnit);

            return ObjectMapper.Map<OrganizationUnitDto>(organizationUnit);
        }

I have no trouble retrieving OrganizationUnit from this appService, but whenever I call UpdateOrganizationUnit, I get a 500 response, without ever reaching the method (Breakpoints inside the methos are not reached).

Is there something obvious I'm missing?


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

    Hi @Hammer

    If you are seeing HTTP 500, then there must be an error log in Logs.txt file under App_Data/Logs folder. Could you check that ?

  • User Avatar
    0
    Hammer created

    My problem was due to the fact that no log is recorded anywhere on my computer, apparently. After checking a bit everywhere online, I found that I could still check the output directly in VS, in the output window by selecting the Web.Host output.

    Obvious, but if you don't know... Problem was about a validator that was incorrectly set.

    [Range(OrganizationUnitExtendedConsts.MaxDDDefaultDay, OrganizationUnitExtendedConsts.MinDDDefaultDay)]
            public int DirectDebitPreferedDay { get; set; }
    

    Should be

    [Range(OrganizationUnitExtendedConsts.MinDDDefaultDay, OrganizationUnitExtendedConsts.MaxDDDefaultDay)]
            public int DirectDebitPreferedDay { get; set; }
    

    One thing remains to be seen: why don't I have any record of the logs in my IIS Express directory ?...

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    These errors should be logged to App_Data/Logs/Logs.txt file under your website. If this is happening on production, your app might not have write permission for this folder.