public async Task ResetReserveProductsAsync(TimeSpan oldReserveTime, CancellationToken token) { const int page = 30; var date = DateTime.UtcNow - oldReserveTime; int count = 0; do { var orderNumbers = await _warehouseContext.Reserves .Where(g => g.ReserveDate < date).Select(g => g.OrderNumber) .OrderBy(g => g) .Skip(count).Take(page) .Distinct().ToArrayAsync(); if (orderNumbers.Length <= 0) { break; } foreach (var g in orderNumbers) { await _warehouseService.ResetReserveProductsAsync(g); } count += orderNumbers.Length; if (token.IsCancellationRequested) { break; } }while (true); }
public async Task <ActionResult> ReserveProducts([FromQuery] string orderNumber) { bool res = await _warehouseService.ResetReserveProductsAsync(orderNumber); if (res) { return(Ok()); } else { return(BadRequest()); } }