public async Task <Result <CurrenciesErrorCodes> > DeleteAsync(string id, string username, string correlationId) { var existing = await _currenciesRepository.GetByIdAsync(id); if (existing.IsSuccess) { var productsExist = await _currenciesRepository.CurrencyHasProductsAsync(id); if (productsExist) { return(new Result <CurrenciesErrorCodes>(CurrenciesErrorCodes.CannotDeleteCurrencyWithAttachedProducts)); } var result = await _currenciesRepository.DeleteAsync(id, existing.Value.Timestamp); if (result.IsSuccess) { await _auditService.TryAudit(correlationId, username, id, AuditDataType.Currency, oldStateJson : existing.Value.ToJson()); await PublishCurrencyChangedEvent(existing.Value, null, username, correlationId, ChangeType.Deletion); } return(result); } return(existing.ToResultWithoutValue()); }