diff --git a/Controllers/TransactionController.cs b/Controllers/TransactionController.cs index 72c3655..d142ba1 100644 --- a/Controllers/TransactionController.cs +++ b/Controllers/TransactionController.cs @@ -55,9 +55,16 @@ namespace FirmTracker_Server.Controllers foreach (var product in transaction.TransactionProducts) { - product.TransactionId = transaction.Id; - decimal price = _productCRUD.GetProductPrice(product.ProductID); - int type = _productCRUD.GetProductType(product.ProductID); + var productByName = _productCRUD.GetProductByName(product.ProductName); + if (productByName == null) + { + throw new InvalidOperationException($"Product with name {product.ProductName} does not exist."); + } + product.ProductID = productByName.Id; + product.TransactionId = transaction.Id; + + decimal price = productByName.Price;// _productCRUD.GetProductPrice(product.ProductID); + int type = productByName.Type;//_productCRUD.GetProductType(product.ProductID); if (type == 1) { var prod = _productCRUD.GetProduct(product.ProductID); @@ -120,8 +127,16 @@ namespace FirmTracker_Server.Controllers { foreach (var product in transaction.TransactionProducts) { - product.TransactionId = transaction.Id; - decimal price = _productCRUD.GetProductPrice(product.ProductID); + var productByName = _productCRUD.GetProductByName(product.ProductName); + if (productByName == null) + { + throw new InvalidOperationException($"Product with name {product.ProductName} does not exist."); + } + product.ProductID = productByName.Id; + product.TransactionId = transaction.Id; + + decimal price = productByName.Price;// _productCRUD.GetProductPrice(product.ProductID); + int type = productByName.Type;//_productCRUD.GetProductType(product.ProductID); } diff --git a/nHibernate/Transactions/TransactionProduct.cs b/nHibernate/Transactions/TransactionProduct.cs index 943e7a2..1d88ad7 100644 --- a/nHibernate/Transactions/TransactionProduct.cs +++ b/nHibernate/Transactions/TransactionProduct.cs @@ -8,7 +8,8 @@ namespace FirmTracker_Server.nHibernate.Transactions { public virtual int Id { get; set; } public virtual int TransactionId { get; set; } - public virtual int ProductID { get; set; } + public virtual int ProductID { get; set; } + public virtual string ProductName { get; set; } public virtual int Quantity { get; set; } } }