I built an app with c# and ionic\angula
r and got to the point where I need to implement authentication.
I have developed several APIs that I contact from my frontend but I would like the fields (DeleterId\CreatorId\LastModifierId)
to be auto-filled without having to dig into the individual APIs. I know abp has a procedure that should suit me. My goal is to send the id from the frontend and i don't know how to put it in the api url. currently I generate the url then before sending it to the backend I intercept it to add data. How should I fill in the data to pass him the ID?
I hope there is a way to send the id via url to the backend.
CodePudding user response:
To achieve this in the ABP framework, you can use the Auditing feature.
Here is how you can enable auditing for your entity:
- Install the Volo.Abp.Auditing NuGet package.
- Add the IAuditedObject interface to your entity class and implement it:
using Volo.Abp.Auditing; public class MyEntity : Entity, IAuditedObject { public Guid DeleterId { get; set; } public Guid CreatorId { get; set; } public Guid LastModifierId { get; set; } public DateTime CreationTime { get; set; } public DateTime? LastModificationTime { get; set; } public DateTime? DeletionTime { get; set; } public bool IsDeleted { get; set; } }
- Enable the auditing feature in your module:
using Volo.Abp.Auditing; using Volo.Abp.Modularity; [DependsOn(typeof(AbpAuditingModule))] public class MyModule : AbpModule { // ...
}
With these steps, the DeleterId, CreatorId, and LastModifierId fields will be automatically set whenever you create, modify, or delete an entity using the repository. The CreationTime, LastModificationTime, and DeletionTime fields will also be automatically set.
Note that the auditing feature works by intercepting the repository method calls and modifying the entity before it is saved to the database. If you are not using the repository and are directly accessing the database, the auditing feature will not work.
CodePudding user response:
I hope there is a way to send the id via url to the backend.
You can create a regular MVC Controller and use the standart Route
attribute to map URL with the action parameters.
If you want to use ABP's auto controllers (which exposes application services as REST APIs), you can use an Guid id
(or whatever your primary key) parameter as the first argument of the method. ABP will use path parameter for it.