public async Task <Result <ProductsErrorCodes> > UpdateAsync(Product product, string username, string correlationId) { var existing = await _repository.GetByIdAsync(product.ProductId); if (existing.IsSuccess) { var validationResult = await _addOrUpdateValidationAndEnrichment.ValidateAllAsync(product, username, correlationId, existing.Value); if (validationResult.IsFailed) { return(validationResult.ToResultWithoutValue()); } product = validationResult.Value; var result = await _repository.UpdateAsync(product); if (result.IsSuccess) { await _auditService.TryAudit(correlationId, username, product.ProductId, AuditDataType.Product, product.ToJson(), existing.Value.ToJson()); await _entityChangedSender.SendEntityEditedEvent <Product, ProductContract, ProductChangedEvent>( existing.Value, product, username, correlationId); } return(result); } return(existing.ToResultWithoutValue()); }
public async Task UpdateAsync(ClientProfileSettings model, string username, string correlationId) { var existing = await _regulatorySettingsRepository.GetByIdsAsync(model.ClientProfileId, model.AssetTypeId); if (existing == null) { throw new ClientSettingsDoNotExistException(); } var regulatorySettings = await _regulatorySettingsApi.GetRegulatorySettingsByIdsAsync(existing.RegulatoryProfileId, existing.RegulatoryTypeId); //This should not happen when we handle deleting of RegulatorySettings in MDM if (regulatorySettings.ErrorCode == RegulationsErrorCodesContract.RegulatorySettingsDoNotExist) { throw new RegulatorySettingsDoNotExistException(); } if (model.IsAvailable && !regulatorySettings.RegulatorySettings.IsAvailable) { throw new CannotSetToAvailableException(); } if (model.Margin > 100 || model.Margin < regulatorySettings.RegulatorySettings.MarginMinPercent) { throw new InvalidMarginValueException(); } if (model.OnBehalfFee < 0) { throw new InvalidOnBehalfFeeException(); } if (model.ExecutionFeesRate < 0 || model.ExecutionFeesRate > 100) { throw new InvalidExecutionFeesRateException(); } if (model.ExecutionFeesCap < model.ExecutionFeesFloor) { throw new InvalidExecutionFeesCapException(); } if (model.ExecutionFeesFloor > model.ExecutionFeesCap || model.ExecutionFeesFloor < 0) { throw new InvalidExecutionFeesFloorException(); } await _regulatorySettingsRepository.UpdateAsync(model); var referenceId = $"ClientProfileId:{model.ClientProfileId},AssetTypeId:{model.AssetTypeId}"; await _auditService.TryAudit(correlationId, username, referenceId, AuditDataType.ClientProfileSettings, model.ToJson(), existing.ToJson()); await _entityChangedSender .SendEntityEditedEvent <ClientProfileSettings, ClientProfileSettingsContract, ClientProfileSettingsChangedEvent>(existing, model, username, correlationId); }
public async Task <Result <TickFormulaErrorCodes> > UpdateAsync(ITickFormula model, string username, string correlationId) { var currentSettings = await _tickFormulaRepository.GetByIdAsync(model.Id); if (currentSettings == null) { return(new Result <TickFormulaErrorCodes>(TickFormulaErrorCodes.TickFormulaDoesNotExist)); } SetDefaultLadderAndTicksIfNeeded(model); var validationResult = ValidateLaddersAndTicks(model); if (validationResult.IsFailed) { return(validationResult); } var updateResult = await _tickFormulaRepository.UpdateAsync(model); if (updateResult.IsFailed) { return(updateResult); } await _auditService.TryAudit(correlationId, username, currentSettings.Id, AuditDataType.TickFormula, model.ToJson(), currentSettings.ToJson()); await _entityChangedSender.SendEntityEditedEvent <ITickFormula, TickFormulaContract, TickFormulaChangedEvent>( currentSettings, model, username, correlationId); return(new Result <TickFormulaErrorCodes>()); }
public async Task UpdateAsync(AssetType model, string username, string correlationId) { var brokerSettingsResponse = await _brokerSettingsApi.GetByIdAsync(_brokerId); if (brokerSettingsResponse.ErrorCode == BrokerSettingsErrorCodesContract.BrokerSettingsDoNotExist) { throw new BrokerSettingsDoNotExistException(); } await ValidateUnderlyingCategory(model.UnderlyingCategoryId); var regulationId = brokerSettingsResponse.BrokerSettings.RegulationId; await ValidateRegulatoryType(model.RegulatoryTypeId, regulationId); var existing = await _assetTypesRepository.GetByIdAsync(model.Id); if (existing == null) { throw new AssetTypeDoesNotExistException(); } var clientProfileSettings = await _clientProfileSettingsRepository.GetAllAsync(null, model.Id); foreach (var setting in clientProfileSettings) { var regulatorySettings = await _regulatorySettingsApi.GetRegulatorySettingsByIdsAsync( setting.RegulatoryProfileId, model.RegulatoryTypeId); ValidateRegulatoryConstraint(regulatorySettings, setting); } await _assetTypesRepository.UpdateAsync(model); await _auditService.TryAudit(correlationId, username, model.Id, AuditDataType.AssetType, model.ToJson(), existing.ToJson()); await _entityChangedSender.SendEntityEditedEvent <AssetType, AssetTypeContract, AssetTypeChangedEvent>( existing, model, username, correlationId); }