PI2024-23 #2
@ -41,11 +41,11 @@ namespace FirmTracker_Server.Controllers
|
|||||||
{
|
{
|
||||||
if (product.Type != 0 && product.Type != 1)
|
if (product.Type != 0 && product.Type != 1)
|
||||||
{
|
{
|
||||||
return BadRequest("Product type must be set to 0 or 1");
|
return BadRequest("Kategoria produktu musi być ustawiona na 0 lub 1.");
|
||||||
}
|
}
|
||||||
if (product.Type == 0 && product.Availability != 0)
|
if (product.Type == 0 && product.Availability != 0)
|
||||||
{
|
{
|
||||||
return BadRequest("Services availability must be set to 0");
|
return BadRequest("Dostępność usługi musi być ustawiona na 0.");
|
||||||
}
|
}
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -88,14 +88,14 @@ namespace FirmTracker_Server.Controllers
|
|||||||
public IActionResult UpdateProduct(int id, [FromBody] Product product)
|
public IActionResult UpdateProduct(int id, [FromBody] Product product)
|
||||||
{
|
{
|
||||||
if (id != product.Id)
|
if (id != product.Id)
|
||||||
return BadRequest("Product ID mismatch");
|
return BadRequest("ID produktu nie zgadza się.");
|
||||||
if (product.Type != 0 && product.Type != 1)
|
if (product.Type != 0 && product.Type != 1)
|
||||||
{
|
{
|
||||||
return BadRequest("Product type must be set to 0 or 1");
|
return BadRequest("Kategoria produktu musi być ustawiona na 0 lub 1.");
|
||||||
}
|
}
|
||||||
if (product.Type == 0 && product.Availability != 0)
|
if (product.Type == 0 && product.Availability != 0)
|
||||||
{
|
{
|
||||||
return BadRequest("Services availability must be set to 0");
|
return BadRequest("Dostępność usługi musi być ustawiona na 0.");
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
@ -149,7 +149,7 @@ namespace FirmTracker_Server.Controllers
|
|||||||
var product = _productCrud.GetProduct(order.ProductId);
|
var product = _productCrud.GetProduct(order.ProductId);
|
||||||
if (product == null)
|
if (product == null)
|
||||||
{
|
{
|
||||||
return BadRequest($"Product with ID {order.ProductId} not found.");
|
return BadRequest($"Nie znaleziono produktu o ID {order.ProductId}.");
|
||||||
}
|
}
|
||||||
totalPrice += product.Price * order.Quantity;
|
totalPrice += product.Price * order.Quantity;
|
||||||
}
|
}
|
||||||
|
@ -51,7 +51,7 @@ namespace FirmTracker_Server.Controllers
|
|||||||
var toDate = dateRange.ToDate;
|
var toDate = dateRange.ToDate;
|
||||||
if (fromDate >= toDate)
|
if (fromDate >= toDate)
|
||||||
{
|
{
|
||||||
return BadRequest();
|
return BadRequest("Nieprawidłowy zakres dat.");
|
||||||
}
|
}
|
||||||
using (var session = SessionFactory.OpenSession())
|
using (var session = SessionFactory.OpenSession())
|
||||||
{
|
{
|
||||||
@ -191,7 +191,7 @@ namespace FirmTracker_Server.Controllers
|
|||||||
var toDate = dateRange.ToDate;
|
var toDate = dateRange.ToDate;
|
||||||
if (fromDate >= toDate)
|
if (fromDate >= toDate)
|
||||||
{
|
{
|
||||||
return BadRequest();
|
return BadRequest("Nieprawidłowy zakres dat.");
|
||||||
}
|
}
|
||||||
var transactions = session.Query<nHibernate.Transactions.Transaction>()
|
var transactions = session.Query<nHibernate.Transactions.Transaction>()
|
||||||
.Where(t => t.Date >= fromDate && t.Date <= toDate)
|
.Where(t => t.Date >= fromDate && t.Date <= toDate)
|
||||||
|
@ -58,7 +58,7 @@ namespace FirmTracker_Server.Controllers
|
|||||||
var productByName = _productCRUD.GetProductByName(product.ProductName);
|
var productByName = _productCRUD.GetProductByName(product.ProductName);
|
||||||
if (productByName == null)
|
if (productByName == null)
|
||||||
{
|
{
|
||||||
throw new InvalidOperationException($"Product with name {product.ProductName} does not exist.");
|
throw new InvalidOperationException($"Produkt o nazwie {product.ProductName} nie istnieje.");
|
||||||
}
|
}
|
||||||
product.ProductID = productByName.Id;
|
product.ProductID = productByName.Id;
|
||||||
product.TransactionId = transaction.Id;
|
product.TransactionId = transaction.Id;
|
||||||
@ -71,7 +71,7 @@ namespace FirmTracker_Server.Controllers
|
|||||||
|
|
||||||
if (product.Quantity > prod.Availability)
|
if (product.Quantity > prod.Availability)
|
||||||
{
|
{
|
||||||
throw new InvalidOperationException($"Can't add product {prod.Name} to transaction. Available: {prod.Availability}, Desired: {product.Quantity}");
|
throw new InvalidOperationException($"Nie można dodać {prod.Name} do transakcji. Dostępność: {prod.Availability}, Zażądano: {product.Quantity}");
|
||||||
//return BadRequest($"Can't add product {product.ProductID} to transaction. Available: {availability}, Desired: {product.Quantity}");
|
//return BadRequest($"Can't add product {product.ProductID} to transaction. Available: {availability}, Desired: {product.Quantity}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -121,7 +121,7 @@ namespace FirmTracker_Server.Controllers
|
|||||||
public IActionResult UpdateTransaction(int id, [FromBody] nHibernate.Transactions.Transaction transaction)
|
public IActionResult UpdateTransaction(int id, [FromBody] nHibernate.Transactions.Transaction transaction)
|
||||||
{
|
{
|
||||||
if (id != transaction.Id)
|
if (id != transaction.Id)
|
||||||
return BadRequest("Transaction ID mismatch");
|
return BadRequest("ID transakcji nie zgadza się.");
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -130,7 +130,7 @@ namespace FirmTracker_Server.Controllers
|
|||||||
var productByName = _productCRUD.GetProductByName(product.ProductName);
|
var productByName = _productCRUD.GetProductByName(product.ProductName);
|
||||||
if (productByName == null)
|
if (productByName == null)
|
||||||
{
|
{
|
||||||
throw new InvalidOperationException($"Product with name {product.ProductName} does not exist.");
|
throw new InvalidOperationException($"Produkt o nazwie {product.ProductName} nie istnieje.");
|
||||||
}
|
}
|
||||||
product.ProductID = productByName.Id;
|
product.ProductID = productByName.Id;
|
||||||
product.TransactionId = transaction.Id;
|
product.TransactionId = transaction.Id;
|
||||||
|
@ -91,7 +91,6 @@ namespace FirmTracker_Server.nHibernate.Transactions
|
|||||||
foreach (var tp in oldTransaction.TransactionProducts)
|
foreach (var tp in oldTransaction.TransactionProducts)
|
||||||
{
|
{
|
||||||
var product = session.Get<Product>(tp.ProductID);
|
var product = session.Get<Product>(tp.ProductID);
|
||||||
Console.WriteLine($"Product {product.Name} before quantity: {tp.Quantity}");
|
|
||||||
|
|
||||||
if (product.Type != 0)
|
if (product.Type != 0)
|
||||||
{
|
{
|
||||||
@ -116,9 +115,6 @@ namespace FirmTracker_Server.nHibernate.Transactions
|
|||||||
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.SaveOrUpdate(transactionProduct);
|
session.SaveOrUpdate(transactionProduct);
|
||||||
}
|
}
|
||||||
@ -134,7 +130,7 @@ namespace FirmTracker_Server.nHibernate.Transactions
|
|||||||
{
|
{
|
||||||
if (transactionProduct.Quantity > product.Availability)
|
if (transactionProduct.Quantity > product.Availability)
|
||||||
{
|
{
|
||||||
throw new InvalidOperationException($"Can't add product {product.Name} to transaction. Available: {product.Availability}, Desired: {transactionProduct.Quantity}");
|
throw new InvalidOperationException($"Nie można dodać {product.Name} do transakcji. Dostępność: {product.Availability}, Zażądano: {transactionProduct.Quantity}");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user