Beispiel #1
0
        protected override async Task DeleteExecuteAsync(List <int> ids)
        {
            // For the entities we're about to delete retrieve their imageIds (if any) to delete from the blob storage
            var dbEntitiesWithImageIds = await _repo.Agents
                                         .Select(nameof(Agent.ImageId))
                                         .Filter($"{nameof(Agent.ImageId)} ne null")
                                         .FilterByIds(ids.ToArray())
                                         .ToListAsync();

            var blobsToDelete = dbEntitiesWithImageIds
                                .Select(e => BlobName(e.ImageId))
                                .ToList();

            try
            {
                using var trx = ControllerUtilities.CreateTransaction();
                await _repo.Agents__Delete(ids);

                if (blobsToDelete.Any())
                {
                    await _blobService.DeleteBlobsAsync(blobsToDelete);
                }

                trx.Complete();
            }
            catch (ForeignKeyViolationException)
            {
                throw new BadRequestException(_localizer["Error_CannotDelete0AlreadyInUse", _localizer["Agent"]]);
            }
        }
Beispiel #2
0
 protected override async Task DeleteExecuteAsync(List <int> ids)
 {
     try
     {
         await _repo.Agents__Delete(ids);
     }
     catch (ForeignKeyViolationException)
     {
         throw new BadRequestException(_localizer["Error_CannotDelete0AlreadyInUse", _localizer["Agent"]]);
     }
 }