public async Task <bool> Handle(UpdateAvailableStockCountReadModelCommand request, CancellationToken cancellationToken) { IExpressionSpecification <Stock> specification = new ProductIdIs(request.ProductId); var stockRepository = _stockDbContext.StockRepository; Stock stock = await stockRepository.GetFirstAsync(specification, cancellationToken); if (stock.LastStockActionDate > request.LastStockUpdatedOn) { return(false); } stock.UpdateStock(request.AvailableStockCount, request.LastStockActionId, request.LastStockUpdatedOn); return(true); }
public async Task <bool> CheckAsync(string productId, CancellationToken cancellationToken) { var stockRepository = _stockDbContext.StockRepository; var specification = new ProductIdIs(productId); bool isUnique = false; try { await stockRepository.GetFirstAsync(specification, cancellationToken); } catch (StockNotFoundException) { isUnique = true; } return(isUnique); }