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(); }
public void AddMovement(ProductMovement movement) { Manager.AddMovement(movement); }
public ProductMovementViewModel(ProductMovement movement) { Movement = movement; }
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); }