Ejemplo n.º 1
0
        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(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 <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);
        }