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()); }
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(); }
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); }