If you want the Audit History of both operations then you’d need 2 separate Service operations as you’re doing here.
I’ve added a new PartialUpdate
API to IAutoQueryDb
which may be able to save you defining the SoftDeleteConfiguration
operation by re-using the DeleteConfiguration
to perform the Soft Delete, so if you populate audit fields on your DeleteConfiguration
API, e.g:
[AutoPopulate(nameof(IAudit.DeletedDate), Eval = "utcNow")]
[AutoPopulate(nameof(IAudit.DeletedBy), Eval = "userAuthName")]
public class DeleteConfiguration : IDeleteDb<Configuration>
{
public int Id { get; set; }
}
You should be able to use the same DTO to perform the Soft Delete where it will populate the DeletedDate
& DeletedBy
audit fields, whilst the Delete API continues to perform the hard delete, e.g:
public DeleteConfigurationResponse Delete(DeleteConfiguration request)
{
// step 1: soft delete
var response1 = AutoQuery.PartialUpdate<Configuration>(
request, base.Request);
// step 2: hard delete
var response2 = AutoQuery.Delete(request, base.Request);
return response2;
}
Although I’m not sure why in your example you’re creating a new instance instead of using the DeleteConfiguration
Request DTO the service was called with.
This new API is available in the latest v5.9.3+ that’s now available on MyGet.
New AutoApply behavior
As it’s related I should mention the latest ServiceStack now includes a AuditBase.cs class with Created*
, Modified*
& Deleted*
Date
/By
properties whose properties are populated with the new [AutoApply(Behavior)]
attribute where you can apply generic behavior to your AutoQuery operations, in this case the in-built behavios populates the AuditBase
properties where if you had DeletedBy
and DeletedDate
fields you can instead populate them with.
[AutoApply(Behavior.AuditDelete)]
public class DeleteConfiguration : IDeleteDb<Configuration>
{
public int Id { get; set; }
}
But you can also add your custom behavior by extending the metadata on each AutoQuery Request DTO with additional attributes. So instead of adding multiple [AutoPopulate]
attributes on each DTO you can define a custom behavior like:
[AutoApply("MyDelete")]
public class DeleteConfiguration : IDeleteDb<Configuration>
{
public int Id { get; set; }
}
Then register its behavior in AutoCrudMetadataFilters
using it as a marker to add AutoQuery attributes that auto populates your preferred fields, e.g. Assuming you’re using a MyBase
class with MyDeletedDate
and MyDeletedBy
properties:
void MyAuditFilter(AutoCrudMetadata meta)
{
if (meta.HasAutoApply("MyDelete"))
{
meta.Add(new AutoPopulateAttribute(nameof(MyBase.MyDeletedDate)) {
Eval = "utcNow"
});
meta.Add(new AutoPopulateAttribute(nameof(MyBase.MyDeletedBy)) {
Eval = "userAuthName"
});
}
}
Plugins.Add(new AutoQueryFeature {
AutoCrudMetadataFilters = { MyAuditFilter },
});
I’m currently writing the release notes which will include more info on how this works but you can find an example project & demo that uses this at GitHub - NetCoreApps/BookingsCrud: Code-first, declarative, multi-user .NET Core Booking system using Auto CRUD & ServiceStack Studio project.