private async Task HandleTradingDisabled(ProductContract product, string username) { if (product.IsTradingDisabled) { _log.WriteInfo(nameof(ProductChangedProjection), nameof(HandleTradingDisabled), $"Trading disabled for product {product.ProductId}"); var allRfq = await RetrieveAllRfq(product.ProductId, canBePaused : true); _log.WriteInfo(nameof(ProductChangedProjection), nameof(HandleTradingDisabled), $"Found rfqs to pause: {allRfq.Select(x => x.Id).ToJson()}"); foreach (var rfq in allRfq) { _log.WriteInfo(nameof(ProductChangedProjection), nameof(HandleTradingDisabled), $"Trying to pause rfq: {rfq.Id}"); await _rfqPauseService.AddAsync(rfq.Id, PauseSource.TradingDisabled, username); } } else { _log.WriteInfo(nameof(ProductChangedProjection), nameof(HandleTradingDisabled), $"Trading enabled for product {product.ProductId}"); var allRfq = await RetrieveAllRfq(product.ProductId, canBeResumed : true, canBeStopped : true); _log.WriteInfo(nameof(ProductChangedProjection), nameof(HandleTradingDisabled), $"Found rfqs to resume or stop: {allRfq.Select(x => x.Id).ToJson()}"); foreach (var rfq in allRfq) { if (rfq.PauseSummary?.CanBeResumed ?? false) { _log.WriteInfo(nameof(ProductChangedProjection), nameof(HandleTradingDisabled), $"Trying to resume rfq: {rfq.Id}"); await _rfqPauseService.ResumeAsync(rfq.Id, PauseCancellationSource.TradingEnabled, username); } else if (rfq.PauseSummary?.CanBeStopped ?? false) { _log.WriteInfo(nameof(ProductChangedProjection), nameof(HandleTradingDisabled), $"Trying to stop pending pause for rfq: {rfq.Id}"); await _rfqPauseService.StopPendingAsync(rfq.Id, PauseCancellationSource.TradingEnabled, username); } else { _log.WriteWarning(nameof(ProductChangedProjection), nameof(HandleTradingDisabled), $"Unexpected state for rfq: {rfq.Id}, {rfq.ToJson()}"); } } } }
public async Task <RfqPauseErrorCode> PauseAsync(string id, [FromBody] RfqPauseRequest request) { var errorCode = await _rfqPauseService.AddAsync(id, PauseSource.Manual, request.Initiator); return(errorCode); }