korekta dostępności produktów i totalprice przy updacie transakcji

This commit is contained in:
Kamil Ryżek 2024-06-13 15:25:07 +02:00
parent aa81bfe248
commit 06f22951c9
2 changed files with 28 additions and 5 deletions

View File

@ -134,7 +134,7 @@ namespace FirmTracker_Server.Controllers
{
product.TransactionId = transaction.Id;
decimal price = _productCRUD.GetProductPrice(product.ProductID);
transaction.TotalPrice += ((product.Quantity * price) * ((1 - (transaction.Discount / 100))));
//transaction.TotalPrice += ((product.Quantity * price) * ((1 - (transaction.Discount / 100))));
}
transaction.TotalPrice = Math.Round(transaction.TotalPrice, 2, MidpointRounding.AwayFromZero);

View File

@ -86,9 +86,30 @@ namespace FirmTracker_Server.nHibernate.Transactions
{
try
{
var oldTransaction = session.Load<Transaction>(transaction.Id);
foreach (var tp in oldTransaction.TransactionProducts)
{
var product = session.Get<Product>(tp.ProductID);
Console.WriteLine($"Product {product.Name} before quantity: {tp.Quantity}");
if (product.Type != 0)
{
product.Availability += tp.Quantity;
transaction.TotalPrice -= ((tp.Quantity * product.Price) * ((1 - (transaction.Discount / 100))));
}
else
{
transaction.TotalPrice -= (product.Price) * ((1 - (transaction.Discount / 100)));
}
session.Update(product);
}
session.Flush();
session.Clear();
foreach (var transactionProduct in transaction.TransactionProducts)
{
/*var product = session.Get<Product>(transactionProduct.ProductID);
var product = session.Get<Product>(transactionProduct.ProductID);
if (product.Type != 0)
{
transaction.TotalPrice += ((transactionProduct.Quantity * product.Price) * ((1 - (transaction.Discount / 100))));
@ -96,10 +117,13 @@ namespace FirmTracker_Server.nHibernate.Transactions
else
{
transaction.TotalPrice += (product.Price) * ((1 - (transaction.Discount / 100)));
}*/
}
//var product = session.Load<Product>(transactionProduct.ProductID);
Console.WriteLine($"Product {product.Name} after quantity: {transactionProduct.Quantity}");
transactionProduct.TransactionId = transaction.Id;
session.Update(transactionProduct);
session.SaveOrUpdate(transactionProduct);
}
session.Update(transaction);
@ -114,7 +138,6 @@ namespace FirmTracker_Server.nHibernate.Transactions
session.Update(product);
}
}
sessionTransaction.Commit();
}
catch