public async Task Handle(StockInitializedEvent notification, CancellationToken cancellationToken) { StockAction stockAction = notification.StockAction; StockSnapshot stockSnapshot = StockSnapshot.Create(stockAction.ProductId, stockAction.Count, stockAction.Id, stockAction.CreatedOn, _snapshotUniqueChecker, cancellationToken); IStockSnapshotRepository snapshotRepository = _stockDbContext.StockSnapshotRepository; await snapshotRepository.AddAsync(stockSnapshot, cancellationToken); }
public async Task Handle(StockIncreasedEvent notification, CancellationToken cancellationToken) { StockAction stockAction = notification.StockAction; IStockSnapshotRepository stockSnapshotRepository = _stockDbContext.StockSnapshotRepository; StockSnapshot stockSnapshot = await stockSnapshotRepository.GetByProductIdAsync(stockAction.ProductId, cancellationToken); stockSnapshot.IncreaseStock(stockAction.Count, stockAction.Id, stockAction.CreatedOn); }
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); }