示例#1
0
        public void AddMovement(ProductMovement movement)
        {
            using (var transaction = new TransactionScope())
            using (var connection = new ConnectionScope())
            {
                var product = GetProduct(movement.ProductId);
                if (product == null)
                    throw new Exception("Product not found");

                if (product.QuantityOnHand + movement.Quantity < 0)
                    throw new Exception("Quantity on hand cannot become negative.");

                movement.Insert();
                product.QuantityOnHand += movement.Quantity;
                product.Update();

                transaction.Complete();
            }
        }
        public void Save()
        {
            var movement = new ProductMovement
            {
                Id = Guid.NewGuid(),
                ProductId = Product.Id,
                DateTime = DateTimeOffset.Now,
                MovementType = ProductMovementType.Adjustment,
                Quantity = Quantity
            };

            ProductService.AddMovement(movement);

            Close();
        }
示例#3
0
 public void AddMovement(ProductMovement movement)
 {
     Manager.AddMovement(movement);
 }
示例#4
0
 public ProductMovementViewModel(ProductMovement movement)
 {
     Movement = movement;
 }
示例#5
0
文件: UnitTests.cs 项目: edjo23/shop
        public void AddStockReceipt()
        {
            IProductService productService = new ProductService(new ProductManager());

            var product = productService.GetProducts().First();

            var movement = new ProductMovement
            {
                Id = Guid.NewGuid(),
                ProductId = product.Id,
                DateTime = DateTimeOffset.Now,
                MovementType = ProductMovementType.Receipt, // Stock Receipt
                Quantity = 10
            };

            productService.AddMovement(movement);

            Assert.AreEqual<int>(product.QuantityOnHand + movement.Quantity, productService.GetProduct(product.Id).QuantityOnHand);
        }