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

Setting Audited Entity Reason #5493


User avatar
0
mdframe created

Hi, I am a new to ASPNET.Zero and have been working on some samples for understanding the architecture. I created a Contacts application from the RAD Tool with ASP.NET Core and Angular. When I look at the change logs I see the details of which fields were changed from their old value to the new one however I do not see a Reason description as I set in the service module.

I have the entity class defined as:

[Table("Contacts")]
    [Audited]
    public class Contact : FullAuditedEntity , IMayHaveTenant
    {
		public int? TenantId { get; set; }

Then in my ApplicationService I have the following:

        [AbpAuthorize(AppPermissions.Pages_Contacts_Edit)]       
        private async Task Update(CreateOrEditContactDto input)
         {
            var contact = await _contactRepository.FirstOrDefaultAsync((int)input.Id);

            var reason = string.Format("User: {0} was updated!", input.UserId.ToString());            
            using (_reasonProvider.Use(reason))
            {
                ObjectMapper.Map(input, contact);                
            }
            
         }

I do not have the UnitOfWork defined per the sample as I am assuming the DTO Mapper is taking care of the actual data layer so I made an assumption on how to set the Reason. What should I do and where would I see the Reason once it is recorded correctly?

Thank you,

Matt


6 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team

    <a class="postlink" href="https://aspnetboilerplate.com/Pages/Documents/Entity-History#reason-property">https://aspnetboilerplate.com/Pages/Doc ... n-property</a>

    You can take a look at the documentation for [Entity-History]

  • User Avatar
    0
    mdframe created

    Yes, I have read through the documentation several times. I have also applied the UseCase attribute, per the documentation, to the function and still no reason description other than the standard shows in the table for logging. I am not receiving any errors in the logs or in the application.

  • User Avatar
    0
    maliming created
    Support Team

    UseCase Attribute Restrictions You can use the UseCase attribute for:

    All public or public virtual methods for classes that are used via its interface, e.g. an application service used via its interface. All public virtual methods for self-injected classes, e.g. MVC Controllers. All protected virtual methods.

  • User Avatar
    0
    mdframe created

    Thanks I see where I missed the declaration of private not being supported. For a quick test I made a change to the location and function with the UseCase declaration to see if I would get a different result. Even after making a change with the following method I am still seeing the URL as the Reason in the database.

    [UseCase(Description = "Updating User Contact Information")] public async Task CreateOrEdit(CreateOrEditContactDto input) { if(input.Id == null){ await Create(input); } else{ await Update(input); }

        }
    

    I know I am missing something and that it is not the framework, just trying to learn.

    Thanks,

    Matt

  • User Avatar
    0
    aaron created
    Support Team

    You need to save changes in that method:

    [UseCase(Description = "Updating User Contact Information")]
    public async Task CreateOrEdit(CreateOrEditContactDto input)
    {
        if (input.Id == null)
        {
            await Create(input);
        }
        else
        {
            await Update(input);
        }
    
        // CurrentUnitOfWork.SaveChanges();
        _unitOfWorkManager.Current.SaveChanges();
    }
    
  • User Avatar
    0
    mdframe created

    Thank you Aaron! That was the missing piece. I see the entity reason code I set now. An update to the screen now will complete the requirement I have for my customer.

    Thanks again,

    Matt