Compare commits
No commits in common. "abac84ccf26ee4bc7b3450e9f36a43dbea84294b" and "a25a1a3d232f3eedb5b76009cf2314694cadc54f" have entirely different histories.
abac84ccf2
...
a25a1a3d23
@ -45,17 +45,6 @@ namespace FirmTracker_Server.Controllers
|
|||||||
return Ok(product);
|
return Ok(product);
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet("name/{name}")]
|
|
||||||
[ProducesResponseType(200)]
|
|
||||||
[ProducesResponseType(404)]
|
|
||||||
public IActionResult GetProductByName(string name)
|
|
||||||
{
|
|
||||||
var product = _productCrud.GetProductByName(name);
|
|
||||||
if (product ==null)
|
|
||||||
return NotFound();
|
|
||||||
return Ok(product);
|
|
||||||
}
|
|
||||||
|
|
||||||
// PUT: api/Products/5
|
// PUT: api/Products/5
|
||||||
[HttpPut("{id}")]
|
[HttpPut("{id}")]
|
||||||
[ProducesResponseType(200)] // Created
|
[ProducesResponseType(200)] // Created
|
||||||
|
@ -5,7 +5,6 @@ using System.Text.Json.Serialization;
|
|||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using System.Transactions;
|
using System.Transactions;
|
||||||
using FirmTracker_Server.nHibernate.Products;
|
using FirmTracker_Server.nHibernate.Products;
|
||||||
using FirmTracker_Server.nHibernate;
|
|
||||||
|
|
||||||
namespace FirmTracker_Server.Controllers
|
namespace FirmTracker_Server.Controllers
|
||||||
{
|
{
|
||||||
@ -42,17 +41,7 @@ namespace FirmTracker_Server.Controllers
|
|||||||
int type = _productCRUD.GetProductType(product.ProductID);
|
int type = _productCRUD.GetProductType(product.ProductID);
|
||||||
if (type == 1)
|
if (type == 1)
|
||||||
{
|
{
|
||||||
int availability = _productCRUD.GetProductAvailability(product.ProductID);
|
transaction.TotalPrice += ((product.Quantity * price) * ((1 - (transaction.Discount / 100))));
|
||||||
|
|
||||||
if (product.Quantity > availability)
|
|
||||||
{
|
|
||||||
return BadRequest($"Can't add product {product.ProductID} to transaction. Available: {availability}, Desired: {product.Quantity}");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
transaction.TotalPrice += ((product.Quantity * price) * ((1 - (transaction.Discount / 100))));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -110,7 +99,7 @@ namespace FirmTracker_Server.Controllers
|
|||||||
product.TransactionId = transaction.Id; // This might be 0 at this point if transaction isn't saved yet
|
product.TransactionId = transaction.Id; // This might be 0 at this point if transaction isn't saved yet
|
||||||
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))));
|
||||||
}
|
}
|
||||||
_transactionCRUD.UpdateTransaction(transaction);
|
_transactionCRUD.UpdateTransaction(transaction);
|
||||||
|
|
||||||
// Now that the transaction is saved, update each product with the correct TransactionId
|
// Now that the transaction is saved, update each product with the correct TransactionId
|
||||||
|
@ -53,19 +53,6 @@ namespace FirmTracker_Server.nHibernate.Products
|
|||||||
return product;
|
return product;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int GetProductAvailability(int productId)
|
|
||||||
{
|
|
||||||
using(var session = SessionFactory.OpenSession())
|
|
||||||
{
|
|
||||||
var product = session.Query<Product>()
|
|
||||||
.Where(p => p.Id == productId)
|
|
||||||
.Select(p => p.Availability)
|
|
||||||
.FirstOrDefault();
|
|
||||||
return product;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Product GetProduct(int productId)
|
public Product GetProduct(int productId)
|
||||||
{
|
{
|
||||||
using (var session = SessionFactory.OpenSession())
|
using (var session = SessionFactory.OpenSession())
|
||||||
@ -74,16 +61,6 @@ namespace FirmTracker_Server.nHibernate.Products
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Product GetProductByName(string productName)
|
|
||||||
{
|
|
||||||
using (var session = SessionFactory.OpenSession())
|
|
||||||
{
|
|
||||||
var query = session.CreateQuery("from Product where Name = :name");
|
|
||||||
query.SetParameter("name", productName);
|
|
||||||
return query.UniqueResult<Product>();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void UpdateProduct(Product product)
|
public void UpdateProduct(Product product)
|
||||||
{
|
{
|
||||||
using (var session = SessionFactory.OpenSession())
|
using (var session = SessionFactory.OpenSession())
|
||||||
|
Loading…
Reference in New Issue
Block a user