public void DeleteFile(MediaFile file, bool permanent, bool force = false) { Guard.NotNull(file, nameof(file)); // Delete thumb _imageCache.Delete(file); if (!permanent) { file.Deleted = true; _fileRepo.Update(file); } else { try { if (!force && file.Tracks.Any()) { throw _exceptionFactory.DeleteTrackedFile(file, null); } // Delete entity _fileRepo.Delete(file); // Delete from storage _storageProvider.Remove(file); } catch (DbUpdateException ex) { if (ex.IsUniquenessViolationException()) { throw _exceptionFactory.DeleteTrackedFile(file, ex); } else { throw; } } catch (Exception) { throw; } } }