Compare commits
56 Commits
Task_1_Mod
...
Task_6_Rep
| Author | SHA1 | Date | |
|---|---|---|---|
| 1f78b58025 | |||
| a7e7dd1a67 | |||
| 6e9ce4678a | |||
| c09cf2d078 | |||
| 4afd35c6e7 | |||
| 5cb1d2e440 | |||
| 934cb5ebf5 | |||
| 681ae1d484 | |||
| 1b9cbc274d | |||
| 55c269a934 | |||
| 7e8e7a5ee8 | |||
| b4c6d0110a | |||
| f9cfe3dc00 | |||
| 5c1b458ffd | |||
| 2b92a2b9bd | |||
| c960ed7320 | |||
| 4393d5097e | |||
| f1c2d1d3d8 | |||
| cea9386132 | |||
| 620832b1a8 | |||
| f886b16532 | |||
| db9da65e76 | |||
| 629e20e498 | |||
| f89577598a | |||
| 99fa16d354 | |||
| 0706b6e6e5 | |||
| 472ad965a8 | |||
| 75d8b547cb | |||
| c0f3362f42 | |||
| d92732140c | |||
| 5924d86f90 | |||
| 03d8022433 | |||
| c1a09db223 | |||
| e64854e1f9 | |||
| 70b42a97f4 | |||
| bb93edd951 | |||
| d28bb63707 | |||
| f54c8ecd02 | |||
| ca8e1737d0 | |||
| aeffe2f451 | |||
| ab3a3f6819 | |||
| 6f2d341f01 | |||
| 148b67f195 | |||
| dbf2331511 | |||
| 4b72fdbe96 | |||
| f5a54bab32 | |||
| 0d4a275328 | |||
| 684073e3be | |||
| 5cc67e747e | |||
| 56a54e19aa | |||
| 2e976740af | |||
| 1d72951b99 | |||
| 595041c319 | |||
| 71b48ba503 | |||
| 1d8c331535 | |||
| 362f1e73de |
@@ -5,7 +5,13 @@ VisualStudioVersion = 17.9.34728.123
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SladkieBulkiContrakts", "SladkieBulkiContrakts\SladkieBulkiContrakts.csproj", "{04F3CF43-43CA-4EF0-B5BB-913425A85E29}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SladkieBulkiTests", "SladkieBulkiTests\SladkieBulkiTests.csproj", "{12312C3E-A15B-4563-BD04-BB814149B2F6}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SladkieBulkiTests", "SladkieBulkiTests\SladkieBulkiTests.csproj", "{12312C3E-A15B-4563-BD04-BB814149B2F6}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SladkieBulkiBusinessLogic", "SladkieBulkiBusinessLogic\SladkieBulkiBusinessLogic.csproj", "{004CA71C-5308-44C7-82DA-4098BA6F5F1C}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SladkieBulkiDatabase", "SladkieBulkiDatabase\SladkieBulkiDatabase.csproj", "{A39687D5-A64A-4EF1-B988-BD58CFCACDDE}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SladkieBulkiWedApi", "SladkieBulkiWedApi\SladkieBulkiWedApi.csproj", "{8623B6C7-0506-4C36-A337-CA363B92FFA2}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
@@ -21,6 +27,18 @@ Global
|
||||
{12312C3E-A15B-4563-BD04-BB814149B2F6}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{12312C3E-A15B-4563-BD04-BB814149B2F6}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{12312C3E-A15B-4563-BD04-BB814149B2F6}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{004CA71C-5308-44C7-82DA-4098BA6F5F1C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{004CA71C-5308-44C7-82DA-4098BA6F5F1C}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{004CA71C-5308-44C7-82DA-4098BA6F5F1C}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{004CA71C-5308-44C7-82DA-4098BA6F5F1C}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{A39687D5-A64A-4EF1-B988-BD58CFCACDDE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{A39687D5-A64A-4EF1-B988-BD58CFCACDDE}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{A39687D5-A64A-4EF1-B988-BD58CFCACDDE}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{A39687D5-A64A-4EF1-B988-BD58CFCACDDE}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{8623B6C7-0506-4C36-A337-CA363B92FFA2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{8623B6C7-0506-4C36-A337-CA363B92FFA2}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{8623B6C7-0506-4C36-A337-CA363B92FFA2}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{8623B6C7-0506-4C36-A337-CA363B92FFA2}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using SladkieBulkiContrakts.BusinessLogicsContracts;
|
||||
using SladkieBulkiContrakts.DataModels;
|
||||
using SladkieBulkiContrakts.Exceptions;
|
||||
using SladkieBulkiContrakts.Extensions;
|
||||
using SladkieBulkiContrakts.StoragesContarcts;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SladkieBulkiBusinessLogic.Implementations;
|
||||
|
||||
internal class IngredientBusinessLogicContract (IIngredientStorageContract ingredientStorageContract, ILogger logger) : IIngredientBusinessLogicContract
|
||||
{
|
||||
private readonly ILogger _logger = logger;
|
||||
private readonly IIngredientStorageContract _ingredientStorageContract = ingredientStorageContract;
|
||||
|
||||
public List<IngredientDataModel> GetAllIngredients()
|
||||
{
|
||||
_logger.LogInformation("GetAllBuyers");
|
||||
return _ingredientStorageContract.GetList() ?? throw new NullListException();
|
||||
}
|
||||
|
||||
public List<IngredientDataModel> GetIngredientsBySizeUnit(string sizeUnit)
|
||||
{
|
||||
_logger.LogInformation("GetIngredientsBySizeUnit: {sizeUnit}", sizeUnit);
|
||||
if (string.IsNullOrWhiteSpace(sizeUnit))
|
||||
{
|
||||
throw new ArgumentNullException(nameof(sizeUnit));
|
||||
}
|
||||
|
||||
var list = _ingredientStorageContract.GetElementBySizeUnit(sizeUnit);
|
||||
if (list == null)
|
||||
{
|
||||
throw new NullListException();
|
||||
}
|
||||
|
||||
return list.Where(x => x.SizeInit == sizeUnit).ToList();
|
||||
}
|
||||
|
||||
public IngredientDataModel? GetIngredientById(string id)
|
||||
{
|
||||
_logger.LogInformation("GetIngredientById: {id}", id);
|
||||
|
||||
if (id.IsEmpty())
|
||||
{
|
||||
throw new ArgumentNullException(nameof(id));
|
||||
}
|
||||
|
||||
if (!id.IsGuid())
|
||||
{
|
||||
throw new ValidationException("Id is not a unique identifier");
|
||||
}
|
||||
|
||||
return _ingredientStorageContract.GetElementById(id) ?? throw new ElementNotFoundException(id);
|
||||
}
|
||||
|
||||
public IngredientDataModel? GetIngredientByName(string name)
|
||||
{
|
||||
_logger.LogInformation("GetIngredientByName: {name}", name);
|
||||
|
||||
if (string.IsNullOrWhiteSpace(name))
|
||||
{
|
||||
throw new ArgumentNullException(nameof(name));
|
||||
}
|
||||
|
||||
return _ingredientStorageContract.GetElementByName(name) ?? throw new ElementNotFoundException(name);
|
||||
}
|
||||
|
||||
public void InsertIngredient(IngredientDataModel ingredientDataModel)
|
||||
{
|
||||
_logger.LogInformation("New ingredient: {json}", JsonSerializer.Serialize(ingredientDataModel));
|
||||
|
||||
ArgumentNullException.ThrowIfNull(ingredientDataModel);
|
||||
ingredientDataModel.Validate();
|
||||
|
||||
_ingredientStorageContract.AddElement(ingredientDataModel);
|
||||
}
|
||||
|
||||
public void UpdateIngredient(IngredientDataModel ingredientDataModel)
|
||||
{
|
||||
_logger.LogInformation("Update ingredient: {json}", JsonSerializer.Serialize(ingredientDataModel));
|
||||
|
||||
ArgumentNullException.ThrowIfNull(ingredientDataModel);
|
||||
ingredientDataModel.Validate();
|
||||
|
||||
_ingredientStorageContract.UpdElement(ingredientDataModel);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using SladkieBulkiContrakts.BusinessLogicsContracts;
|
||||
using SladkieBulkiContrakts.DataModels;
|
||||
using SladkieBulkiContrakts.Exceptions;
|
||||
using SladkieBulkiContrakts.Extensions;
|
||||
using SladkieBulkiContrakts.StoragesContarcts;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace SladkieBulkiBusinessLogic.Implementations;
|
||||
|
||||
internal class PostBusinessLogicContract(IPostStorageContract postStorageContract, ILogger logger) : IPostBusinessLogicContract
|
||||
{
|
||||
private readonly ILogger _logger = logger;
|
||||
private readonly IPostStorageContract _postStorageContract = postStorageContract;
|
||||
|
||||
public List<PostDataModel> GetAllPosts()
|
||||
{
|
||||
_logger.LogInformation("GetAllPosts");
|
||||
return _postStorageContract.GetList() ?? throw new NullListException();
|
||||
}
|
||||
|
||||
public List<PostDataModel> GetAllDataOfPost(string postId)
|
||||
{
|
||||
_logger.LogInformation("GetAllDataOfPost for {postId}", postId);
|
||||
if (postId.IsEmpty())
|
||||
{
|
||||
throw new ArgumentNullException(nameof(postId));
|
||||
}
|
||||
if (!postId.IsGuid())
|
||||
{
|
||||
throw new ValidationException("The value in the field postId is not a unique identifier.");
|
||||
}
|
||||
return _postStorageContract.GetPostWithHistory(postId) ?? throw new NullListException();
|
||||
}
|
||||
|
||||
public PostDataModel GetPostByData(string data)
|
||||
{
|
||||
_logger.LogInformation("Get element by data: {data}", data);
|
||||
if (data.IsEmpty())
|
||||
{
|
||||
throw new ArgumentNullException(nameof(data));
|
||||
}
|
||||
if (data.IsGuid())
|
||||
{
|
||||
return _postStorageContract.GetElementById(data) ?? throw new ElementNotFoundException(data);
|
||||
}
|
||||
return _postStorageContract.GetElementByName(data) ?? throw new ElementNotFoundException(data);
|
||||
}
|
||||
|
||||
public void InsertPost(PostDataModel postDataModel)
|
||||
{
|
||||
_logger.LogInformation("New data: {json}", JsonSerializer.Serialize(postDataModel));
|
||||
ArgumentNullException.ThrowIfNull(postDataModel);
|
||||
postDataModel.Validate();
|
||||
_postStorageContract.AddElement(postDataModel);
|
||||
}
|
||||
|
||||
public void UpdatePost(PostDataModel postDataModel)
|
||||
{
|
||||
_logger.LogInformation("Update data: {json}", JsonSerializer.Serialize(postDataModel));
|
||||
ArgumentNullException.ThrowIfNull(postDataModel);
|
||||
postDataModel.Validate();
|
||||
_postStorageContract.UpdElement(postDataModel);
|
||||
}
|
||||
|
||||
public void DeletePost(string id)
|
||||
{
|
||||
_logger.LogInformation("Delete by id: {id}", id);
|
||||
if (id.IsEmpty())
|
||||
{
|
||||
throw new ArgumentNullException(nameof(id));
|
||||
}
|
||||
if (!id.IsGuid())
|
||||
{
|
||||
throw new ValidationException("Id is not a unique identifier");
|
||||
}
|
||||
_postStorageContract.DelElement(id);
|
||||
}
|
||||
|
||||
public void RestorePost(string id)
|
||||
{
|
||||
_logger.LogInformation("Restore by id: {id}", id);
|
||||
if (id.IsEmpty())
|
||||
{
|
||||
throw new ArgumentNullException(nameof(id));
|
||||
}
|
||||
if (!id.IsGuid())
|
||||
{
|
||||
throw new ValidationException("Id is not a unique identifier");
|
||||
}
|
||||
_postStorageContract.ResElement(id);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using SladkieBulkiContrakts.BusinessLogicsContracts;
|
||||
using SladkieBulkiContrakts.DataModels;
|
||||
using SladkieBulkiContrakts.Exceptions;
|
||||
using SladkieBulkiContrakts.Extensions;
|
||||
using SladkieBulkiContrakts.StoragesContarcts;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace SladkieBulkiBusinessLogic.Implementations;
|
||||
|
||||
internal class ProductBusinessLogicContract(IProductStorageContract productStorageContract, ILogger logger) : IProductBusinessLogicContract
|
||||
{
|
||||
private readonly ILogger _logger = logger;
|
||||
private readonly IProductStorageContract _productStorageContract = productStorageContract;
|
||||
|
||||
|
||||
|
||||
public List<ProductDataModel> GetAllProducts(bool onlyActive)
|
||||
{
|
||||
_logger.LogInformation("GetAllProducts params: {onlyActive}", onlyActive);
|
||||
return _productStorageContract.GetList(onlyActive) ?? throw new NullListException();
|
||||
|
||||
//return [];
|
||||
}
|
||||
|
||||
public List<ProductHistoryDataModel> GetProductHistoryByProduct(string productId)
|
||||
{
|
||||
_logger.LogInformation("GetProductHistoryByProduct for {productId}", productId);
|
||||
if (productId.IsEmpty())
|
||||
{
|
||||
throw new ArgumentNullException(nameof(productId));
|
||||
}
|
||||
if (!productId.IsGuid())
|
||||
{
|
||||
throw new ValidationException("The value in the field productId is not a unique identifier.");
|
||||
}
|
||||
return _productStorageContract.GetHistoryByProductId(productId) ?? throw new NullListException();
|
||||
|
||||
//return [];
|
||||
}
|
||||
|
||||
public ProductDataModel GetProductByData(string data)
|
||||
{
|
||||
_logger.LogInformation("Get element by data: {data}", data);
|
||||
if (data.IsEmpty())
|
||||
{
|
||||
throw new ArgumentNullException(nameof(data));
|
||||
}
|
||||
if (data.IsGuid())
|
||||
{
|
||||
return _productStorageContract.GetElementById(data) ?? throw new ElementNotFoundException(data);
|
||||
}
|
||||
return _productStorageContract.GetElementByName(data) ?? throw new ElementNotFoundException(data);
|
||||
|
||||
//return new("", "", "", 0, [], 0, false);
|
||||
}
|
||||
|
||||
public void InsertProduct(ProductDataModel productDataModel)
|
||||
{
|
||||
_logger.LogInformation("New data: {json}", JsonSerializer.Serialize(productDataModel));
|
||||
ArgumentNullException.ThrowIfNull(productDataModel);
|
||||
productDataModel.Validate();
|
||||
_productStorageContract.AddElement(productDataModel);
|
||||
}
|
||||
|
||||
public void UpdateProduct(ProductDataModel productDataModel)
|
||||
{
|
||||
_logger.LogInformation("Update data: {json}", JsonSerializer.Serialize(productDataModel));
|
||||
ArgumentNullException.ThrowIfNull(productDataModel);
|
||||
productDataModel.Validate();
|
||||
_productStorageContract.UpdElement(productDataModel);
|
||||
}
|
||||
public void DeleteProduct(string id)
|
||||
{
|
||||
_logger.LogInformation("Delete by id: {id}", id);
|
||||
if (id.IsEmpty())
|
||||
{
|
||||
throw new ArgumentNullException(nameof(id));
|
||||
}
|
||||
if (!id.IsGuid())
|
||||
{
|
||||
throw new ValidationException("Id is not a unique identifier");
|
||||
}
|
||||
_productStorageContract.DelElement(id);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using SladkieBulkiContrakts.BusinessLogicsContracts;
|
||||
using SladkieBulkiContrakts.DataModels;
|
||||
using SladkieBulkiContrakts.Exceptions;
|
||||
using SladkieBulkiContrakts.Extensions;
|
||||
using SladkieBulkiContrakts.StoragesContarcts;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace SladkieBulkiBusinessLogic.Implementations;
|
||||
|
||||
internal class ProductionBusinessLogicContract(IProductionStorageContract productionStorageContract,ILogger logger) : IProductionBusinessLogicContract
|
||||
{
|
||||
private readonly ILogger _logger = logger;
|
||||
private readonly IProductionStorageContract _productionStorageContract = productionStorageContract;
|
||||
|
||||
|
||||
public List<ProductionDataModel> GetAllSalesByPeriod(DateTime fromDate, DateTime toDate)
|
||||
{
|
||||
_logger.LogInformation("GetAllProductionsByPeriod params: {fromDate}, {toDate}", fromDate, toDate);
|
||||
if (fromDate.IsDateNotOlder(toDate))
|
||||
{
|
||||
throw new IncorrectDatesException(fromDate, toDate);
|
||||
}
|
||||
return _productionStorageContract.GetList(fromDate, toDate) ?? throw new NullListException();
|
||||
}
|
||||
|
||||
public List<ProductionDataModel> GetAllSalesByProductByPeriod(string productId, DateTime fromDate, DateTime toDate)
|
||||
{
|
||||
_logger.LogInformation("GetAllProductionsByProduct params: {productId}, {fromDate}, {toDate}", productId, fromDate, toDate);
|
||||
if (fromDate.IsDateNotOlder(toDate))
|
||||
{
|
||||
throw new IncorrectDatesException(fromDate, toDate);
|
||||
}
|
||||
if (productId.IsEmpty())
|
||||
{
|
||||
throw new ArgumentNullException(nameof(productId));
|
||||
}
|
||||
if (!productId.IsGuid())
|
||||
{
|
||||
throw new ValidationException("The value in the field productId is not a unique identifier.");
|
||||
}
|
||||
return _productionStorageContract.GetList(fromDate, toDate, productId: productId) ?? throw new NullListException();
|
||||
}
|
||||
|
||||
public List<ProductionDataModel> GetAllSalesByWorkerByPeriod(string workerId, DateTime fromDate, DateTime toDate)
|
||||
{
|
||||
_logger.LogInformation("GetAllProductionsByWorker params: {workerId}, {fromDate}, {toDate}", workerId, fromDate, toDate);
|
||||
if (fromDate.IsDateNotOlder(toDate))
|
||||
{
|
||||
throw new IncorrectDatesException(fromDate, toDate);
|
||||
}
|
||||
if (workerId.IsEmpty())
|
||||
{
|
||||
throw new ArgumentNullException(nameof(workerId));
|
||||
}
|
||||
if (!workerId.IsGuid())
|
||||
{
|
||||
throw new ValidationException("The value in the field workerId is not a unique identifier.");
|
||||
}
|
||||
return _productionStorageContract.GetList(fromDate, toDate, workerId: workerId) ?? throw new NullListException();
|
||||
}
|
||||
|
||||
public ProductionDataModel GetProductionByData(string data)
|
||||
{
|
||||
_logger.LogInformation("GetProductionByData: {data}", data);
|
||||
if (data.IsEmpty())
|
||||
{
|
||||
throw new ArgumentNullException(nameof(data));
|
||||
}
|
||||
if (!data.IsGuid())
|
||||
{
|
||||
throw new ValidationException("Id is not a unique identifier");
|
||||
}
|
||||
return _productionStorageContract.GetElementById(data) ?? throw new ElementNotFoundException(data);
|
||||
}
|
||||
|
||||
public void InsertProduction(ProductionDataModel productionDataModel)
|
||||
{
|
||||
_logger.LogInformation("InsertProduction: {json}", JsonSerializer.Serialize(productionDataModel));
|
||||
ArgumentNullException.ThrowIfNull(productionDataModel);
|
||||
productionDataModel.Validate();
|
||||
_productionStorageContract.AddElement(productionDataModel);
|
||||
}
|
||||
|
||||
public void CancelProduction(string id)
|
||||
{
|
||||
_logger.LogInformation("CancelProduction by id: {id}", id);
|
||||
if (id.IsEmpty())
|
||||
{
|
||||
throw new ArgumentNullException(nameof(id));
|
||||
}
|
||||
if (!id.IsGuid())
|
||||
{
|
||||
throw new ValidationException("Id is not a unique identifier");
|
||||
}
|
||||
_productionStorageContract.DelElement(id);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,252 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using SladkieBulkiBusinessLogic.OfficePackage;
|
||||
using SladkieBulkiContrakts.BusinessLogicsContracts;
|
||||
using SladkieBulkiContrakts.DataModels;
|
||||
using SladkieBulkiContrakts.Extensions;
|
||||
using SladkieBulkiContrakts.StoragesContarcts;
|
||||
using SladkieBulkiContrakts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SladkieBulkiBusinessLogic.Implementations;
|
||||
|
||||
internal class ReportContract(IProductStorageContract productStorageContract, IIngredientStorageContract ingredientStorageContract, IProductionStorageContract productionStorageContract, ISalaryStorageContract salaryStorageContract,IWorkerStorageContract workerStorageContract, BaseWordBuilder baseWordBuilder, BaseExcelBuilder baseExcelBuilder, BasePdfBuilder basePdfBuilder, ILogger logger) : IReportContract
|
||||
{
|
||||
private readonly IProductStorageContract _productStorageContract = productStorageContract;
|
||||
private readonly IIngredientStorageContract _ingredientStorageContract = ingredientStorageContract;
|
||||
private readonly IProductionStorageContract _productionStorageContract = productionStorageContract;
|
||||
private readonly ISalaryStorageContract _salaryStorageContract = salaryStorageContract;
|
||||
private readonly IWorkerStorageContract _workerStorageContract = workerStorageContract;
|
||||
|
||||
private readonly BaseWordBuilder _baseWordBuilder = baseWordBuilder;
|
||||
private readonly BaseExcelBuilder _baseExcelBuilder = baseExcelBuilder;
|
||||
private readonly BasePdfBuilder _basePdfBuilder = basePdfBuilder;
|
||||
private readonly ILogger _logger = logger;
|
||||
internal static readonly string[] productDocumentHeader = [
|
||||
"Продукт", "Описание", "Тип", "Цена", "Ингредиент", "Ед. изм.", "Цена за ед.", "Кол-во"
|
||||
];
|
||||
|
||||
|
||||
public async Task<Stream> CreateDocumentSalaryByPeriodAsync(DateTime dateStart, DateTime dateFinish, CancellationToken ct)
|
||||
{
|
||||
_logger.LogInformation("Create report SalaryByPeriod from {dateStart} to {dateFinish}", dateStart, dateFinish);
|
||||
var data = await GetDataBySalaryAsync(dateStart, dateFinish, ct) ?? throw new InvalidOperationException("No found data");
|
||||
return _basePdfBuilder
|
||||
.AddHeader("Зарплатная ведомость")
|
||||
.AddParagraph($"за период с {dateStart.ToShortDateString()} по {dateFinish.ToShortDateString()}")
|
||||
.AddPieChart("Начисления", [.. data.Select(x => (x.WorkerFIO, x.TotalSalary))])
|
||||
.Build();
|
||||
}
|
||||
|
||||
public async Task<Stream> CreateDocumentProductsWithIngredientsAsync(CancellationToken ct)
|
||||
{
|
||||
_logger.LogInformation("Create report ProductsWithIngredients");
|
||||
var data = await GetDataByProductsAsync(ct);
|
||||
|
||||
// Генерируем строки таблицы
|
||||
var tableRows = new List<string[]>();
|
||||
|
||||
// Добавляем заголовок
|
||||
tableRows.Add(productDocumentHeader);
|
||||
|
||||
foreach (var product in data)
|
||||
{
|
||||
// Если нет ингредиентов — пустые колонки для ингредиентов
|
||||
if (product.Ingredients == null || product.Ingredients.Count == 0)
|
||||
{
|
||||
tableRows.Add(new[]
|
||||
{
|
||||
product.Name,
|
||||
product.Description,
|
||||
product.ProductType,
|
||||
product.UnitPrice.ToString("F2"),
|
||||
"-", "-", "-", "-"
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
// Первая строка — продукт + первый ингредиент
|
||||
var first = product.Ingredients[0];
|
||||
tableRows.Add(new[]
|
||||
{
|
||||
product.Name,
|
||||
product.Description,
|
||||
product.ProductType,
|
||||
product.UnitPrice.ToString("F2", CultureInfo.InvariantCulture),
|
||||
first.NameIngredients,
|
||||
first.SizeUnit,
|
||||
first.InitPrice.ToString("F2", CultureInfo.InvariantCulture),
|
||||
first.Count.ToString()
|
||||
});
|
||||
// Остальные строки — только ингредиенты, без продукта
|
||||
for (int i = 1; i < product.Ingredients.Count; i++)
|
||||
{
|
||||
var ing = product.Ingredients[i];
|
||||
tableRows.Add(new[]
|
||||
{
|
||||
"", "", "", "",
|
||||
ing.NameIngredients,
|
||||
ing.SizeUnit,
|
||||
ing.InitPrice.ToString("F2"),
|
||||
ing.Count.ToString()
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Пример ширин столбцов — можно подогнать под свой Word шаблон
|
||||
int[] widths = { 3000, 4000, 2000, 2000, 2000, 2000, 2000, 1500 };
|
||||
|
||||
return _baseWordBuilder
|
||||
.AddHeader("Продукты и ингредиенты")
|
||||
.AddParagraph($"Сформировано на дату {DateTime.Now:dd.MM.yyyy HH:mm}")
|
||||
.AddTable(widths, tableRows)
|
||||
.Build();
|
||||
}
|
||||
|
||||
public async Task<Stream> CreateDocumentProductionsByPeriodAsync(DateTime dateStart, DateTime dateFinish, CancellationToken ct)
|
||||
{
|
||||
_logger.LogInformation("Create report ProductionsByPeriod from {dateStart} to {dateFinish}", dateStart, dateFinish);
|
||||
|
||||
// Получаем данные о производстве (ProductionDataModel)
|
||||
var data = await GetDataByProductionsAsync(dateStart, dateFinish, ct);
|
||||
|
||||
// Для получения названий продуктов и работников — собираем все нужные Id и получаем имена
|
||||
var productIds = data.Select(x => x.ProductId).Distinct().ToList();
|
||||
var workerIds = data.Select(x => x.WorkerId).Distinct().ToList();
|
||||
|
||||
var products = new List<ProductDataModel>();
|
||||
foreach (var productId in productIds)
|
||||
{
|
||||
var product = _productStorageContract.GetElementById(productId);
|
||||
if (product != null) products.Add(product);
|
||||
}
|
||||
|
||||
var workers = new List<WorkerDataModel>();
|
||||
foreach (var workerId in workerIds)
|
||||
{
|
||||
var worker = _workerStorageContract.GetElementById(workerId);
|
||||
if (worker != null) workers.Add(worker);
|
||||
}
|
||||
|
||||
// Генерируем строки для таблицы
|
||||
var tableRows = new List<string[]>();
|
||||
// Заголовок
|
||||
tableRows.Add(new[] { "Дата", "Продукт", "Количество", "Сумма", "Работник" });
|
||||
|
||||
foreach (var prod in data)
|
||||
{
|
||||
var product = products.FirstOrDefault(p => p.Id == prod.ProductId);
|
||||
var worker = workers.FirstOrDefault(w => w.Id == prod.WorkerId);
|
||||
tableRows.Add(new[]
|
||||
{
|
||||
prod.ProductionDate.ToString("dd.MM.yyyy"),
|
||||
product?.Name ?? "",
|
||||
prod.Count.ToString(),
|
||||
prod.Sum.ToString("F2", CultureInfo.InvariantCulture),
|
||||
worker?.FIO ?? ""
|
||||
});
|
||||
}
|
||||
|
||||
// Подсчёт итогов
|
||||
var totalCount = data.Sum(x => x.Count);
|
||||
var totalSum = data.Sum(x => x.Sum);
|
||||
|
||||
// Итоговая строка
|
||||
tableRows.Add(new[]
|
||||
{
|
||||
"", // Пусто в "Дата"
|
||||
"ИТОГО:",
|
||||
totalCount.ToString(),
|
||||
totalSum.ToString("F2", CultureInfo.InvariantCulture),
|
||||
"" // Пусто для колонки "Работник"
|
||||
});
|
||||
|
||||
// Пример ширины столбцов, можно подогнать
|
||||
int[] widths = { 15, 25, 10, 12, 20 };
|
||||
|
||||
return _baseExcelBuilder
|
||||
.AddHeader("Производство за период", 0, 5)
|
||||
.AddParagraph($"c {dateStart:dd.MM.yyyy} по {dateFinish:dd.MM.yyyy}", 1)
|
||||
.AddTable(widths, tableRows)
|
||||
.Build();
|
||||
}
|
||||
|
||||
|
||||
|
||||
public Task<List<WorkerSalaryByPeriodDataModel>> GetDataSalaryByPeriodAsync(DateTime dateStart, DateTime dateFinish, CancellationToken ct)
|
||||
{
|
||||
_logger.LogInformation("Get data SalaryByPeriod from {dateStart} to {dateFinish}", dateStart, dateFinish);
|
||||
return GetDataBySalaryAsync(dateStart, dateFinish, ct);
|
||||
}
|
||||
|
||||
public Task<List<ProductWithIngredientsReportDataModel>> GetProductsWithIngredientsAsync(CancellationToken ct)
|
||||
{
|
||||
_logger.LogInformation("Get data ProductsWithIngredients");
|
||||
return GetDataByProductsAsync(ct);
|
||||
}
|
||||
|
||||
|
||||
public Task<List<ProductionDataModel>> GetDataProductionsByPeriodAsync(DateTime dateStart, DateTime dateFinish, CancellationToken ct)
|
||||
{
|
||||
_logger.LogInformation("Get data SalesByPeriod from {dateStart} to {dateFinish}", dateStart, dateFinish);
|
||||
return GetDataByProductionsAsync(dateStart, dateFinish, ct);
|
||||
}
|
||||
|
||||
private async Task<List<ProductWithIngredientsReportDataModel>> GetDataByProductsAsync(CancellationToken ct)
|
||||
{
|
||||
// Получаем все продукты
|
||||
var products = await _productStorageContract.GetListAsync(ct);
|
||||
|
||||
// Получаем все ингредиенты одним запросом для сопоставления по id (оптимально!)
|
||||
var allIngredients = await _ingredientStorageContract.GetListAsync(ct);
|
||||
|
||||
var result = products.Select(p => new ProductWithIngredientsReportDataModel
|
||||
{
|
||||
ProductId = p.Id,
|
||||
Name = p.Name,
|
||||
Description = p.Description,
|
||||
ProductType = p.ProductType.ToString(),
|
||||
UnitPrice = p.UnitPrice,
|
||||
Ingredients = (p.Ingredients ?? Enumerable.Empty<ProductIngredientDataModel>())
|
||||
.Select(pi =>
|
||||
{
|
||||
var ingredient = allIngredients.FirstOrDefault(x => x.Id == pi.IngredientId);
|
||||
return ingredient == null ? null : new IngredientInProductDto
|
||||
{
|
||||
NameIngredients = ingredient.NameIngredients,
|
||||
SizeUnit = ingredient.SizeInit,
|
||||
InitPrice = ingredient.InitPrice,
|
||||
Count = pi.Count
|
||||
};
|
||||
})
|
||||
.Where(x => x != null)
|
||||
.ToList()!
|
||||
}).ToList();
|
||||
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private async Task<List<ProductionDataModel>> GetDataByProductionsAsync(DateTime dateStart, DateTime dateFinish, CancellationToken ct)
|
||||
{
|
||||
if (dateStart >= dateFinish)
|
||||
throw new IncorrectDatesException(dateStart, dateFinish);
|
||||
|
||||
var productions = await _productionStorageContract.GetListAsync(dateStart, dateFinish, ct);
|
||||
return productions.OrderBy(x => x.ProductionDate).ToList();
|
||||
}
|
||||
|
||||
private async Task<List<WorkerSalaryByPeriodDataModel>> GetDataBySalaryAsync(DateTime dateStart, DateTime dateFinish, CancellationToken ct)
|
||||
{
|
||||
if (dateStart.IsDateNotOlder(dateFinish))
|
||||
{
|
||||
throw new IncorrectDatesException(dateStart, dateFinish);
|
||||
}
|
||||
return [.. (await _salaryStorageContract.GetListAsync(dateStart, dateFinish, ct)).GroupBy(x => x.WorkerFIO).Select(x => new WorkerSalaryByPeriodDataModel { WorkerFIO = x.Key, TotalSalary = x.Sum(y => y.WorkerSalary), FromPeriod = x.Min(y => y.SalaryDate), ToPeriod = x.Max(y => y.SalaryDate) }).OrderBy(x => x.WorkerFIO)];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,127 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using SladkieBulkiContrakts.BusinessLogicsContracts;
|
||||
using SladkieBulkiContrakts.DataModels;
|
||||
using SladkieBulkiContrakts.Exceptions;
|
||||
using SladkieBulkiContrakts.Extensions;
|
||||
using SladkieBulkiContrakts.Infrastructure;
|
||||
using SladkieBulkiContrakts.Infrastructure.PostConfigurations;
|
||||
using SladkieBulkiContrakts.StoragesContarcts;
|
||||
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace SladkieBulkiBusinessLogic.Implementations;
|
||||
|
||||
internal class SalaryBusinessLogicContract(ISalaryStorageContract salaryStorageContract, IProductionStorageContract productionStorageContract, IPostStorageContract postStorageContract, IWorkerStorageContract workerStorageContract, ILogger logger, IConfigurationSalary сonfiguration) : ISalaryBusinessLogicContract
|
||||
{
|
||||
private readonly ILogger _logger = logger;
|
||||
private readonly ISalaryStorageContract _salaryStorageContract =
|
||||
salaryStorageContract;
|
||||
private readonly IProductionStorageContract _productionStorageContract = productionStorageContract;
|
||||
private readonly IPostStorageContract _postStorageContract =
|
||||
postStorageContract;
|
||||
private readonly IWorkerStorageContract _workerStorageContract =
|
||||
workerStorageContract;
|
||||
private readonly IConfigurationSalary _salaryConfiguration = сonfiguration;
|
||||
private readonly object _lockObject = new();
|
||||
|
||||
|
||||
public List<SalaryDataModel> GetAllSalariesByPeriod(DateTime fromDate, DateTime toDate)
|
||||
{
|
||||
_logger.LogInformation("GetAllSalaries params: {fromDate}, {toDate}", fromDate, toDate);
|
||||
if (fromDate.IsDateNotOlder(toDate))
|
||||
{
|
||||
throw new IncorrectDatesException(fromDate, toDate);
|
||||
}
|
||||
return _salaryStorageContract.GetList(fromDate, toDate) ?? throw new NullListException();
|
||||
}
|
||||
|
||||
public List<SalaryDataModel> GetAllSalariesByPeriodByWorker(DateTime fromDate, DateTime toDate, string workerId)
|
||||
{
|
||||
if (fromDate.IsDateNotOlder(toDate))
|
||||
{
|
||||
throw new IncorrectDatesException(fromDate, toDate);
|
||||
}
|
||||
if (workerId.IsEmpty())
|
||||
{
|
||||
throw new ArgumentNullException(nameof(workerId));
|
||||
}
|
||||
if (!workerId.IsGuid())
|
||||
{
|
||||
throw new ValidationException("The value in the field workerId is not a unique identifier.");
|
||||
}
|
||||
_logger.LogInformation("GetAllSalaries params: {fromDate}, {toDate}, {workerId}", fromDate, toDate, workerId);
|
||||
return _salaryStorageContract.GetList(fromDate, toDate, workerId) ?? throw new NullListException();
|
||||
}
|
||||
|
||||
public void CalculateSalaryByMounth(DateTime date)
|
||||
{
|
||||
_logger.LogInformation("CalculateSalaryByMounth: {date}", date);
|
||||
var startDate = new DateTime(date.Year, date.Month, 1);
|
||||
var finishDate = new DateTime(date.Year, date.Month, DateTime.DaysInMonth(date.Year, date.Month));
|
||||
var workers = _workerStorageContract.GetList() ?? throw new NullListException();
|
||||
foreach (var worker in workers)
|
||||
{
|
||||
var sales = _productionStorageContract.GetList(startDate, finishDate, workerId: worker.Id) ?? throw new NullListException();
|
||||
var post = _postStorageContract.GetElementById(worker.PostId) ?? throw new NullListException();
|
||||
var salary = post.ConfigurationModel switch
|
||||
{
|
||||
null => 0,
|
||||
ManufacturerPostConfiguration cpc => CalculateSalaryForCashier(sales, startDate, finishDate, cpc),
|
||||
PackerPostConfiguration spc => CalculateSalaryForSupervisor(startDate, finishDate, spc),
|
||||
PostConfiguration pc => pc.Rate,
|
||||
};
|
||||
_logger.LogDebug("The employee {workerId} was paid a salary of {salary}", worker.Id, salary);
|
||||
_salaryStorageContract.AddElement(new SalaryDataModel(worker.Id, finishDate, salary));
|
||||
}
|
||||
}
|
||||
|
||||
private double CalculateSalaryForCashier(List<ProductionDataModel> sales, DateTime startDate, DateTime finishDate, ManufacturerPostConfiguration config)
|
||||
{
|
||||
var tasks = new List<Task>();
|
||||
var calcPercent = 0.0;
|
||||
for (var date = startDate; date < finishDate; date = date.AddDays(1))
|
||||
{
|
||||
tasks.Add(Task.Factory.StartNew((object? obj) =>
|
||||
{
|
||||
var dateInTask = (DateTime)obj!;
|
||||
var salesInDay = sales.Where(x => x.ProductionDate >= dateInTask && x.ProductionDate < dateInTask.AddDays(1)).ToArray();
|
||||
if (salesInDay.Length > 0)
|
||||
{
|
||||
lock (_lockObject)
|
||||
{
|
||||
calcPercent += (salesInDay.Sum(x => x.Sum) / salesInDay.Length) * config.SalePercent;
|
||||
}
|
||||
}
|
||||
}, date));
|
||||
}
|
||||
var calcBonusTask = Task.Run(() =>
|
||||
{
|
||||
return sales.Where(x => x.Sum > _salaryConfiguration.ExtraSaleSum).Sum(x => x.Sum) * config.BonusForExtraSales;
|
||||
});
|
||||
try
|
||||
{
|
||||
Task.WaitAll([Task.WhenAll(tasks), calcBonusTask]);
|
||||
}
|
||||
catch (AggregateException agEx)
|
||||
{
|
||||
foreach (var ex in agEx.InnerExceptions)
|
||||
{
|
||||
_logger.LogError(ex, "Error in the cashier payroll process");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
return config.Rate + calcPercent + calcBonusTask.Result;
|
||||
}
|
||||
private double CalculateSalaryForSupervisor(DateTime startDate, DateTime finishDate, PackerPostConfiguration config)
|
||||
{
|
||||
try
|
||||
{
|
||||
return config.Rate + config.PersonalCountPack * _workerStorageContract.GetWorkerTrend(startDate, finishDate);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error in the supervisor payroll process");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using SladkieBulkiContrakts.BusinessLogicsContracts;
|
||||
using SladkieBulkiContrakts.DataModels;
|
||||
using SladkieBulkiContrakts.Exceptions;
|
||||
using SladkieBulkiContrakts.Extensions;
|
||||
using SladkieBulkiContrakts.StoragesContarcts;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace SladkieBulkiBusinessLogic.Implementations;
|
||||
|
||||
internal class WorkerBusinessLogicContract(IWorkerStorageContract workerStorageContract, ILogger logger) : IWorkerBusinessLogicContract
|
||||
{
|
||||
private readonly ILogger _logger = logger;
|
||||
private readonly IWorkerStorageContract _workerStorageContract = workerStorageContract;
|
||||
|
||||
public List<WorkerDataModel> GetAllWorkers(bool onlyActive = true)
|
||||
{
|
||||
_logger.LogInformation("GetAllWorkers params: {onlyActive}", onlyActive);
|
||||
return _workerStorageContract.GetList(onlyActive) ?? throw new NullListException();
|
||||
}
|
||||
|
||||
public List<WorkerDataModel> GetAllWorkersByPost(string postId, bool onlyActive = true)
|
||||
{
|
||||
_logger.LogInformation("GetAllWorkers params: {postId}, {onlyActive},", postId, onlyActive);
|
||||
if (postId.IsEmpty())
|
||||
{
|
||||
throw new ArgumentNullException(nameof(postId));
|
||||
}
|
||||
if (!postId.IsGuid())
|
||||
{
|
||||
throw new ValidationException("The value in the field postId is not a unique identifier.");
|
||||
}
|
||||
return _workerStorageContract.GetList(onlyActive, postId) ?? throw new NullListException();
|
||||
}
|
||||
|
||||
public List<WorkerDataModel> GetAllWorkersByBirthDate(DateTime fromDate, DateTime toDate, bool onlyActive = true)
|
||||
{
|
||||
_logger.LogInformation("GetAllWorkers params: {onlyActive}, {fromDate}, {toDate}", onlyActive, fromDate, toDate);
|
||||
if (fromDate.IsDateNotOlder(toDate))
|
||||
{
|
||||
throw new IncorrectDatesException(fromDate, toDate);
|
||||
}
|
||||
return _workerStorageContract.GetList(onlyActive, fromBirthDate: fromDate, toBirthDate: toDate) ?? throw new NullListException();
|
||||
}
|
||||
|
||||
public List<WorkerDataModel> GetAllWorkersByEmploymentDate(DateTime fromDate, DateTime toDate, bool onlyActive = true)
|
||||
{
|
||||
_logger.LogInformation("GetAllWorkers params: {onlyActive}, {fromDate}, {toDate}", onlyActive, fromDate, toDate);
|
||||
if (fromDate.IsDateNotOlder(toDate))
|
||||
{
|
||||
throw new IncorrectDatesException(fromDate, toDate);
|
||||
}
|
||||
return _workerStorageContract.GetList(onlyActive, fromEmploymentDate: fromDate, toEmploymentDate: toDate) ?? throw new NullListException();
|
||||
}
|
||||
|
||||
public WorkerDataModel GetWorkerByData(string data)
|
||||
{
|
||||
_logger.LogInformation("Get element by data: {data}", data);
|
||||
if (data.IsEmpty())
|
||||
{
|
||||
throw new ArgumentNullException(nameof(data));
|
||||
}
|
||||
if (data.IsGuid())
|
||||
{
|
||||
return _workerStorageContract.GetElementById(data) ?? throw new ElementNotFoundException(data);
|
||||
}
|
||||
return _workerStorageContract.GetElementByFIO(data) ?? throw new ElementNotFoundException(data);
|
||||
}
|
||||
|
||||
public void InsertWorker(WorkerDataModel workerDataModel)
|
||||
{
|
||||
_logger.LogInformation("New data: {json}", JsonSerializer.Serialize(workerDataModel));
|
||||
ArgumentNullException.ThrowIfNull(workerDataModel);
|
||||
workerDataModel.Validate();
|
||||
_workerStorageContract.AddElement(workerDataModel);
|
||||
}
|
||||
|
||||
public void UpdateWorker(WorkerDataModel workerDataModel)
|
||||
{
|
||||
_logger.LogInformation("Update data: {json}", JsonSerializer.Serialize(workerDataModel));
|
||||
ArgumentNullException.ThrowIfNull(workerDataModel);
|
||||
workerDataModel.Validate();
|
||||
_workerStorageContract.UpdElement(workerDataModel);
|
||||
}
|
||||
|
||||
public void DeleteWorker(string id)
|
||||
{
|
||||
_logger.LogInformation("Delete by id: {id}", id);
|
||||
if (id.IsEmpty())
|
||||
{
|
||||
throw new ArgumentNullException(nameof(id));
|
||||
}
|
||||
if (!id.IsGuid())
|
||||
{
|
||||
throw new ValidationException("Id is not a unique identifier");
|
||||
}
|
||||
_workerStorageContract.DelElement(id);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SladkieBulkiBusinessLogic.OfficePackage;
|
||||
|
||||
public abstract class BaseExcelBuilder
|
||||
{
|
||||
public abstract BaseExcelBuilder AddHeader(string header, int startIndex, int count);
|
||||
|
||||
public abstract BaseExcelBuilder AddParagraph(string text, int columnIndex);
|
||||
|
||||
public abstract BaseExcelBuilder AddTable(int[] columnsWidths, List<string[]> data);
|
||||
|
||||
public abstract Stream Build();
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SladkieBulkiBusinessLogic.OfficePackage;
|
||||
|
||||
public abstract class BasePdfBuilder
|
||||
{
|
||||
public abstract BasePdfBuilder AddHeader(string header);
|
||||
|
||||
public abstract BasePdfBuilder AddParagraph(string text);
|
||||
|
||||
public abstract BasePdfBuilder AddPieChart(string title, List<(string Caption, double Value)> data);
|
||||
|
||||
public abstract Stream Build();
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SladkieBulkiBusinessLogic.OfficePackage;
|
||||
|
||||
public abstract class BaseWordBuilder
|
||||
{
|
||||
public abstract BaseWordBuilder AddHeader(string header);
|
||||
|
||||
public abstract BaseWordBuilder AddParagraph(string text);
|
||||
|
||||
public abstract BaseWordBuilder AddTable(int[] widths, List<string[]> data);
|
||||
|
||||
public abstract Stream Build();
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
using MigraDoc.DocumentObjectModel;
|
||||
using MigraDoc.DocumentObjectModel.Shapes.Charts;
|
||||
using MigraDoc.Rendering;
|
||||
using System.Text;
|
||||
|
||||
namespace SladkieBulkiBusinessLogic.OfficePackage;
|
||||
|
||||
internal class MigraDocPdfBuilder : BasePdfBuilder
|
||||
{
|
||||
private readonly Document _document;
|
||||
|
||||
public MigraDocPdfBuilder()
|
||||
{
|
||||
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
|
||||
_document = new Document();
|
||||
DefineStyles();
|
||||
}
|
||||
|
||||
public override BasePdfBuilder AddHeader(string header)
|
||||
{
|
||||
_document.AddSection().AddParagraph(header, "NormalBold");
|
||||
return this;
|
||||
}
|
||||
|
||||
public override BasePdfBuilder AddParagraph(string text)
|
||||
{
|
||||
_document.LastSection.AddParagraph(text, "Normal");
|
||||
return this;
|
||||
}
|
||||
|
||||
public override BasePdfBuilder AddPieChart(string title, List<(string Caption, double Value)> data)
|
||||
{
|
||||
if (data == null || data.Count == 0)
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
var chart = new Chart(ChartType.Pie2D);
|
||||
var series = chart.SeriesCollection.AddSeries();
|
||||
series.Add(data.Select(x => x.Value).ToArray());
|
||||
|
||||
var xseries = chart.XValues.AddXSeries();
|
||||
xseries.Add(data.Select(x => x.Caption).ToArray());
|
||||
|
||||
chart.DataLabel.Type = DataLabelType.Percent;
|
||||
chart.DataLabel.Position = DataLabelPosition.OutsideEnd;
|
||||
|
||||
chart.Width = Unit.FromCentimeter(16);
|
||||
chart.Height = Unit.FromCentimeter(12);
|
||||
|
||||
chart.TopArea.AddParagraph(title);
|
||||
|
||||
chart.XAxis.MajorTickMark = TickMarkType.Outside;
|
||||
|
||||
chart.YAxis.MajorTickMark = TickMarkType.Outside;
|
||||
chart.YAxis.HasMajorGridlines = true;
|
||||
|
||||
chart.PlotArea.LineFormat.Width = 1;
|
||||
chart.PlotArea.LineFormat.Visible = true;
|
||||
|
||||
chart.TopArea.AddLegend();
|
||||
|
||||
_document.LastSection.Add(chart);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public override Stream Build()
|
||||
{
|
||||
var stream = new MemoryStream();
|
||||
var renderer = new PdfDocumentRenderer(true)
|
||||
{
|
||||
Document = _document
|
||||
};
|
||||
renderer.RenderDocument();
|
||||
renderer.PdfDocument.Save(stream);
|
||||
return stream;
|
||||
}
|
||||
|
||||
private void DefineStyles()
|
||||
{
|
||||
var style = _document.Styles.AddStyle("NormalBold", "Normal");
|
||||
style.Font.Bold = true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,308 @@
|
||||
using DocumentFormat.OpenXml.Packaging;
|
||||
using DocumentFormat.OpenXml.Spreadsheet;
|
||||
using DocumentFormat.OpenXml;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SladkieBulkiBusinessLogic.OfficePackage;
|
||||
|
||||
internal class OpenXmlExcelBuilder : BaseExcelBuilder
|
||||
{
|
||||
private readonly SheetData _sheetData;
|
||||
|
||||
private readonly MergeCells _mergeCells;
|
||||
|
||||
private readonly Columns _columns;
|
||||
|
||||
private uint _rowIndex = 0;
|
||||
|
||||
public OpenXmlExcelBuilder()
|
||||
{
|
||||
_sheetData = new SheetData();
|
||||
_mergeCells = new MergeCells();
|
||||
_columns = new Columns();
|
||||
_rowIndex = 1;
|
||||
}
|
||||
|
||||
public override BaseExcelBuilder AddHeader(string header, int startIndex, int count)
|
||||
{
|
||||
CreateCell(startIndex, _rowIndex, header, StyleIndex.BoldTextWithoutBorder);
|
||||
for (int i = startIndex + 1; i < startIndex + count; ++i)
|
||||
{
|
||||
CreateCell(i, _rowIndex, "", StyleIndex.SimpleTextWithoutBorder);
|
||||
}
|
||||
|
||||
_mergeCells.Append(new MergeCell()
|
||||
{
|
||||
Reference =
|
||||
new StringValue($"{GetExcelColumnName(startIndex)}{_rowIndex}:{GetExcelColumnName(startIndex + count - 1)}{_rowIndex}")
|
||||
});
|
||||
|
||||
_rowIndex++;
|
||||
return this;
|
||||
}
|
||||
|
||||
public override BaseExcelBuilder AddParagraph(string text, int columnIndex)
|
||||
{
|
||||
CreateCell(columnIndex, _rowIndex++, text, StyleIndex.SimpleTextWithoutBorder);
|
||||
return this;
|
||||
}
|
||||
|
||||
public override BaseExcelBuilder AddTable(int[] columnsWidths, List<string[]> data)
|
||||
{
|
||||
if (columnsWidths == null || columnsWidths.Length == 0)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(columnsWidths));
|
||||
}
|
||||
|
||||
if (data == null || data.Count == 0)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(data));
|
||||
}
|
||||
|
||||
if (data.Any(x => x.Length != columnsWidths.Length))
|
||||
{
|
||||
throw new InvalidOperationException("widths.Length != data.Length");
|
||||
}
|
||||
|
||||
uint counter = 1;
|
||||
int coef = 2;
|
||||
_columns.Append(columnsWidths.Select(x => new Column
|
||||
{
|
||||
Min = counter,
|
||||
Max = counter++,
|
||||
Width = x * coef,
|
||||
CustomWidth = true
|
||||
}));
|
||||
|
||||
for (var j = 0; j < data.First().Length; ++j)
|
||||
{
|
||||
CreateCell(j, _rowIndex, data.First()[j], StyleIndex.BoldTextWithBorder);
|
||||
}
|
||||
|
||||
_rowIndex++;
|
||||
for (var i = 1; i < data.Count - 1; ++i)
|
||||
{
|
||||
for (var j = 0; j < data[i].Length; ++j)
|
||||
{
|
||||
CreateCell(j, _rowIndex, data[i][j], StyleIndex.SimpleTextWithBorder);
|
||||
}
|
||||
|
||||
_rowIndex++;
|
||||
}
|
||||
|
||||
for (var j = 0; j < data.Last().Length; ++j)
|
||||
{
|
||||
CreateCell(j, _rowIndex, data.Last()[j], StyleIndex.BoldTextWithBorder);
|
||||
}
|
||||
|
||||
_rowIndex++;
|
||||
return this;
|
||||
}
|
||||
|
||||
public override Stream Build()
|
||||
{
|
||||
var stream = new MemoryStream();
|
||||
using var spreadsheetDocument = SpreadsheetDocument.Create(stream, SpreadsheetDocumentType.Workbook);
|
||||
var workbookpart = spreadsheetDocument.AddWorkbookPart();
|
||||
GenerateStyle(workbookpart);
|
||||
workbookpart.Workbook = new Workbook();
|
||||
var worksheetPart = workbookpart.AddNewPart<WorksheetPart>();
|
||||
worksheetPart.Worksheet = new Worksheet();
|
||||
if (_columns.HasChildren)
|
||||
{
|
||||
worksheetPart.Worksheet.Append(_columns);
|
||||
}
|
||||
|
||||
worksheetPart.Worksheet.Append(_sheetData);
|
||||
var sheets = spreadsheetDocument.WorkbookPart!.Workbook.AppendChild(new Sheets());
|
||||
var sheet = new Sheet()
|
||||
{
|
||||
Id = spreadsheetDocument.WorkbookPart.GetIdOfPart(worksheetPart),
|
||||
SheetId = 1,
|
||||
Name = "Лист 1"
|
||||
};
|
||||
|
||||
sheets.Append(sheet);
|
||||
if (_mergeCells.HasChildren)
|
||||
{
|
||||
worksheetPart.Worksheet.InsertAfter(_mergeCells, worksheetPart.Worksheet.Elements<SheetData>().First());
|
||||
}
|
||||
return stream;
|
||||
}
|
||||
|
||||
private static void GenerateStyle(WorkbookPart workbookPart)
|
||||
{
|
||||
var workbookStylesPart = workbookPart.AddNewPart<WorkbookStylesPart>();
|
||||
workbookStylesPart.Stylesheet = new Stylesheet();
|
||||
|
||||
var fonts = new Fonts() { Count = 2, KnownFonts = BooleanValue.FromBoolean(true) };
|
||||
fonts.Append(new DocumentFormat.OpenXml.Spreadsheet.Font
|
||||
{
|
||||
FontSize = new FontSize() { Val = 11 },
|
||||
FontName = new FontName() { Val = "Calibri" },
|
||||
FontFamilyNumbering = new FontFamilyNumbering() { Val = 2 },
|
||||
FontScheme = new FontScheme() { Val = new EnumValue<FontSchemeValues>(FontSchemeValues.Minor) }
|
||||
});
|
||||
fonts.Append(new DocumentFormat.OpenXml.Spreadsheet.Font
|
||||
{
|
||||
FontSize = new FontSize() { Val = 11 },
|
||||
FontName = new FontName() { Val = "Calibri" },
|
||||
FontFamilyNumbering = new FontFamilyNumbering() { Val = 2 },
|
||||
FontScheme = new FontScheme() { Val = new EnumValue<FontSchemeValues>(FontSchemeValues.Minor) },
|
||||
Bold = new Bold()
|
||||
});
|
||||
workbookStylesPart.Stylesheet.Append(fonts);
|
||||
|
||||
// Default Fill
|
||||
var fills = new Fills() { Count = 1 };
|
||||
fills.Append(new Fill
|
||||
{
|
||||
PatternFill = new PatternFill() { PatternType = new EnumValue<PatternValues>(PatternValues.None) }
|
||||
});
|
||||
workbookStylesPart.Stylesheet.Append(fills);
|
||||
|
||||
// Default Border
|
||||
var borders = new Borders() { Count = 2 };
|
||||
borders.Append(new Border
|
||||
{
|
||||
LeftBorder = new LeftBorder(),
|
||||
RightBorder = new RightBorder(),
|
||||
TopBorder = new TopBorder(),
|
||||
BottomBorder = new BottomBorder(),
|
||||
DiagonalBorder = new DiagonalBorder()
|
||||
});
|
||||
borders.Append(new Border
|
||||
{
|
||||
LeftBorder = new LeftBorder() { Style = BorderStyleValues.Thin },
|
||||
RightBorder = new RightBorder() { Style = BorderStyleValues.Thin },
|
||||
TopBorder = new TopBorder() { Style = BorderStyleValues.Thin },
|
||||
BottomBorder = new BottomBorder() { Style = BorderStyleValues.Thin }
|
||||
});
|
||||
workbookStylesPart.Stylesheet.Append(borders);
|
||||
|
||||
// Default cell format and a date cell format
|
||||
var cellFormats = new CellFormats() { Count = 4 };
|
||||
cellFormats.Append(new CellFormat
|
||||
{
|
||||
NumberFormatId = 0,
|
||||
FormatId = 0,
|
||||
FontId = 0,
|
||||
BorderId = 0,
|
||||
FillId = 0,
|
||||
Alignment = new Alignment()
|
||||
{
|
||||
Horizontal = HorizontalAlignmentValues.Left,
|
||||
Vertical = VerticalAlignmentValues.Center,
|
||||
WrapText = true
|
||||
}
|
||||
});
|
||||
cellFormats.Append(new CellFormat
|
||||
{
|
||||
NumberFormatId = 0,
|
||||
FormatId = 0,
|
||||
FontId = 0,
|
||||
BorderId = 1,
|
||||
FillId = 0,
|
||||
Alignment = new Alignment()
|
||||
{
|
||||
Horizontal = HorizontalAlignmentValues.Left,
|
||||
Vertical = VerticalAlignmentValues.Center,
|
||||
WrapText = true
|
||||
}
|
||||
});
|
||||
cellFormats.Append(new CellFormat
|
||||
{
|
||||
NumberFormatId = 0,
|
||||
FormatId = 0,
|
||||
FontId = 1,
|
||||
BorderId = 0,
|
||||
FillId = 0,
|
||||
Alignment = new Alignment()
|
||||
{
|
||||
Horizontal = HorizontalAlignmentValues.Center,
|
||||
Vertical = VerticalAlignmentValues.Center,
|
||||
WrapText = true
|
||||
}
|
||||
});
|
||||
cellFormats.Append(new CellFormat
|
||||
{
|
||||
NumberFormatId = 0,
|
||||
FormatId = 0,
|
||||
FontId = 1,
|
||||
BorderId = 1,
|
||||
FillId = 0,
|
||||
Alignment = new Alignment()
|
||||
{
|
||||
Horizontal = HorizontalAlignmentValues.Center,
|
||||
Vertical = VerticalAlignmentValues.Center,
|
||||
WrapText = true
|
||||
}
|
||||
});
|
||||
workbookStylesPart.Stylesheet.Append(cellFormats);
|
||||
}
|
||||
|
||||
private enum StyleIndex
|
||||
{
|
||||
SimpleTextWithoutBorder = 0,
|
||||
SimpleTextWithBorder = 1,
|
||||
BoldTextWithoutBorder = 2,
|
||||
BoldTextWithBorder = 3
|
||||
}
|
||||
|
||||
private void CreateCell(int columnIndex, uint rowIndex, string text, StyleIndex styleIndex)
|
||||
{
|
||||
var columnName = GetExcelColumnName(columnIndex);
|
||||
var cellReference = columnName + rowIndex;
|
||||
var row = _sheetData.Elements<Row>().FirstOrDefault(r => r.RowIndex! == rowIndex);
|
||||
if (row == null)
|
||||
{
|
||||
row = new Row() { RowIndex = rowIndex };
|
||||
_sheetData.Append(row);
|
||||
}
|
||||
|
||||
var newCell = row.Elements<Cell>()
|
||||
.FirstOrDefault(c => c.CellReference != null && c.CellReference.Value == columnName + rowIndex);
|
||||
if (newCell == null)
|
||||
{
|
||||
Cell? refCell = null;
|
||||
foreach (Cell cell in row.Elements<Cell>())
|
||||
{
|
||||
if (cell.CellReference?.Value != null && cell.CellReference.Value.Length == cellReference.Length)
|
||||
{
|
||||
if (string.Compare(cell.CellReference.Value, cellReference, true) > 0)
|
||||
{
|
||||
refCell = cell;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
newCell = new Cell() { CellReference = cellReference };
|
||||
row.InsertBefore(newCell, refCell);
|
||||
}
|
||||
|
||||
newCell.CellValue = new CellValue(text);
|
||||
newCell.DataType = CellValues.String;
|
||||
newCell.StyleIndex = (uint)styleIndex;
|
||||
}
|
||||
|
||||
private static string GetExcelColumnName(int columnNumber)
|
||||
{
|
||||
columnNumber += 1;
|
||||
int dividend = columnNumber;
|
||||
string columnName = string.Empty;
|
||||
int modulo;
|
||||
|
||||
while (dividend > 0)
|
||||
{
|
||||
modulo = (dividend - 1) % 26;
|
||||
columnName = Convert.ToChar(65 + modulo).ToString() + columnName;
|
||||
dividend = (dividend - modulo) / 26;
|
||||
}
|
||||
|
||||
return columnName;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
using DocumentFormat.OpenXml;
|
||||
using DocumentFormat.OpenXml.Packaging;
|
||||
using DocumentFormat.OpenXml.Wordprocessing;
|
||||
|
||||
|
||||
namespace SladkieBulkiBusinessLogic.OfficePackage;
|
||||
|
||||
internal class OpenXmlWordBuilder : BaseWordBuilder
|
||||
{
|
||||
private readonly Document _document;
|
||||
|
||||
private readonly Body _body;
|
||||
|
||||
public OpenXmlWordBuilder()
|
||||
{
|
||||
_document = new Document();
|
||||
_body = _document.AppendChild(new Body());
|
||||
}
|
||||
|
||||
public override BaseWordBuilder AddHeader(string header)
|
||||
{
|
||||
var paragraph = _body.AppendChild(new Paragraph());
|
||||
var run = paragraph.AppendChild(new Run());
|
||||
run.AppendChild(new RunProperties(new Bold()));
|
||||
run.AppendChild(new Text(header));
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public override BaseWordBuilder AddParagraph(string text)
|
||||
{
|
||||
var paragraph = _body.AppendChild(new Paragraph());
|
||||
var run = paragraph.AppendChild(new Run());
|
||||
run.AppendChild(new Text(text));
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public override BaseWordBuilder AddTable(int[] widths, List<string[]> data)
|
||||
{
|
||||
if (widths == null || widths.Length == 0)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(widths));
|
||||
}
|
||||
|
||||
if (data == null || data.Count == 0)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(data));
|
||||
}
|
||||
|
||||
if (data.Any(x => x.Length != widths.Length))
|
||||
{
|
||||
throw new InvalidOperationException("widths.Length != data.Length");
|
||||
}
|
||||
|
||||
var table = new Table();
|
||||
table.AppendChild(new TableProperties(
|
||||
new TableBorders(
|
||||
new TopBorder() { Val = new EnumValue<BorderValues>(BorderValues.Single), Size = 12 },
|
||||
new BottomBorder() { Val = new EnumValue<BorderValues>(BorderValues.Single), Size = 12 },
|
||||
new LeftBorder() { Val = new EnumValue<BorderValues>(BorderValues.Single), Size = 12 },
|
||||
new RightBorder() { Val = new EnumValue<BorderValues>(BorderValues.Single), Size = 12 },
|
||||
new InsideHorizontalBorder() { Val = new EnumValue<BorderValues>(BorderValues.Single), Size = 12 },
|
||||
new InsideVerticalBorder() { Val = new EnumValue<BorderValues>(BorderValues.Single), Size = 12 }
|
||||
)
|
||||
));
|
||||
|
||||
// Заголовок
|
||||
var tr = new TableRow();
|
||||
for (var j = 0; j < widths.Length; ++j)
|
||||
{
|
||||
tr.Append(new TableCell(
|
||||
new TableCellProperties(new TableCellWidth() { Width = widths[j].ToString() }),
|
||||
new Paragraph(new Run(new RunProperties(new Bold()), new Text(data.First()[j])))));
|
||||
}
|
||||
table.Append(tr);
|
||||
|
||||
// Данные
|
||||
table.Append(data.Skip(1).Select(x =>
|
||||
new TableRow(x.Select(y => new TableCell(new Paragraph(new Run(new Text(y))))))));
|
||||
|
||||
_body.Append(table);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public override Stream Build()
|
||||
{
|
||||
var stream = new MemoryStream();
|
||||
using var wordDocument = WordprocessingDocument.Create(stream, WordprocessingDocumentType.Document);
|
||||
var mainPart = wordDocument.AddMainDocumentPart();
|
||||
mainPart.Document = _document;
|
||||
return stream;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<InternalsVisibleTo Include="SladkieBulkiWedApi" />
|
||||
<InternalsVisibleTo Include="SladkieBulkiTests" />
|
||||
<InternalsVisibleTo Include="DynamicProxyGenAssembly2" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="DocumentFormat.OpenXml" Version="3.3.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="9.0.1" />
|
||||
<PackageReference Include="PdfSharp.MigraDoc.Standard" Version="1.51.15" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\SladkieBulkiContrakts\SladkieBulkiContrakts.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,21 @@
|
||||
using SladkieBulkiContrakts.AdapterContracts.OperationResponses;
|
||||
using SladkieBulkiContrakts.BindingModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SladkieBulkiContrakts.AdapterContracts;
|
||||
|
||||
public interface IIngredientAdapter
|
||||
{
|
||||
IngredientOperationResponse GetList();
|
||||
|
||||
IngredientOperationResponse GetElement(string data);
|
||||
|
||||
IngredientOperationResponse RegisterIngredient(IngredientBindingModel ingredientModel);
|
||||
|
||||
IngredientOperationResponse ChangeIngredientInfo(IngredientBindingModel ingredientModel);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
using SladkieBulkiContrakts.AdapterContracts.OperationResponses;
|
||||
using SladkieBulkiContrakts.BindingModels;
|
||||
|
||||
namespace SladkieBulkiContrakts.AdapterContracts;
|
||||
|
||||
public interface IPostAdapter
|
||||
{
|
||||
PostOperationResponse GetList();
|
||||
|
||||
PostOperationResponse GetHistory(string id);
|
||||
|
||||
PostOperationResponse GetElement(string data);
|
||||
|
||||
PostOperationResponse RegisterPost(PostBindingModel postModel);
|
||||
|
||||
PostOperationResponse ChangePostInfo(PostBindingModel postModel);
|
||||
|
||||
PostOperationResponse RemovePost(string id);
|
||||
|
||||
PostOperationResponse RestorePost(string id);
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
using SladkieBulkiContrakts.AdapterContracts.OperationResponses;
|
||||
using SladkieBulkiContrakts.BindingModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SladkieBulkiContrakts.AdapterContracts;
|
||||
|
||||
public interface IProductAdapter
|
||||
{
|
||||
ProductOperationResponse GetList();
|
||||
ProductOperationResponse GetElement(string data);
|
||||
ProductOperationResponse RegisterProduct(ProductBindingModel model);
|
||||
ProductOperationResponse ChangeProductInfo(ProductBindingModel model);
|
||||
ProductOperationResponse DeleteProduct(string id);
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
using SladkieBulkiContrakts.AdapterContracts.OperationResponses;
|
||||
using SladkieBulkiContrakts.BindingModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SladkieBulkiContrakts.AdapterContracts;
|
||||
|
||||
public interface IProductionAdapter
|
||||
{
|
||||
ProductionOperationResponse GetList(DateTime? from = null, DateTime? to = null, string? workerId = null, string? productId = null);
|
||||
ProductionOperationResponse GetElement(string id);
|
||||
ProductionOperationResponse RegisterProduction(ProductionBindingModel model);
|
||||
ProductionOperationResponse CancelProduction(string id);
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
using SladkieBulkiContrakts.AdapterContracts.OperationResponses;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SladkieBulkiContrakts.AdapterContracts;
|
||||
|
||||
public interface IReportAdapter
|
||||
{
|
||||
Task<ReportOperationResponse> GetProductsWithIngredientsAsync(CancellationToken ct);
|
||||
Task<ReportOperationResponse> GetDataProductionsByPeriodAsync(DateTime dateStart, DateTime dateFinish, CancellationToken ct);
|
||||
Task<ReportOperationResponse> GetDataSalaryByPeriodAsync(DateTime dateStart, DateTime dateFinish, CancellationToken ct);
|
||||
|
||||
Task<ReportOperationResponse> CreateDocumentProductsWithIngredientsAsync(CancellationToken ct);
|
||||
Task<ReportOperationResponse> CreateDocumentProductionsByPeriodAsync(DateTime dateStart, DateTime dateFinish, CancellationToken ct);
|
||||
Task<ReportOperationResponse> CreateDocumentSalaryByPeriodAsync(DateTime dateStart, DateTime dateFinish, CancellationToken ct);
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
using SladkieBulkiContrakts.AdapterContracts.OperationResponses;
|
||||
|
||||
namespace SladkieBulkiContrakts.AdapterContracts;
|
||||
public interface ISalaryAdapter
|
||||
{
|
||||
SalaryOperationResponse GetListByPeriod(DateTime fromDate, DateTime toDate);
|
||||
|
||||
SalaryOperationResponse GetListByPeriodByWorker(DateTime fromDate, DateTime toDate, string workerId);
|
||||
|
||||
SalaryOperationResponse CalculateSalary(DateTime date);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
using SladkieBulkiContrakts.AdapterContracts.OperationResponses;
|
||||
using SladkieBulkiContrakts.BindingModels;
|
||||
|
||||
namespace SladkieBulkiContrakts.AdapterContracts;
|
||||
|
||||
public interface IWorkerAdapter
|
||||
{
|
||||
WorkerOperationResponse GetList(bool includeDeleted);
|
||||
|
||||
WorkerOperationResponse GetPostList(string id, bool includeDeleted);
|
||||
|
||||
WorkerOperationResponse GetListByBirthDate(DateTime fromDate, DateTime toDate, bool includeDeleted);
|
||||
|
||||
WorkerOperationResponse GetListByEmploymentDate(DateTime fromDate, DateTime toDate, bool includeDeleted);
|
||||
|
||||
WorkerOperationResponse GetElement(string data);
|
||||
|
||||
WorkerOperationResponse RegisterWorker(WorkerBindingModel workerModel);
|
||||
|
||||
WorkerOperationResponse ChangeWorkerInfo(WorkerBindingModel workerModel);
|
||||
|
||||
WorkerOperationResponse RemoveWorker(string id);
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
using SladkieBulkiContrakts.Infrastructure;
|
||||
using SladkieBulkiContrakts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SladkieBulkiContrakts.AdapterContracts.OperationResponses;
|
||||
|
||||
public class IngredientOperationResponse : OperationResponse
|
||||
{
|
||||
public static IngredientOperationResponse OK(List<IngredientViewModel> data) => OK<IngredientOperationResponse, List<IngredientViewModel>>(data);
|
||||
|
||||
public static IngredientOperationResponse OK(IngredientViewModel data) => OK<IngredientOperationResponse, IngredientViewModel>(data);
|
||||
|
||||
public static IngredientOperationResponse NoContent() => NoContent<IngredientOperationResponse>();
|
||||
|
||||
public static IngredientOperationResponse NotFound(string message) => NotFound<IngredientOperationResponse>(message);
|
||||
|
||||
public static IngredientOperationResponse BadRequest(string message) => BadRequest<IngredientOperationResponse>(message);
|
||||
|
||||
public static IngredientOperationResponse InternalServerError(string message) => InternalServerError<IngredientOperationResponse>(message);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
using SladkieBulkiContrakts.Infrastructure;
|
||||
using SladkieBulkiContrakts.ViewModels;
|
||||
|
||||
namespace SladkieBulkiContrakts.AdapterContracts.OperationResponses;
|
||||
|
||||
public class PostOperationResponse : OperationResponse
|
||||
{
|
||||
public static PostOperationResponse OK(List<PostViewModel> data) => OK<PostOperationResponse, List<PostViewModel>>(data);
|
||||
|
||||
public static PostOperationResponse OK(PostViewModel data) => OK<PostOperationResponse, PostViewModel>(data);
|
||||
|
||||
public static PostOperationResponse NoContent() => NoContent<PostOperationResponse>();
|
||||
|
||||
public static PostOperationResponse NotFound(string message) => NotFound<PostOperationResponse>(message);
|
||||
|
||||
public static PostOperationResponse BadRequest(string message) => BadRequest<PostOperationResponse>(message);
|
||||
|
||||
public static PostOperationResponse InternalServerError(string message) => InternalServerError<PostOperationResponse>(message);
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
using SladkieBulkiContrakts.Infrastructure;
|
||||
using SladkieBulkiContrakts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SladkieBulkiContrakts.AdapterContracts.OperationResponses;
|
||||
|
||||
public class ProductOperationResponse : OperationResponse
|
||||
{
|
||||
public static ProductOperationResponse OK(List<ProductViewModel> data) =>
|
||||
OK<ProductOperationResponse, List<ProductViewModel>>(data);
|
||||
|
||||
public static ProductOperationResponse OK(ProductViewModel data) =>
|
||||
OK<ProductOperationResponse, ProductViewModel>(data);
|
||||
|
||||
public static ProductOperationResponse NoContent() =>
|
||||
NoContent<ProductOperationResponse>();
|
||||
|
||||
public static ProductOperationResponse NotFound(string message) =>
|
||||
NotFound<ProductOperationResponse>(message);
|
||||
|
||||
public static ProductOperationResponse BadRequest(string message) =>
|
||||
BadRequest<ProductOperationResponse>(message);
|
||||
|
||||
public static ProductOperationResponse InternalServerError(string message) =>
|
||||
InternalServerError<ProductOperationResponse>(message);
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
using SladkieBulkiContrakts.Infrastructure;
|
||||
using SladkieBulkiContrakts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SladkieBulkiContrakts.AdapterContracts.OperationResponses;
|
||||
|
||||
|
||||
public class ProductionOperationResponse : OperationResponse
|
||||
{
|
||||
public static ProductionOperationResponse OK(List<ProductionViewModel> data) =>
|
||||
OK<ProductionOperationResponse, List<ProductionViewModel>>(data);
|
||||
|
||||
public static ProductionOperationResponse OK(ProductionViewModel data) =>
|
||||
OK<ProductionOperationResponse, ProductionViewModel>(data);
|
||||
|
||||
public static ProductionOperationResponse NoContent() =>
|
||||
NoContent<ProductionOperationResponse>();
|
||||
|
||||
public static ProductionOperationResponse NotFound(string message) =>
|
||||
NotFound<ProductionOperationResponse>(message);
|
||||
|
||||
public static ProductionOperationResponse BadRequest(string message) =>
|
||||
BadRequest<ProductionOperationResponse>(message);
|
||||
|
||||
public static ProductionOperationResponse InternalServerError(string message) =>
|
||||
InternalServerError<ProductionOperationResponse>(message);
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
using SladkieBulkiContrakts.Infrastructure;
|
||||
using SladkieBulkiContrakts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SladkieBulkiContrakts.AdapterContracts.OperationResponses;
|
||||
|
||||
public class ReportOperationResponse : OperationResponse
|
||||
{
|
||||
public static ReportOperationResponse OK(Stream data, string fileName) => OK<ReportOperationResponse, Stream>(data, fileName);
|
||||
public static ReportOperationResponse OK(List<ProductionViewModel> data) => OK<ReportOperationResponse, List<ProductionViewModel>>(data);
|
||||
public static ReportOperationResponse OK(List<WorkerSalaryByPeriodViewModel> data) => OK<ReportOperationResponse, List<WorkerSalaryByPeriodViewModel>>(data);
|
||||
|
||||
public static ReportOperationResponse OK(List<ProductWithIngredientsViewModel> data) => OK<ReportOperationResponse, List<ProductWithIngredientsViewModel>>(data);
|
||||
|
||||
public static ReportOperationResponse BadRequest(string message) => BadRequest<ReportOperationResponse>(message);
|
||||
|
||||
public static ReportOperationResponse InternalServerError(string message) => InternalServerError<ReportOperationResponse>(message);
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
|
||||
using SladkieBulkiContrakts.Infrastructure;
|
||||
using SladkieBulkiContrakts.ViewModels;
|
||||
|
||||
namespace SladkieBulkiContrakts.AdapterContracts.OperationResponses;
|
||||
public class SalaryOperationResponse : OperationResponse
|
||||
{
|
||||
public static SalaryOperationResponse OK(List<SalaryViewModel> data) => OK<SalaryOperationResponse, List<SalaryViewModel>>(data);
|
||||
|
||||
public static SalaryOperationResponse NoContent() => NoContent<SalaryOperationResponse>();
|
||||
|
||||
public static SalaryOperationResponse NotFound(string message) => NotFound<SalaryOperationResponse>(message);
|
||||
|
||||
public static SalaryOperationResponse BadRequest(string message) => BadRequest<SalaryOperationResponse>(message);
|
||||
|
||||
public static SalaryOperationResponse InternalServerError(string message) => InternalServerError<SalaryOperationResponse>(message);
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
using SladkieBulkiContrakts.Infrastructure;
|
||||
using SladkieBulkiContrakts.ViewModels;
|
||||
|
||||
namespace SladkieBulkiContrakts.AdapterContracts.OperationResponses;
|
||||
|
||||
public class WorkerOperationResponse : OperationResponse
|
||||
{
|
||||
public static WorkerOperationResponse OK(List<WorkerViewModel> data) => OK<WorkerOperationResponse, List<WorkerViewModel>>(data);
|
||||
|
||||
public static WorkerOperationResponse OK(WorkerViewModel data) => OK<WorkerOperationResponse, WorkerViewModel>(data);
|
||||
|
||||
public static WorkerOperationResponse NoContent() => NoContent<WorkerOperationResponse>();
|
||||
|
||||
public static WorkerOperationResponse NotFound(string message) => NotFound<WorkerOperationResponse>(message);
|
||||
|
||||
public static WorkerOperationResponse BadRequest(string message) => BadRequest<WorkerOperationResponse>(message);
|
||||
|
||||
public static WorkerOperationResponse InternalServerError(string message) => InternalServerError<WorkerOperationResponse>(message);
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SladkieBulkiContrakts.BindingModels;
|
||||
|
||||
public class IngredientBindingModel
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
|
||||
public string? NameIngredients { get; set; }
|
||||
|
||||
public string? SizeInit { get; set; }
|
||||
|
||||
public double InitPrice { get; set; }
|
||||
}
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
namespace SladkieBulkiContrakts.BindingModels;
|
||||
|
||||
public class PostBindingModel
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
|
||||
public string? PostId => Id;
|
||||
|
||||
public string? PostName { get; set; }
|
||||
|
||||
public string? PostType { get; set; }
|
||||
|
||||
public string? ConfigurationJson { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SladkieBulkiContrakts.BindingModels;
|
||||
|
||||
|
||||
public class ProductBindingModel
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? Name { get; set; }
|
||||
public string? Description { get; set; }
|
||||
public double UnitPrice { get; set; }
|
||||
public string? ProductType { get; set; }
|
||||
public List<IngredientBindingModel> Ingredients { get; set; } = new();
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SladkieBulkiContrakts.BindingModels;
|
||||
public class ProductionBindingModel
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public DateTime ProductionDate { get; set; }
|
||||
public int Count { get; set; }
|
||||
public double Sum { get; set; }
|
||||
public string WorkerId { get; set; } = default!;
|
||||
public string ProductId { get; set; } = default!;
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
namespace SladkieBulkiContrakts.BindingModels;
|
||||
|
||||
public class WorkerBindingModel
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? FIO { get; set; }
|
||||
public DateTime BirthDate { get; set; }
|
||||
public DateTime EmploymentDate { get; set; }
|
||||
public string? PostId { get; set; }
|
||||
public string? Email { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
using SladkieBulkiContrakts.DataModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SladkieBulkiContrakts.BusinessLogicsContracts;
|
||||
|
||||
public interface IIngredientBusinessLogicContract
|
||||
{
|
||||
List<IngredientDataModel> GetAllIngredients();
|
||||
|
||||
List<IngredientDataModel> GetIngredientsBySizeUnit(string sizeUnit);
|
||||
|
||||
IngredientDataModel? GetIngredientByName(string name);
|
||||
|
||||
IngredientDataModel? GetIngredientById(string id);
|
||||
|
||||
void InsertIngredient(IngredientDataModel ingredientDataModel);
|
||||
|
||||
void UpdateIngredient(IngredientDataModel ingredientDataModel);
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
using SladkieBulkiContrakts.DataModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SladkieBulkiContrakts.BusinessLogicsContracts;
|
||||
|
||||
public interface IPostBusinessLogicContract
|
||||
{
|
||||
List<PostDataModel> GetAllPosts();
|
||||
List<PostDataModel> GetAllDataOfPost(string postId);
|
||||
PostDataModel GetPostByData(string data);
|
||||
void InsertPost(PostDataModel postDataModel);
|
||||
void UpdatePost(PostDataModel postDataModel);
|
||||
void DeletePost(string id);
|
||||
void RestorePost(string id);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
using SladkieBulkiContrakts.DataModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SladkieBulkiContrakts.BusinessLogicsContracts;
|
||||
|
||||
public interface IProductBusinessLogicContract
|
||||
{
|
||||
List<ProductDataModel> GetAllProducts(bool onlyActive = true);
|
||||
List<ProductHistoryDataModel> GetProductHistoryByProduct(string productId);
|
||||
ProductDataModel GetProductByData(string data);
|
||||
void InsertProduct(ProductDataModel productDataModel);
|
||||
void UpdateProduct(ProductDataModel productDataModel);
|
||||
void DeleteProduct(string id);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
using SladkieBulkiContrakts.DataModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SladkieBulkiContrakts.BusinessLogicsContracts;
|
||||
|
||||
public interface IProductionBusinessLogicContract
|
||||
{
|
||||
List<ProductionDataModel> GetAllSalesByPeriod(DateTime fromDate, DateTime toDate);
|
||||
List<ProductionDataModel> GetAllSalesByWorkerByPeriod(string workerId, DateTime fromDate, DateTime toDate);
|
||||
List<ProductionDataModel> GetAllSalesByProductByPeriod(string productId, DateTime fromDate, DateTime toDate);
|
||||
ProductionDataModel GetProductionByData(string data);
|
||||
void InsertProduction(ProductionDataModel productionDataModel);
|
||||
void CancelProduction(string id);
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
using SladkieBulkiContrakts.DataModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SladkieBulkiContrakts.BusinessLogicsContracts;
|
||||
|
||||
public interface IReportContract
|
||||
{
|
||||
Task<List<ProductWithIngredientsReportDataModel>> GetProductsWithIngredientsAsync(CancellationToken ct);
|
||||
Task<List<ProductionDataModel>> GetDataProductionsByPeriodAsync(DateTime dateStart, DateTime dateFinish, CancellationToken ct);
|
||||
Task<List<WorkerSalaryByPeriodDataModel>> GetDataSalaryByPeriodAsync(DateTime dateStart, DateTime dateFinish, CancellationToken ct);
|
||||
|
||||
Task<Stream> CreateDocumentProductionsByPeriodAsync(DateTime dateStart, DateTime dateFinish, CancellationToken ct);
|
||||
Task<Stream> CreateDocumentProductsWithIngredientsAsync(CancellationToken ct);
|
||||
Task<Stream> CreateDocumentSalaryByPeriodAsync(DateTime dateStart, DateTime dateFinish, CancellationToken ct);
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
using SladkieBulkiContrakts.DataModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SladkieBulkiContrakts.BusinessLogicsContracts;
|
||||
|
||||
public interface ISalaryBusinessLogicContract
|
||||
{
|
||||
List<SalaryDataModel> GetAllSalariesByPeriod(DateTime fromDate, DateTime toDate);
|
||||
List<SalaryDataModel> GetAllSalariesByPeriodByWorker(DateTime fromDate, DateTime toDate, string workerId);
|
||||
void CalculateSalaryByMounth(DateTime date);
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
using SladkieBulkiContrakts.DataModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SladkieBulkiContrakts.BusinessLogicsContracts;
|
||||
|
||||
public interface IWorkerBusinessLogicContract
|
||||
{
|
||||
List<WorkerDataModel> GetAllWorkers(bool onlyActive = true);
|
||||
List<WorkerDataModel> GetAllWorkersByPost(string postId, bool onlyActive = true);
|
||||
List<WorkerDataModel> GetAllWorkersByBirthDate(DateTime fromDate, DateTime toDate, bool onlyActive = true);
|
||||
List<WorkerDataModel> GetAllWorkersByEmploymentDate(DateTime fromDate, DateTime toDate, bool onlyActive = true);
|
||||
WorkerDataModel GetWorkerByData(string data);
|
||||
void InsertWorker(WorkerDataModel workerDataModel);
|
||||
void UpdateWorker(WorkerDataModel workerDataModel);
|
||||
void DeleteWorker(string id);
|
||||
}
|
||||
@@ -8,10 +8,10 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace SladkieBulkiContrakts.DataModels;
|
||||
|
||||
public class IngredientDataModel(string id, string nameIngridients, string sizeInit, double initPrice) : IValidation
|
||||
public class IngredientDataModel(string id, string NameIngredients, string sizeInit, double initPrice) : IValidation
|
||||
{
|
||||
public string Id { get; private set; } = id;
|
||||
public string NameIngridients { get; private set; } = nameIngridients;
|
||||
public string NameIngredients { get; private set; } = NameIngredients;
|
||||
public string SizeInit { get; private set; } = sizeInit;
|
||||
public double InitPrice { get; private set; } = initPrice;
|
||||
|
||||
@@ -21,8 +21,8 @@ public class IngredientDataModel(string id, string nameIngridients, string sizeI
|
||||
throw new ValidationException("Field Id is empty");
|
||||
if (!Id.IsGuid())
|
||||
throw new ValidationException("The value in the field Id is not a unique identifier");
|
||||
if (NameIngridients.IsEmpty())
|
||||
throw new ValidationException("Field NameIngridients is empty");
|
||||
if (NameIngredients.IsEmpty())
|
||||
throw new ValidationException("Field NameIngredients is empty");
|
||||
if (SizeInit.IsEmpty())
|
||||
throw new ValidationException("Field SizeInit is empty");
|
||||
if (InitPrice <= 0)
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
using SladkieBulkiContrakts.Enums;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Newtonsoft.Json;
|
||||
using SladkieBulkiContrakts.Enums;
|
||||
using SladkieBulkiContrakts.Extensions;
|
||||
using SladkieBulkiContrakts.Infrastructure;
|
||||
using SladkieBulkiContrakts.Infrastructure.PostConfigurations;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -10,24 +13,48 @@ using System.Xml;
|
||||
|
||||
namespace SladkieBulkiContrakts.DataModels;
|
||||
|
||||
public class PostDataModel(string id, string postName, PostType postType, double salary) : IValidation
|
||||
public class PostDataModel(string postId, string postName, PostType postType, PostConfiguration configuration) : IValidation
|
||||
{
|
||||
public string Id { get; private set; } = id;
|
||||
public string Id { get; private set; } = postId;
|
||||
|
||||
public string PostName { get; private set; } = postName;
|
||||
|
||||
public PostType PostType { get; private set; } = postType;
|
||||
public double Salary { get; private set; } = salary; // Ставка за 1 булку тк по заданию зп на основе изготовленной продукции
|
||||
|
||||
public PostConfiguration ConfigurationModel { get; private set; } = configuration;
|
||||
|
||||
public PostDataModel(string postId, string postName, PostType postType, string configurationJson) : this(postId, postName, postType, (PostConfiguration)null)
|
||||
{
|
||||
var obj = JToken.Parse(configurationJson);
|
||||
if (obj is not null)
|
||||
{
|
||||
ConfigurationModel = obj.Value<string>("Type") switch
|
||||
{
|
||||
nameof(ManufacturerPostConfiguration) => JsonConvert.DeserializeObject<ManufacturerPostConfiguration>(configurationJson)!,
|
||||
nameof(PackerPostConfiguration) => JsonConvert.DeserializeObject<PackerPostConfiguration>(configurationJson)!,
|
||||
_ => JsonConvert.DeserializeObject<PostConfiguration>(configurationJson)!,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
if (Id.IsEmpty())
|
||||
throw new ValidationException("Field Id is empty");
|
||||
|
||||
if (!Id.IsGuid())
|
||||
throw new ValidationException("The value in the field Id is not a unique identifier");
|
||||
|
||||
if (PostName.IsEmpty())
|
||||
throw new ValidationException("Field PostName is empty");
|
||||
|
||||
if (PostType == PostType.None)
|
||||
throw new ValidationException("Field PostType is empty");
|
||||
if (Salary <= 0)
|
||||
throw new ValidationException("Field Salary is empty");
|
||||
|
||||
if (ConfigurationModel is null)
|
||||
throw new ValidationException("Field ConfigurationModel is not initialized");
|
||||
|
||||
if (ConfigurationModel!.Rate <= 0)
|
||||
throw new ValidationException("Field Rate is less or equal zero");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,42 +1,71 @@
|
||||
using SladkieBulkiContrakts.Enums;
|
||||
using SladkieBulkiContrakts.Exceptions;
|
||||
using SladkieBulkiContrakts.Extensions;
|
||||
using SladkieBulkiContrakts.Infrastructure;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace SladkieBulkiContrakts.DataModels;
|
||||
|
||||
public class ProductDataModel (string id, string name, string description, ProductType productType, int unitPrice, bool isDeleted) : IValidation
|
||||
|
||||
|
||||
public class ProductDataModel : IValidation
|
||||
{
|
||||
public string Id { get; private set; } = id;
|
||||
public string Id { get; private set; }
|
||||
public string Name { get; private set; }
|
||||
public string Description { get; private set; }
|
||||
public ProductType ProductType { get; private set; }
|
||||
public List<ProductIngredientDataModel> Ingredients { get; private set; }
|
||||
public double UnitPrice { get; private set; }
|
||||
public bool IsDeleted { get; private set; }
|
||||
|
||||
public string Name { get; private set; } = name;
|
||||
public ProductDataModel()
|
||||
{
|
||||
Ingredients = new List<ProductIngredientDataModel>();
|
||||
}
|
||||
|
||||
public string Description { get; private set; } = description;
|
||||
public ProductDataModel(string id, string name, string description, ProductType productType, List<ProductIngredientDataModel> ingredients, double unitPrice, bool isDeleted)
|
||||
{
|
||||
Id = id;
|
||||
Name = name;
|
||||
Description = description;
|
||||
ProductType = productType;
|
||||
Ingredients = ingredients ?? new List<ProductIngredientDataModel>();
|
||||
UnitPrice = unitPrice;
|
||||
IsDeleted = isDeleted;
|
||||
}
|
||||
public ProductDataModel(
|
||||
string id,
|
||||
string name,
|
||||
string description,
|
||||
ProductType productType,
|
||||
List<ProductIngredientDataModel> ingredients,
|
||||
double unitPrice)
|
||||
: this(id, name, description, productType, ingredients, unitPrice, false) { }
|
||||
|
||||
public ProductType ProductType { get; private set; } = productType;
|
||||
|
||||
public int UnitPrice { get; private set; } = unitPrice;
|
||||
// Валидация
|
||||
public void Validate()
|
||||
{
|
||||
if (Id.IsEmpty())
|
||||
throw new ValidationException("Field Id is empty");
|
||||
|
||||
public bool IsDeleted { get; private set; } = isDeleted;
|
||||
if (!Id.IsGuid())
|
||||
throw new ValidationException("The value in the field Id is not a unique identifier");
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
if (Id.IsEmpty())
|
||||
throw new ValidationException("Field Id is empty");
|
||||
if (!Id.IsGuid())
|
||||
throw new ValidationException("The value in the field Id is not a unique identifier");
|
||||
if (Name.IsEmpty())
|
||||
throw new ValidationException("Field Name is empty");
|
||||
if (Description.IsEmpty())
|
||||
throw new ValidationException("Field Description is empty");
|
||||
if (ProductType == ProductType.None)
|
||||
throw new ValidationException("Field ProductType is empty");
|
||||
if (UnitPrice <= 0)
|
||||
throw new ValidationException("Field UnitPrice must be greater than zero");
|
||||
}
|
||||
if (Name.IsEmpty())
|
||||
throw new ValidationException("Field Name is empty");
|
||||
|
||||
if (Description.IsEmpty())
|
||||
throw new ValidationException("Field Description is empty");
|
||||
|
||||
if (ProductType == ProductType.None)
|
||||
throw new ValidationException("Field ProductType is empty");
|
||||
|
||||
if (UnitPrice <= 0)
|
||||
throw new ValidationException("Field UnitPrice must be greater than zero");
|
||||
|
||||
if (Ingredients == null || Ingredients.Count == 0)
|
||||
throw new ValidationException("No ingredients defined");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SladkieBulkiContrakts.DataModels;
|
||||
|
||||
public class ProductWithIngredientsReportDataModel
|
||||
{
|
||||
public string ProductId { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string Description { get; set; }
|
||||
public string ProductType { get; set; }
|
||||
public double UnitPrice { get; set; }
|
||||
public List<IngredientInProductDto> Ingredients { get; set; } = new();
|
||||
}
|
||||
|
||||
public class IngredientInProductDto
|
||||
{
|
||||
public string IngredientId { get; set; }
|
||||
public string NameIngredients { get; set; }
|
||||
public string SizeUnit { get; set; } // мера измерения
|
||||
public double InitPrice { get; set; }
|
||||
public int Count { get; set; } // количество ингредиента в продукте
|
||||
}
|
||||
@@ -1,14 +1,7 @@
|
||||
using SladkieBulkiContrakts.Extensions;
|
||||
using SladkieBulkiContrakts.Infrastructure;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SladkieBulkiContrakts.DataModels;
|
||||
|
||||
public class ProductionDataModel(string id, DateTime productionDate, int count, double sum, string workerId, string productId, List<ProductIngredientDataModel>? products) : IValidation
|
||||
public class ProductionDataModel(string id, DateTime productionDate, int count, double sum, string workerId, string productId) : IValidation
|
||||
{
|
||||
public string Id { get; private set; } = id;
|
||||
public DateTime ProductionDate { get; private set; } = productionDate;
|
||||
@@ -16,7 +9,6 @@ public class ProductionDataModel(string id, DateTime productionDate, int count,
|
||||
public double Sum { get; private set; } = sum;
|
||||
public string WorkerId { get; private set; } = workerId;
|
||||
public string ProductId { get; private set; } = productId;
|
||||
public List<ProductIngredientDataModel>? Products { get; private set; } = products;
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
@@ -38,8 +30,5 @@ public class ProductionDataModel(string id, DateTime productionDate, int count,
|
||||
throw new ValidationException("The value in the field ProductId is not a unique identifier");
|
||||
if (Sum <= 0)
|
||||
throw new ValidationException("Field Sum is less than or equal to 0");
|
||||
if ((Products?.Count ?? 0) == 0)
|
||||
throw new ValidationException("The sale must include products");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,16 +10,22 @@ namespace SladkieBulkiContrakts.DataModels;
|
||||
|
||||
public class SalaryDataModel(string workerId, DateTime salaryDate, double workerSalary) : IValidation
|
||||
{
|
||||
private readonly WorkerDataModel? _worker;
|
||||
public string WorkerId { get; private set; } = workerId;
|
||||
public DateTime SalaryDate { get; private set; } = salaryDate;
|
||||
public double Salary { get; private set; } = workerSalary;
|
||||
public double WorkerSalary { get; private set; } = workerSalary;
|
||||
public string WorkerFIO => _worker?.FIO ?? string.Empty;
|
||||
public SalaryDataModel(string workerId, DateTime salaryDate, double workerSalary, WorkerDataModel? worker) : this(workerId, salaryDate, workerSalary)
|
||||
{
|
||||
_worker = worker;
|
||||
}
|
||||
public void Validate()
|
||||
{
|
||||
if (WorkerId.IsEmpty())
|
||||
throw new ValidationException("Field WorkerId is empty");
|
||||
if (!WorkerId.IsGuid())
|
||||
throw new ValidationException("The value in the field WorkerId is not a unique identifier");
|
||||
if (Salary <= 0)
|
||||
if (WorkerSalary <= 0)
|
||||
throw new ValidationException("Field Salary is less than or equal to 0");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,11 +9,13 @@ using static System.Runtime.InteropServices.JavaScript.JSType;
|
||||
using System.Xml;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Numerics;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
|
||||
namespace SladkieBulkiContrakts.DataModels;
|
||||
|
||||
public class WorkerDataModel(string id, string fio, string postId, DateTime birthDate, DateTime employmentDate, bool isDeleted, string email) : IValidation
|
||||
{
|
||||
private readonly PostDataModel? _post;
|
||||
public string Id { get; private set; } = id;
|
||||
public string FIO { get; private set; } = fio;
|
||||
public string PostId { get; private set; } = postId;
|
||||
@@ -21,6 +23,15 @@ public class WorkerDataModel(string id, string fio, string postId, DateTime birt
|
||||
public DateTime EmploymentDate { get; private set; } = employmentDate;
|
||||
public bool IsDeleted { get; private set; } = isDeleted;
|
||||
public string Email { get; private set; } = email;
|
||||
|
||||
public string PostName => _post?.PostName ?? string.Empty;
|
||||
public WorkerDataModel(string id, string fio, string postId, DateTime birthDate, DateTime employmentDate, bool isDeleted, string email, PostDataModel post) : this(id, fio, postId, birthDate, employmentDate, isDeleted, email)
|
||||
{
|
||||
_post = post;
|
||||
}
|
||||
|
||||
public WorkerDataModel(string id, string fio, string postId, DateTime birthDate, DateTime employmentDate, string email) : this(id, fio, postId, birthDate, employmentDate, false, email) { }
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
if (Id.IsEmpty())
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SladkieBulkiContrakts.DataModels;
|
||||
|
||||
public class WorkerSalaryByPeriodDataModel
|
||||
{
|
||||
public required string WorkerFIO { get; set; }
|
||||
|
||||
public double TotalSalary { get; set; }
|
||||
|
||||
public DateTime FromPeriod { get; set; }
|
||||
|
||||
public DateTime ToPeriod { get; set; }
|
||||
}
|
||||
@@ -11,6 +11,6 @@ public enum PostType
|
||||
None = 0,
|
||||
Preform = 1, // Заготовщик
|
||||
Manufacturer = 2, // Изготовитель
|
||||
packer = 3 // Упаковщик
|
||||
Packer = 3 // Упаковщик
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SladkieBulkiContrakts.Exceptions;
|
||||
|
||||
public class ElementDeletedException : Exception
|
||||
{
|
||||
public ElementDeletedException(string id) : base($"Cannot modify a deleted item (id: {id})") { }
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SladkieBulkiContrakts.Exceptions;
|
||||
|
||||
public class ElementExistsException : Exception
|
||||
{
|
||||
public string ParamName { get; private set; }
|
||||
public string ParamValue { get; private set; }
|
||||
public ElementExistsException(string paramName, string paramValue) : base($"There is already an element with value{paramValue} of parameter {paramName}")
|
||||
{
|
||||
ParamName = paramName;
|
||||
ParamValue = paramValue;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SladkieBulkiContrakts.Exceptions;
|
||||
|
||||
public class ElementNotFoundException : Exception
|
||||
|
||||
{
|
||||
public string Value { get; private set; }
|
||||
public ElementNotFoundException(string value) : base($"Element not found at value = { value}")
|
||||
{
|
||||
Value = value;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
public class IncorrectDatesException : Exception
|
||||
{
|
||||
public IncorrectDatesException(DateTime start, DateTime end) : base($"The end date must be later than the start date.. StartDate: {start:dd.MM.YYYY}. EndDate: {end:dd.MM.YYYY}") { }
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SladkieBulkiContrakts.Exceptions;
|
||||
|
||||
public class NullListException : Exception
|
||||
{
|
||||
public NullListException() : base("The returned list is null") { }
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SladkieBulkiContrakts.Exceptions;
|
||||
|
||||
public class StorageException : Exception
|
||||
{
|
||||
public StorageException(Exception ex) : base($"Error while working in storage: { ex.Message}", ex) { }
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SladkieBulkiContrakts.Extensions;
|
||||
|
||||
public static class DateTimeExtensions
|
||||
{
|
||||
public static bool IsDateNotOlder(this DateTime date, DateTime olderDate)
|
||||
{
|
||||
return date >= olderDate;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SladkieBulkiContrakts.Infrastructure;
|
||||
|
||||
public interface IConfigurationDatabase
|
||||
{
|
||||
string ConnectionString { get; }
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SladkieBulkiContrakts.Infrastructure;
|
||||
|
||||
public interface IConfigurationSalary
|
||||
{
|
||||
double ExtraSaleSum { get; }
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SladkieBulkiContrakts.Infrastructure;
|
||||
|
||||
public class OperationResponse
|
||||
{
|
||||
protected HttpStatusCode StatusCode { get; set; }
|
||||
|
||||
protected object? Result { get; set; }
|
||||
protected string? FileName { get; set; }
|
||||
|
||||
|
||||
public IActionResult GetResponse(HttpRequest request, HttpResponse response)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(request);
|
||||
ArgumentNullException.ThrowIfNull(response);
|
||||
|
||||
response.StatusCode = (int)StatusCode;
|
||||
|
||||
if (Result is null)
|
||||
{
|
||||
return new StatusCodeResult((int)StatusCode);
|
||||
}
|
||||
if (Result is Stream stream)
|
||||
{
|
||||
return new FileStreamResult(stream, "application/octet-stream")
|
||||
{
|
||||
FileDownloadName = FileName
|
||||
};
|
||||
}
|
||||
|
||||
return new ObjectResult(Result);
|
||||
}
|
||||
|
||||
protected static TResult OK<TResult, TData>(TData data) where TResult : OperationResponse, new() => new() { StatusCode = HttpStatusCode.OK, Result = data };
|
||||
|
||||
protected static TResult OK<TResult, TData>(TData data, string fileName) where TResult : OperationResponse, new() => new() { StatusCode = HttpStatusCode.OK, Result = data, FileName = fileName };
|
||||
|
||||
protected static TResult NoContent<TResult>() where TResult : OperationResponse, new() => new() { StatusCode = HttpStatusCode.NoContent };
|
||||
|
||||
protected static TResult BadRequest<TResult>(string? errorMessage = null) where TResult : OperationResponse, new() => new() { StatusCode = HttpStatusCode.BadRequest, Result = errorMessage };
|
||||
|
||||
protected static TResult NotFound<TResult>(string? errorMessage = null) where TResult : OperationResponse, new() => new() { StatusCode = HttpStatusCode.NotFound, Result = errorMessage };
|
||||
|
||||
protected static TResult InternalServerError<TResult>(string? errorMessage = null) where TResult : OperationResponse, new() => new() { StatusCode = HttpStatusCode.InternalServerError, Result = errorMessage };
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SladkieBulkiContrakts.Infrastructure.PostConfigurations;
|
||||
|
||||
public class ManufacturerPostConfiguration : PostConfiguration
|
||||
{
|
||||
public override string Type => nameof(ManufacturerPostConfiguration);
|
||||
|
||||
public double SalePercent { get; set; }
|
||||
|
||||
public double BonusForExtraSales { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SladkieBulkiContrakts.Infrastructure.PostConfigurations;
|
||||
|
||||
public class PackerPostConfiguration : PostConfiguration
|
||||
{
|
||||
public override string Type => nameof(PackerPostConfiguration);
|
||||
|
||||
public double PersonalCountPack { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SladkieBulkiContrakts.Infrastructure.PostConfigurations;
|
||||
|
||||
public class PostConfiguration
|
||||
{
|
||||
public virtual string Type => nameof(PostConfiguration);
|
||||
|
||||
public double Rate { get; set; }
|
||||
}
|
||||
|
||||
@@ -6,4 +6,10 @@
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.3.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Abstractions" Version="2.3.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="2.3.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
using SladkieBulkiContrakts.DataModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SladkieBulkiContrakts.StoragesContarcts;
|
||||
|
||||
public interface IIngredientStorageContract
|
||||
{
|
||||
List<IngredientDataModel> GetList();
|
||||
|
||||
Task<List<IngredientDataModel>> GetListAsync(CancellationToken ct);
|
||||
|
||||
// Получить ингредиенты по единице измерения
|
||||
List<IngredientDataModel>? GetElementBySizeUnit(string sizeInit);
|
||||
|
||||
IngredientDataModel? GetElementById(string id);
|
||||
|
||||
IngredientDataModel? GetElementByName(string name);
|
||||
|
||||
void AddElement(IngredientDataModel ingredientDataModel);
|
||||
|
||||
void UpdElement(IngredientDataModel ingredientDataModel);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
using SladkieBulkiContrakts.DataModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SladkieBulkiContrakts.StoragesContarcts;
|
||||
|
||||
public interface IPostStorageContract
|
||||
{
|
||||
List<PostDataModel> GetList();
|
||||
List<PostDataModel> GetPostWithHistory(string postId);
|
||||
PostDataModel? GetElementById(string id);
|
||||
PostDataModel? GetElementByName(string name);
|
||||
void AddElement(PostDataModel postDataModel);
|
||||
void UpdElement(PostDataModel postDataModel);
|
||||
void DelElement(string id);
|
||||
void ResElement(string id);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
using SladkieBulkiContrakts.DataModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SladkieBulkiContrakts.StoragesContarcts;
|
||||
|
||||
public interface IProductStorageContract
|
||||
{
|
||||
List<ProductDataModel> GetList(bool onlyActive = true);
|
||||
Task<List<ProductDataModel>> GetListAsync(CancellationToken ct);
|
||||
List<ProductHistoryDataModel> GetHistoryByProductId(string productId);
|
||||
ProductDataModel? GetElementById(string id);
|
||||
ProductDataModel? GetElementByName(string name);
|
||||
void AddElement(ProductDataModel productDataModel);
|
||||
void UpdElement(ProductDataModel productDataModel);
|
||||
void DelElement(string id);
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
using SladkieBulkiContrakts.DataModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SladkieBulkiContrakts.StoragesContarcts;
|
||||
|
||||
public interface IProductionStorageContract
|
||||
{
|
||||
List<ProductionDataModel> GetList(DateTime? startDate = null, DateTime? endDate = null, string? workerId = null, string? productId = null);
|
||||
Task<List<ProductionDataModel>> GetListAsync(DateTime startDate, DateTime endDate, CancellationToken ct);
|
||||
|
||||
ProductionDataModel? GetElementById(string id);
|
||||
void AddElement(ProductionDataModel productionDataModel);
|
||||
void DelElement(string id);
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
using SladkieBulkiContrakts.DataModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SladkieBulkiContrakts.StoragesContarcts;
|
||||
|
||||
public interface ISalaryStorageContract
|
||||
{
|
||||
List<SalaryDataModel> GetList(DateTime startDate, DateTime endDate, string? workerId = null);
|
||||
Task<List<SalaryDataModel>> GetListAsync(DateTime startDate, DateTime endDate, CancellationToken ct);
|
||||
|
||||
void AddElement(SalaryDataModel salaryDataModel);
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
using SladkieBulkiContrakts.DataModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SladkieBulkiContrakts.StoragesContarcts;
|
||||
|
||||
public interface IWorkerStorageContract
|
||||
{
|
||||
List<WorkerDataModel> GetList(bool onlyActive = true, string? postId = null, DateTime? fromBirthDate = null, DateTime? toBirthDate = null, DateTime? fromEmploymentDate = null, DateTime? toEmploymentDate = null);
|
||||
WorkerDataModel? GetElementById(string id);
|
||||
WorkerDataModel? GetElementByFIO(string fio);
|
||||
void AddElement(WorkerDataModel workerDataModel);
|
||||
void UpdElement(WorkerDataModel workerDataModel);
|
||||
void DelElement(string id);
|
||||
int GetWorkerTrend(DateTime fromPeriod, DateTime toPeriod);
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SladkieBulkiContrakts.ViewModels;
|
||||
|
||||
public class IngredientViewModel
|
||||
{
|
||||
public string Id { get; set; } = string.Empty;
|
||||
|
||||
public string NameIngredients { get; set; } = string.Empty;
|
||||
|
||||
public string SizeInit { get; set; } = string.Empty;
|
||||
|
||||
public double InitPrice { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
namespace SladkieBulkiContrakts.ViewModels;
|
||||
|
||||
public class PostViewModel
|
||||
{
|
||||
public required string Id { get; set; }
|
||||
|
||||
public required string PostName { get; set; }
|
||||
|
||||
public required string PostType { get; set; }
|
||||
|
||||
public required string Configuration { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
using SladkieBulkiContrakts.BindingModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SladkieBulkiContrakts.ViewModels;
|
||||
|
||||
public class ProductViewModel
|
||||
{
|
||||
public required string Id { get; set; }
|
||||
public required string Name { get; set; }
|
||||
public required string Description { get; set; }
|
||||
public required double UnitPrice { get; set; }
|
||||
public required string ProductType { get; set; }
|
||||
public bool IsDeleted { get; set; }
|
||||
public List<IngredientViewModel> Ingredients { get; set; } = [];
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SladkieBulkiContrakts.ViewModels;
|
||||
|
||||
public class ProductWithIngredientsViewModel
|
||||
{
|
||||
public required string Name { get; set; }
|
||||
public required string Description { get; set; }
|
||||
public required string ProductType { get; set; }
|
||||
public double UnitPrice { get; set; }
|
||||
public required List<IngredientInProductViewModel> Ingredients { get; set; }
|
||||
}
|
||||
|
||||
public class IngredientInProductViewModel
|
||||
{
|
||||
public required string NameIngredients { get; set; }
|
||||
public required string SizeUnit { get; set; }
|
||||
public double InitPrice { get; set; }
|
||||
public int Count { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SladkieBulkiContrakts.ViewModels;
|
||||
|
||||
public class ProductionViewModel
|
||||
{
|
||||
public string Id { get; set; } = default!;
|
||||
public DateTime ProductionDate { get; set; }
|
||||
public int Count { get; set; }
|
||||
public double Sum { get; set; }
|
||||
public string WorkerId { get; set; } = default!;
|
||||
public string ProductId { get; set; } = default!;
|
||||
public string Name { get; set; } = default!;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SladkieBulkiContrakts.ViewModels;
|
||||
|
||||
public class SalaryViewModel
|
||||
{
|
||||
public required string WorkerId { get; set; }
|
||||
public required string WorkerFIO { get; set; }
|
||||
public DateTime SalaryDate { get; set; }
|
||||
public double WorkerSalary { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SladkieBulkiContrakts.ViewModels;
|
||||
|
||||
public class WorkerSalaryByPeriodViewModel
|
||||
{
|
||||
public required string WorkerFIO { get; set; }
|
||||
|
||||
public double TotalSalary { get; set; }
|
||||
|
||||
public DateTime FromPeriod { get; set; }
|
||||
|
||||
public DateTime ToPeriod { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
namespace SladkieBulkiContrakts.ViewModels;
|
||||
|
||||
public class WorkerViewModel
|
||||
{
|
||||
public required string Id { get; set; }
|
||||
public required string FIO { get; set; }
|
||||
public required string PostId { get; set; }
|
||||
public required string PostName { get; set; }
|
||||
public required string Email { get; set; }
|
||||
public bool IsDeleted { get; set; }
|
||||
public DateTime BirthDate { get; set; }
|
||||
public DateTime EmploymentDate { get; set; }
|
||||
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using SladkieBulkiContrakts.Infrastructure;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SladkieBulkiDatabase;
|
||||
|
||||
class DefaultConfigurationDatabase : IConfigurationDatabase
|
||||
{
|
||||
public string ConnectionString => "";
|
||||
}
|
||||
@@ -0,0 +1,159 @@
|
||||
using AutoMapper;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Npgsql;
|
||||
using SladkieBulkiContrakts.DataModels;
|
||||
using SladkieBulkiContrakts.Exceptions;
|
||||
using SladkieBulkiContrakts.StoragesContarcts;
|
||||
using SladkieBulkiDatabase.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SladkieBulkiDatabase.Implementations;
|
||||
|
||||
internal class IngredientStorageContract : IIngredientStorageContract
|
||||
{
|
||||
private readonly SladkieBulkiDbContext _dbContext;
|
||||
private readonly Mapper _mapper;
|
||||
|
||||
public IngredientStorageContract(SladkieBulkiDbContext sladkieBulkiDbContext)
|
||||
{
|
||||
_dbContext = sladkieBulkiDbContext;
|
||||
var config = new MapperConfiguration(cfg =>
|
||||
{
|
||||
cfg.CreateMap<Ingredient, IngredientDataModel>();
|
||||
cfg.CreateMap<IngredientDataModel, Ingredient>();
|
||||
});
|
||||
_mapper = new Mapper(config);
|
||||
}
|
||||
|
||||
public List<IngredientDataModel> GetList()
|
||||
{
|
||||
try
|
||||
{
|
||||
return [.. _dbContext.Ingredients.Select(x => _mapper.Map<IngredientDataModel>(x))];
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<List<IngredientDataModel>> GetListAsync(CancellationToken ct)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
return [.. await _dbContext.Ingredients
|
||||
.Select(x => _mapper.Map<IngredientDataModel>(x))
|
||||
.ToListAsync(ct)];
|
||||
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public IngredientDataModel? GetElementById(string id)
|
||||
{
|
||||
try
|
||||
{
|
||||
return _mapper.Map<IngredientDataModel>(GetIngredientById(id));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public IngredientDataModel? GetElementByName(string nameIngredients)
|
||||
{
|
||||
try
|
||||
{
|
||||
return _mapper.Map<IngredientDataModel>(_dbContext.Ingredients.FirstOrDefault(x => x.NameIngredients == nameIngredients));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public List<IngredientDataModel>? GetElementBySizeUnit(string sizeInit)
|
||||
{
|
||||
try
|
||||
{
|
||||
var ingredients = _dbContext.Ingredients.Where(x => x.SizeInit == sizeInit).ToList();
|
||||
|
||||
return _mapper.Map<List<IngredientDataModel>>(ingredients);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public void AddElement(IngredientDataModel ingredientDataModel)
|
||||
{
|
||||
try
|
||||
{
|
||||
_dbContext.Ingredients.Add(_mapper.Map<Ingredient>(ingredientDataModel));
|
||||
_dbContext.SaveChanges();
|
||||
}
|
||||
catch (InvalidOperationException ex) when (ex.TargetSite?.Name == "ThrowIdentityConflict")
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new ElementExistsException("Id", ingredientDataModel.Id);
|
||||
}
|
||||
catch (DbUpdateException ex) when (ex.InnerException is PostgresException { ConstraintName: "IX_Ingredients_NameIngridients" })
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new ElementExistsException("NameIngredients", ingredientDataModel.NameIngredients);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void UpdElement(IngredientDataModel ingredientDataModel)
|
||||
{
|
||||
try
|
||||
{
|
||||
var element = GetIngredientById(ingredientDataModel.Id) ?? throw new ElementNotFoundException(ingredientDataModel.Id);
|
||||
_dbContext.Ingredients.Update(_mapper.Map(ingredientDataModel, element));
|
||||
_dbContext.SaveChanges();
|
||||
}
|
||||
catch (ElementNotFoundException)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw;
|
||||
}
|
||||
catch (DbUpdateException ex) when (ex.InnerException is PostgresException { ConstraintName: "IX_Ingredients_NameIngridients" })
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new ElementExistsException("NameIngredients", ingredientDataModel.NameIngredients);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
private Ingredient? GetIngredientById(string id) => _dbContext.Ingredients.FirstOrDefault(x => x.Id == id);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,191 @@
|
||||
using AutoMapper;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Npgsql;
|
||||
using SladkieBulkiContrakts.DataModels;
|
||||
using SladkieBulkiContrakts.Exceptions;
|
||||
using SladkieBulkiContrakts.StoragesContarcts;
|
||||
using SladkieBulkiDatabase.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SladkieBulkiDatabase.Implementations;
|
||||
|
||||
internal class PostStorageContract : IPostStorageContract
|
||||
{
|
||||
private readonly SladkieBulkiDbContext _dbContext;
|
||||
private readonly Mapper _mapper;
|
||||
|
||||
public PostStorageContract(SladkieBulkiDbContext dbContext)
|
||||
{
|
||||
_dbContext = dbContext;
|
||||
var config = new MapperConfiguration(cfg =>
|
||||
{
|
||||
cfg.CreateMap<Post, PostDataModel>()
|
||||
.ForMember(x => x.Id, x => x.MapFrom(src => src.PostId));
|
||||
cfg.CreateMap<PostDataModel, Post>()
|
||||
.ForMember(x => x.Id, x => x.Ignore())
|
||||
.ForMember(x => x.PostId, x => x.MapFrom(src => src.Id))
|
||||
.ForMember(x => x.IsActual, x => x.MapFrom(src => true))
|
||||
.ForMember(x => x.ChangeDate, x => x.MapFrom(src => DateTime.UtcNow))
|
||||
.ForMember(x => x.Configuration, x => x.MapFrom(src => src.ConfigurationModel));
|
||||
});
|
||||
_mapper = new Mapper(config);
|
||||
}
|
||||
|
||||
public List<PostDataModel> GetList()
|
||||
{
|
||||
try
|
||||
{
|
||||
return [.. _dbContext.Posts.Select(x => _mapper.Map<PostDataModel>(x))];
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public List<PostDataModel> GetPostWithHistory(string postId)
|
||||
{
|
||||
try
|
||||
{
|
||||
return [.. _dbContext.Posts.Where(x => x.PostId == postId).Select(x => _mapper.Map<PostDataModel>(x))];
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public PostDataModel? GetElementById(string id)
|
||||
{
|
||||
try
|
||||
{
|
||||
return _mapper.Map<PostDataModel>(_dbContext.Posts.FirstOrDefault(x => x.PostId == id && x.IsActual));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public PostDataModel? GetElementByName(string name)
|
||||
{
|
||||
try
|
||||
{
|
||||
return _mapper.Map<PostDataModel>(_dbContext.Posts.FirstOrDefault(x => x.PostName == name && x.IsActual));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public void AddElement(PostDataModel postDataModel)
|
||||
{
|
||||
try
|
||||
{
|
||||
_dbContext.Posts.Add(_mapper.Map<Post>(postDataModel));
|
||||
_dbContext.SaveChanges();
|
||||
}
|
||||
catch (DbUpdateException ex) when (ex.InnerException is PostgresException { ConstraintName: "IX_Posts_PostName_IsActual" })
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new ElementExistsException("PostName", postDataModel.PostName);
|
||||
}
|
||||
catch (DbUpdateException ex) when (ex.InnerException is PostgresException { ConstraintName: "IX_Posts_PostId_IsActual" })
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new ElementExistsException("PostId", postDataModel.Id);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdElement(PostDataModel postDataModel)
|
||||
{
|
||||
try
|
||||
{
|
||||
var transaction = _dbContext.Database.BeginTransaction();
|
||||
try
|
||||
{
|
||||
var element = GetPostById(postDataModel.Id) ?? throw new ElementNotFoundException(postDataModel.Id);
|
||||
if (!element.IsActual)
|
||||
{
|
||||
throw new ElementDeletedException(postDataModel.Id);
|
||||
}
|
||||
element.IsActual = false;
|
||||
_dbContext.SaveChanges();
|
||||
var newElement = _mapper.Map<Post>(postDataModel);
|
||||
_dbContext.Posts.Add(newElement);
|
||||
_dbContext.SaveChanges();
|
||||
transaction.Commit();
|
||||
}
|
||||
catch
|
||||
{
|
||||
transaction.Rollback();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
catch (DbUpdateException ex) when (ex.InnerException is PostgresException { ConstraintName: "IX_Posts_PostName_IsActual" })
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new ElementExistsException("PostName", postDataModel.PostName);
|
||||
}
|
||||
catch (Exception ex) when (ex is ElementDeletedException || ex is ElementNotFoundException)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public void DelElement(string id)
|
||||
{
|
||||
try
|
||||
{
|
||||
var element = GetPostById(id) ?? throw new ElementNotFoundException(id);
|
||||
if (!element.IsActual)
|
||||
{
|
||||
throw new ElementDeletedException(id);
|
||||
}
|
||||
element.IsActual = false;
|
||||
_dbContext.SaveChanges();
|
||||
}
|
||||
catch
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public void ResElement(string id)
|
||||
{
|
||||
try
|
||||
{
|
||||
var element = GetPostById(id) ?? throw new ElementNotFoundException(id);
|
||||
element.IsActual = true;
|
||||
_dbContext.SaveChanges();
|
||||
}
|
||||
catch
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
private Post? GetPostById(string id) => _dbContext.Posts.Where(x => x.PostId == id).OrderByDescending(x => x.ChangeDate).FirstOrDefault();
|
||||
}
|
||||
@@ -0,0 +1,239 @@
|
||||
using AutoMapper;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Npgsql;
|
||||
using SladkieBulkiContrakts.DataModels;
|
||||
using SladkieBulkiContrakts.Exceptions;
|
||||
using SladkieBulkiContrakts.StoragesContarcts;
|
||||
using SladkieBulkiDatabase.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SladkieBulkiDatabase.Implementations;
|
||||
|
||||
internal class ProductStorageContract : IProductStorageContract
|
||||
{
|
||||
private readonly SladkieBulkiDbContext _dbContext;
|
||||
private readonly Mapper _mapper;
|
||||
|
||||
public ProductStorageContract(SladkieBulkiDbContext dbContext)
|
||||
{
|
||||
_dbContext = dbContext;
|
||||
var config = new MapperConfiguration(cfg =>
|
||||
{
|
||||
cfg.CreateMap<ProductIngredient, ProductIngredientDataModel>();
|
||||
cfg.CreateMap<ProductIngredientDataModel, ProductIngredient>();
|
||||
cfg.CreateMap<Product, ProductDataModel>()
|
||||
.ForMember(dest => dest.Ingredients,
|
||||
opt => opt.MapFrom(src =>
|
||||
src.ProductIngredients != null
|
||||
? src.ProductIngredients.Select(pi => new ProductIngredientDataModel(
|
||||
pi.ProductId,
|
||||
pi.IngredientId,
|
||||
pi.Count)).ToList()
|
||||
: new List<ProductIngredientDataModel>()));
|
||||
cfg.CreateMap<ProductDataModel, Product>()
|
||||
.ForMember(x => x.IsDeleted, x => x.MapFrom(src => false))
|
||||
.ForMember(x => x.ProductIngredients, x => x.MapFrom(src => src.Ingredients));
|
||||
cfg.CreateMap<ProductHistory, ProductHistoryDataModel>();
|
||||
});
|
||||
_mapper = new Mapper(config);
|
||||
}
|
||||
|
||||
|
||||
public List<ProductDataModel> GetList(bool onlyActive = true)
|
||||
{
|
||||
try
|
||||
{
|
||||
var query = _dbContext.Products.Include(x => x.ProductIngredients).AsQueryable();
|
||||
if (onlyActive)
|
||||
{
|
||||
query = query.Where(x => !x.IsDeleted);
|
||||
}
|
||||
return [.. query.Select(x => _mapper.Map<ProductDataModel>(x))];
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<List<ProductDataModel>> GetListAsync(CancellationToken ct)
|
||||
{
|
||||
try
|
||||
{
|
||||
return [.. await _dbContext.Products
|
||||
.Include(x => x.ProductIngredients) // Загружаем связи продукт-ингредиент
|
||||
.Select(x => _mapper.Map<ProductDataModel>(x))
|
||||
.ToListAsync(ct)];
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public List<ProductHistoryDataModel> GetHistoryByProductId(string productId)
|
||||
{
|
||||
try
|
||||
{
|
||||
return _dbContext.ProductHistories
|
||||
.Where(x => x.ProductId == productId)
|
||||
.OrderByDescending(x => x.ChangeDate)
|
||||
.Select(x => _mapper.Map<ProductHistoryDataModel>(x)).ToList();
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public ProductDataModel? GetElementById(string id)
|
||||
{
|
||||
try
|
||||
{
|
||||
return _mapper.Map<ProductDataModel>(GetProductById(id));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public ProductDataModel? GetElementByName(string name)
|
||||
{
|
||||
try
|
||||
{
|
||||
return _mapper.Map<ProductDataModel>(
|
||||
_dbContext.Products.FirstOrDefault(x => x.Name == name && !x.IsDeleted));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public void AddElement(ProductDataModel productDataModel)
|
||||
{
|
||||
try
|
||||
{
|
||||
_dbContext.Products.Add(_mapper.Map<Product>(productDataModel));
|
||||
_dbContext.SaveChanges();
|
||||
}
|
||||
catch (InvalidOperationException ex) when (ex.TargetSite?.Name == "ThrowIdentityConflict")
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new ElementExistsException("Id", productDataModel.Id);
|
||||
}
|
||||
catch (DbUpdateException ex) when (ex.InnerException is PostgresException pgEx &&
|
||||
pgEx.ConstraintName == "IX_Products_Name_IsDeleted")
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new ElementExistsException("Name", productDataModel.Name);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void UpdElement(ProductDataModel productDataModel)
|
||||
{
|
||||
try
|
||||
{
|
||||
using var transaction = _dbContext.Database.BeginTransaction();
|
||||
try
|
||||
{
|
||||
var element = GetProductById(productDataModel.Id)
|
||||
?? throw new ElementNotFoundException(productDataModel.Id);
|
||||
|
||||
if (element.IsDeleted)
|
||||
throw new ElementDeletedException(productDataModel.Id);
|
||||
|
||||
// Проверяем, если цена изменилась, то добавляем её в историю
|
||||
if (element.UnitPrice != productDataModel.UnitPrice)
|
||||
{
|
||||
_dbContext.ProductHistories.Add(new ProductHistory
|
||||
{
|
||||
ProductId = element.Id,
|
||||
OldPrice = element.UnitPrice
|
||||
});
|
||||
_dbContext.SaveChanges();
|
||||
}
|
||||
|
||||
// Обновляем флаг IsDeleted, если он изменился
|
||||
if (element.IsDeleted != productDataModel.IsDeleted)
|
||||
{
|
||||
element.IsDeleted = productDataModel.IsDeleted;
|
||||
}
|
||||
|
||||
// Маппим остальные данные
|
||||
_mapper.Map(productDataModel, element);
|
||||
_dbContext.SaveChanges();
|
||||
transaction.Commit();
|
||||
}
|
||||
catch
|
||||
{
|
||||
transaction.Rollback();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
catch (DbUpdateException ex) when (ex.InnerException is PostgresException postgresEx && postgresEx.SqlState == "23505" && postgresEx.ConstraintName == "IX_Products_Name_IsDeleted")
|
||||
{
|
||||
// Обработка ошибки уникальности
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new ElementExistsException("Name", productDataModel.Name);
|
||||
}
|
||||
catch (Exception ex) when (ex is ElementDeletedException || ex is ElementNotFoundException)
|
||||
{
|
||||
// Перекидываем только специфичные ошибки
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// В случае других исключений — логируем ошибку
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void DelElement(string id)
|
||||
{
|
||||
try
|
||||
{
|
||||
var element = GetProductById(id) ?? throw new ElementNotFoundException(id);
|
||||
element.IsDeleted = true;
|
||||
_dbContext.SaveChanges();
|
||||
}
|
||||
catch (ElementNotFoundException)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
private Product? GetProductById(string id) =>
|
||||
_dbContext.Products.FirstOrDefault(x => x.Id == id && !x.IsDeleted);
|
||||
}
|
||||
@@ -0,0 +1,124 @@
|
||||
using AutoMapper;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using SladkieBulkiContrakts.Exceptions;
|
||||
using SladkieBulkiContrakts.StoragesContarcts;
|
||||
using SladkieBulkiDatabase.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SladkieBulkiDatabase.Implementations;
|
||||
|
||||
internal class ProductionStorageContract : IProductionStorageContract
|
||||
{
|
||||
private readonly SladkieBulkiDbContext _dbContext;
|
||||
private readonly Mapper _mapper;
|
||||
|
||||
public ProductionStorageContract(SladkieBulkiDbContext dbContext)
|
||||
{
|
||||
_dbContext = dbContext;
|
||||
var config = new MapperConfiguration(cfg =>
|
||||
{
|
||||
cfg.CreateMap<Production, ProductionDataModel>();
|
||||
cfg.CreateMap<ProductionDataModel, Production>()
|
||||
.ForMember(dest => dest.Worker, opt => opt.Ignore())
|
||||
.ForMember(dest => dest.Product, opt => opt.Ignore());
|
||||
});
|
||||
_mapper = new Mapper(config);
|
||||
}
|
||||
|
||||
public List<ProductionDataModel> GetList(DateTime? startDate = null, DateTime? endDate = null, string? workerId = null, string? productId = null)
|
||||
{
|
||||
try
|
||||
{
|
||||
var query = _dbContext.Productions.AsQueryable();
|
||||
|
||||
if (startDate is not null && endDate is not null)
|
||||
{
|
||||
query = query.Where(p => p.ProductionDate >= startDate && p.ProductionDate < endDate);
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(workerId))
|
||||
{
|
||||
query = query.Where(p => p.WorkerId == workerId);
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(productId))
|
||||
{
|
||||
query = query.Where(p => p.ProductId == productId);
|
||||
}
|
||||
|
||||
return [.. query.Select(p => _mapper.Map<ProductionDataModel>(p))];
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<List<ProductionDataModel>> GetListAsync(DateTime startDate, DateTime endDate, CancellationToken ct)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
return [.. await _dbContext.Productions
|
||||
.Where(p => p.ProductionDate >= startDate && p.ProductionDate <= endDate)
|
||||
.Select(p => _mapper.Map<ProductionDataModel>(p))
|
||||
.ToListAsync(ct)];
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public ProductionDataModel? GetElementById(string id)
|
||||
{
|
||||
try
|
||||
{
|
||||
return _mapper.Map<ProductionDataModel>(GetProductionById(id));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public void AddElement(ProductionDataModel productionDataModel)
|
||||
{
|
||||
try
|
||||
{
|
||||
_dbContext.Productions.Add(_mapper.Map<Production>(productionDataModel));
|
||||
_dbContext.SaveChanges();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public void DelElement(string id)
|
||||
{
|
||||
var element = GetProductionById(id);
|
||||
if (element == null)
|
||||
{
|
||||
throw new ElementNotFoundException($"Element not found at value = {id}");
|
||||
}
|
||||
|
||||
_dbContext.Productions.Remove(element);
|
||||
_dbContext.SaveChanges();
|
||||
}
|
||||
|
||||
|
||||
|
||||
private Production? GetProductionById(string id)
|
||||
{
|
||||
return _dbContext.Productions.FirstOrDefault(p => p.Id == id);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
using AutoMapper;
|
||||
using SladkieBulkiContrakts.DataModels;
|
||||
using SladkieBulkiContrakts.Exceptions;
|
||||
using SladkieBulkiContrakts.StoragesContarcts;
|
||||
using SladkieBulkiDatabase.Models;
|
||||
using SladkieBulkiDatabase;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
internal class SalaryStorageContract : ISalaryStorageContract
|
||||
{
|
||||
private readonly SladkieBulkiDbContext _dbContext;
|
||||
private readonly Mapper _mapper;
|
||||
|
||||
public SalaryStorageContract(SladkieBulkiDbContext dbContext)
|
||||
{
|
||||
_dbContext = dbContext;
|
||||
var config = new MapperConfiguration(cfg =>
|
||||
{
|
||||
cfg.CreateMap<Worker, WorkerDataModel>();
|
||||
cfg.CreateMap<Salary, SalaryDataModel>();
|
||||
cfg.CreateMap<SalaryDataModel, Salary>()
|
||||
.ForMember(dest => dest.WorkerSalary, opt => opt.MapFrom(src => src.WorkerSalary));
|
||||
});
|
||||
_mapper = new Mapper(config);
|
||||
}
|
||||
|
||||
public List<SalaryDataModel> GetList(DateTime startDate, DateTime endDate, string? workerId = null)
|
||||
{
|
||||
try
|
||||
{
|
||||
var query = _dbContext.Salaries.Include(x => x.Worker)
|
||||
.Where(x => x.SalaryDate >= startDate && x.SalaryDate <= endDate);
|
||||
if (workerId is not null)
|
||||
{
|
||||
query = query.Where(x => x.WorkerId == workerId);
|
||||
}
|
||||
return [.. query.Select(x => _mapper.Map<SalaryDataModel>(x))];
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<List<SalaryDataModel>> GetListAsync(DateTime startDate, DateTime endDate, CancellationToken ct)
|
||||
{
|
||||
try
|
||||
{
|
||||
return [.. await _dbContext.Salaries.Include(x => x.Worker).Where(x => x.SalaryDate >= startDate && x.SalaryDate <= endDate).Select(x => _mapper.Map<SalaryDataModel>(x)).ToListAsync(ct)];
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public void AddElement(SalaryDataModel salaryDataModel)
|
||||
{
|
||||
try
|
||||
{
|
||||
_dbContext.Salaries.Add(_mapper.Map<Salary>(salaryDataModel));
|
||||
_dbContext.SaveChanges();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,168 @@
|
||||
using AutoMapper;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Npgsql;
|
||||
using SladkieBulkiContrakts.DataModels;
|
||||
using SladkieBulkiContrakts.Exceptions;
|
||||
using SladkieBulkiContrakts.StoragesContarcts;
|
||||
using SladkieBulkiDatabase.Models;
|
||||
|
||||
namespace SladkieBulkiDatabase.Implementations;
|
||||
|
||||
internal class WorkerStorageContract : IWorkerStorageContract
|
||||
{
|
||||
private readonly SladkieBulkiDbContext _dbContext;
|
||||
private readonly Mapper _mapper;
|
||||
|
||||
public WorkerStorageContract(SladkieBulkiDbContext dbContext)
|
||||
{
|
||||
_dbContext = dbContext;
|
||||
var config = new MapperConfiguration(cfg =>
|
||||
{
|
||||
cfg.CreateMap<Post, PostDataModel>()
|
||||
.ForMember(x => x.Id, x => x.MapFrom(src => src.PostId));
|
||||
cfg.CreateMap<Worker, WorkerDataModel>();
|
||||
cfg.CreateMap<WorkerDataModel, Worker>();
|
||||
});
|
||||
_mapper = new Mapper(config);
|
||||
}
|
||||
|
||||
public List<WorkerDataModel> GetList(bool onlyActive = true, string? postId = null, DateTime? fromBirthDate = null, DateTime? toBirthDate = null, DateTime? fromEmploymentDate = null, DateTime? toEmploymentDate = null)
|
||||
{
|
||||
try
|
||||
{
|
||||
var query = _dbContext.Workers.AsQueryable();
|
||||
if (onlyActive)
|
||||
{
|
||||
query = query.Where(x => !x.IsDeleted);
|
||||
}
|
||||
if (postId is not null)
|
||||
{
|
||||
query = query.Where(x => x.PostId == postId);
|
||||
}
|
||||
if (fromBirthDate is not null && toBirthDate is not null)
|
||||
{
|
||||
query = query.Where(x => x.BirthDate >= fromBirthDate && x.BirthDate <= toBirthDate);
|
||||
}
|
||||
if (fromEmploymentDate is not null && toEmploymentDate is not null)
|
||||
{
|
||||
query = query.Where(x => x.EmploymentDate >= fromEmploymentDate && x.EmploymentDate <= toEmploymentDate);
|
||||
}
|
||||
return [.. JoinPost(query).Select(x => _mapper.Map<WorkerDataModel>(x))];
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public WorkerDataModel? GetElementById(string id)
|
||||
{
|
||||
try
|
||||
{
|
||||
return _mapper.Map<WorkerDataModel>(GetWorkerById(id));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public WorkerDataModel? GetElementByFIO(string fio)
|
||||
{
|
||||
try
|
||||
{
|
||||
return _mapper.Map<WorkerDataModel>(AddPost(_dbContext.Workers.FirstOrDefault(x => x.FIO == fio && !x.IsDeleted)));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public void AddElement(WorkerDataModel workerDataModel)
|
||||
{
|
||||
try
|
||||
{
|
||||
_dbContext.Workers.Add(_mapper.Map<Worker>(workerDataModel));
|
||||
_dbContext.SaveChanges();
|
||||
}
|
||||
catch (InvalidOperationException ex) when (ex.TargetSite?.Name == "ThrowIdentityConflict")
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new ElementExistsException("Id", workerDataModel.Id);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdElement(WorkerDataModel workerDataModel)
|
||||
{
|
||||
try
|
||||
{
|
||||
var element = GetWorkerById(workerDataModel.Id) ?? throw new ElementNotFoundException(workerDataModel.Id);
|
||||
_dbContext.Workers.Update(_mapper.Map(workerDataModel, element));
|
||||
_dbContext.SaveChanges();
|
||||
}
|
||||
catch (ElementNotFoundException)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public void DelElement(string id)
|
||||
{
|
||||
try
|
||||
{
|
||||
var element = GetWorkerById(id) ?? throw new ElementNotFoundException(id);
|
||||
element.IsDeleted = true;
|
||||
element.DateOfDelete = DateTime.UtcNow;
|
||||
_dbContext.SaveChanges();
|
||||
}
|
||||
catch (ElementNotFoundException)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public int GetWorkerTrend(DateTime fromPeriod, DateTime toPeriod)
|
||||
{
|
||||
try
|
||||
{
|
||||
var countWorkersOnBegining = _dbContext.Workers.Count(x => x.EmploymentDate < fromPeriod && (!x.IsDeleted || x.DateOfDelete > fromPeriod));
|
||||
var countWorkersOnEnding = _dbContext.Workers.Count(x => x.EmploymentDate < toPeriod && (!x.IsDeleted || x.DateOfDelete > toPeriod));
|
||||
return countWorkersOnEnding - countWorkersOnBegining;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
private Worker? GetWorkerById(string id) => AddPost(_dbContext.Workers.FirstOrDefault(x => x.Id == id && !x.IsDeleted));
|
||||
|
||||
private IQueryable<Worker> JoinPost(IQueryable<Worker> query)
|
||||
=> query.GroupJoin(_dbContext.Posts.Where(x => x.IsActual), x => x.PostId, y => y.PostId, (x, y) => new { Worker = x, Post = y })
|
||||
.SelectMany(xy => xy.Post.DefaultIfEmpty(), (x, y) => x.Worker.AddPost(y));
|
||||
|
||||
private Worker? AddPost(Worker? worker)
|
||||
=> worker?.AddPost(_dbContext.Posts.FirstOrDefault(x => x.PostId == worker.PostId && x.IsActual));
|
||||
}
|
||||
363
SladkieBulki/SladkieBulkiDatabase/Migrations/20250520155308_FirstMigration.Designer.cs
generated
Normal file
363
SladkieBulki/SladkieBulkiDatabase/Migrations/20250520155308_FirstMigration.Designer.cs
generated
Normal file
@@ -0,0 +1,363 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
using SladkieBulkiDatabase;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace SladkieBulkiDatabase.Migrations
|
||||
{
|
||||
[DbContext(typeof(SladkieBulkiDbContext))]
|
||||
[Migration("20250520155308_FirstMigration")]
|
||||
partial class FirstMigration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "9.0.4")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||
|
||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("SladkieBulkiDatabase.Models.Ingredient", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<double>("InitPrice")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.Property<string>("NameIngredients")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("SizeInit")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("NameIngredients")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("Ingredients");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SladkieBulkiDatabase.Models.IngredientHistory", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTime>("ChangeDate")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.Property<string>("IngredienId")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<double>("OldPrice")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("IngredienId");
|
||||
|
||||
b.ToTable("IngredientHistories");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SladkieBulkiDatabase.Models.Post", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTime>("ChangeDate")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.Property<bool>("IsActual")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<string>("PostId")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("PostName")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int>("PostType")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<double>("Salary")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("PostId", "IsActual")
|
||||
.IsUnique()
|
||||
.HasFilter("\"IsActual\" = TRUE");
|
||||
|
||||
b.HasIndex("PostName", "IsActual")
|
||||
.IsUnique()
|
||||
.HasFilter("\"IsActual\" = TRUE");
|
||||
|
||||
b.ToTable("Posts");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SladkieBulkiDatabase.Models.Product", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("Description")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<bool>("IsDeleted")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int>("ProductType")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("UnitPrice")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("Name", "IsDeleted")
|
||||
.IsUnique()
|
||||
.HasFilter("\"IsDeleted\" = FALSE");
|
||||
|
||||
b.ToTable("Products");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SladkieBulkiDatabase.Models.ProductHistory", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTime>("ChangeDate")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.Property<double>("OldPrice")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.Property<string>("ProductId")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ProductId");
|
||||
|
||||
b.ToTable("ProductHistories");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SladkieBulkiDatabase.Models.ProductIngredient", b =>
|
||||
{
|
||||
b.Property<string>("ProductId")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("IngredientId")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("ProductId", "IngredientId");
|
||||
|
||||
b.HasIndex("IngredientId");
|
||||
|
||||
b.ToTable("ProductIngredients");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SladkieBulkiDatabase.Models.Production", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<string>("ProductId")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTime>("ProductionDate")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.Property<double>("Sum")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.Property<string>("WorkerId")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ProductId");
|
||||
|
||||
b.HasIndex("WorkerId");
|
||||
|
||||
b.ToTable("Productions");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SladkieBulkiDatabase.Models.Salary", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTime>("SalaryDate")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.Property<string>("WorkerId")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<double>("WorkerSalary")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("WorkerId");
|
||||
|
||||
b.ToTable("Salaries");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SladkieBulkiDatabase.Models.Worker", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTime>("BirthDate")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.Property<string>("Email")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTime>("EmploymentDate")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.Property<string>("FIO")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<bool>("IsDeleted")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<string>("PostId")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Workers");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SladkieBulkiDatabase.Models.IngredientHistory", b =>
|
||||
{
|
||||
b.HasOne("SladkieBulkiDatabase.Models.Ingredient", "Ingredient")
|
||||
.WithMany("IngredientHistory")
|
||||
.HasForeignKey("IngredienId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Ingredient");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SladkieBulkiDatabase.Models.ProductHistory", b =>
|
||||
{
|
||||
b.HasOne("SladkieBulkiDatabase.Models.Product", "Product")
|
||||
.WithMany("ProductHistories")
|
||||
.HasForeignKey("ProductId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Product");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SladkieBulkiDatabase.Models.ProductIngredient", b =>
|
||||
{
|
||||
b.HasOne("SladkieBulkiDatabase.Models.Ingredient", "Ingredient")
|
||||
.WithMany("ProductIngredients")
|
||||
.HasForeignKey("IngredientId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("SladkieBulkiDatabase.Models.Product", "Product")
|
||||
.WithMany("ProductIngredients")
|
||||
.HasForeignKey("ProductId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Ingredient");
|
||||
|
||||
b.Navigation("Product");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SladkieBulkiDatabase.Models.Production", b =>
|
||||
{
|
||||
b.HasOne("SladkieBulkiDatabase.Models.Product", "Product")
|
||||
.WithMany("Productions")
|
||||
.HasForeignKey("ProductId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("SladkieBulkiDatabase.Models.Worker", "Worker")
|
||||
.WithMany("Productions")
|
||||
.HasForeignKey("WorkerId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Product");
|
||||
|
||||
b.Navigation("Worker");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SladkieBulkiDatabase.Models.Salary", b =>
|
||||
{
|
||||
b.HasOne("SladkieBulkiDatabase.Models.Worker", "Worker")
|
||||
.WithMany("Salaries")
|
||||
.HasForeignKey("WorkerId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Worker");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SladkieBulkiDatabase.Models.Ingredient", b =>
|
||||
{
|
||||
b.Navigation("IngredientHistory");
|
||||
|
||||
b.Navigation("ProductIngredients");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SladkieBulkiDatabase.Models.Product", b =>
|
||||
{
|
||||
b.Navigation("ProductHistories");
|
||||
|
||||
b.Navigation("ProductIngredients");
|
||||
|
||||
b.Navigation("Productions");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SladkieBulkiDatabase.Models.Worker", b =>
|
||||
{
|
||||
b.Navigation("Productions");
|
||||
|
||||
b.Navigation("Salaries");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,280 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace SladkieBulkiDatabase.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class FirstMigration : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Ingredients",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<string>(type: "text", nullable: false),
|
||||
NameIngredients = table.Column<string>(type: "text", nullable: false),
|
||||
SizeInit = table.Column<string>(type: "text", nullable: false),
|
||||
InitPrice = table.Column<double>(type: "double precision", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Ingredients", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Posts",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<string>(type: "text", nullable: false),
|
||||
PostId = table.Column<string>(type: "text", nullable: false),
|
||||
PostName = table.Column<string>(type: "text", nullable: false),
|
||||
PostType = table.Column<int>(type: "integer", nullable: false),
|
||||
Salary = table.Column<double>(type: "double precision", nullable: false),
|
||||
IsActual = table.Column<bool>(type: "boolean", nullable: false),
|
||||
ChangeDate = table.Column<DateTime>(type: "timestamp without time zone", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Posts", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Products",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<string>(type: "text", nullable: false),
|
||||
Name = table.Column<string>(type: "text", nullable: false),
|
||||
Description = table.Column<string>(type: "text", nullable: false),
|
||||
ProductType = table.Column<int>(type: "integer", nullable: false),
|
||||
UnitPrice = table.Column<int>(type: "integer", nullable: false),
|
||||
IsDeleted = table.Column<bool>(type: "boolean", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Products", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Workers",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<string>(type: "text", nullable: false),
|
||||
FIO = table.Column<string>(type: "text", nullable: false),
|
||||
PostId = table.Column<string>(type: "text", nullable: false),
|
||||
BirthDate = table.Column<DateTime>(type: "timestamp without time zone", nullable: false),
|
||||
EmploymentDate = table.Column<DateTime>(type: "timestamp without time zone", nullable: false),
|
||||
IsDeleted = table.Column<bool>(type: "boolean", nullable: false),
|
||||
Email = table.Column<string>(type: "text", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Workers", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "IngredientHistories",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<string>(type: "text", nullable: false),
|
||||
IngredienId = table.Column<string>(type: "text", nullable: false),
|
||||
OldPrice = table.Column<double>(type: "double precision", nullable: false),
|
||||
ChangeDate = table.Column<DateTime>(type: "timestamp without time zone", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_IngredientHistories", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_IngredientHistories_Ingredients_IngredienId",
|
||||
column: x => x.IngredienId,
|
||||
principalTable: "Ingredients",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "ProductHistories",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<string>(type: "text", nullable: false),
|
||||
ProductId = table.Column<string>(type: "text", nullable: false),
|
||||
OldPrice = table.Column<double>(type: "double precision", nullable: false),
|
||||
ChangeDate = table.Column<DateTime>(type: "timestamp without time zone", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_ProductHistories", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_ProductHistories_Products_ProductId",
|
||||
column: x => x.ProductId,
|
||||
principalTable: "Products",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "ProductIngredients",
|
||||
columns: table => new
|
||||
{
|
||||
ProductId = table.Column<string>(type: "text", nullable: false),
|
||||
IngredientId = table.Column<string>(type: "text", nullable: false),
|
||||
Count = table.Column<int>(type: "integer", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_ProductIngredients", x => new { x.ProductId, x.IngredientId });
|
||||
table.ForeignKey(
|
||||
name: "FK_ProductIngredients_Ingredients_IngredientId",
|
||||
column: x => x.IngredientId,
|
||||
principalTable: "Ingredients",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
table.ForeignKey(
|
||||
name: "FK_ProductIngredients_Products_ProductId",
|
||||
column: x => x.ProductId,
|
||||
principalTable: "Products",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Productions",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<string>(type: "text", nullable: false),
|
||||
ProductionDate = table.Column<DateTime>(type: "timestamp without time zone", nullable: false),
|
||||
Count = table.Column<int>(type: "integer", nullable: false),
|
||||
Sum = table.Column<double>(type: "double precision", nullable: false),
|
||||
WorkerId = table.Column<string>(type: "text", nullable: false),
|
||||
ProductId = table.Column<string>(type: "text", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Productions", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_Productions_Products_ProductId",
|
||||
column: x => x.ProductId,
|
||||
principalTable: "Products",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
table.ForeignKey(
|
||||
name: "FK_Productions_Workers_WorkerId",
|
||||
column: x => x.WorkerId,
|
||||
principalTable: "Workers",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Salaries",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<string>(type: "text", nullable: false),
|
||||
WorkerId = table.Column<string>(type: "text", nullable: false),
|
||||
SalaryDate = table.Column<DateTime>(type: "timestamp without time zone", nullable: false),
|
||||
WorkerSalary = table.Column<double>(type: "double precision", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Salaries", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_Salaries_Workers_WorkerId",
|
||||
column: x => x.WorkerId,
|
||||
principalTable: "Workers",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_IngredientHistories_IngredienId",
|
||||
table: "IngredientHistories",
|
||||
column: "IngredienId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Ingredients_NameIngredients",
|
||||
table: "Ingredients",
|
||||
column: "NameIngredients",
|
||||
unique: true);
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Posts_PostId_IsActual",
|
||||
table: "Posts",
|
||||
columns: new[] { "PostId", "IsActual" },
|
||||
unique: true,
|
||||
filter: "\"IsActual\" = TRUE");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Posts_PostName_IsActual",
|
||||
table: "Posts",
|
||||
columns: new[] { "PostName", "IsActual" },
|
||||
unique: true,
|
||||
filter: "\"IsActual\" = TRUE");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_ProductHistories_ProductId",
|
||||
table: "ProductHistories",
|
||||
column: "ProductId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_ProductIngredients_IngredientId",
|
||||
table: "ProductIngredients",
|
||||
column: "IngredientId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Productions_ProductId",
|
||||
table: "Productions",
|
||||
column: "ProductId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Productions_WorkerId",
|
||||
table: "Productions",
|
||||
column: "WorkerId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Products_Name_IsDeleted",
|
||||
table: "Products",
|
||||
columns: new[] { "Name", "IsDeleted" },
|
||||
unique: true,
|
||||
filter: "\"IsDeleted\" = FALSE");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Salaries_WorkerId",
|
||||
table: "Salaries",
|
||||
column: "WorkerId");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "IngredientHistories");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Posts");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "ProductHistories");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "ProductIngredients");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Productions");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Salaries");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Ingredients");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Products");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Workers");
|
||||
}
|
||||
}
|
||||
}
|
||||
364
SladkieBulki/SladkieBulkiDatabase/Migrations/20250520203540_ChangeFieldsInPost.Designer.cs
generated
Normal file
364
SladkieBulki/SladkieBulkiDatabase/Migrations/20250520203540_ChangeFieldsInPost.Designer.cs
generated
Normal file
@@ -0,0 +1,364 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
using SladkieBulkiDatabase;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace SladkieBulkiDatabase.Migrations
|
||||
{
|
||||
[DbContext(typeof(SladkieBulkiDbContext))]
|
||||
[Migration("20250520203540_ChangeFieldsInPost")]
|
||||
partial class ChangeFieldsInPost
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "9.0.4")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||
|
||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("SladkieBulkiDatabase.Models.Ingredient", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<double>("InitPrice")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.Property<string>("NameIngredients")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("SizeInit")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("NameIngredients")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("Ingredients");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SladkieBulkiDatabase.Models.IngredientHistory", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTime>("ChangeDate")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.Property<string>("IngredienId")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<double>("OldPrice")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("IngredienId");
|
||||
|
||||
b.ToTable("IngredientHistories");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SladkieBulkiDatabase.Models.Post", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTime>("ChangeDate")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.Property<string>("Configuration")
|
||||
.IsRequired()
|
||||
.HasColumnType("jsonb");
|
||||
|
||||
b.Property<bool>("IsActual")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<string>("PostId")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("PostName")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int>("PostType")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("PostId", "IsActual")
|
||||
.IsUnique()
|
||||
.HasFilter("\"IsActual\" = TRUE");
|
||||
|
||||
b.HasIndex("PostName", "IsActual")
|
||||
.IsUnique()
|
||||
.HasFilter("\"IsActual\" = TRUE");
|
||||
|
||||
b.ToTable("Posts");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SladkieBulkiDatabase.Models.Product", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("Description")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<bool>("IsDeleted")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int>("ProductType")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("UnitPrice")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("Name", "IsDeleted")
|
||||
.IsUnique()
|
||||
.HasFilter("\"IsDeleted\" = FALSE");
|
||||
|
||||
b.ToTable("Products");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SladkieBulkiDatabase.Models.ProductHistory", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTime>("ChangeDate")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.Property<double>("OldPrice")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.Property<string>("ProductId")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ProductId");
|
||||
|
||||
b.ToTable("ProductHistories");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SladkieBulkiDatabase.Models.ProductIngredient", b =>
|
||||
{
|
||||
b.Property<string>("ProductId")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("IngredientId")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("ProductId", "IngredientId");
|
||||
|
||||
b.HasIndex("IngredientId");
|
||||
|
||||
b.ToTable("ProductIngredients");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SladkieBulkiDatabase.Models.Production", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<string>("ProductId")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTime>("ProductionDate")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.Property<double>("Sum")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.Property<string>("WorkerId")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ProductId");
|
||||
|
||||
b.HasIndex("WorkerId");
|
||||
|
||||
b.ToTable("Productions");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SladkieBulkiDatabase.Models.Salary", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTime>("SalaryDate")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.Property<string>("WorkerId")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<double>("WorkerSalary")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("WorkerId");
|
||||
|
||||
b.ToTable("Salaries");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SladkieBulkiDatabase.Models.Worker", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTime>("BirthDate")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.Property<string>("Email")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTime>("EmploymentDate")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.Property<string>("FIO")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<bool>("IsDeleted")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<string>("PostId")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Workers");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SladkieBulkiDatabase.Models.IngredientHistory", b =>
|
||||
{
|
||||
b.HasOne("SladkieBulkiDatabase.Models.Ingredient", "Ingredient")
|
||||
.WithMany("IngredientHistory")
|
||||
.HasForeignKey("IngredienId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Ingredient");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SladkieBulkiDatabase.Models.ProductHistory", b =>
|
||||
{
|
||||
b.HasOne("SladkieBulkiDatabase.Models.Product", "Product")
|
||||
.WithMany("ProductHistories")
|
||||
.HasForeignKey("ProductId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Product");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SladkieBulkiDatabase.Models.ProductIngredient", b =>
|
||||
{
|
||||
b.HasOne("SladkieBulkiDatabase.Models.Ingredient", "Ingredient")
|
||||
.WithMany("ProductIngredients")
|
||||
.HasForeignKey("IngredientId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("SladkieBulkiDatabase.Models.Product", "Product")
|
||||
.WithMany("ProductIngredients")
|
||||
.HasForeignKey("ProductId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Ingredient");
|
||||
|
||||
b.Navigation("Product");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SladkieBulkiDatabase.Models.Production", b =>
|
||||
{
|
||||
b.HasOne("SladkieBulkiDatabase.Models.Product", "Product")
|
||||
.WithMany("Productions")
|
||||
.HasForeignKey("ProductId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("SladkieBulkiDatabase.Models.Worker", "Worker")
|
||||
.WithMany("Productions")
|
||||
.HasForeignKey("WorkerId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Product");
|
||||
|
||||
b.Navigation("Worker");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SladkieBulkiDatabase.Models.Salary", b =>
|
||||
{
|
||||
b.HasOne("SladkieBulkiDatabase.Models.Worker", "Worker")
|
||||
.WithMany("Salaries")
|
||||
.HasForeignKey("WorkerId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Worker");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SladkieBulkiDatabase.Models.Ingredient", b =>
|
||||
{
|
||||
b.Navigation("IngredientHistory");
|
||||
|
||||
b.Navigation("ProductIngredients");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SladkieBulkiDatabase.Models.Product", b =>
|
||||
{
|
||||
b.Navigation("ProductHistories");
|
||||
|
||||
b.Navigation("ProductIngredients");
|
||||
|
||||
b.Navigation("Productions");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SladkieBulkiDatabase.Models.Worker", b =>
|
||||
{
|
||||
b.Navigation("Productions");
|
||||
|
||||
b.Navigation("Salaries");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace SladkieBulkiDatabase.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class ChangeFieldsInPost : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropColumn(
|
||||
name: "Salary",
|
||||
table: "Posts");
|
||||
|
||||
migrationBuilder.AddColumn<string>(
|
||||
name: "Configuration",
|
||||
table: "Posts",
|
||||
type: "jsonb",
|
||||
nullable: false,
|
||||
defaultValue: "{\"Rate\": 0, \"Type\": \"PostConfiguration\"}");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropColumn(
|
||||
name: "Configuration",
|
||||
table: "Posts");
|
||||
|
||||
migrationBuilder.AddColumn<double>(
|
||||
name: "Salary",
|
||||
table: "Posts",
|
||||
type: "double precision",
|
||||
nullable: false,
|
||||
defaultValue: 0.0);
|
||||
}
|
||||
}
|
||||
}
|
||||
367
SladkieBulki/SladkieBulkiDatabase/Migrations/20250520222914_AddDateOfDeleteInWorker.Designer.cs
generated
Normal file
367
SladkieBulki/SladkieBulkiDatabase/Migrations/20250520222914_AddDateOfDeleteInWorker.Designer.cs
generated
Normal file
@@ -0,0 +1,367 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
using SladkieBulkiDatabase;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace SladkieBulkiDatabase.Migrations
|
||||
{
|
||||
[DbContext(typeof(SladkieBulkiDbContext))]
|
||||
[Migration("20250520222914_AddDateOfDeleteInWorker")]
|
||||
partial class AddDateOfDeleteInWorker
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "9.0.4")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||
|
||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("SladkieBulkiDatabase.Models.Ingredient", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<double>("InitPrice")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.Property<string>("NameIngredients")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("SizeInit")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("NameIngredients")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("Ingredients");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SladkieBulkiDatabase.Models.IngredientHistory", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTime>("ChangeDate")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.Property<string>("IngredienId")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<double>("OldPrice")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("IngredienId");
|
||||
|
||||
b.ToTable("IngredientHistories");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SladkieBulkiDatabase.Models.Post", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTime>("ChangeDate")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.Property<string>("Configuration")
|
||||
.IsRequired()
|
||||
.HasColumnType("jsonb");
|
||||
|
||||
b.Property<bool>("IsActual")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<string>("PostId")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("PostName")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int>("PostType")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("PostId", "IsActual")
|
||||
.IsUnique()
|
||||
.HasFilter("\"IsActual\" = TRUE");
|
||||
|
||||
b.HasIndex("PostName", "IsActual")
|
||||
.IsUnique()
|
||||
.HasFilter("\"IsActual\" = TRUE");
|
||||
|
||||
b.ToTable("Posts");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SladkieBulkiDatabase.Models.Product", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("Description")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<bool>("IsDeleted")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int>("ProductType")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("UnitPrice")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("Name", "IsDeleted")
|
||||
.IsUnique()
|
||||
.HasFilter("\"IsDeleted\" = FALSE");
|
||||
|
||||
b.ToTable("Products");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SladkieBulkiDatabase.Models.ProductHistory", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTime>("ChangeDate")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.Property<double>("OldPrice")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.Property<string>("ProductId")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ProductId");
|
||||
|
||||
b.ToTable("ProductHistories");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SladkieBulkiDatabase.Models.ProductIngredient", b =>
|
||||
{
|
||||
b.Property<string>("ProductId")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("IngredientId")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("ProductId", "IngredientId");
|
||||
|
||||
b.HasIndex("IngredientId");
|
||||
|
||||
b.ToTable("ProductIngredients");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SladkieBulkiDatabase.Models.Production", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<string>("ProductId")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTime>("ProductionDate")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.Property<double>("Sum")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.Property<string>("WorkerId")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ProductId");
|
||||
|
||||
b.HasIndex("WorkerId");
|
||||
|
||||
b.ToTable("Productions");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SladkieBulkiDatabase.Models.Salary", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTime>("SalaryDate")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.Property<string>("WorkerId")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<double>("WorkerSalary")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("WorkerId");
|
||||
|
||||
b.ToTable("Salaries");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SladkieBulkiDatabase.Models.Worker", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTime>("BirthDate")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.Property<DateTime?>("DateOfDelete")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.Property<string>("Email")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTime>("EmploymentDate")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.Property<string>("FIO")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<bool>("IsDeleted")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<string>("PostId")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Workers");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SladkieBulkiDatabase.Models.IngredientHistory", b =>
|
||||
{
|
||||
b.HasOne("SladkieBulkiDatabase.Models.Ingredient", "Ingredient")
|
||||
.WithMany("IngredientHistory")
|
||||
.HasForeignKey("IngredienId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Ingredient");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SladkieBulkiDatabase.Models.ProductHistory", b =>
|
||||
{
|
||||
b.HasOne("SladkieBulkiDatabase.Models.Product", "Product")
|
||||
.WithMany("ProductHistories")
|
||||
.HasForeignKey("ProductId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Product");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SladkieBulkiDatabase.Models.ProductIngredient", b =>
|
||||
{
|
||||
b.HasOne("SladkieBulkiDatabase.Models.Ingredient", "Ingredient")
|
||||
.WithMany("ProductIngredients")
|
||||
.HasForeignKey("IngredientId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("SladkieBulkiDatabase.Models.Product", "Product")
|
||||
.WithMany("ProductIngredients")
|
||||
.HasForeignKey("ProductId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Ingredient");
|
||||
|
||||
b.Navigation("Product");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SladkieBulkiDatabase.Models.Production", b =>
|
||||
{
|
||||
b.HasOne("SladkieBulkiDatabase.Models.Product", "Product")
|
||||
.WithMany("Productions")
|
||||
.HasForeignKey("ProductId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("SladkieBulkiDatabase.Models.Worker", "Worker")
|
||||
.WithMany("Productions")
|
||||
.HasForeignKey("WorkerId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Product");
|
||||
|
||||
b.Navigation("Worker");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SladkieBulkiDatabase.Models.Salary", b =>
|
||||
{
|
||||
b.HasOne("SladkieBulkiDatabase.Models.Worker", "Worker")
|
||||
.WithMany("Salaries")
|
||||
.HasForeignKey("WorkerId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Worker");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SladkieBulkiDatabase.Models.Ingredient", b =>
|
||||
{
|
||||
b.Navigation("IngredientHistory");
|
||||
|
||||
b.Navigation("ProductIngredients");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SladkieBulkiDatabase.Models.Product", b =>
|
||||
{
|
||||
b.Navigation("ProductHistories");
|
||||
|
||||
b.Navigation("ProductIngredients");
|
||||
|
||||
b.Navigation("Productions");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SladkieBulkiDatabase.Models.Worker", b =>
|
||||
{
|
||||
b.Navigation("Productions");
|
||||
|
||||
b.Navigation("Salaries");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace SladkieBulkiDatabase.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class AddDateOfDeleteInWorker : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AddColumn<DateTime>(
|
||||
name: "DateOfDelete",
|
||||
table: "Workers",
|
||||
type: "timestamp without time zone",
|
||||
nullable: true);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropColumn(
|
||||
name: "DateOfDelete",
|
||||
table: "Workers");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,364 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
using SladkieBulkiDatabase;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace SladkieBulkiDatabase.Migrations
|
||||
{
|
||||
[DbContext(typeof(SladkieBulkiDbContext))]
|
||||
partial class SladkieBulkiDbContextModelSnapshot : ModelSnapshot
|
||||
{
|
||||
protected override void BuildModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "9.0.4")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||
|
||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("SladkieBulkiDatabase.Models.Ingredient", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<double>("InitPrice")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.Property<string>("NameIngredients")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("SizeInit")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("NameIngredients")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("Ingredients");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SladkieBulkiDatabase.Models.IngredientHistory", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTime>("ChangeDate")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.Property<string>("IngredienId")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<double>("OldPrice")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("IngredienId");
|
||||
|
||||
b.ToTable("IngredientHistories");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SladkieBulkiDatabase.Models.Post", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTime>("ChangeDate")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.Property<string>("Configuration")
|
||||
.IsRequired()
|
||||
.HasColumnType("jsonb");
|
||||
|
||||
b.Property<bool>("IsActual")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<string>("PostId")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("PostName")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int>("PostType")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("PostId", "IsActual")
|
||||
.IsUnique()
|
||||
.HasFilter("\"IsActual\" = TRUE");
|
||||
|
||||
b.HasIndex("PostName", "IsActual")
|
||||
.IsUnique()
|
||||
.HasFilter("\"IsActual\" = TRUE");
|
||||
|
||||
b.ToTable("Posts");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SladkieBulkiDatabase.Models.Product", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("Description")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<bool>("IsDeleted")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int>("ProductType")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("UnitPrice")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("Name", "IsDeleted")
|
||||
.IsUnique()
|
||||
.HasFilter("\"IsDeleted\" = FALSE");
|
||||
|
||||
b.ToTable("Products");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SladkieBulkiDatabase.Models.ProductHistory", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTime>("ChangeDate")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.Property<double>("OldPrice")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.Property<string>("ProductId")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ProductId");
|
||||
|
||||
b.ToTable("ProductHistories");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SladkieBulkiDatabase.Models.ProductIngredient", b =>
|
||||
{
|
||||
b.Property<string>("ProductId")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("IngredientId")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("ProductId", "IngredientId");
|
||||
|
||||
b.HasIndex("IngredientId");
|
||||
|
||||
b.ToTable("ProductIngredients");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SladkieBulkiDatabase.Models.Production", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<string>("ProductId")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTime>("ProductionDate")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.Property<double>("Sum")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.Property<string>("WorkerId")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ProductId");
|
||||
|
||||
b.HasIndex("WorkerId");
|
||||
|
||||
b.ToTable("Productions");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SladkieBulkiDatabase.Models.Salary", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTime>("SalaryDate")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.Property<string>("WorkerId")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<double>("WorkerSalary")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("WorkerId");
|
||||
|
||||
b.ToTable("Salaries");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SladkieBulkiDatabase.Models.Worker", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTime>("BirthDate")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.Property<DateTime?>("DateOfDelete")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.Property<string>("Email")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTime>("EmploymentDate")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.Property<string>("FIO")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<bool>("IsDeleted")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<string>("PostId")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Workers");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SladkieBulkiDatabase.Models.IngredientHistory", b =>
|
||||
{
|
||||
b.HasOne("SladkieBulkiDatabase.Models.Ingredient", "Ingredient")
|
||||
.WithMany("IngredientHistory")
|
||||
.HasForeignKey("IngredienId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Ingredient");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SladkieBulkiDatabase.Models.ProductHistory", b =>
|
||||
{
|
||||
b.HasOne("SladkieBulkiDatabase.Models.Product", "Product")
|
||||
.WithMany("ProductHistories")
|
||||
.HasForeignKey("ProductId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Product");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SladkieBulkiDatabase.Models.ProductIngredient", b =>
|
||||
{
|
||||
b.HasOne("SladkieBulkiDatabase.Models.Ingredient", "Ingredient")
|
||||
.WithMany("ProductIngredients")
|
||||
.HasForeignKey("IngredientId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("SladkieBulkiDatabase.Models.Product", "Product")
|
||||
.WithMany("ProductIngredients")
|
||||
.HasForeignKey("ProductId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Ingredient");
|
||||
|
||||
b.Navigation("Product");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SladkieBulkiDatabase.Models.Production", b =>
|
||||
{
|
||||
b.HasOne("SladkieBulkiDatabase.Models.Product", "Product")
|
||||
.WithMany("Productions")
|
||||
.HasForeignKey("ProductId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("SladkieBulkiDatabase.Models.Worker", "Worker")
|
||||
.WithMany("Productions")
|
||||
.HasForeignKey("WorkerId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Product");
|
||||
|
||||
b.Navigation("Worker");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SladkieBulkiDatabase.Models.Salary", b =>
|
||||
{
|
||||
b.HasOne("SladkieBulkiDatabase.Models.Worker", "Worker")
|
||||
.WithMany("Salaries")
|
||||
.HasForeignKey("WorkerId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Worker");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SladkieBulkiDatabase.Models.Ingredient", b =>
|
||||
{
|
||||
b.Navigation("IngredientHistory");
|
||||
|
||||
b.Navigation("ProductIngredients");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SladkieBulkiDatabase.Models.Product", b =>
|
||||
{
|
||||
b.Navigation("ProductHistories");
|
||||
|
||||
b.Navigation("ProductIngredients");
|
||||
|
||||
b.Navigation("Productions");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SladkieBulkiDatabase.Models.Worker", b =>
|
||||
{
|
||||
b.Navigation("Productions");
|
||||
|
||||
b.Navigation("Salaries");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
22
SladkieBulki/SladkieBulkiDatabase/Models/Ingredient.cs
Normal file
22
SladkieBulki/SladkieBulkiDatabase/Models/Ingredient.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SladkieBulkiDatabase.Models;
|
||||
|
||||
internal class Ingredient
|
||||
{
|
||||
public required string Id { get; set; } = Guid.NewGuid().ToString();
|
||||
public required string NameIngredients { get; set; }
|
||||
public required string SizeInit { get; set; }
|
||||
public double InitPrice { get; set; }
|
||||
|
||||
[ForeignKey("IngredientId")]
|
||||
public List<ProductIngredient>? ProductIngredients { get; set; }
|
||||
|
||||
[ForeignKey("IngredienId")]
|
||||
public List<IngredientHistory>? IngredientHistory { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SladkieBulkiDatabase.Models;
|
||||
|
||||
internal class IngredientHistory
|
||||
{
|
||||
public string Id { get; set; }
|
||||
public required string IngredienId { get; set; }
|
||||
public double OldPrice { get; set; }
|
||||
public DateTime ChangeDate { get; set; }
|
||||
public Ingredient Ingredient { get; set; }
|
||||
}
|
||||
20
SladkieBulki/SladkieBulkiDatabase/Models/Post.cs
Normal file
20
SladkieBulki/SladkieBulkiDatabase/Models/Post.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
using SladkieBulkiContrakts.Enums;
|
||||
using SladkieBulkiContrakts.Infrastructure.PostConfigurations;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SladkieBulkiDatabase.Models;
|
||||
|
||||
internal class Post
|
||||
{
|
||||
public required string Id { get; set; } = Guid.NewGuid().ToString();
|
||||
public required string PostId { get; set; }
|
||||
public required string PostName { get; set; }
|
||||
public PostType PostType { get; set; }
|
||||
public required PostConfiguration Configuration { get; set; }
|
||||
public bool IsActual { get; set; }
|
||||
public DateTime ChangeDate { get; set; }
|
||||
}
|
||||
30
SladkieBulki/SladkieBulkiDatabase/Models/Product.cs
Normal file
30
SladkieBulki/SladkieBulkiDatabase/Models/Product.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
using SladkieBulkiContrakts.DataModels;
|
||||
using SladkieBulkiContrakts.Enums;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace SladkieBulkiDatabase.Models;
|
||||
|
||||
internal class Product
|
||||
{
|
||||
public required string Id { get; set; }
|
||||
public required string Name { get; set; }
|
||||
public required string Description { get; set; }
|
||||
public ProductType ProductType { get; set; }
|
||||
public int UnitPrice { get; set; }
|
||||
public bool IsDeleted { get; set; }
|
||||
|
||||
[ForeignKey("ProductId")]
|
||||
public List<ProductIngredient>? ProductIngredients { get; set; }
|
||||
|
||||
[ForeignKey("ProductId")]
|
||||
public List<Production>? Productions { get; set; }
|
||||
|
||||
[ForeignKey("ProductId")]
|
||||
public List<ProductHistory>? ProductHistories { get; set; }
|
||||
}
|
||||
16
SladkieBulki/SladkieBulkiDatabase/Models/ProductHistory.cs
Normal file
16
SladkieBulki/SladkieBulkiDatabase/Models/ProductHistory.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SladkieBulkiDatabase.Models;
|
||||
|
||||
internal class ProductHistory
|
||||
{
|
||||
public string Id { get; set; } = Guid.NewGuid().ToString();
|
||||
public required string ProductId { get; set; }
|
||||
public double OldPrice { get; set; }
|
||||
public DateTime ChangeDate { get; set; } = DateTime.UtcNow;
|
||||
public Product? Product { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SladkieBulkiDatabase.Models;
|
||||
|
||||
internal class ProductIngredient
|
||||
{
|
||||
public required string ProductId { get; set; }
|
||||
public required string IngredientId { get; set; }
|
||||
public int Count { get; set; }
|
||||
public Ingredient? Ingredient { get; set; }
|
||||
public Product? Product { get; set; }
|
||||
}
|
||||
22
SladkieBulki/SladkieBulkiDatabase/Models/Production.cs
Normal file
22
SladkieBulki/SladkieBulkiDatabase/Models/Production.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SladkieBulkiDatabase.Models;
|
||||
|
||||
internal class Production
|
||||
{
|
||||
public string Id { get; set; } = Guid.NewGuid().ToString();
|
||||
public DateTime ProductionDate { get; set; }
|
||||
public int Count { get; set; }
|
||||
public double Sum { get; set; }
|
||||
public required string WorkerId { get; set; }
|
||||
public required string ProductId { get; set; }
|
||||
public Worker? Worker { get; set; }
|
||||
public Product? Product { get; set; }
|
||||
|
||||
|
||||
}
|
||||
18
SladkieBulki/SladkieBulkiDatabase/Models/Salary.cs
Normal file
18
SladkieBulki/SladkieBulkiDatabase/Models/Salary.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using AutoMapper;
|
||||
using SladkieBulkiContrakts.DataModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SladkieBulkiDatabase.Models;
|
||||
|
||||
internal class Salary
|
||||
{
|
||||
public string Id { get; set; } = Guid.NewGuid().ToString();
|
||||
public required string WorkerId { get; set; }
|
||||
public DateTime SalaryDate { get; set; }
|
||||
public double WorkerSalary { get; set; }
|
||||
public Worker? Worker { get; set; }
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user