korekta dostępności produktów i totalprice przy updacie transakcji
This commit is contained in:
parent
aa81bfe248
commit
06f22951c9
@ -134,7 +134,7 @@ namespace FirmTracker_Server.Controllers
|
|||||||
{
|
{
|
||||||
product.TransactionId = transaction.Id;
|
product.TransactionId = transaction.Id;
|
||||||
decimal price = _productCRUD.GetProductPrice(product.ProductID);
|
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);
|
transaction.TotalPrice = Math.Round(transaction.TotalPrice, 2, MidpointRounding.AwayFromZero);
|
||||||
|
@ -86,9 +86,30 @@ namespace FirmTracker_Server.nHibernate.Transactions
|
|||||||
{
|
{
|
||||||
try
|
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)
|
foreach (var transactionProduct in transaction.TransactionProducts)
|
||||||
{
|
{
|
||||||
/*var product = session.Get<Product>(transactionProduct.ProductID);
|
var product = session.Get<Product>(transactionProduct.ProductID);
|
||||||
if (product.Type != 0)
|
if (product.Type != 0)
|
||||||
{
|
{
|
||||||
transaction.TotalPrice += ((transactionProduct.Quantity * product.Price) * ((1 - (transaction.Discount / 100))));
|
transaction.TotalPrice += ((transactionProduct.Quantity * product.Price) * ((1 - (transaction.Discount / 100))));
|
||||||
@ -96,10 +117,13 @@ namespace FirmTracker_Server.nHibernate.Transactions
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
transaction.TotalPrice += (product.Price) * ((1 - (transaction.Discount / 100)));
|
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;
|
transactionProduct.TransactionId = transaction.Id;
|
||||||
session.Update(transactionProduct);
|
session.SaveOrUpdate(transactionProduct);
|
||||||
}
|
}
|
||||||
session.Update(transaction);
|
session.Update(transaction);
|
||||||
|
|
||||||
@ -114,7 +138,6 @@ namespace FirmTracker_Server.nHibernate.Transactions
|
|||||||
session.Update(product);
|
session.Update(product);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sessionTransaction.Commit();
|
sessionTransaction.Commit();
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
|
Loading…
Reference in New Issue
Block a user