Base solution for your next web application
Open Closed

Method not included in Audit Log #239


User avatar
0
ninomartini created

I have the following method, which is NOT being included in the Audit Log when executed:

[AbpAuthorize(AppPermissions.Pages_Tenant_Account_Groups_Create)]
        public async Task CreateGroup(CreateGroupInput input)
        {
            var group = input.MapTo<Group>();
            await _groupRepository.InsertAsync(group);
        }

However, this method is included in the Audit Log when executed:

[AbpAuthorize(AppPermissions.Pages_Tenant_Account_Groups_Edit)]
        public async Task<GroupEditDto> GetGroupForEdit(EntityRequestInput input)
        {
            var group = await _groupRepository.FirstOrDefaultAsync(g => g.Id == input.Id);
            return group.MapTo<GroupEditDto>();
        }

Here are the Dto classes begin used:

[AutoMapTo(typeof(Group))]
    public class CreateGroupInput: IInputDto
    {
        [Required]
        [StringLength(Group.MaxNameLength)]
        public string Name { get; set; }

        [StringLength(Group.MaxDescriptionLength)]
        public string Description { get; set; }  
    }
[AutoMap(typeof(Group))]
    public class GroupEditDto : EntityDto, IDoubleWayDto
    {
        [Required]
        [StringLength(Group.MaxNameLength)]
        public string Name { get; set; }

        [StringLength(Group.MaxDescriptionLength)]
        public string Description { get; set; }
    }

Does anyone know what I am missing?

Thank you in advance.


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

    Hi,

    I suppose that both methods are in the same class, both are defined in service interface and used over interface. In this case, it should work property because there is no difference. Just try to make CreateGroup virtual and write me again. How CreateGroup is called? is it called from UI via ajax or from some other C# code?

  • User Avatar
    0
    ninomartini created

    Hello, Thank you for the quick reply.

    Yes, both methods are in the same class which implements from an interface. However, making CreateGroup virtual had no impact. Maybe you can see something I did wrong? FYI, I am using 1.3.0 from a fresh download.

    Again, I appreciate any assistance.

    IGroupAppService.cs

    public interface IGroupAppService : IApplicationService
        {
            Task<PagedResultOutput<GroupListDto>> GetGroups(GetGroupsInput input);
            Task CreateGroup(CreateGroupInput input);
            Task<GroupEditDto> GetGroupForEdit(EntityRequestInput input);        
            Task UpdateGroup(GroupEditDto input);
            Task DeleteGroup(EntityRequestInput input);
        }
    

    Here is the complete GroupAppService.cs

    [AbpAuthorize(AppPermissions.Pages_Tenant_Account_Groups)]
        public class GroupAppService : TracZuAppServiceBase, IGroupAppService
        {
            private readonly IRepository<Group, long> _groupRepository;
    
            public GroupAppService(IRepository<Group, long> groupRepository)
            {
                _groupRepository = groupRepository;
            }
    
            public async Task<PagedResultOutput<GroupListDto>> GetGroups(GetGroupsInput input)
            {
                var query = _groupRepository
                    .GetAll()
                    .WhereIf(
                        !input.Filter.IsNullOrEmpty(),
                        g => g.Name.Contains(input.Filter) ||
                             g.Description.Contains(input.Filter)
                    );
    
                var resultCount = await query.CountAsync();
                var results = await query
                    .AsNoTracking()
                    .OrderBy(input.Sorting)
                    .PageBy(input)
                    .ToListAsync();
    
                return new PagedResultOutput<GroupListDto>(resultCount, results.MapTo<List<GroupListDto>>());
            }
    
            [AbpAuthorize(AppPermissions.Pages_Tenant_Account_Groups_Create)]
            public async Task CreateGroup(CreateGroupInput input)
            {
                var group = input.MapTo<Group>();
                await _groupRepository.InsertAsync(group);
            }
    
            [AbpAuthorize(AppPermissions.Pages_Tenant_Account_Groups_Edit)]
            public async Task<GroupEditDto> GetGroupForEdit(EntityRequestInput input)
            {
                var group = await _groupRepository.FirstOrDefaultAsync(g => g.Id == input.Id);
                return group.MapTo<GroupEditDto>();
            }
    
            [AbpAuthorize(AppPermissions.Pages_Tenant_Account_Groups_Edit)]
            public async Task UpdateGroup(GroupEditDto input)
            {
                var group = input.MapTo<Group>();
                await _groupRepository.UpdateAsync(group);
            }
    
            [AbpAuthorize(AppPermissions.Pages_Tenant_Account_Groups_Delete)]
            public async Task DeleteGroup(EntityRequestInput input)
            {
                await _groupRepository.DeleteAsync(input.Id);
            }
        }
    

    I am calling the CreateGroup from the Angular application via the following controller:

    (function () {
        appModule.controller('tenant.views.groups.createModal', [
            '$scope', '$modalInstance', 'abp.services.app.group',
            function ($scope, $modalInstance, groupService) {
                var vm = this;
    
                vm.saving = false;
                vm.group = {};
    
                vm.save = function () {
                    vm.saving = true;
                    groupService.createGroup(vm.group)
                        .success(function () {
                            abp.notify.info(app.localize('SavedSuccessfully'));
                            $modalInstance.close();
                        }).finally(function () {
                            vm.saving = false;
                        });
                }
    
                vm.cancel = function () {
                    $modalInstance.dismiss();
                }
            }
        ]);
    })();
    
  • User Avatar
    0
    hikalkan created
    Support Team

    Thank you for code sharing. I'll try to simulate the behaviour and return you.

  • User Avatar
    0
    ninomartini created

    Any suggestions?

  • User Avatar
    0
    hikalkan created
    Support Team

    Hi,

    Your CreateGroup seems not different. It' hard to repeat it and I had no time. I'll check it now and return you in a short time.

  • User Avatar
    0
    hikalkan created
    Support Team

    I created a method with same signature and same arguments and it inserted audit log for it. I really could not understand the reason. It seems impossible. If this is so critical for you and can not resolve it, I may try to remotely login to your computer and test it in your environment.