Hi,
I am following the link displayed below for implementing entity history.
https://docs.aspnetzero.com/en/aspnet-core-mvc/latest/Features-Mvc-Core-Entity-History
I have an entity class which has some properties. When I update this entity, audit logs does not show old (previous) value, it only shows the new i.e. updated values. For example, if my entity has a property called Name and I update its value from UserA to UserB, the audit log does not show UserA as old Values.
Entity is shown below
EntityFrameworkCoreModule is shown below
EntityHistoryHelper code is shown below:
Can you please help?
Thanks
8 Answer(s)
-
0
Hi @learner29
- What is your product version?
- What is ABP Framework version?
- What is product framework type (.net framework or .net core)?
-
0
Hi @demirmusa,
Product version is 8.0.0. ABP Framework is the one which came with version 8.0.0. ASP.NET Core MVC & jQuery Project
-
0
hi @learner29
Please share the code of your entity class and update entity methods.
-
0
Hi @maliming,
Please see below the required information.
[Table("Ethnicities")] //[Audited] public class Ethnicity : FullAuditedEntity, IMustHaveTenant { public Ethnicity() { Clients = new HashSet<Client>(); } [MinLength(EthnicityConsts.MinCodeLength)] [MaxLength(EthnicityConsts.MaxCodeLength)] [Required] // [Audited] public string Code { get; set; } [MinLength(EthnicityConsts.MinTextLength)] [MaxLength(EthnicityConsts.MaxTextLength)] [Required] // [Audited] public string Text { get; set; } //[Audited] public virtual int TenantId { get; set; } [Required] public int DisplayOrder { get; set; } public virtual ICollection<Client> Clients { get; set; } }
App service is displayed below.
//[DisableAuditing] [AbpAuthorize(AppPermissions.Pages_Administration_Ethnicities)] // [Audited] public class EthnicityAppService : MyAppServiceBase, IEthnicityAppService { private readonly IRepository<Ethnicity> _ethnicityPLRepositroy; public EthnicityAppService(IRepository<Ethnicity> ethnicityPLRepositroy) { _ethnicityPLRepositroy = ethnicityPLRepositroy; } [AbpAuthorize(AppPermissions.Pages_Administration_Ethnicities)] public async Task<ListResultDto<EthnicitiesListDto>> GetEthnicity(GetEthnicityInput getEthnicityInput) { var ethnicity = _ethnicityPLRepositroy.GetAll() .WhereIf( !getEthnicityInput.Filter.IsNullOrWhiteSpace(), filter => (filter.Code.Contains(getEthnicityInput.Filter) || filter.Code.StartsWith(getEthnicityInput.Filter)) || (filter.Text.Contains(getEthnicityInput.Filter) || filter.Text.StartsWith(getEthnicityInput.Filter)) ); var ethnicityCount = await ethnicity.CountAsync(); ethnicity = ethnicity.OrderBy(getEthnicityInput.Sorting).PageBy(getEthnicityInput); return new PagedResultDto<EthnicitiesListDto>( ethnicityCount, ObjectMapper.Map<List<EthnicitiesListDto>>(ethnicity) ); } [AbpAuthorize(AppPermissions.Pages_Administration_Ethnicities_Create)] public async Task Create(CreateEthnicityInputDto createEthnicityPLInputDto) { var ethnicityEntity = ObjectMapper.Map<Ethnicity>(createEthnicityPLInputDto); ethnicityEntity.TenantId = (Int32)AbpSession.TenantId; var displayOrder = _ethnicityPLRepositroy .GetAll().Where(x => x.IsDeleted == false & x.TenantId == ethnicityEntity.TenantId) .Select(x => x.DisplayOrder) .Max(); ethnicityEntity.DisplayOrder = displayOrder + 1; var result = await _ethnicityPLRepositroy.InsertAsync(ethnicityEntity); } public async Task<GetEthnicityEditOutput> GetById(int id) { var ethnicityPLEntity = await _ethnicityPLRepositroy.GetAsync(id); var ethnicityPLEditDto = ObjectMapper.Map<EthnicityEditDto>(ethnicityPLEntity); var getEthnicityPLEditOutput = new GetEthnicityEditOutput(); getEthnicityPLEditOutput.EthnicityEditDto = ethnicityPLEditDto; return getEthnicityPLEditOutput; } [AbpAuthorize(AppPermissions.Pages_Administration_Ethnicities_Edit)] public async Task Update(UpdateEthnicityInputDto updateEthnicityPLInputDto) { var ethnicityPLEntity = ObjectMapper.Map<Ethnicity>(updateEthnicityPLInputDto); ethnicityPLEntity.TenantId = (Int32)AbpSession.TenantId; var result = await _ethnicityPLRepositroy.UpdateAsync(ethnicityPLEntity); } [AbpAuthorize(AppPermissions.Pages_Administration_Ethnicities_Delete)] public async Task Delete(UpdateEthnicityInputDto updateEthnicityPLInputDto) { await _ethnicityPLRepositroy.DeleteAsync(updateEthnicityPLInputDto.Id); } }
-
1
hi @learner29
try
[AbpAuthorize(AppPermissions.Pages_Administration_Ethnicities_Edit)] public async Task Update(UpdateEthnicityInputDto updateEthnicityPLInputDto) { var ethnicityPLEntity = await_ethnicityPLRepositroy.GetAsync(updateEthnicityPLInputDto.Id); ObjectMapper.Map(updateEthnicityPLInputDto, ethnicityPLEntity); ethnicityPLEntity.TenantId = (Int32)AbpSession.TenantId; var result = await _ethnicityPLRepositroy.UpdateAsync(ethnicityPLEntity); }
-
0
-
0
You have missing mapping. Check https://aspnetboilerplate.com/Pages/Documents/Object-To-Object-Mapping#creating-mappings
-
0
hi @learner29
The key point of the problem is that you need to query the entity first and then update it
eg
var ethnicityPLEntity = await _ethnicityPLRepositroy.GetAsync(Id); ethnicityPLEntity.Name = "123123"; await _ethnicityPLRepositroy.UpdateAsync(ethnicityPLEntity);