Compare commits
No commits in common. "7cbe1129ef763ed8d123dfd487f258757bcf3152" and "8fef792a1ac8250e963b303b0f75caf6c04936ac" have entirely different histories.
7cbe1129ef
...
8fef792a1a
@ -16,7 +16,6 @@
|
||||
*/
|
||||
|
||||
using FirmTracker_Server.nHibernate.Expenses;
|
||||
using FirmTracker_Server.nHibernate.Products;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
namespace FirmTracker_Server.Controllers
|
||||
{
|
||||
@ -35,24 +34,14 @@ namespace FirmTracker_Server.Controllers
|
||||
[ProducesResponseType(201)] // Created
|
||||
[ProducesResponseType(400)] // Bad Request
|
||||
public IActionResult CreateExpense([FromBody] Expense expense) {
|
||||
try
|
||||
try
|
||||
{
|
||||
if (expense.Value <= 0)
|
||||
{
|
||||
throw new InvalidOperationException("Wydatek nie może posiadać kwoty mniejszej lub równej 0.");
|
||||
}
|
||||
|
||||
_expenseCrud.AddExpense(expense);
|
||||
return CreatedAtAction("GetExpense", new { id = expense.Id }, expense);
|
||||
}
|
||||
catch (InvalidOperationException ioe)
|
||||
{
|
||||
return BadRequest(ioe.Message);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
catch (System.Exception ex) {
|
||||
return BadRequest(ex.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// GET: api/Expenses
|
||||
@ -75,26 +64,16 @@ namespace FirmTracker_Server.Controllers
|
||||
[ProducesResponseType(400)]
|
||||
public IActionResult UpdateExpense(int id, [FromBody] Expense expense)
|
||||
{
|
||||
if (id != expense.Id)
|
||||
{
|
||||
return BadRequest("Expense ID mismatch");
|
||||
}
|
||||
try
|
||||
{
|
||||
if (id != expense.Id)
|
||||
{
|
||||
return BadRequest("Nieprawidłowe ID wydatku");
|
||||
}
|
||||
if (expense.Value <= 0)
|
||||
{
|
||||
throw new InvalidOperationException("Wydatek nie może posiadać kwoty mniejszej lub równej 0.");
|
||||
}
|
||||
|
||||
|
||||
_expenseCrud.UpdateExpense(expense);
|
||||
return NoContent();
|
||||
}
|
||||
catch (InvalidOperationException ioe)
|
||||
{
|
||||
return BadRequest(ioe.Message);
|
||||
}
|
||||
catch (Exception ex)
|
||||
catch (System.Exception ex)
|
||||
{
|
||||
return BadRequest(ex.Message);
|
||||
}
|
||||
@ -110,10 +89,6 @@ namespace FirmTracker_Server.Controllers
|
||||
_expenseCrud.DeleteExpense(id);
|
||||
return NoContent();
|
||||
}
|
||||
catch (InvalidOperationException ioe)
|
||||
{
|
||||
return BadRequest($"{ioe.Message}");
|
||||
}
|
||||
catch (System.Exception ex)
|
||||
{
|
||||
return NotFound(ex.Message);
|
||||
|
@ -17,8 +17,6 @@
|
||||
|
||||
using FirmTracker_Server.nHibernate.Products;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System;
|
||||
|
||||
namespace FirmTracker_Server.Controllers
|
||||
{
|
||||
[Route("api/[controller]")]
|
||||
@ -41,33 +39,20 @@ namespace FirmTracker_Server.Controllers
|
||||
[ProducesResponseType(400)] // Bad Request
|
||||
public IActionResult CreateProduct([FromBody] Product product)
|
||||
{
|
||||
if (product.Type != 0 && product.Type != 1)
|
||||
{
|
||||
return BadRequest("Kategoria produktu musi być ustawiona na 0 lub 1.");
|
||||
}
|
||||
if (product.Type == 0 && product.Availability != 0)
|
||||
{
|
||||
return BadRequest("Dostępność usługi musi być ustawiona na 0.");
|
||||
}
|
||||
try
|
||||
{
|
||||
if (product.Type != 0 && product.Type != 1)
|
||||
{
|
||||
throw new InvalidOperationException("Kategoria produktu musi być ustawiona na 0 lub 1.");
|
||||
}
|
||||
if (product.Type == 0 && product.Availability != 0)
|
||||
{
|
||||
throw new InvalidOperationException("Dostępność usługi musi być ustawiona na 0.");
|
||||
}
|
||||
if (product.Type == 1 && product.Availability < 0)
|
||||
{
|
||||
throw new InvalidOperationException("Dostępność towaru nie może być ujemna.");
|
||||
}
|
||||
if (product.Price < 0)
|
||||
{
|
||||
throw new InvalidOperationException("Produkt nie może posiadać ujemnej ceny.");
|
||||
}
|
||||
|
||||
_productCrud.AddProduct(product);
|
||||
return CreatedAtAction("GetProduct", new { id = product.Id }, product);
|
||||
}
|
||||
catch (InvalidOperationException ioe)
|
||||
{
|
||||
return BadRequest(ioe.Message);
|
||||
}
|
||||
catch (Exception ex)
|
||||
catch (System.Exception ex)
|
||||
{
|
||||
return BadRequest(ex.Message);
|
||||
}
|
||||
@ -102,36 +87,23 @@ namespace FirmTracker_Server.Controllers
|
||||
[ProducesResponseType(400)] // Bad Request
|
||||
public IActionResult UpdateProduct(int id, [FromBody] Product product)
|
||||
{
|
||||
if (id != product.Id)
|
||||
return BadRequest("ID produktu nie zgadza się.");
|
||||
if (product.Type != 0 && product.Type != 1)
|
||||
{
|
||||
return BadRequest("Kategoria produktu musi być ustawiona na 0 lub 1.");
|
||||
}
|
||||
if (product.Type == 0 && product.Availability != 0)
|
||||
{
|
||||
return BadRequest("Dostępność usługi musi być ustawiona na 0.");
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if (id != product.Id)
|
||||
throw new InvalidOperationException("ID produktu nie zgadza się.");
|
||||
if (product.Type != 0 && product.Type != 1)
|
||||
{
|
||||
throw new InvalidOperationException("Kategoria produktu musi być ustawiona na 0 lub 1.");
|
||||
}
|
||||
if (product.Type == 0 && product.Availability != 0)
|
||||
{
|
||||
throw new InvalidOperationException("Dostępność usługi musi być ustawiona na 0.");
|
||||
}
|
||||
if (product.Type == 1 && product.Availability < 0)
|
||||
{
|
||||
throw new InvalidOperationException("Dostępność towaru nie może być ujemna.");
|
||||
}
|
||||
if (product.Price < 0)
|
||||
{
|
||||
throw new InvalidOperationException("Produkt nie może posiadać ujemnej ceny.");
|
||||
}
|
||||
|
||||
|
||||
_productCrud.UpdateProduct(product);
|
||||
return NoContent();
|
||||
}
|
||||
catch (InvalidOperationException ioe)
|
||||
{
|
||||
return BadRequest(ioe.Message);
|
||||
}
|
||||
catch (Exception ex)
|
||||
catch (System.Exception ex)
|
||||
{
|
||||
return BadRequest(ex.Message);
|
||||
}
|
||||
@ -148,10 +120,6 @@ namespace FirmTracker_Server.Controllers
|
||||
_productCrud.DeleteProduct(id);
|
||||
return NoContent();
|
||||
}
|
||||
catch (InvalidOperationException ioe)
|
||||
{
|
||||
return BadRequest($"{ioe.Message}");
|
||||
}
|
||||
catch (System.Exception ex)
|
||||
{
|
||||
return NotFound(ex.Message);
|
||||
|
@ -241,7 +241,7 @@ namespace FirmTracker_Server.Controllers
|
||||
}
|
||||
}
|
||||
|
||||
[HttpDelete("{id}")]
|
||||
[HttpDelete]
|
||||
[ProducesResponseType(204)]
|
||||
[ProducesResponseType(404)]
|
||||
public IActionResult DeleteReport(int id)
|
||||
|
@ -167,10 +167,6 @@ namespace FirmTracker_Server.Controllers
|
||||
_transactionCRUD.DeleteTransaction(id);
|
||||
return NoContent();
|
||||
}
|
||||
catch (InvalidOperationException ioe)
|
||||
{
|
||||
return BadRequest($"{ioe.Message}");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return NotFound(ex.Message);
|
||||
|
@ -54,7 +54,7 @@ namespace FirmTracker_Server
|
||||
var products = new List<Product>
|
||||
{
|
||||
CreateProduct("Tarta_truskawka", "produkt", 31.99m, 1, 10),
|
||||
CreateProduct("Tarta_czekolada", "produkt", 30.99m, 1, 10),
|
||||
CreateProduct("Tarta_czekolada", "produkt", 30.99m, 1, 8),
|
||||
CreateProduct("Tarta_agrest", "produkt", 32.90m, 1, 8),
|
||||
CreateProduct("Tarta_pistacja", "produkt", 35.99m, 1, 12),
|
||||
CreateProduct("Tarta_karmel", "produkt", 32.00m, 1, 12),
|
||||
|
@ -17,8 +17,6 @@
|
||||
|
||||
using FirmTracker_Server.nHibernate;
|
||||
using FirmTracker_Server.nHibernate.Products;
|
||||
using FirmTracker_Server.nHibernate.Reports;
|
||||
using NHibernate.Criterion;
|
||||
|
||||
namespace FirmTracker_Server.nHibernate.Expenses
|
||||
{
|
||||
@ -104,16 +102,6 @@ namespace FirmTracker_Server.nHibernate.Expenses
|
||||
var expense = session.Get<Expense>(expenseId);
|
||||
if (expense != null)
|
||||
{
|
||||
var criteria = session.CreateCriteria<ReportExpense>();
|
||||
criteria.Add(Restrictions.Eq("Expense.Id", expenseId));
|
||||
var reportExpenses = criteria.List<ReportExpense>();
|
||||
|
||||
if (reportExpenses.Any())
|
||||
{
|
||||
throw new InvalidOperationException("Nie można usunąć wydatku. Wydatek jest ujęty w co najmniej jednym z raportów.");
|
||||
}
|
||||
|
||||
|
||||
session.Delete(expense);
|
||||
transaction.Commit();
|
||||
}
|
||||
|
@ -22,9 +22,6 @@ using System.Collections.Generic;
|
||||
using Microsoft.AspNetCore.OpenApi;
|
||||
using Microsoft.AspNetCore.Http.HttpResults;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
using FirmTracker_Server.nHibernate.Reports;
|
||||
using NHibernate.Criterion;
|
||||
using FirmTracker_Server.nHibernate.Transactions;
|
||||
|
||||
namespace FirmTracker_Server.nHibernate.Products
|
||||
{
|
||||
@ -132,16 +129,6 @@ namespace FirmTracker_Server.nHibernate.Products
|
||||
var product = session.Get<Product>(productId);
|
||||
if (product != null)
|
||||
{
|
||||
|
||||
var criteria = session.CreateCriteria<TransactionProduct>();
|
||||
criteria.Add(Restrictions.Eq("ProductID", productId));
|
||||
var transactionProducts = criteria.List<TransactionProduct>();
|
||||
|
||||
if (transactionProducts.Any())
|
||||
{
|
||||
throw new InvalidOperationException("Nie można usunąć produktu. Produkt jest ujęty w co najmniej jednej transakcji.");
|
||||
}
|
||||
|
||||
session.Delete(product);
|
||||
transaction.Commit();
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ namespace FirmTracker_Server.nHibernate.Transactions
|
||||
HasMany(x => x.TransactionProducts)
|
||||
.KeyColumn("TransactionId")
|
||||
.Cascade.AllDeleteOrphan()
|
||||
.Inverse();
|
||||
.Inverse(); // Ustawienie Inverse() wskazuje, że to `TransactionProduct` jest właścicielem relacji
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,5 @@
|
||||
using FirmTracker_Server.nHibernate.Products;
|
||||
using FirmTracker_Server.nHibernate.Reports;
|
||||
using NHibernate;
|
||||
using NHibernate.Criterion;
|
||||
using NHibernate.Linq;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@ -179,15 +177,6 @@ namespace FirmTracker_Server.nHibernate.Transactions
|
||||
var transaction = session.Get<Transaction>(transactionId);
|
||||
if (transaction != null)
|
||||
{
|
||||
var criteria = session.CreateCriteria<ReportTransaction>();
|
||||
criteria.Add(Restrictions.Eq("Transaction.Id", transactionId));
|
||||
var reportTransactions = criteria.List<ReportTransaction>();
|
||||
|
||||
if (reportTransactions.Any())
|
||||
{
|
||||
throw new InvalidOperationException("Nie można usunąć transakcji. Transakcja jest ujęta w co najmniej jednym z raportów.");
|
||||
}
|
||||
|
||||
foreach (var transactionProduct in transaction.TransactionProducts)
|
||||
{
|
||||
var product = session.Get<Product>(transactionProduct.ProductID);
|
||||
|
@ -18,7 +18,7 @@ namespace FirmTracker_Server.nHibernate.Transactions
|
||||
HasMany(x => x.TransactionProducts)
|
||||
.KeyColumn("TransactionId")
|
||||
.Cascade.AllDeleteOrphan()
|
||||
.Inverse();
|
||||
.Inverse(); // Ustawienie Inverse() wskazuje, że to `TransactionProduct` jest właścicielem relacji
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user