In one of my application services, I am trying to update a record prior to deleting (with soft delete). After playing around, i find that i can either update the record or delete it, but i cant do both. the last operation (in this case delete) always takes precedence.
If i delete and then update, the record is not marked as deleted and the column updates, so how can i update the records url
and displayname
prior to deleting? I added the UnitOfWork
attribute, but it didnt seem to have any affect
My method can be found below.
[AbpAuthorize(AppPermissions.Pages_PmnyDocuments_Delete)]
[UnitOfWork]
public async Task Delete(EntityDto input)
{
var entity = await _pmnyDocumentsRepository.GetAsync(input.Id);
var output = await _fileServerManager.DeleteAsync(new DeleteFileServerObjectInput(PmnyConsts.Bucket, $"{entity.MasterId}/{entity.ParentIdentifier}".AsFilePath(), entity.DisplayName));
entity.Url = output.FilePath;
entity.DisplayName = output.FileName;
await _pmnyDocumentsRepository.UpdateAsync(entity);
var entity2 = await _pmnyDocumentsRepository.GetAsync(entity.Id);
await _pmnyDocumentsRepository.DeleteAsync(entity2.Id);
}
I would try removing the [UnitOfWork]
attribute and instead wrapping the update & delete in their own uow.
using (var unitOfWork = _unitOfWorkManager.Begin())
{
//UPDATE
}
using (var unitOfWork = _unitOfWorkManager.Begin())
{
//DELETE
}
There is further info in the documentation here