public async Task DeleteAsync(string id, string username, string correlationId) { var existing = await _assetTypesRepository.GetByIdAsync(id); if (existing == null) { throw new AssetTypeDoesNotExistException(); } if (await _assetTypesRepository.AssignedToAnyProductAsync(id)) { throw new CannotDeleteAssetTypeAssignedToAnyProductException(); } var clientProfileSettings = await _clientProfileSettingsRepository.GetAllAsync(id, null); await _assetTypesRepository.DeleteAsync(id); await _auditService.TryAudit(correlationId, username, id, AuditDataType.AssetType, oldStateJson : existing.ToJson()); await _entityChangedSender.SendEntityDeletedEvent <AssetType, AssetTypeContract, AssetTypeChangedEvent>( existing, username, correlationId); foreach (var profileSettings in clientProfileSettings) { await _entityChangedSender .SendEntityDeletedEvent <ClientProfileSettings, ClientProfileSettingsContract, ClientProfileSettingsChangedEvent>(profileSettings, username, correlationId); } }
public async Task <Result <ProductsErrorCodes> > DeleteAsync(string productId, string username, string correlationId) { var existing = await _repository.GetByIdAsync(productId); if (existing.IsSuccess) { if (existing.Value.IsStarted) { return(new Result <ProductsErrorCodes>(ProductsErrorCodes.CannotDeleteStartedProduct)); } var result = await _repository.DeleteAsync(productId, existing.Value.Timestamp); if (result.IsSuccess) { await _auditService.TryAudit(correlationId, username, productId, AuditDataType.Product, oldStateJson : existing.Value.ToJson()); await _entityChangedSender.SendEntityDeletedEvent <Product, ProductContract, ProductChangedEvent>( existing.Value, username, correlationId); } return(result); } return(existing.ToResultWithoutValue()); }
public async Task <Result <TickFormulaErrorCodes> > DeleteAsync(string id, string username, string correlationId) { var existing = await _tickFormulaRepository.GetByIdAsync(id); if (existing == null) { return(new Result <TickFormulaErrorCodes>(TickFormulaErrorCodes.TickFormulaDoesNotExist)); } if (await _tickFormulaRepository.AssignedToAnyProductAsync(id)) { return(new Result <TickFormulaErrorCodes>(TickFormulaErrorCodes.CannotDeleteTickFormulaAssignedToAnyProduct)); } var result = await _tickFormulaRepository.DeleteAsync(id); if (result.IsSuccess) { await _auditService.TryAudit(correlationId, username, id, AuditDataType.TickFormula, oldStateJson : existing.ToJson()); await _entityChangedSender .SendEntityDeletedEvent <ITickFormula, TickFormulaContract, TickFormulaChangedEvent>(existing, username, correlationId); } return(result); }