2024-05-05 22:08:27 +02:00
|
|
|
|
using FirmTracker_Server.Controllers;
|
|
|
|
|
using FirmTracker_Server.nHibernate;
|
2024-04-15 22:15:29 +02:00
|
|
|
|
using FirmTracker_Server.nHibernate.Products;
|
2024-05-06 21:25:10 +02:00
|
|
|
|
using FirmTracker_Server.nHibernate.Transactions;
|
2024-05-16 18:02:44 +02:00
|
|
|
|
using FirmTracker_Server.nHibernate.Expenses;
|
2024-04-15 22:15:29 +02:00
|
|
|
|
using NHibernate;
|
|
|
|
|
|
|
|
|
|
namespace FirmTracker_Server
|
|
|
|
|
{
|
|
|
|
|
public class TestClass
|
|
|
|
|
{
|
|
|
|
|
public void AddTestProduct()
|
|
|
|
|
{
|
2024-04-26 21:24:17 +02:00
|
|
|
|
// SessionFactory.Init(ConnectionString);
|
2024-04-15 22:15:29 +02:00
|
|
|
|
|
|
|
|
|
var product = new nHibernate.Products.Product
|
|
|
|
|
{
|
2024-04-26 21:24:17 +02:00
|
|
|
|
Name = "Produkt 1",
|
|
|
|
|
Description = "testowy produkt",
|
|
|
|
|
Price = 11.50m,
|
|
|
|
|
Type = 1,
|
|
|
|
|
Availability = 5
|
|
|
|
|
};
|
|
|
|
|
var product2 = new nHibernate.Products.Product
|
|
|
|
|
{
|
|
|
|
|
Name = "Usluga 1",
|
|
|
|
|
Description = "testowa usluga",
|
|
|
|
|
Price = 1120.00m,
|
|
|
|
|
Type = 0,
|
|
|
|
|
Availability = 0
|
2024-04-15 22:15:29 +02:00
|
|
|
|
};
|
2024-05-16 21:25:07 +02:00
|
|
|
|
var product3 = new nHibernate.Products.Product
|
|
|
|
|
{
|
|
|
|
|
Name = "Produkt 2",
|
|
|
|
|
Description = "produkt",
|
|
|
|
|
Price = 16.50m,
|
|
|
|
|
Type = 1,
|
|
|
|
|
Availability = 20
|
|
|
|
|
};
|
2024-05-16 22:30:57 +02:00
|
|
|
|
var product4 = new nHibernate.Products.Product
|
|
|
|
|
{
|
|
|
|
|
Name = "Produkt 3",
|
|
|
|
|
Description = "produkt",
|
|
|
|
|
Price = 25.00m,
|
|
|
|
|
Type = 1,
|
|
|
|
|
Availability = 10
|
|
|
|
|
};
|
|
|
|
|
var product5 = new nHibernate.Products.Product
|
|
|
|
|
{
|
|
|
|
|
Name = "Usługa 2",
|
|
|
|
|
Description = "usługa",
|
|
|
|
|
Price = 700.00m,
|
|
|
|
|
Type = 0,
|
|
|
|
|
Availability = 0
|
|
|
|
|
};
|
2024-05-06 21:25:10 +02:00
|
|
|
|
var transaction1 = new Transaction
|
2024-05-05 22:08:27 +02:00
|
|
|
|
{
|
2024-05-16 22:30:57 +02:00
|
|
|
|
Date = DateTime.Now.AddDays(-2),
|
2024-05-05 22:08:27 +02:00
|
|
|
|
Description = "testowa transakcja",
|
|
|
|
|
Discount = 10,
|
|
|
|
|
EmployeeId = 1,
|
|
|
|
|
PaymentType = "Karta kredytowa",
|
|
|
|
|
};
|
2024-05-16 21:25:07 +02:00
|
|
|
|
var transaction2 = new Transaction
|
|
|
|
|
{
|
2024-05-16 22:30:57 +02:00
|
|
|
|
Date = DateTime.Now.AddDays(-3),
|
2024-05-16 21:25:07 +02:00
|
|
|
|
Description = "testowa transakcja",
|
|
|
|
|
Discount = 30,
|
|
|
|
|
EmployeeId = 2,
|
|
|
|
|
PaymentType = "Gotówka",
|
|
|
|
|
};
|
2024-05-16 22:30:57 +02:00
|
|
|
|
var transaction3 = new Transaction
|
|
|
|
|
{
|
|
|
|
|
Date = DateTime.Now,
|
|
|
|
|
Description = "testowa transakcja",
|
|
|
|
|
Discount = 15,
|
|
|
|
|
EmployeeId = 1,
|
|
|
|
|
PaymentType = "BLIK",
|
|
|
|
|
};
|
2024-04-15 22:15:29 +02:00
|
|
|
|
|
2024-05-16 18:02:44 +02:00
|
|
|
|
var expense1 = new Expense
|
|
|
|
|
{
|
|
|
|
|
Date = DateTime.Now,
|
2024-05-16 21:25:07 +02:00
|
|
|
|
Value = 1003.9m,
|
2024-05-16 18:02:44 +02:00
|
|
|
|
Description = "testowy rozchód"
|
|
|
|
|
};
|
|
|
|
|
|
2024-04-15 22:15:29 +02:00
|
|
|
|
try
|
|
|
|
|
{
|
2024-05-16 21:25:07 +02:00
|
|
|
|
FirmTracker_Server.nHibernate.Products.ProductCRUD productCrud = new ProductCRUD();
|
2024-05-05 22:08:27 +02:00
|
|
|
|
FirmTracker_Server.nHibernate.Transactions.TransactionCRUD transactionCrud = new nHibernate.Transactions.TransactionCRUD();
|
2024-05-16 18:02:44 +02:00
|
|
|
|
ExpenseCRUD expenseCrud = new ExpenseCRUD();
|
2024-05-16 21:25:07 +02:00
|
|
|
|
productCrud.AddProduct(product);
|
|
|
|
|
productCrud.AddProduct(product2);
|
|
|
|
|
productCrud.AddProduct(product3);
|
2024-05-16 22:30:57 +02:00
|
|
|
|
productCrud.AddProduct(product4);
|
|
|
|
|
productCrud.AddProduct(product5);
|
2024-05-05 22:08:27 +02:00
|
|
|
|
transactionCrud.AddTransaction(transaction1);
|
2024-05-16 21:25:07 +02:00
|
|
|
|
transactionCrud.AddTransaction(transaction2);
|
2024-05-16 22:30:57 +02:00
|
|
|
|
transactionCrud.AddTransaction(transaction3);
|
2024-05-16 18:02:44 +02:00
|
|
|
|
expenseCrud.AddExpense(expense1);
|
|
|
|
|
|
2024-05-06 21:25:10 +02:00
|
|
|
|
|
|
|
|
|
List<TransactionProduct> testTransactionProducts = new List<TransactionProduct> {
|
2024-05-16 00:42:06 +02:00
|
|
|
|
new TransactionProduct { ProductID = 1, Quantity = 2 },
|
2024-05-16 21:25:07 +02:00
|
|
|
|
new TransactionProduct { ProductID = 2, Quantity = 1 },
|
|
|
|
|
new TransactionProduct { ProductID = 3, Quantity = 10 }
|
2024-05-06 21:25:10 +02:00
|
|
|
|
};
|
|
|
|
|
foreach (var transactionProduct in testTransactionProducts)
|
|
|
|
|
{
|
|
|
|
|
transactionCrud.AddTransactionProductToTransaction(transaction1.Id, transactionProduct);
|
|
|
|
|
|
|
|
|
|
}
|
2024-05-16 21:25:07 +02:00
|
|
|
|
|
|
|
|
|
List<TransactionProduct> testTransactionProducts2 = new List<TransactionProduct>
|
|
|
|
|
{
|
2024-05-16 22:30:57 +02:00
|
|
|
|
new TransactionProduct { ProductID = 4, Quantity=5},
|
|
|
|
|
new TransactionProduct { ProductID = 5, Quantity=1}
|
2024-05-16 21:25:07 +02:00
|
|
|
|
};
|
|
|
|
|
foreach (var transactionProduct in testTransactionProducts2)
|
|
|
|
|
{
|
|
|
|
|
transactionCrud.AddTransactionProductToTransaction(transaction2.Id, transactionProduct);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-16 22:30:57 +02:00
|
|
|
|
List<TransactionProduct> testTransactionProducts3 = new List<TransactionProduct>
|
|
|
|
|
{
|
|
|
|
|
new TransactionProduct { ProductID = 3, Quantity=12},
|
|
|
|
|
new TransactionProduct { ProductID = 2, Quantity=1}
|
|
|
|
|
};
|
|
|
|
|
foreach (var transactionProduct in testTransactionProducts3)
|
|
|
|
|
{
|
|
|
|
|
transactionCrud.AddTransactionProductToTransaction(transaction3.Id, transactionProduct);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-06 21:25:10 +02:00
|
|
|
|
|
2024-04-15 22:15:29 +02:00
|
|
|
|
}
|
|
|
|
|
catch(Exception ex)
|
|
|
|
|
{
|
2024-05-06 21:25:10 +02:00
|
|
|
|
Console.WriteLine(ex.ToString());
|
2024-04-15 22:15:29 +02:00
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|