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.Expenses;
|
||||||
using FirmTracker_Server.nHibernate.Products;
|
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
namespace FirmTracker_Server.Controllers
|
namespace FirmTracker_Server.Controllers
|
||||||
{
|
{
|
||||||
@ -37,20 +36,10 @@ namespace FirmTracker_Server.Controllers
|
|||||||
public IActionResult CreateExpense([FromBody] Expense expense) {
|
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);
|
_expenseCrud.AddExpense(expense);
|
||||||
return CreatedAtAction("GetExpense", new { id = expense.Id }, expense);
|
return CreatedAtAction("GetExpense", new { id = expense.Id }, expense);
|
||||||
}
|
}
|
||||||
catch (InvalidOperationException ioe)
|
catch (System.Exception ex) {
|
||||||
{
|
|
||||||
return BadRequest(ioe.Message);
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
return BadRequest(ex.Message);
|
return BadRequest(ex.Message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -74,27 +63,17 @@ namespace FirmTracker_Server.Controllers
|
|||||||
[ProducesResponseType(204)]
|
[ProducesResponseType(204)]
|
||||||
[ProducesResponseType(400)]
|
[ProducesResponseType(400)]
|
||||||
public IActionResult UpdateExpense(int id, [FromBody] Expense expense)
|
public IActionResult UpdateExpense(int id, [FromBody] Expense expense)
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
if (id != expense.Id)
|
if (id != expense.Id)
|
||||||
{
|
{
|
||||||
return BadRequest("Nieprawidłowe ID wydatku");
|
return BadRequest("Expense ID mismatch");
|
||||||
}
|
}
|
||||||
if (expense.Value <= 0)
|
try
|
||||||
{
|
{
|
||||||
throw new InvalidOperationException("Wydatek nie może posiadać kwoty mniejszej lub równej 0.");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
_expenseCrud.UpdateExpense(expense);
|
_expenseCrud.UpdateExpense(expense);
|
||||||
return NoContent();
|
return NoContent();
|
||||||
}
|
}
|
||||||
catch (InvalidOperationException ioe)
|
catch (System.Exception ex)
|
||||||
{
|
|
||||||
return BadRequest(ioe.Message);
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
{
|
||||||
return BadRequest(ex.Message);
|
return BadRequest(ex.Message);
|
||||||
}
|
}
|
||||||
@ -110,10 +89,6 @@ namespace FirmTracker_Server.Controllers
|
|||||||
_expenseCrud.DeleteExpense(id);
|
_expenseCrud.DeleteExpense(id);
|
||||||
return NoContent();
|
return NoContent();
|
||||||
}
|
}
|
||||||
catch (InvalidOperationException ioe)
|
|
||||||
{
|
|
||||||
return BadRequest($"{ioe.Message}");
|
|
||||||
}
|
|
||||||
catch (System.Exception ex)
|
catch (System.Exception ex)
|
||||||
{
|
{
|
||||||
return NotFound(ex.Message);
|
return NotFound(ex.Message);
|
||||||
|
@ -17,8 +17,6 @@
|
|||||||
|
|
||||||
using FirmTracker_Server.nHibernate.Products;
|
using FirmTracker_Server.nHibernate.Products;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using System;
|
|
||||||
|
|
||||||
namespace FirmTracker_Server.Controllers
|
namespace FirmTracker_Server.Controllers
|
||||||
{
|
{
|
||||||
[Route("api/[controller]")]
|
[Route("api/[controller]")]
|
||||||
@ -40,34 +38,21 @@ namespace FirmTracker_Server.Controllers
|
|||||||
[ProducesResponseType(200)] // Created
|
[ProducesResponseType(200)] // Created
|
||||||
[ProducesResponseType(400)] // Bad Request
|
[ProducesResponseType(400)] // Bad Request
|
||||||
public IActionResult CreateProduct([FromBody] Product product)
|
public IActionResult CreateProduct([FromBody] Product product)
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
if (product.Type != 0 && product.Type != 1)
|
if (product.Type != 0 && product.Type != 1)
|
||||||
{
|
{
|
||||||
throw new InvalidOperationException("Kategoria produktu musi być ustawiona na 0 lub 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)
|
||||||
{
|
{
|
||||||
throw new InvalidOperationException("Dostępność usługi musi być ustawiona na 0.");
|
return BadRequest("Dostępność usługi musi być ustawiona na 0.");
|
||||||
}
|
}
|
||||||
if (product.Type == 1 && product.Availability < 0)
|
try
|
||||||
{
|
{
|
||||||
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);
|
_productCrud.AddProduct(product);
|
||||||
return CreatedAtAction("GetProduct", new { id = product.Id }, product);
|
return CreatedAtAction("GetProduct", new { id = product.Id }, product);
|
||||||
}
|
}
|
||||||
catch (InvalidOperationException ioe)
|
catch (System.Exception ex)
|
||||||
{
|
|
||||||
return BadRequest(ioe.Message);
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
{
|
||||||
return BadRequest(ex.Message);
|
return BadRequest(ex.Message);
|
||||||
}
|
}
|
||||||
@ -101,37 +86,24 @@ namespace FirmTracker_Server.Controllers
|
|||||||
[ProducesResponseType(200)] // Created
|
[ProducesResponseType(200)] // Created
|
||||||
[ProducesResponseType(400)] // Bad Request
|
[ProducesResponseType(400)] // Bad Request
|
||||||
public IActionResult UpdateProduct(int id, [FromBody] Product product)
|
public IActionResult UpdateProduct(int id, [FromBody] Product product)
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
if (id != product.Id)
|
if (id != product.Id)
|
||||||
throw new InvalidOperationException("ID produktu nie zgadza się.");
|
return BadRequest("ID produktu nie zgadza się.");
|
||||||
if (product.Type != 0 && product.Type != 1)
|
if (product.Type != 0 && product.Type != 1)
|
||||||
{
|
{
|
||||||
throw new InvalidOperationException("Kategoria produktu musi być ustawiona na 0 lub 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)
|
||||||
{
|
{
|
||||||
throw new InvalidOperationException("Dostępność usługi musi być ustawiona na 0.");
|
return BadRequest("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.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
_productCrud.UpdateProduct(product);
|
_productCrud.UpdateProduct(product);
|
||||||
return NoContent();
|
return NoContent();
|
||||||
}
|
}
|
||||||
catch (InvalidOperationException ioe)
|
catch (System.Exception ex)
|
||||||
{
|
|
||||||
return BadRequest(ioe.Message);
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
{
|
||||||
return BadRequest(ex.Message);
|
return BadRequest(ex.Message);
|
||||||
}
|
}
|
||||||
@ -148,10 +120,6 @@ namespace FirmTracker_Server.Controllers
|
|||||||
_productCrud.DeleteProduct(id);
|
_productCrud.DeleteProduct(id);
|
||||||
return NoContent();
|
return NoContent();
|
||||||
}
|
}
|
||||||
catch (InvalidOperationException ioe)
|
|
||||||
{
|
|
||||||
return BadRequest($"{ioe.Message}");
|
|
||||||
}
|
|
||||||
catch (System.Exception ex)
|
catch (System.Exception ex)
|
||||||
{
|
{
|
||||||
return NotFound(ex.Message);
|
return NotFound(ex.Message);
|
||||||
|
@ -241,7 +241,7 @@ namespace FirmTracker_Server.Controllers
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpDelete("{id}")]
|
[HttpDelete]
|
||||||
[ProducesResponseType(204)]
|
[ProducesResponseType(204)]
|
||||||
[ProducesResponseType(404)]
|
[ProducesResponseType(404)]
|
||||||
public IActionResult DeleteReport(int id)
|
public IActionResult DeleteReport(int id)
|
||||||
|
@ -167,10 +167,6 @@ namespace FirmTracker_Server.Controllers
|
|||||||
_transactionCRUD.DeleteTransaction(id);
|
_transactionCRUD.DeleteTransaction(id);
|
||||||
return NoContent();
|
return NoContent();
|
||||||
}
|
}
|
||||||
catch (InvalidOperationException ioe)
|
|
||||||
{
|
|
||||||
return BadRequest($"{ioe.Message}");
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
return NotFound(ex.Message);
|
return NotFound(ex.Message);
|
||||||
|
@ -54,7 +54,7 @@ namespace FirmTracker_Server
|
|||||||
var products = new List<Product>
|
var products = new List<Product>
|
||||||
{
|
{
|
||||||
CreateProduct("Tarta_truskawka", "produkt", 31.99m, 1, 10),
|
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_agrest", "produkt", 32.90m, 1, 8),
|
||||||
CreateProduct("Tarta_pistacja", "produkt", 35.99m, 1, 12),
|
CreateProduct("Tarta_pistacja", "produkt", 35.99m, 1, 12),
|
||||||
CreateProduct("Tarta_karmel", "produkt", 32.00m, 1, 12),
|
CreateProduct("Tarta_karmel", "produkt", 32.00m, 1, 12),
|
||||||
|
@ -17,8 +17,6 @@
|
|||||||
|
|
||||||
using FirmTracker_Server.nHibernate;
|
using FirmTracker_Server.nHibernate;
|
||||||
using FirmTracker_Server.nHibernate.Products;
|
using FirmTracker_Server.nHibernate.Products;
|
||||||
using FirmTracker_Server.nHibernate.Reports;
|
|
||||||
using NHibernate.Criterion;
|
|
||||||
|
|
||||||
namespace FirmTracker_Server.nHibernate.Expenses
|
namespace FirmTracker_Server.nHibernate.Expenses
|
||||||
{
|
{
|
||||||
@ -104,16 +102,6 @@ namespace FirmTracker_Server.nHibernate.Expenses
|
|||||||
var expense = session.Get<Expense>(expenseId);
|
var expense = session.Get<Expense>(expenseId);
|
||||||
if (expense != null)
|
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);
|
session.Delete(expense);
|
||||||
transaction.Commit();
|
transaction.Commit();
|
||||||
}
|
}
|
||||||
|
@ -22,9 +22,6 @@ using System.Collections.Generic;
|
|||||||
using Microsoft.AspNetCore.OpenApi;
|
using Microsoft.AspNetCore.OpenApi;
|
||||||
using Microsoft.AspNetCore.Http.HttpResults;
|
using Microsoft.AspNetCore.Http.HttpResults;
|
||||||
using System.Security.Cryptography.X509Certificates;
|
using System.Security.Cryptography.X509Certificates;
|
||||||
using FirmTracker_Server.nHibernate.Reports;
|
|
||||||
using NHibernate.Criterion;
|
|
||||||
using FirmTracker_Server.nHibernate.Transactions;
|
|
||||||
|
|
||||||
namespace FirmTracker_Server.nHibernate.Products
|
namespace FirmTracker_Server.nHibernate.Products
|
||||||
{
|
{
|
||||||
@ -132,16 +129,6 @@ namespace FirmTracker_Server.nHibernate.Products
|
|||||||
var product = session.Get<Product>(productId);
|
var product = session.Get<Product>(productId);
|
||||||
if (product != null)
|
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);
|
session.Delete(product);
|
||||||
transaction.Commit();
|
transaction.Commit();
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@ namespace FirmTracker_Server.nHibernate.Transactions
|
|||||||
HasMany(x => x.TransactionProducts)
|
HasMany(x => x.TransactionProducts)
|
||||||
.KeyColumn("TransactionId")
|
.KeyColumn("TransactionId")
|
||||||
.Cascade.AllDeleteOrphan()
|
.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.Products;
|
||||||
using FirmTracker_Server.nHibernate.Reports;
|
|
||||||
using NHibernate;
|
using NHibernate;
|
||||||
using NHibernate.Criterion;
|
|
||||||
using NHibernate.Linq;
|
using NHibernate.Linq;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
@ -179,15 +177,6 @@ namespace FirmTracker_Server.nHibernate.Transactions
|
|||||||
var transaction = session.Get<Transaction>(transactionId);
|
var transaction = session.Get<Transaction>(transactionId);
|
||||||
if (transaction != null)
|
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)
|
foreach (var transactionProduct in transaction.TransactionProducts)
|
||||||
{
|
{
|
||||||
var product = session.Get<Product>(transactionProduct.ProductID);
|
var product = session.Get<Product>(transactionProduct.ProductID);
|
||||||
|
@ -18,7 +18,7 @@ namespace FirmTracker_Server.nHibernate.Transactions
|
|||||||
HasMany(x => x.TransactionProducts)
|
HasMany(x => x.TransactionProducts)
|
||||||
.KeyColumn("TransactionId")
|
.KeyColumn("TransactionId")
|
||||||
.Cascade.AllDeleteOrphan()
|
.Cascade.AllDeleteOrphan()
|
||||||
.Inverse();
|
.Inverse(); // Ustawienie Inverse() wskazuje, że to `TransactionProduct` jest właścicielem relacji
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user