コード例 #1
0
        public async Task <StockDTO> GetStockAsync(long stockId, CancellationToken cancellationToken = default)
        {
            var spec  = new GetStockByIdSpecification(stockId);
            var stock = await _stockRepository.GetOneAsync(spec, cancellationToken);

            return(stock.Assemble());
        }
コード例 #2
0
        public async Task LoadProductAsync(long stockId, string ean, int quantity, CancellationToken cancellationToken = default)
        {
            var spec  = new GetStockByIdSpecification(stockId);
            var stock = await _stockRepository.GetOneAsync(spec, cancellationToken);

            if (stock == null)
            {
                throw new ArgumentNullException(nameof(stock));
            }

            stock.LoadProduct(ean, quantity);

            _stockRepository.Update(stock);
            await _stockRepository.SaveChangesAsync();
        }
コード例 #3
0
        public async Task AddProductsAsync(long stockId, IEnumerable <ProductDTO> products, CancellationToken cancellationToken = default)
        {
            var domainProducts = new List <Product>();

            // convert product dto list into domain product list
            products.ToList().ForEach(p => domainProducts.Add(p.Assemble()));

            var spec = new GetStockByIdSpecification(stockId);

            // get stock
            var stock = await _stockRepository.GetOneAsync(spec, cancellationToken);

            if (stock == null)
            {
                throw new ArgumentNullException(nameof(stock));
            }

            // add the new products into stock
            stock.AddProducts(domainProducts);

            _stockRepository.Update(stock);
            await _stockRepository.SaveChangesAsync(cancellationToken);
        }