Ejemplo n.º 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();
            }
        }
Ejemplo n.º 2
0
        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();
        }
Ejemplo n.º 3
0
 public void AddMovement(ProductMovement movement)
 {
     Manager.AddMovement(movement);
 }
Ejemplo n.º 4
0
 public ProductMovementViewModel(ProductMovement movement)
 {
     Movement = movement;
 }
Ejemplo n.º 5
0
        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);
        }