dodawanie produktu do transakcji po nazwie

This commit is contained in:
Kamil Ryżek 2024-06-13 19:10:25 +02:00
parent 3b32e30d00
commit 43c4e20908
2 changed files with 22 additions and 6 deletions

View File

@ -55,9 +55,16 @@ namespace FirmTracker_Server.Controllers
foreach (var product in transaction.TransactionProducts) foreach (var product in transaction.TransactionProducts)
{ {
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; product.TransactionId = transaction.Id;
decimal price = _productCRUD.GetProductPrice(product.ProductID);
int type = _productCRUD.GetProductType(product.ProductID); decimal price = productByName.Price;// _productCRUD.GetProductPrice(product.ProductID);
int type = productByName.Type;//_productCRUD.GetProductType(product.ProductID);
if (type == 1) if (type == 1)
{ {
var prod = _productCRUD.GetProduct(product.ProductID); var prod = _productCRUD.GetProduct(product.ProductID);
@ -120,8 +127,16 @@ namespace FirmTracker_Server.Controllers
{ {
foreach (var product in transaction.TransactionProducts) foreach (var product in transaction.TransactionProducts)
{ {
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; product.TransactionId = transaction.Id;
decimal price = _productCRUD.GetProductPrice(product.ProductID);
decimal price = productByName.Price;// _productCRUD.GetProductPrice(product.ProductID);
int type = productByName.Type;//_productCRUD.GetProductType(product.ProductID);
} }

View File

@ -8,7 +8,8 @@ namespace FirmTracker_Server.nHibernate.Transactions
{ {
public virtual int Id { get; set; } public virtual int Id { get; set; }
public virtual int TransactionId { 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; } public virtual int Quantity { get; set; }
} }
} }