public async Task <bool> Handle(AddToStockCommand request, CancellationToken cancellationToken) { var stockActionModel = StockAction.Create(request.ProductId, StockActionTypes.AddToStock, request.Count, request.CorrelationId, _stockActionUniqueChecker, cancellationToken); IStockActionRepository stockActionRepository = _stockDbContext.StockActionRepository; await stockActionRepository.AddAsync(stockActionModel, cancellationToken); return(true); }
public async Task <Guid> Handle(InitializeStockCommand request, CancellationToken cancellationToken) { StockAction stockAction = StockAction.Create(request.ProductId, StockActionTypes.InitializeStock, request.AvailableStock, request.CorrelationId, _stockActionUniqueChecker, cancellationToken); IStockActionRepository stockActionRepository = _stockDbContext.StockActionRepository; await stockActionRepository.AddAsync(stockAction, cancellationToken); return(stockAction.Id); }
public async Task <bool> Handle(RollbackDecreaseFromStockCommand request, CancellationToken cancellationToken) { IStockActionRepository stockActionRepository = _stockDbContext.StockActionRepository; StockAction stockAction = await stockActionRepository.GetByCorrelationIdAsync(request.CorrelationId, cancellationToken); AddToStockCommand addToStockCommand = new AddToStockCommand(stockAction.ProductId, stockAction.Count, $"{stockAction.CorrelationId}-rollback"); await _domainMessageBroker.SendAsync(addToStockCommand, cancellationToken); return(true); }
public async Task <bool> Handle(ResetStockCommand request, CancellationToken cancellationToken) { IStockSnapshotRepository stockSnapshotRepository = _stockDbContext.StockSnapshotRepository; StockSnapshot stockSnapshot = await stockSnapshotRepository.GetByProductIdAsync(request.ProductId, cancellationToken); var stockActionModel = StockAction.Create(request.ProductId, StockActionTypes.RemoveFromStock, stockSnapshot.AvailableStock, request.CorrelationId, _stockActionUniqueChecker, cancellationToken); IStockActionRepository stockActionRepository = _stockDbContext.StockActionRepository; await stockActionRepository.AddAsync(stockActionModel, cancellationToken); return(true); }
public async Task <bool> CheckAsync(string correlationId, CancellationToken cancellationToken) { IStockActionRepository stockActionRepository = _stockDbContext.StockActionRepository; bool unique = false; try { await stockActionRepository.GetByCorrelationIdAsync(correlationId, cancellationToken); } catch (StockActionNotFoundException) { unique = true; } return(unique); }