Compare commits

..

No commits in common. "ad1fa6e376d2eb7bbd21b444826602a9c4eef856" and "04334f59c04356776bcf188fba1cb88749478dba" have entirely different histories.

5 changed files with 7 additions and 61 deletions

View File

@ -39,14 +39,6 @@ namespace FirmTracker_Server.Controllers
[ProducesResponseType(400)] // Bad Request
public IActionResult CreateProduct([FromBody] Product product)
{
if (product.Type != 0 && product.Type != 1)
{
return BadRequest("Product type must be set to 0 or 1");
}
if (product.Type == 0 && product.Availability != 0)
{
return BadRequest("Services availability must be set to 0");
}
try
{
_productCrud.AddProduct(product);
@ -89,14 +81,6 @@ namespace FirmTracker_Server.Controllers
{
if (id != product.Id)
return BadRequest("Product ID mismatch");
if (product.Type != 0 && product.Type != 1)
{
return BadRequest("Product type must be set to 0 or 1");
}
if (product.Type == 0 && product.Availability != 0)
{
return BadRequest("Services availability must be set to 0");
}
try
{

View File

@ -23,7 +23,6 @@ using System.Text.Json;
using System.Transactions;
using FirmTracker_Server.nHibernate.Products;
using FirmTracker_Server.nHibernate;
using Microsoft.AspNetCore.Http.HttpResults;
namespace FirmTracker_Server.Controllers
{
@ -64,18 +63,17 @@ namespace FirmTracker_Server.Controllers
if (product.Quantity > availability)
{
throw new InvalidOperationException($"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}");
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))));
transaction.TotalPrice += ((product.Quantity * price) * ((1 - (transaction.Discount / 100))));
}
}
else
{
//transaction.TotalPrice += (price * ((1 - (transaction.Discount / 100))));
transaction.TotalPrice += (price * ((1 - (transaction.Discount / 100))));
}
}
@ -93,13 +91,6 @@ namespace FirmTracker_Server.Controllers
return CreatedAtAction(nameof(GetTransaction), new { id = transaction.Id }, transaction);
}
catch (InvalidOperationException ioe)
{
return BadRequest(new {
Message = ioe.Message,
ErrorCode = "Availability"
});
}
catch (Exception ex)
{
return BadRequest(ex.Message);
@ -130,6 +121,7 @@ namespace FirmTracker_Server.Controllers
try
{
foreach (var product in transaction.TransactionProducts)
{
product.TransactionId = transaction.Id;

View File

@ -13,7 +13,6 @@ namespace FirmTracker_Server.nHibernate.Transactions
Map(x => x.PaymentType);
Map(x => x.Discount);
Map(x => x.Description);
Map(x => x.TotalPrice);
HasMany(x => x.TransactionProducts)
.KeyColumn("TransactionId")

View File

@ -19,15 +19,7 @@ namespace FirmTracker_Server.nHibernate.Transactions
{
foreach (var transactionProduct in transaction.TransactionProducts)
{
var product = session.Get<Product>(transactionProduct.ProductID);
if (product.Type != 0)
{
transaction.TotalPrice += ((transactionProduct.Quantity * product.Price) * ((1 - (transaction.Discount / 100))));
}
else
{
transaction.TotalPrice += (product.Price) * ((1 - (transaction.Discount / 100)));
}
transactionProduct.TransactionId = transaction.Id;
session.Save(transactionProduct);
}
@ -86,15 +78,6 @@ namespace FirmTracker_Server.nHibernate.Transactions
{
foreach (var transactionProduct in transaction.TransactionProducts)
{
/*var product = session.Get<Product>(transactionProduct.ProductID);
if (product.Type != 0)
{
transaction.TotalPrice += ((transactionProduct.Quantity * product.Price) * ((1 - (transaction.Discount / 100))));
}
else
{
transaction.TotalPrice += (product.Price) * ((1 - (transaction.Discount / 100)));
}*/
transactionProduct.TransactionId = transaction.Id;
session.Update(transactionProduct);
@ -171,22 +154,11 @@ namespace FirmTracker_Server.nHibernate.Transactions
var transactionToUpdate = session.Get<Transaction>(transactionId);
if (transactionToUpdate != null)
{
var product = session.Get<Product>(transactionProduct.ProductID);
if (product.Type != 0)
{
transactionToUpdate.TotalPrice += ((transactionProduct.Quantity * product.Price) * ((1 - (transactionToUpdate.Discount / 100))));
}
else
{
transactionToUpdate.TotalPrice += (product.Price) * ((1 - (transactionToUpdate.Discount / 100)));
}
transactionProduct.TransactionId= transactionToUpdate.Id;
session.Save(transactionProduct);
transaction.Commit();
session.Update(transactionToUpdate);
//var product = session.Get<Product>(transactionProduct.ProductID);
var product = session.Get<Product>(transactionProduct.ProductID);
if (product.Type != 0)
{
product.Availability -= transactionProduct.Quantity;

View File

@ -13,7 +13,6 @@ namespace FirmTracker_Server.nHibernate.Transactions
Map(x => x.PaymentType);
Map(x => x.Discount);
Map(x => x.Description);
Map(x => x.TotalPrice);
HasMany(x => x.TransactionProducts)
.KeyColumn("TransactionId")