Compare commits
45 Commits
Task_1_Mod
...
Task_6_Rep
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9699999f8a | ||
|
|
1b6691fa23 | ||
|
|
95e254c5c1 | ||
|
|
8c31a8d9e2 | ||
|
|
beb2573977 | ||
|
|
551fb7d000 | ||
|
|
77837c6c90 | ||
|
|
0db164d1a9 | ||
|
|
d88a07037a | ||
|
|
378aa945dc | ||
|
|
b6177d2b4d | ||
|
|
2c33509cb1 | ||
|
|
67c5a3b13d | ||
|
|
4c0050e498 | ||
|
|
4f92cf60d6 | ||
|
|
6da51e4ac6 | ||
|
|
31edceff7d | ||
|
|
f9f9219bc5 | ||
|
|
494f92118a | ||
|
|
1848377cfd | ||
|
|
65f4941d68 | ||
|
|
fffe3e49ed | ||
|
|
f41d3dc92a | ||
|
|
c9a3ad3045 | ||
|
|
171eb51621 | ||
|
|
a2f2c86fe9 | ||
|
|
a4b783c295 | ||
|
|
07ad196f6a | ||
|
|
3f9ad38a9c | ||
|
|
ef340be62a | ||
|
|
37affb0114 | ||
|
|
a325a6558c | ||
|
|
822291ea91 | ||
|
|
0dd30af08c | ||
|
|
8493b4e3c2 | ||
|
|
d9e9892505 | ||
|
|
1d1812acea | ||
|
|
6654a24aff | ||
|
|
edb377c4bb | ||
|
|
c28280efa3 | ||
|
|
63845fbf27 | ||
|
|
1a01d118c3 | ||
|
|
a9aa6b3481 | ||
|
|
24c2125935 | ||
|
|
4699447735 |
13
TwoFromTheCasketContratcs/.idea/.idea.TwoFromTheCasketContratcs/.idea/.gitignore
generated
vendored
Normal file
13
TwoFromTheCasketContratcs/.idea/.idea.TwoFromTheCasketContratcs/.idea/.gitignore
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# Rider ignored files
|
||||
/.idea.TwoFromTheCasketContratcs.iml
|
||||
/projectSettingsUpdater.xml
|
||||
/modules.xml
|
||||
/contentModel.xml
|
||||
# Editor-based HTTP Client requests
|
||||
/httpRequests/
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
||||
4
TwoFromTheCasketContratcs/.idea/.idea.TwoFromTheCasketContratcs/.idea/encodings.xml
generated
Normal file
4
TwoFromTheCasketContratcs/.idea/.idea.TwoFromTheCasketContratcs/.idea/encodings.xml
generated
Normal file
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Encoding" addBOMForNewFiles="with BOM under Windows, with no BOM otherwise" />
|
||||
</project>
|
||||
8
TwoFromTheCasketContratcs/.idea/.idea.TwoFromTheCasketContratcs/.idea/indexLayout.xml
generated
Normal file
8
TwoFromTheCasketContratcs/.idea/.idea.TwoFromTheCasketContratcs/.idea/indexLayout.xml
generated
Normal file
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="UserContentModel">
|
||||
<attachedFolders />
|
||||
<explicitIncludes />
|
||||
<explicitExcludes />
|
||||
</component>
|
||||
</project>
|
||||
6
TwoFromTheCasketContratcs/.idea/.idea.TwoFromTheCasketContratcs/.idea/vcs.xml
generated
Normal file
6
TwoFromTheCasketContratcs/.idea/.idea.TwoFromTheCasketContratcs/.idea/vcs.xml
generated
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
@@ -0,0 +1,121 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using TwoFromTheCasketContratcs.BuisnessLogicsContracts;
|
||||
using TwoFromTheCasketContratcs.DataModels;
|
||||
using TwoFromTheCasketContratcs.Exceptions;
|
||||
using TwoFromTheCasketContratcs.Extensions;
|
||||
using TwoFromTheCasketContratcs.StorageContracts;
|
||||
|
||||
namespace TwoFromTheCasketBuisnessLogic.Implementations;
|
||||
|
||||
internal class MasterBusinessLogicContract(IMasterStorageContract masterStorageContract, ILogger logger) : IMasterBuisnessLogicContract
|
||||
{
|
||||
ILogger _logger = logger;
|
||||
private IMasterStorageContract _masterStorageContract = masterStorageContract;
|
||||
public List<MasterDataModel> GetAllMasters(bool onlyActive = true)
|
||||
{
|
||||
_logger.LogInformation("GetAllWorkers params: {onlyActive}", onlyActive);
|
||||
return _masterStorageContract.GetList(onlyActive) ?? throw new
|
||||
NullListException();
|
||||
}
|
||||
|
||||
public List<MasterDataModel> GetAllMastersByPost(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 _masterStorageContract.GetList(onlyActive, postId) ?? throw new NullListException();
|
||||
}
|
||||
|
||||
public List<MasterDataModel> GetAllMastersByEmploymentDate(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 _masterStorageContract.GetList(onlyActive, fromEmploymentDate:
|
||||
fromDate, toEmploymentDate: toDate) ?? throw new NullListException();
|
||||
}
|
||||
|
||||
public MasterDataModel GetMasterByData(string data)
|
||||
{
|
||||
_logger.LogInformation("Get element by data: {data}", data);
|
||||
if (data.IsEmpty())
|
||||
{
|
||||
throw new ArgumentNullException(nameof(data));
|
||||
}
|
||||
if (data.IsGuid())
|
||||
{
|
||||
return _masterStorageContract.GetElementById(data) ?? throw
|
||||
new ElementNotFoundException(data);
|
||||
}
|
||||
return _masterStorageContract.GetElementByFIO(data) ?? throw new
|
||||
ElementNotFoundException(data);
|
||||
}
|
||||
|
||||
public void InsertMaster(MasterDataModel workerDataModel)
|
||||
{
|
||||
_logger.LogInformation("New data: {json}",
|
||||
JsonSerializer.Serialize(workerDataModel));
|
||||
ArgumentNullException.ThrowIfNull(workerDataModel);
|
||||
workerDataModel.Validate();
|
||||
_masterStorageContract.AddElement(workerDataModel);
|
||||
}
|
||||
|
||||
public void UpdateMaster(MasterDataModel workerDataModel)
|
||||
{
|
||||
_logger.LogInformation("Update data: {json}",
|
||||
JsonSerializer.Serialize(workerDataModel));
|
||||
ArgumentNullException.ThrowIfNull(workerDataModel);
|
||||
workerDataModel.Validate();
|
||||
_masterStorageContract.UpdElement(workerDataModel);
|
||||
}
|
||||
|
||||
public void DeleteMaster(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");
|
||||
}
|
||||
_masterStorageContract.DelElement(id);
|
||||
}
|
||||
|
||||
public List<MasterDataModel> GetAllMastersByBirthDate(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 _masterStorageContract.GetList(onlyActive, fromBirthDate: fromDate, toBirthDate: toDate) ?? throw new NullListException();
|
||||
}
|
||||
|
||||
public List<MasterDataModel> GetAllWorkersByEmploymentDate(DateTime
|
||||
fromDate, DateTime toDate, bool onlyActive = true)
|
||||
{
|
||||
_logger.LogInformation("GetAllMaster params: {onlyActive}, { fromDate}, { toDate}", onlyActive, fromDate, toDate);
|
||||
if (fromDate.IsDateNotOlder(toDate))
|
||||
{
|
||||
throw new IncorrectDatesException(fromDate, toDate);
|
||||
}
|
||||
return _masterStorageContract.GetList(onlyActive, fromEmploymentDate:
|
||||
fromDate, toEmploymentDate: toDate) ?? throw new NullListException();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using TwoFromTheCasketContratcs.BuisnessLogicsContracts;
|
||||
using TwoFromTheCasketContratcs.DataModels;
|
||||
using TwoFromTheCasketContratcs.Exceptions;
|
||||
using TwoFromTheCasketContratcs.Extensions;
|
||||
using TwoFromTheCasketContratcs.StorageContracts;
|
||||
|
||||
namespace TwoFromTheCasketBuisnessLogic.Implementations;
|
||||
|
||||
internal class OrderBusinessLogicContract(IOrderStorageContract orderStorageContract, ILogger logger) : IOrderBuisnessLogicContract
|
||||
{
|
||||
private ILogger _logger = logger;
|
||||
private IOrderStorageContract _orderStorageContract = orderStorageContract;
|
||||
public List<OrderDataModel> GetAllOrder()
|
||||
{
|
||||
_logger.LogInformation("GetAllOrders called");
|
||||
var orders = _orderStorageContract.GetList();
|
||||
if (orders == null)
|
||||
{
|
||||
throw new NullListException();
|
||||
}
|
||||
return orders;
|
||||
}
|
||||
|
||||
public OrderDataModel GetOrderByDate(DateTime fromDate)
|
||||
{
|
||||
_logger.LogInformation("GetAllOrdersByDate called with fromDate: {fromDate} to: {toDate}");
|
||||
|
||||
|
||||
return _orderStorageContract.GetElementByDate(fromDate) ?? throw new NullListException();
|
||||
}
|
||||
|
||||
public OrderDataModel GetOrderByData(string data)
|
||||
{
|
||||
_logger.LogInformation($"GetOrderByData called with data: {data}");
|
||||
if (data.IsEmpty())
|
||||
{
|
||||
throw new ArgumentNullException(nameof(data));
|
||||
}
|
||||
if (data.IsGuid())
|
||||
{
|
||||
return _orderStorageContract.GetElementById(data) ?? throw new ElementNotFoundException(data);
|
||||
}
|
||||
return _orderStorageContract.GetElementById(data) ?? throw new ElementNotFoundException(data);
|
||||
}
|
||||
|
||||
public void InsertOrder(OrderDataModel orderDataModel)
|
||||
{
|
||||
_logger.LogInformation("InsertOrder called with orderDataModel: {orderDataModel}");
|
||||
ValidateOrder(orderDataModel);
|
||||
_orderStorageContract.AddElement(orderDataModel);
|
||||
}
|
||||
|
||||
public void UpdateOrder(OrderDataModel orderDataModel)
|
||||
{
|
||||
_logger.LogInformation("UpdateOrder called with orderDataModel: {orderDataModel}");
|
||||
ValidateOrder(orderDataModel);
|
||||
_orderStorageContract.UpdElement(orderDataModel);
|
||||
}
|
||||
|
||||
public void DeleteOrder(string id)
|
||||
{
|
||||
_logger.LogInformation($"DeleteOrder called with id: {id}");
|
||||
ValidateId(id);
|
||||
_orderStorageContract.DelElement(id);
|
||||
}
|
||||
|
||||
private void ValidateOrder(OrderDataModel orderDataModel)
|
||||
{
|
||||
if (orderDataModel == null)
|
||||
throw new ArgumentNullException(nameof(orderDataModel));
|
||||
|
||||
orderDataModel.Validate();
|
||||
}
|
||||
|
||||
private void ValidateId(string id)
|
||||
{
|
||||
if (string.IsNullOrEmpty(id))
|
||||
throw new ArgumentNullException(nameof(id));
|
||||
|
||||
if (!Guid.TryParse(id, out _))
|
||||
throw new ValidationException("Id is not a unique identifier");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using TwoFromTheCasketContratcs.BuisnessLogicsContracts;
|
||||
using TwoFromTheCasketContratcs.DataModels;
|
||||
using TwoFromTheCasketContratcs.Exceptions;
|
||||
using TwoFromTheCasketContratcs.Extensions;
|
||||
using TwoFromTheCasketContratcs.StorageContracts;
|
||||
|
||||
namespace TwoFromTheCasketBuisnessLogic.Implementations;
|
||||
|
||||
internal class PostBusinessLogicContract(IPostStorageContract postStorageContract, ILogger logger) : IPostBuisnessLogicContract
|
||||
{
|
||||
private IPostStorageContract _postStorageContract = postStorageContract;
|
||||
private ILogger _logger = logger;
|
||||
|
||||
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("InsertPost called with postDataModel: {postDataModel}");
|
||||
|
||||
if (postDataModel == null)
|
||||
throw new ArgumentNullException(nameof(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,311 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using TwoFromTheCasketBuisnessLogic.OfficePackage;
|
||||
using TwoFromTheCasketContratcs.BuisnessLogicsContracts;
|
||||
using TwoFromTheCasketContratcs.DataModels;
|
||||
using TwoFromTheCasketContratcs.Exceptions;
|
||||
using TwoFromTheCasketContratcs.Extensions;
|
||||
using TwoFromTheCasketContratcs.StorageContracts;
|
||||
|
||||
namespace TwoFromTheCasketBuisnessLogic.Implementations;
|
||||
|
||||
internal class ReportContract(IServiceStorageContract serviceStorageContract, IMasterStorageContract masterStorageContract, IOrderStorageContract orderStorageContract, ISalaryStorageContract salaryStorageContract, IPostStorageContract postStorageContract, BaseWordBuilder baseWordBuilder, BaseExcelBuilder baseExcelBuilder, BasePdfBuilder basePdfBuilder, ILogger logger) : IReportContract
|
||||
{
|
||||
private readonly IServiceStorageContract _serviceStorageContract = serviceStorageContract;
|
||||
|
||||
private readonly IMasterStorageContract _masterStorageContract = masterStorageContract;
|
||||
|
||||
private readonly IOrderStorageContract _orderStorageContract = orderStorageContract;
|
||||
|
||||
private readonly ISalaryStorageContract _salaryStorageContract = salaryStorageContract;
|
||||
|
||||
private readonly IPostStorageContract _postStorageContract = postStorageContract;
|
||||
|
||||
private readonly BaseWordBuilder _baseWordBuilder = baseWordBuilder;
|
||||
|
||||
private readonly BaseExcelBuilder _baseExcelBuilder = baseExcelBuilder;
|
||||
|
||||
private readonly BasePdfBuilder _basePdfBuilder = basePdfBuilder;
|
||||
|
||||
private readonly ILogger _logger = logger;
|
||||
|
||||
internal static readonly string[] documentHeader = ["Дата", "Работа"];
|
||||
|
||||
internal static readonly string[] tableHeader = ["Дата", "Сумма", "Работа", "Объём"];
|
||||
|
||||
public async Task<Stream> CreateDocumentServicesWithHistoryAsync(DateTime dateStart, DateTime dateFinish, CancellationToken ct)
|
||||
{
|
||||
var services = await GetDataServicesWithHistoryAsync(dateStart, dateFinish, ct);
|
||||
var builder = _baseWordBuilder
|
||||
.AddHeader("Отчет по услугам и их истории изменений")
|
||||
.AddParagraph($"Период: с {dateStart:dd.MM.yyyy} по {dateFinish:dd.MM.yyyy}")
|
||||
.AddParagraph($"Отчёт сформирован: {DateTime.Now:dd.MM.yyyy HH:mm}");
|
||||
|
||||
if (!services.Any())
|
||||
{
|
||||
builder.AddParagraph("За указанный период услуги не найдены.");
|
||||
return builder.Build();
|
||||
}
|
||||
|
||||
|
||||
var tableData = new List<string[]>
|
||||
{
|
||||
new[] { "Услуга", "Тип", "Текущая цена", "Дата изменения", "Старая цена" }
|
||||
};
|
||||
|
||||
foreach (var service in services)
|
||||
{
|
||||
if (service.History.Any())
|
||||
{
|
||||
|
||||
var sortedHistory = service.History.OrderByDescending(h => h.ChangeDate).ToList();
|
||||
|
||||
for (int i = 0; i < sortedHistory.Count; i++)
|
||||
{
|
||||
var history = sortedHistory[i];
|
||||
tableData.Add(new[]
|
||||
{
|
||||
i == 0 ? service.ServiceName : "",
|
||||
i == 0 ? service.ServiceType.ToString() : "",
|
||||
i == 0 ? service.Price.ToString("C") : "",
|
||||
history.ChangeDate.ToString("dd.MM.yyyy HH:mm"),
|
||||
history.OldPrice.ToString("C")
|
||||
});
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
tableData.Add(new[]
|
||||
{
|
||||
service.ServiceName,
|
||||
service.ServiceType.ToString(),
|
||||
service.Price.ToString("C"),
|
||||
"—",
|
||||
"—"
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
builder.AddTable(new[] { 2500, 1500, 1500, 2000, 1500 }, tableData);
|
||||
|
||||
return builder.Build();
|
||||
}
|
||||
|
||||
public async Task<Stream> CreateDocumentOrdersByPeriodAsync(DateTime dateStart, DateTime dateFinish, CancellationToken ct)
|
||||
{
|
||||
var orders = await GetDataOrderByPeriodAsync(dateStart, dateFinish, ct);
|
||||
|
||||
var tableData = new List<string[]> { new[] { "Дата заказа", "Статус", "Тип помещения", "Мастер", "Услуга", "Время работы", "Сумма" } };
|
||||
|
||||
foreach (var order in orders)
|
||||
{
|
||||
|
||||
var orderDetails = await GetOrderDetailsAsync(order.Id, ct);
|
||||
|
||||
if (orderDetails.Any())
|
||||
{
|
||||
foreach (var detail in orderDetails)
|
||||
{
|
||||
tableData.Add(new[]
|
||||
{
|
||||
order.Date.ToString("dd.MM.yyyy"),
|
||||
order.Status.ToString(),
|
||||
order.RoomType.ToString(),
|
||||
detail.MasterFIO,
|
||||
detail.ServiceName,
|
||||
$"{detail.TimeOfWorking} ч.",
|
||||
detail.TotalAmount.ToString("C")
|
||||
});
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
tableData.Add(new[]
|
||||
{
|
||||
order.Date.ToString("dd.MM.yyyy"),
|
||||
order.Status.ToString(),
|
||||
order.RoomType.ToString(),
|
||||
"Не назначен",
|
||||
"Нет услуг",
|
||||
"0 ч.",
|
||||
"0,00 ₽"
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return _baseExcelBuilder
|
||||
.AddHeader("Отчет по продажам за период", 0, 7)
|
||||
.AddParagraph($"с {dateStart.ToShortDateString()} по {dateFinish.ToShortDateString()}", 2)
|
||||
.AddTable([15, 12, 15, 20, 25, 12, 15], tableData)
|
||||
.Build();
|
||||
}
|
||||
|
||||
public async Task<Stream> CreateDocumentSalaryByPeriodAsync(DateTime dateStart, DateTime dateFinish, CancellationToken ct)
|
||||
{
|
||||
var data = await GetDataSalaryByPeriodAsync(dateStart, dateFinish, ct);
|
||||
|
||||
if (!data.Any())
|
||||
{
|
||||
return _basePdfBuilder
|
||||
.AddHeader("Зарплатная ведомость")
|
||||
.AddParagraph($"за период с {dateStart.ToShortDateString()} по {dateFinish.ToShortDateString()}")
|
||||
.AddParagraph("За указанный период зарплаты не найдены.")
|
||||
.Build();
|
||||
}
|
||||
|
||||
|
||||
var groupedData = data.GroupBy(x => x.MasterFIO)
|
||||
.Select(g => new { MasterFIO = g.Key, TotalSalary = g.Sum(x => x.TotalSalary) })
|
||||
.ToList();
|
||||
|
||||
|
||||
var tableData = new List<string[]>
|
||||
{
|
||||
new[] { "ФИО мастера", "Дата зачисления", "Сумма зарплаты" }
|
||||
};
|
||||
|
||||
foreach (var salary in data)
|
||||
{
|
||||
var row = new[]
|
||||
{
|
||||
salary.MasterFIO,
|
||||
salary.FromPeriod.ToString("dd.MM.yyyy"),
|
||||
salary.TotalSalary.ToString("C")
|
||||
};
|
||||
tableData.Add(row);
|
||||
}
|
||||
|
||||
return _basePdfBuilder
|
||||
.AddHeader("Зарплатная ведомость")
|
||||
.AddParagraph($"за период с {dateStart.ToShortDateString()} по {dateFinish.ToShortDateString()}")
|
||||
.AddPieChart("Начисления", groupedData.Select(x => (x.MasterFIO, x.TotalSalary)).ToList())
|
||||
.AddParagraph("")
|
||||
.AddTable(new[] { 200, 150, 150 }, tableData)
|
||||
.Build();
|
||||
}
|
||||
|
||||
public async Task<List<ServiceHistoryDataModel>> GetDataServiceHistoryAsync(CancellationToken ct)
|
||||
{
|
||||
var histories = new List<ServiceHistoryDataModel>();
|
||||
var services = _serviceStorageContract.GetList() ?? new List<ServiceDataModel>();
|
||||
|
||||
foreach (var service in services)
|
||||
{
|
||||
var serviceHistories = _serviceStorageContract.GetHistoryByServiceId(service.Id);
|
||||
if (serviceHistories != null)
|
||||
{
|
||||
histories.AddRange(serviceHistories);
|
||||
}
|
||||
}
|
||||
|
||||
return histories.OrderByDescending(h => h.ChangeDate).ToList();
|
||||
}
|
||||
|
||||
public async Task<List<OrderDataModel>> GetDataOrderByPeriodAsync(DateTime dateStart, DateTime dateFinish, CancellationToken ct)
|
||||
{
|
||||
if (dateStart.IsDateNotOlder(dateFinish))
|
||||
{
|
||||
throw new IncorrectDatesException(dateStart, dateFinish);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
var orders = await _orderStorageContract.GetListAsync(dateStart, dateFinish, ct);
|
||||
return orders.OrderBy(o => o.Date).ToList();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
public async Task<List<MasterSalaryByPeriodDataModel>> GetDataSalaryByPeriodAsync(DateTime dateStart, DateTime dateFinish, CancellationToken ct)
|
||||
{
|
||||
|
||||
if (dateStart > dateFinish)
|
||||
{
|
||||
throw new IncorrectDatesException(dateStart, dateFinish);
|
||||
}
|
||||
|
||||
var salaries = await _salaryStorageContract.GetListAsync(dateStart, dateFinish, ct);
|
||||
var masters = _masterStorageContract.GetList(onlyActive: true) ?? new List<MasterDataModel>();
|
||||
|
||||
var salaryRecords = salaries
|
||||
.GroupBy(salary => salary.MasterId)
|
||||
.Select(group =>
|
||||
{
|
||||
var master = masters.FirstOrDefault(m => m.Id == group.Key);
|
||||
var totalSalary = group.Sum(salary => salary.Salary + salary.Prize);
|
||||
|
||||
return new MasterSalaryByPeriodDataModel
|
||||
{
|
||||
MasterFIO = master?.FIO ?? "Неизвестный мастер",
|
||||
TotalSalary = totalSalary,
|
||||
FromPeriod = dateStart,
|
||||
ToPeriod = dateFinish
|
||||
};
|
||||
})
|
||||
.OrderBy(x => x.MasterFIO)
|
||||
.ToList();
|
||||
|
||||
return salaryRecords;
|
||||
}
|
||||
|
||||
public async Task<List<ServiceWithHistoryDataModel>> GetDataServicesWithHistoryAsync(DateTime dateStart, DateTime dateFinish, CancellationToken ct)
|
||||
{
|
||||
if (dateStart.IsDateNotOlder(dateFinish))
|
||||
{
|
||||
throw new IncorrectDatesException(dateStart, dateFinish);
|
||||
}
|
||||
|
||||
|
||||
var services = _serviceStorageContract.GetList() ?? new List<ServiceDataModel>();
|
||||
|
||||
var result = new List<ServiceWithHistoryDataModel>();
|
||||
|
||||
foreach (var service in services)
|
||||
{
|
||||
|
||||
var serviceHistories = _serviceStorageContract.GetHistoryByServiceId(service.Id) ?? new List<ServiceHistoryDataModel>();
|
||||
|
||||
|
||||
var filteredHistories = serviceHistories
|
||||
.Where(h => h.ChangeDate >= dateStart && h.ChangeDate <= dateFinish)
|
||||
.OrderByDescending(h => h.ChangeDate)
|
||||
.ToList();
|
||||
|
||||
result.Add(new ServiceWithHistoryDataModel
|
||||
{
|
||||
Id = service.Id,
|
||||
ServiceName = service.ServiceName,
|
||||
ServiceType = service.ServiceType,
|
||||
MasterId = service.MasterId,
|
||||
Price = service.Price,
|
||||
IsDeleted = service.IsDeleted,
|
||||
History = filteredHistories
|
||||
});
|
||||
}
|
||||
|
||||
return result.OrderBy(s => s.ServiceName).ToList();
|
||||
}
|
||||
|
||||
private async Task<List<(string MasterFIO, string ServiceName, int TimeOfWorking, decimal TotalAmount)>> GetOrderDetailsAsync(string orderId, CancellationToken ct)
|
||||
{
|
||||
try
|
||||
{
|
||||
return await _orderStorageContract.GetOrderDetailsAsync(orderId, ct);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return new List<(string MasterFIO, string ServiceName, int TimeOfWorking, decimal TotalAmount)>();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,213 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using TwoFromTheCasketContratcs.BuisnessLogicsContracts;
|
||||
using TwoFromTheCasketContratcs.DataModels;
|
||||
using TwoFromTheCasketContratcs.StorageContracts;
|
||||
using TwoFromTheCasketContratcs.Extensions;
|
||||
using TwoFromTheCasketContratcs.Exceptions;
|
||||
using TwoFromTheCasketContratcs.Infrastructure;
|
||||
using TwoFromTheCasketContratcs.Infrastructure.PostConfigurations;
|
||||
|
||||
namespace TwoFromTheCasketBuisnessLogic.Implementations
|
||||
{
|
||||
internal class SalaryBusinessLogicContract(ISalaryStorageContract
|
||||
salaryStorageContract, IPostStorageContract
|
||||
postStorageContract, IMasterStorageContract masterStorageContract, ILogger
|
||||
logger, IOrderStorageContract orderStorageContract, IConfigurationSalary configurationSalary) : ISalaryBuisnessLogicContract
|
||||
{
|
||||
private readonly ILogger _logger = logger;
|
||||
private readonly ISalaryStorageContract _salaryStorageContract = salaryStorageContract;
|
||||
private readonly IPostStorageContract _postStorageContract = postStorageContract;
|
||||
private readonly IMasterStorageContract _masterStorageContract = masterStorageContract;
|
||||
private readonly IOrderStorageContract _orderStorageContract = orderStorageContract;
|
||||
private readonly IConfigurationSalary _configurationSalary = configurationSalary;
|
||||
private readonly object _lockObject = new object();
|
||||
|
||||
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> GetAllSalariesByPeriodByMaster(DateTime fromDate, DateTime toDate, string masterId)
|
||||
{
|
||||
if (fromDate.IsDateNotOlder(toDate))
|
||||
{
|
||||
throw new IncorrectDatesException(fromDate, toDate);
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(masterId))
|
||||
{
|
||||
throw new ArgumentNullException(nameof(masterId));
|
||||
}
|
||||
|
||||
if (!Guid.TryParse(masterId, out _))
|
||||
{
|
||||
throw new ValidationException("The value in the field masterId is not a unique identifier.");
|
||||
}
|
||||
|
||||
_logger.LogInformation("GetAllSalaries params: {fromDate}, {toDate}, {masterId}", fromDate, toDate, masterId);
|
||||
return _salaryStorageContract.GetList(fromDate, toDate, masterId) ?? throw new NullListException();
|
||||
}
|
||||
|
||||
public void CalculateSalaryByMonth(DateTime date)
|
||||
{
|
||||
_logger.LogInformation("CalculateSalaryByMonth: {date}", date);
|
||||
var startDate = new DateTime(date.Year, date.Month, 1, 0, 0, 0, DateTimeKind.Utc);
|
||||
var finishDate = new DateTime(date.Year, date.Month, DateTime.DaysInMonth(date.Year, date.Month), 0, 0, 0, DateTimeKind.Utc);
|
||||
var masters = _masterStorageContract.GetList() ?? throw new NullListException();
|
||||
|
||||
foreach (var master in masters)
|
||||
{
|
||||
var orders = _orderStorageContract.GetList() ?? throw new NullListException();
|
||||
|
||||
// Фильтруем заказы по дате (связь с мастером идет через ServiceOrder)
|
||||
var masterOrders = orders.Where(o => o.Date >= startDate && o.Date <= finishDate).ToList();
|
||||
|
||||
var post = _postStorageContract.GetElementById(master.PostId) ?? throw new ElementNotFoundException(master.PostId);
|
||||
|
||||
var salary = post.ConfigurationModel switch
|
||||
{
|
||||
null => 0,
|
||||
CarpenterPostConfiguration cpc => CalculateSalaryForCarpenter(masterOrders, startDate, finishDate, cpc),
|
||||
PainterPostConfiguration ppc => CalculateSalaryForPainter(masterOrders, startDate, finishDate, ppc),
|
||||
PlastererPostConfiguration plpc => CalculateSalaryForPlasterer(masterOrders, startDate, finishDate, plpc),
|
||||
PostConfiguration pc => pc.Rate,
|
||||
};
|
||||
|
||||
_logger.LogDebug("The master {masterId} was paid a salary of {salary}", master.Id, salary);
|
||||
|
||||
_salaryStorageContract.AddElement(new SalaryDataModel(master.Id, finishDate, salary, 0));
|
||||
}
|
||||
|
||||
// Сохраняем все изменения одним вызовом
|
||||
_salaryStorageContract.SaveChanges();
|
||||
}
|
||||
|
||||
private double CalculateSalaryForCarpenter(List<OrderDataModel> orders, DateTime startDate, DateTime finishDate, CarpenterPostConfiguration config)
|
||||
{
|
||||
var maxThreads = Math.Max(1, _configurationSalary.MaxThreads);
|
||||
var options = new ParallelOptions { MaxDegreeOfParallelism = maxThreads };
|
||||
var calcPercent = 0.0;
|
||||
var days = new List<DateTime>();
|
||||
|
||||
for (var date = startDate; date < finishDate; date = date.AddDays(1))
|
||||
{
|
||||
days.Add(date);
|
||||
}
|
||||
|
||||
Parallel.ForEach(days, options, date =>
|
||||
{
|
||||
var ordersInDay = orders.Where(x => x.Date.Date == date.Date).ToArray();
|
||||
if (ordersInDay.Length > 0)
|
||||
{
|
||||
lock (_lockObject)
|
||||
{
|
||||
calcPercent += ordersInDay.Length * config.BonusForExtraCarpentry;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return config.Rate + calcPercent;
|
||||
}
|
||||
|
||||
private double CalculateSalaryForPainter(List<OrderDataModel> orders, DateTime startDate, DateTime finishDate, PainterPostConfiguration config)
|
||||
{
|
||||
var maxThreads = Math.Max(1, _configurationSalary.MaxThreads);
|
||||
var options = new ParallelOptions { MaxDegreeOfParallelism = maxThreads };
|
||||
var calcPercent = 0.0;
|
||||
var days = new List<DateTime>();
|
||||
|
||||
for (var date = startDate; date < finishDate; date = date.AddDays(1))
|
||||
{
|
||||
days.Add(date);
|
||||
}
|
||||
|
||||
Parallel.ForEach(days, options, date =>
|
||||
{
|
||||
var ordersInDay = orders.Where(x => x.Date.Date == date.Date).ToArray();
|
||||
if (ordersInDay.Length > 0)
|
||||
{
|
||||
lock (_lockObject)
|
||||
{
|
||||
calcPercent += ordersInDay.Length * config.PainterPercent;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
var calcBonusTask = Task.Run(() =>
|
||||
{
|
||||
return orders.Count * config.BonusForExtraPainter;
|
||||
});
|
||||
|
||||
try
|
||||
{
|
||||
calcBonusTask.Wait();
|
||||
}
|
||||
catch (AggregateException agEx)
|
||||
{
|
||||
foreach (var ex in agEx.InnerExceptions)
|
||||
{
|
||||
_logger.LogError(ex, "Error in the painter payroll process");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
return config.Rate + calcPercent + calcBonusTask.Result;
|
||||
}
|
||||
|
||||
private double CalculateSalaryForPlasterer(List<OrderDataModel> orders, DateTime startDate, DateTime finishDate, PlastererPostConfiguration config)
|
||||
{
|
||||
var maxThreads = Math.Max(1, _configurationSalary.MaxThreads);
|
||||
var options = new ParallelOptions { MaxDegreeOfParallelism = maxThreads };
|
||||
var calcPercent = 0.0;
|
||||
var days = new List<DateTime>();
|
||||
|
||||
for (var date = startDate; date < finishDate; date = date.AddDays(1))
|
||||
{
|
||||
days.Add(date);
|
||||
}
|
||||
|
||||
Parallel.ForEach(days, options, date =>
|
||||
{
|
||||
var ordersInDay = orders.Where(x => x.Date.Date == date.Date).ToArray();
|
||||
if (ordersInDay.Length > 0)
|
||||
{
|
||||
lock (_lockObject)
|
||||
{
|
||||
calcPercent += ordersInDay.Length * config.PlastererPercent;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
var calcBonusTask = Task.Run(() =>
|
||||
{
|
||||
return orders.Count * config.BonusForExtraPlasterer;
|
||||
});
|
||||
|
||||
try
|
||||
{
|
||||
calcBonusTask.Wait();
|
||||
}
|
||||
catch (AggregateException agEx)
|
||||
{
|
||||
foreach (var ex in agEx.InnerExceptions)
|
||||
{
|
||||
_logger.LogError(ex, "Error in the plasterer payroll process");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
return config.Rate + calcPercent + calcBonusTask.Result;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using TwoFromTheCasketContratcs.BuisnessLogicsContracts;
|
||||
using TwoFromTheCasketContratcs.DataModels;
|
||||
using TwoFromTheCasketContratcs.Enums;
|
||||
using TwoFromTheCasketContratcs.Exceptions;
|
||||
using TwoFromTheCasketContratcs.Extensions;
|
||||
using TwoFromTheCasketContratcs.StorageContracts;
|
||||
|
||||
namespace TwoFromTheCasketBuisnessLogic.Implementations;
|
||||
|
||||
internal class ServiceBusinessLogicContract(IServiceStorageContract serviceStorageContract, ILogger logger) : IServiceBuisnessLogicContract
|
||||
{
|
||||
ILogger _logger = logger;
|
||||
private IServiceStorageContract _serviceStorageContract = serviceStorageContract;
|
||||
public List<ServiceDataModel> GetAllServices(bool onlyActive)
|
||||
{
|
||||
_logger.LogInformation("GetAllService called");
|
||||
var services = _serviceStorageContract.GetList();
|
||||
if(services == null)
|
||||
{
|
||||
throw new NullListException();
|
||||
}
|
||||
return services;
|
||||
}
|
||||
|
||||
public List<ServiceDataModel> GetServicesByMasterId(string masterId, bool onlyActive)
|
||||
{
|
||||
_logger.LogInformation("GetAllServicesByMasterId called");
|
||||
if (masterId.IsEmpty())
|
||||
{
|
||||
throw new ArgumentNullException(nameof(masterId));
|
||||
}
|
||||
if (!masterId.IsGuid())
|
||||
{
|
||||
throw new ValidationException("The value in the field masterId is not a unique identifier.");
|
||||
}
|
||||
return _serviceStorageContract.GetElementByMasterId(masterId) ?? throw new NullListException();
|
||||
}
|
||||
|
||||
public List<ServiceDataModel> GetServicesByServiceType(ServiceType serviceType, bool onlyActive)
|
||||
{
|
||||
_logger.LogInformation($"GetServicesByServiceType called for {serviceType} (onlyActive: {onlyActive})");
|
||||
|
||||
|
||||
var allServices = _serviceStorageContract.GetList() ?? new List<ServiceDataModel>();
|
||||
|
||||
|
||||
var filteredByType = allServices.Where(s => s.ServiceType == serviceType);
|
||||
|
||||
|
||||
if (onlyActive)
|
||||
{
|
||||
filteredByType = filteredByType.Where(s => s.IsDeleted!);
|
||||
}
|
||||
|
||||
return filteredByType.ToList();
|
||||
}
|
||||
|
||||
public void InsertService(ServiceDataModel serviceDataModel)
|
||||
{
|
||||
_logger.LogInformation("New data: {json}",
|
||||
JsonSerializer.Serialize(serviceDataModel));
|
||||
ArgumentNullException.ThrowIfNull(serviceDataModel);
|
||||
serviceDataModel.Validate();
|
||||
_serviceStorageContract.AddElement(serviceDataModel);
|
||||
|
||||
}
|
||||
|
||||
public void UpdateService(ServiceDataModel serviceDataModel)
|
||||
{
|
||||
_logger.LogInformation("Update data: {json}",
|
||||
JsonSerializer.Serialize(serviceDataModel));
|
||||
ArgumentNullException.ThrowIfNull(serviceDataModel);
|
||||
serviceDataModel.Validate();
|
||||
_serviceStorageContract.UpdElement(serviceDataModel);
|
||||
}
|
||||
public void DeleteService(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");
|
||||
}
|
||||
_serviceStorageContract.DelElement(id);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace TwoFromTheCasketBuisnessLogic.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,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace TwoFromTheCasketBuisnessLogic.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 BasePdfBuilder AddTable(int[] widths, List<string[]> data);
|
||||
public abstract Stream Build();
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace TwoFromTheCasketBuisnessLogic.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,115 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations.Internal;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using MigraDoc.DocumentObjectModel;
|
||||
using MigraDoc.DocumentObjectModel.Shapes.Charts;
|
||||
using MigraDoc.Rendering;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace TwoFromTheCasketBuisnessLogic.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 BasePdfBuilder AddTable(int[] widths, List<string[]> data)
|
||||
{
|
||||
if (data == null || data.Count == 0)
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
var table = _document.LastSection.AddTable();
|
||||
table.Style = "Table";
|
||||
table.Borders.Color = Colors.Black;
|
||||
table.Borders.Width = 0.25;
|
||||
table.Borders.Left.Width = 0.5;
|
||||
table.Borders.Right.Width = 0.5;
|
||||
table.Rows.LeftIndent = 0;
|
||||
|
||||
// Настройка колонок
|
||||
for (int i = 0; i < widths.Length; i++)
|
||||
{
|
||||
var column = table.AddColumn(Unit.FromPoint(widths[i]));
|
||||
column.Format.Alignment = ParagraphAlignment.Center;
|
||||
}
|
||||
|
||||
// Добавление данных
|
||||
for (int rowIndex = 0; rowIndex < data.Count; rowIndex++)
|
||||
{
|
||||
var row = table.AddRow();
|
||||
row.HeadingFormat = (rowIndex == 0); // Первая строка - заголовок
|
||||
row.Format.Alignment = ParagraphAlignment.Center;
|
||||
row.Format.Font.Bold = (rowIndex == 0);
|
||||
|
||||
for (int colIndex = 0; colIndex < data[rowIndex].Length && colIndex < widths.Length; colIndex++)
|
||||
{
|
||||
var cell = row.Cells[colIndex];
|
||||
var cellText = data[rowIndex][colIndex];
|
||||
cell.AddParagraph(cellText);
|
||||
cell.Format.Alignment = ParagraphAlignment.Center;
|
||||
}
|
||||
}
|
||||
|
||||
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,271 @@
|
||||
using DocumentFormat.OpenXml;
|
||||
using DocumentFormat.OpenXml.Packaging;
|
||||
using DocumentFormat.OpenXml.Spreadsheet;
|
||||
|
||||
namespace TwoFromTheCasketBuisnessLogic.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,79 @@
|
||||
using DocumentFormat.OpenXml;
|
||||
using DocumentFormat.OpenXml.Packaging;
|
||||
using DocumentFormat.OpenXml.Wordprocessing;
|
||||
|
||||
namespace TwoFromTheCasketBuisnessLogic.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,26 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<InternalsVisibleTo Include="TwoFromTheCasketTest" />
|
||||
<InternalsVisibleTo Include="TwoFromTheCasketWebApi" />
|
||||
<InternalsVisibleTo Include="DynamicProxyGenAssembly2" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="DocumentFormat.OpenXml" Version="3.3.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="9.0.3" />
|
||||
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="9.0.4" />
|
||||
<PackageReference Include="PDFsharp-MigraDoc-gdi" Version="6.2.1" />
|
||||
<PackageReference Include="System.Drawing.Common" Version="9.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\TwoFromTheCasketContratcs\TwoFromTheCasketContratcs.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -7,6 +7,12 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TwoFromTheCasketContratcs",
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TwoFromTheCasketTest", "TwoFromTheCasketTest\TwoFromTheCasketTest.csproj", "{71E6B2F8-F494-4500-A887-481047D885DF}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TwoFromTheCasketBuisnessLogic", "TwoFromTheCasketBuisnessLogic\TwoFromTheCasketBuisnessLogic.csproj", "{371435E4-6D04-4302-86C8-23F063FBE57A}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TwoFromTheCasketDatabase", "TwoFromTheCasketDatabase\TwoFromTheCasketDatabase.csproj", "{C77C86D0-B620-4737-93D9-1A5A69BD7128}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TwoFromTheCasketWebApi", "TwoFromTheCasketWebApi\TwoFromTheCasketWebApi.csproj", "{9627CDA8-1A24-4093-8D46-ED40DC05C942}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@@ -21,8 +27,23 @@ Global
|
||||
{71E6B2F8-F494-4500-A887-481047D885DF}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{71E6B2F8-F494-4500-A887-481047D885DF}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{71E6B2F8-F494-4500-A887-481047D885DF}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{371435E4-6D04-4302-86C8-23F063FBE57A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{371435E4-6D04-4302-86C8-23F063FBE57A}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{371435E4-6D04-4302-86C8-23F063FBE57A}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{371435E4-6D04-4302-86C8-23F063FBE57A}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{C77C86D0-B620-4737-93D9-1A5A69BD7128}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{C77C86D0-B620-4737-93D9-1A5A69BD7128}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{C77C86D0-B620-4737-93D9-1A5A69BD7128}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{C77C86D0-B620-4737-93D9-1A5A69BD7128}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{9627CDA8-1A24-4093-8D46-ED40DC05C942}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{9627CDA8-1A24-4093-8D46-ED40DC05C942}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{9627CDA8-1A24-4093-8D46-ED40DC05C942}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{9627CDA8-1A24-4093-8D46-ED40DC05C942}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {7B5E57DB-A427-4A96-9581-F3FF00AC4923}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using TwoFromTheCasketContratcs.AdapterContracts.OperationResponses;
|
||||
using TwoFromTheCasketContratcs.BindingModels;
|
||||
using TwoFromTheCasketContratcs.DataModels;
|
||||
|
||||
namespace TwoFromTheCasketContratcs.AdapterContracts;
|
||||
|
||||
public interface IMasterAdapter
|
||||
{
|
||||
MasterOperationResponse GetList(bool onlyActive);
|
||||
|
||||
MasterOperationResponse GetListByPost(string postId, bool onlyActive);
|
||||
MasterOperationResponse GetListByBirthDate(DateTime fromDate, DateTime toDate, bool onlyActive);
|
||||
|
||||
MasterOperationResponse GetListByEmploymentDate(DateTime fromDate, DateTime toDate, bool onlyActive);
|
||||
|
||||
MasterOperationResponse GetElementByData(string data);
|
||||
|
||||
MasterOperationResponse RegisterMaster(MasterBindingModel masterModel);
|
||||
|
||||
MasterOperationResponse ChangeMasterInfo(MasterBindingModel masterModel);
|
||||
|
||||
MasterOperationResponse RemoveMaster(string id);
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
using TwoFromTheCasketContratcs.AdapterContracts.OperationResponses;
|
||||
using TwoFromTheCasketContratcs.BindingModels;
|
||||
|
||||
namespace TwoFromTheCasketContratcs.AdapterContracts;
|
||||
|
||||
public interface IOrderAdapter
|
||||
{
|
||||
OrderOperationResponse GetList();
|
||||
|
||||
OrderOperationResponse GetListByDate(DateTime fromDate);
|
||||
|
||||
OrderOperationResponse GetElementByData(string data);
|
||||
|
||||
OrderOperationResponse RegisterOrder(OrderBindingModel orderModel);
|
||||
|
||||
OrderOperationResponse ChangeOrderInfo(OrderBindingModel orderModel);
|
||||
|
||||
OrderOperationResponse RemoveOrder(string id);
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using TwoFromTheCasketContratcs.AdapterContracts.OperationResponses;
|
||||
using TwoFromTheCasketContratcs.BindingModels;
|
||||
|
||||
namespace TwoFromTheCasketContratcs.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,23 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using TwoFromTheCasketContratcs.AdapterContracts.OperationResponses;
|
||||
|
||||
namespace TwoFromTheCasketContratcs.AdapterContracts;
|
||||
|
||||
public interface IReportAdapter
|
||||
{
|
||||
Task<ReportOperationResponse> GetDataServicesWithHistoryAsync(DateTime dateStart, DateTime dateFinish, CancellationToken ct);
|
||||
|
||||
Task<ReportOperationResponse> GetDataOrderByPeriodAsync(DateTime dateStart, DateTime dateFinish, CancellationToken ct);
|
||||
|
||||
Task<ReportOperationResponse> GetDataSalaryByPeriodAsync(DateTime dateStart, DateTime dateFinish, CancellationToken ct);
|
||||
|
||||
Task<ReportOperationResponse> CreateDocumentServicesWithHistoryAsync(DateTime dateStart, DateTime dateFinish, CancellationToken ct);
|
||||
|
||||
Task<ReportOperationResponse> CreateDocumentOrdersByPeriodAsync(DateTime dateStart, DateTime dateFinish, CancellationToken ct);
|
||||
|
||||
Task<ReportOperationResponse> CreateDocumentSalaryByPeriodAsync(DateTime dateStart, DateTime dateFinish, CancellationToken ct);
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
using TwoFromTheCasketContratcs.AdapterContracts.OperationResponses;
|
||||
|
||||
namespace TwoFromTheCasketContratcs.AdapterContracts;
|
||||
|
||||
public interface ISalaryAdapter
|
||||
{
|
||||
SalaryOperationResponse GetListByPeriod(DateTime fromDate, DateTime toDate);
|
||||
SalaryOperationResponse GetListByPeriodByMaster(DateTime fromDate, DateTime toDate, string masterId);
|
||||
SalaryOperationResponse CalculateSalaryByMonth(DateTime date);
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
using TwoFromTheCasketContratcs.AdapterContracts.OperationResponses;
|
||||
using TwoFromTheCasketContratcs.BindingModels;
|
||||
using TwoFromTheCasketContratcs.Enums;
|
||||
|
||||
namespace TwoFromTheCasketContratcs.AdapterContracts;
|
||||
|
||||
public interface IServiceAdapter
|
||||
{
|
||||
ServiceOperationResponse GetList(bool onlyActive);
|
||||
ServiceOperationResponse GetListByServiceType(ServiceType serviceType, bool onlyActive);
|
||||
ServiceOperationResponse GetListByMasterId(string masterId, bool onlyActive);
|
||||
ServiceOperationResponse RegisterService(ServiceBindingModel serviceModel);
|
||||
ServiceOperationResponse ChangeServiceInfo(ServiceBindingModel serviceModel);
|
||||
ServiceOperationResponse RemoveService(string id);
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using TwoFromTheCasketContratcs.Infrastructure;
|
||||
using TwoFromTheCasketContratcs.ViewModels;
|
||||
|
||||
namespace TwoFromTheCasketContratcs.AdapterContracts.OperationResponses;
|
||||
|
||||
public class MasterOperationResponse : OperationResponse
|
||||
{
|
||||
public static MasterOperationResponse OK(List<MasterViewModel> data) => OK<MasterOperationResponse, List<MasterViewModel>>(data);
|
||||
public static MasterOperationResponse OK(MasterViewModel data) => OK<MasterOperationResponse, MasterViewModel>(data);
|
||||
public static MasterOperationResponse NoContent() => NoContent<MasterOperationResponse>();
|
||||
public static MasterOperationResponse NotFound(string message) => NotFound<MasterOperationResponse>(message);
|
||||
public static MasterOperationResponse BadRequest(string message) => BadRequest<MasterOperationResponse>(message);
|
||||
public static MasterOperationResponse InternalServerError(string message) => InternalServerError<MasterOperationResponse>(message);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using TwoFromTheCasketContratcs.Infrastructure;
|
||||
using TwoFromTheCasketContratcs.ViewModels;
|
||||
|
||||
namespace TwoFromTheCasketContratcs.AdapterContracts.OperationResponses;
|
||||
|
||||
public class OrderOperationResponse : OperationResponse
|
||||
{
|
||||
public static OrderOperationResponse OK(List<OrderViewModel> data) => OK<OrderOperationResponse, List<OrderViewModel>>(data);
|
||||
public static OrderOperationResponse OK(OrderViewModel data) => OK<OrderOperationResponse, OrderViewModel>(data);
|
||||
public static OrderOperationResponse NoContent() => NoContent<OrderOperationResponse>();
|
||||
public static OrderOperationResponse NotFound(string message) => NotFound<OrderOperationResponse>(message);
|
||||
public static OrderOperationResponse BadRequest(string message) => BadRequest<OrderOperationResponse>(message);
|
||||
public static OrderOperationResponse InternalServerError(string message) => InternalServerError<OrderOperationResponse>(message);
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
using TwoFromTheCasketContratcs.Infrastructure;
|
||||
using TwoFromTheCasketContratcs.ViewModels;
|
||||
|
||||
namespace TwoFromTheCasketContratcs.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,28 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using TwoFromTheCasketContratcs.Infrastructure;
|
||||
using TwoFromTheCasketContratcs.ViewModels;
|
||||
|
||||
namespace TwoFromTheCasketContratcs.AdapterContracts.OperationResponses;
|
||||
|
||||
public class ReportOperationResponse : OperationResponse
|
||||
{
|
||||
public static ReportOperationResponse OK(List<ServiceHistoryViewModel> data) => OK<ReportOperationResponse, List<ServiceHistoryViewModel>>(data);
|
||||
|
||||
public static ReportOperationResponse OK(List<OrderViewModel> data) => OK<ReportOperationResponse, List<OrderViewModel>>(data);
|
||||
|
||||
public static ReportOperationResponse OK(List<MasterSalaryByPeriodViewModel> data) => OK<ReportOperationResponse, List<MasterSalaryByPeriodViewModel>>(data);
|
||||
|
||||
public static ReportOperationResponse OK(List<ServiceWithHistoryViewModel> data) => OK<ReportOperationResponse, List<ServiceWithHistoryViewModel>>(data);
|
||||
|
||||
public static ReportOperationResponse OK(Stream data, string fileName) => OK<ReportOperationResponse, Stream>(data, fileName);
|
||||
|
||||
public static ReportOperationResponse BadRequest(string message) =>
|
||||
BadRequest<ReportOperationResponse>(message);
|
||||
|
||||
public static ReportOperationResponse InternalServerError(string message) =>
|
||||
InternalServerError<ReportOperationResponse>(message);
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using TwoFromTheCasketContratcs.Infrastructure;
|
||||
using TwoFromTheCasketContratcs.ViewModels;
|
||||
|
||||
namespace TwoFromTheCasketContratcs.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,14 @@
|
||||
using TwoFromTheCasketContratcs.Infrastructure;
|
||||
using TwoFromTheCasketContratcs.ViewModels;
|
||||
|
||||
namespace TwoFromTheCasketContratcs.AdapterContracts.OperationResponses;
|
||||
|
||||
public class ServiceOperationResponse : OperationResponse
|
||||
{
|
||||
public static ServiceOperationResponse OK(List<ServiceViewModel> data) => OK<ServiceOperationResponse, List<ServiceViewModel>>(data);
|
||||
public static ServiceOperationResponse OK(ServiceViewModel data) => OK<ServiceOperationResponse, ServiceViewModel>(data);
|
||||
public static ServiceOperationResponse NoContent() => NoContent<ServiceOperationResponse>();
|
||||
public static ServiceOperationResponse NotFound(string message) => NotFound<ServiceOperationResponse>(message);
|
||||
public static ServiceOperationResponse BadRequest(string message) => BadRequest<ServiceOperationResponse>(message);
|
||||
public static ServiceOperationResponse InternalServerError(string message) => InternalServerError<ServiceOperationResponse>(message);
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace TwoFromTheCasketContratcs.BindingModels;
|
||||
|
||||
public class MasterBindingModel
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
|
||||
public string? FIO { get; set; }
|
||||
|
||||
public string? PostId { get; set; }
|
||||
|
||||
public DateTime? BirthDate { get; set; }
|
||||
|
||||
public DateTime? EmploymentDate { get; set; }
|
||||
|
||||
public bool IsDeleted { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using TwoFromTheCasketContratcs.Enums;
|
||||
|
||||
namespace TwoFromTheCasketContratcs.BindingModels;
|
||||
|
||||
public class OrderBindingModel
|
||||
{
|
||||
public required string? Id { get; set; }
|
||||
|
||||
public required DateTime Date { get; set; }
|
||||
|
||||
public required StatusType Status { get; set; }
|
||||
|
||||
public required RoomType RoomType { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace TwoFromTheCasketContratcs.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,15 @@
|
||||
using System.Diagnostics.Metrics;
|
||||
|
||||
namespace TwoFromTheCasketContratcs.BindingModels;
|
||||
|
||||
public class SalaryBindingModel
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? MasterId { get; set; }
|
||||
|
||||
public DateTime SalaryDate { get; set; }
|
||||
|
||||
public double SalarySize { get; set; }
|
||||
|
||||
public double Prize { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
using TwoFromTheCasketContratcs.Enums;
|
||||
|
||||
namespace TwoFromTheCasketContratcs.BindingModels;
|
||||
|
||||
public class ServiceBindingModel
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
|
||||
public string? ServiceName { get; set; }
|
||||
|
||||
public ServiceType ServiceType { get; set; }
|
||||
|
||||
public string? MasterId { get; set; }
|
||||
|
||||
public double Price { get; set; }
|
||||
|
||||
public bool IsDeleted { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
namespace TwoFromTheCasketContratcs.BindingModels;
|
||||
|
||||
public class ServiceOrderBindingModel
|
||||
{
|
||||
public string? OrderId { get; set; }
|
||||
|
||||
public string? ServiceId { get; set; }
|
||||
|
||||
public string? MasterId { get; set; }
|
||||
|
||||
public int TimeOfWorking { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using TwoFromTheCasketContratcs.DataModels;
|
||||
|
||||
namespace TwoFromTheCasketContratcs.BuisnessLogicsContracts;
|
||||
|
||||
public interface IMasterBuisnessLogicContract
|
||||
{
|
||||
List<MasterDataModel> GetAllMasters(bool onlyActive = true);
|
||||
|
||||
List<MasterDataModel> GetAllMastersByPost(string postId, bool onlyActive = true);
|
||||
List<MasterDataModel> GetAllMastersByBirthDate(DateTime fromDate, DateTime toDate, bool onlyActive = true);
|
||||
|
||||
List<MasterDataModel> GetAllMastersByEmploymentDate(DateTime fromDate, DateTime toDate, bool onlyActive = true);
|
||||
|
||||
MasterDataModel GetMasterByData(string data);
|
||||
|
||||
void InsertMaster(MasterDataModel masterDataModel);
|
||||
|
||||
void UpdateMaster(MasterDataModel masterDataModel);
|
||||
|
||||
void DeleteMaster(string id);
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using TwoFromTheCasketContratcs.DataModels;
|
||||
|
||||
namespace TwoFromTheCasketContratcs.BuisnessLogicsContracts;
|
||||
|
||||
public interface IOrderBuisnessLogicContract
|
||||
{
|
||||
List<OrderDataModel> GetAllOrder();
|
||||
|
||||
OrderDataModel GetOrderByDate(DateTime fromDate);
|
||||
|
||||
OrderDataModel GetOrderByData(string data);
|
||||
|
||||
void InsertOrder(OrderDataModel orderDataModel);
|
||||
|
||||
void UpdateOrder(OrderDataModel orderDataModel);
|
||||
|
||||
void DeleteOrder(string id);
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using TwoFromTheCasketContratcs.DataModels;
|
||||
|
||||
namespace TwoFromTheCasketContratcs.BuisnessLogicsContracts;
|
||||
|
||||
public interface IPostBuisnessLogicContract
|
||||
{
|
||||
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,25 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using TwoFromTheCasketContratcs.DataModels;
|
||||
|
||||
namespace TwoFromTheCasketContratcs.BuisnessLogicsContracts;
|
||||
|
||||
public interface IReportContract
|
||||
{
|
||||
Task<List<ServiceHistoryDataModel>> GetDataServiceHistoryAsync(CancellationToken ct);
|
||||
|
||||
Task<List<OrderDataModel>> GetDataOrderByPeriodAsync(DateTime dateStart, DateTime dateFinish, CancellationToken ct);
|
||||
|
||||
Task<List<MasterSalaryByPeriodDataModel>> GetDataSalaryByPeriodAsync(DateTime dateStart, DateTime dateFinish, CancellationToken ct);
|
||||
|
||||
Task<List<ServiceWithHistoryDataModel>> GetDataServicesWithHistoryAsync(DateTime dateStart, DateTime dateFinish, CancellationToken ct);
|
||||
|
||||
Task<Stream> CreateDocumentServicesWithHistoryAsync(DateTime dateStart, DateTime dateFinish, CancellationToken ct);
|
||||
|
||||
Task<Stream> CreateDocumentOrdersByPeriodAsync(DateTime dateStart, DateTime dateFinish, CancellationToken ct);
|
||||
|
||||
Task<Stream> CreateDocumentSalaryByPeriodAsync(DateTime dateStart, DateTime dateFinish, CancellationToken ct);
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using TwoFromTheCasketContratcs.DataModels;
|
||||
|
||||
namespace TwoFromTheCasketContratcs.BuisnessLogicsContracts;
|
||||
|
||||
public interface ISalaryBuisnessLogicContract
|
||||
{
|
||||
List<SalaryDataModel> GetAllSalariesByPeriod(DateTime fromDate, DateTime toDate);
|
||||
|
||||
List<SalaryDataModel> GetAllSalariesByPeriodByMaster(DateTime fromDate, DateTime toDate, string masterId);
|
||||
|
||||
void CalculateSalaryByMonth(DateTime date);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using TwoFromTheCasketContratcs.DataModels;
|
||||
using TwoFromTheCasketContratcs.Enums;
|
||||
|
||||
namespace TwoFromTheCasketContratcs.BuisnessLogicsContracts;
|
||||
|
||||
public interface IServiceBuisnessLogicContract
|
||||
{
|
||||
List<ServiceDataModel> GetAllServices(bool onlyActive);
|
||||
|
||||
List<ServiceDataModel> GetServicesByServiceType(ServiceType serviceType, bool onlyActive);
|
||||
|
||||
List<ServiceDataModel> GetServicesByMasterId(string masterId, bool onlyActive);
|
||||
|
||||
void InsertService(ServiceDataModel serviceDataModel);
|
||||
|
||||
void UpdateService(ServiceDataModel serviceDataModel);
|
||||
|
||||
void DeleteService(string id);
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace TwoFromTheCasketContratcs.DataModels;
|
||||
|
||||
public class MasterSalaryByPeriodDataModel
|
||||
{
|
||||
public required string MasterFIO { get; set; }
|
||||
|
||||
public double TotalSalary { get; set; }
|
||||
|
||||
public DateTime FromPeriod { get; set; }
|
||||
|
||||
public DateTime ToPeriod { get; set; }
|
||||
}
|
||||
@@ -11,16 +11,16 @@ using TwoFromTheCasketContratcs.Infrastructure;
|
||||
|
||||
namespace TwoFromTheCasketContratcs.DataModels;
|
||||
|
||||
public class OrderDataModel( string id, DateTime dataTime, StatusType status, RoomType roomType) : IValidation
|
||||
public class OrderDataModel( string id, DateTime data, StatusType status, RoomType roomType) : IValidation
|
||||
{
|
||||
public string Id { get; private set; } = id;
|
||||
|
||||
public DateTime Date { get; private set; } = dataTime;
|
||||
public DateTime Date { get; private set; } = data;
|
||||
|
||||
public StatusType Status { get; private set; } = status;
|
||||
|
||||
public RoomType RoomType { get; private set; } = roomType;
|
||||
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
if (Id.IsEmpty())
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
using System;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
@@ -8,26 +11,40 @@ using TwoFromTheCasketContratcs.Enums;
|
||||
using TwoFromTheCasketContratcs.Exceptions;
|
||||
using TwoFromTheCasketContratcs.Extensions;
|
||||
using TwoFromTheCasketContratcs.Infrastructure;
|
||||
using TwoFromTheCasketContratcs.Infrastructure.PostConfigurations;
|
||||
|
||||
namespace TwoFromTheCasketContratcs.DataModels;
|
||||
|
||||
public class PostDataModel(string id, string postId, string postName, PostType
|
||||
postType, double salary, bool isActual, DateTime changeDate) : IValidation
|
||||
public class PostDataModel(string postId, string postName, PostType
|
||||
postType, PostConfiguration configuration) : IValidation
|
||||
{
|
||||
public string Id { get; private set; } = id;
|
||||
|
||||
public string PostId { get; private set; } = postId;
|
||||
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;
|
||||
public PostConfiguration ConfigurationModel { get; private set; } = configuration;
|
||||
|
||||
public bool IsActual { get; private set; } = isActual;
|
||||
|
||||
public DateTime ChangeDate { get; private set; } = changeDate;
|
||||
|
||||
public PostDataModel(string postId, string postName, PostType postType, string configurationJson) : this(postId,
|
||||
postName, postType, new PostConfiguration())
|
||||
{
|
||||
var obj = JToken.Parse(configurationJson);
|
||||
if (obj is not null)
|
||||
{
|
||||
ConfigurationModel = obj.Value<string>("Type") switch
|
||||
{
|
||||
nameof(CarpenterPostConfiguration) => JsonConvert.DeserializeObject<CarpenterPostConfiguration>(
|
||||
configurationJson)!,
|
||||
nameof(PainterPostConfiguration) => JsonConvert
|
||||
.DeserializeObject<PainterPostConfiguration>(configurationJson)!,
|
||||
nameof(PlastererPostConfiguration) => JsonConvert.DeserializeObject<PlastererPostConfiguration>(
|
||||
configurationJson)!,
|
||||
_ => JsonConvert.DeserializeObject<PostConfiguration>(configurationJson)!,
|
||||
};
|
||||
}
|
||||
}
|
||||
public void Validate()
|
||||
{
|
||||
if (Id.IsEmpty())
|
||||
@@ -36,11 +53,6 @@ postType, double salary, bool isActual, DateTime changeDate) : IValidation
|
||||
if (!Id.IsGuid())
|
||||
throw new ValidationException("The value in the field Id is not a unique identifier");
|
||||
|
||||
if (PostId.IsEmpty())
|
||||
throw new ValidationException("Field PostId is empty");
|
||||
|
||||
if (!PostId.IsGuid())
|
||||
throw new ValidationException("The value in the field PostId is not a unique identifier");
|
||||
|
||||
if (PostName.IsEmpty())
|
||||
throw new ValidationException("Field PostName is empty");
|
||||
@@ -48,7 +60,10 @@ postType, double salary, bool isActual, DateTime changeDate) : IValidation
|
||||
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");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
using TwoFromTheCasketContratcs.Enums;
|
||||
|
||||
namespace TwoFromTheCasketContratcs.DataModels;
|
||||
|
||||
public class ServiceWithHistoryDataModel
|
||||
{
|
||||
public string Id { get; set; } = string.Empty;
|
||||
public string ServiceName { get; set; } = string.Empty;
|
||||
public ServiceType ServiceType { get; set; }
|
||||
public double Price { get; set; }
|
||||
public string MasterId { get; set; } = string.Empty;
|
||||
public DateTime CreatedAt { get; set; }
|
||||
public bool IsDeleted { get; set; }
|
||||
public List<ServiceHistoryDataModel> History { get; set; } = new();
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace TwoFromTheCasketContratcs.Exceptions;
|
||||
|
||||
public class ElementDeletedException : Exception
|
||||
{
|
||||
public ElementDeletedException(string id) : base($"Cannot modify a deleteditem(id: { id})") { }
|
||||
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace TwoFromTheCasketContratcs.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 alredy an element with value {paramValue} of parameter {paramName}")
|
||||
{
|
||||
ParamName = paramName;
|
||||
ParamValue = paramValue;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace TwoFromTheCasketContratcs.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,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using static System.Runtime.InteropServices.JavaScript.JSType;
|
||||
|
||||
namespace TwoFromTheCasketContratcs.Exceptions;
|
||||
|
||||
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 TwoFromTheCasketContratcs.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 TwoFromTheCasketContratcs.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 TwoFromTheCasketContratcs.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 TwoFromTheCasketContratcs.Infrastructure;
|
||||
|
||||
public interface IConfigurationDatabase
|
||||
{
|
||||
string ConnectionString { get; }
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace TwoFromTheCasketContratcs.Infrastructure;
|
||||
|
||||
public interface IConfigurationSalary
|
||||
{
|
||||
double ExtraSaleSum { get; }
|
||||
double ExtraInstallationSum { get; }
|
||||
int MaxThreads { get; }
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
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 TwoFromTheCasketContratcs.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 == null)
|
||||
return new StatusCodeResult((int)StatusCode);
|
||||
|
||||
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,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace TwoFromTheCasketContratcs.Infrastructure.PostConfigurations;
|
||||
|
||||
public class CarpenterPostConfiguration : PostConfiguration
|
||||
{
|
||||
|
||||
public override string Type => nameof(CarpenterPostConfiguration);
|
||||
|
||||
public double BonusForExtraCarpentry { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace TwoFromTheCasketContratcs.Infrastructure.PostConfigurations;
|
||||
|
||||
public class PainterPostConfiguration : PostConfiguration
|
||||
{
|
||||
public override string Type => nameof(PainterPostConfiguration);
|
||||
|
||||
public double PainterPercent { get; set; }
|
||||
|
||||
public double BonusForExtraPainter { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace TwoFromTheCasketContratcs.Infrastructure.PostConfigurations;
|
||||
|
||||
public class PlastererPostConfiguration : PostConfiguration
|
||||
{
|
||||
public override string Type => nameof(PlastererPostConfiguration);
|
||||
|
||||
public double PlastererPercent { get; set; }
|
||||
|
||||
public double BonusForExtraPlasterer { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace TwoFromTheCasketContratcs.Infrastructure.PostConfigurations;
|
||||
|
||||
public class PostConfiguration
|
||||
{
|
||||
|
||||
public virtual string Type => nameof(PostConfiguration);
|
||||
|
||||
public double Rate { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using TwoFromTheCasketContratcs.DataModels;
|
||||
|
||||
namespace TwoFromTheCasketContratcs.StorageContracts;
|
||||
|
||||
public interface IMasterStorageContract
|
||||
{
|
||||
List<MasterDataModel> GetList(bool onlyActive = true, string? postId =
|
||||
null, DateTime? fromBirthDate = null, DateTime? toBirthDate = null, DateTime?
|
||||
fromEmploymentDate = null, DateTime? toEmploymentDate = null);
|
||||
|
||||
MasterDataModel? GetElementById(string id);
|
||||
|
||||
MasterDataModel? GetElementByFIO(string name);
|
||||
|
||||
MasterDataModel? GetElementByPostId(string postId);
|
||||
|
||||
void AddElement(MasterDataModel masterDataModel);
|
||||
|
||||
void UpdElement(MasterDataModel masterDataModel);
|
||||
|
||||
void DelElement(string id);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using TwoFromTheCasketContratcs.DataModels;
|
||||
using TwoFromTheCasketContratcs.Enums;
|
||||
|
||||
namespace TwoFromTheCasketContratcs.StorageContracts;
|
||||
|
||||
public interface IOrderStorageContract
|
||||
{
|
||||
List<OrderDataModel> GetList();
|
||||
|
||||
Task<List<OrderDataModel>> GetListAsync(DateTime startDate, DateTime endDate, CancellationToken ct);
|
||||
|
||||
OrderDataModel? GetElementById(string id);
|
||||
|
||||
OrderDataModel? GetElementByDate(DateTime date);
|
||||
|
||||
OrderDataModel? GetElementByStatus(StatusType status);
|
||||
|
||||
void AddElement(OrderDataModel orderDataModel);
|
||||
|
||||
void UpdElement(OrderDataModel orderDataModel);
|
||||
|
||||
void DelElement(string id);
|
||||
|
||||
Task<List<(string MasterFIO, string ServiceName, int TimeOfWorking, decimal TotalAmount)>> GetOrderDetailsAsync(string orderId, CancellationToken ct);
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using TwoFromTheCasketContratcs.DataModels;
|
||||
|
||||
namespace TwoFromTheCasketContratcs.StorageContracts;
|
||||
|
||||
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,25 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using TwoFromTheCasketContratcs.DataModels;
|
||||
using TwoFromTheCasketContratcs.Enums;
|
||||
|
||||
namespace TwoFromTheCasketContratcs.StorageContracts;
|
||||
|
||||
public interface ISalaryStorageContract
|
||||
{
|
||||
List<SalaryDataModel> GetList(DateTime startDate, DateTime endDate, string?
|
||||
masterId = null);
|
||||
|
||||
Task<List<SalaryDataModel>> GetListAsync(DateTime startDate, DateTime endDate, CancellationToken ct);
|
||||
|
||||
SalaryDataModel? GetElementByMasterId(string masterId);
|
||||
|
||||
SalaryDataModel? GetElementBySalaryDate(DateTime salaryDate);
|
||||
|
||||
void AddElement(SalaryDataModel salaryDataModel);
|
||||
|
||||
void SaveChanges();
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using TwoFromTheCasketContratcs.DataModels;
|
||||
using TwoFromTheCasketContratcs.Enums;
|
||||
|
||||
namespace TwoFromTheCasketContratcs.StorageContracts;
|
||||
|
||||
public interface IServiceStorageContract
|
||||
{
|
||||
List<ServiceDataModel> GetList();
|
||||
Task<List<ServiceDataModel>> GetListAsync();
|
||||
Task<List<ServiceDataModel>> GetListAsync(DateTime startDate, DateTime endDate, CancellationToken ct);
|
||||
List<ServiceHistoryDataModel> GetHistoryByServiceId(string serviceId);
|
||||
ServiceDataModel? GetElementById(string id);
|
||||
|
||||
List<ServiceDataModel>? GetElementByServiceName(string name);
|
||||
|
||||
List<ServiceDataModel>? GetElementByMasterId(string masterId);
|
||||
void AddElement(ServiceDataModel serviceDataModel);
|
||||
|
||||
void UpdElement(ServiceDataModel serviceDataModel);
|
||||
|
||||
void DelElement(string id);
|
||||
}
|
||||
@@ -6,4 +6,15 @@
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Abstractions" Version="2.3.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="2.3.0" />
|
||||
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="9.0.4" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<InternalsVisibleTo Include="TwoFromTheCasketTest" />
|
||||
<InternalsVisibleTo Include="TwoFromTheCasketWebApi" />
|
||||
<InternalsVisibleTo Include="DynamicProxyGenAssembly2" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace TwoFromTheCasketContratcs.ViewModels;
|
||||
|
||||
public class MasterSalaryByPeriodViewModel
|
||||
{
|
||||
public required string MasterFIO { get; set; }
|
||||
|
||||
public double TotalSalary { get; set; }
|
||||
|
||||
public DateTime FromPeriod { get; set; }
|
||||
|
||||
public DateTime ToPeriod { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace TwoFromTheCasketContratcs.ViewModels;
|
||||
|
||||
public class MasterViewModel
|
||||
{
|
||||
public required string Id { get; set; }
|
||||
|
||||
public required string FIO { get; set; }
|
||||
|
||||
public required string PostId { get; set; }
|
||||
|
||||
public required DateTime BirthDate { get; set; }
|
||||
|
||||
public required DateTime EmploymentDate { get; set; }
|
||||
|
||||
public required bool IsDeleted { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using TwoFromTheCasketContratcs.Enums;
|
||||
|
||||
namespace TwoFromTheCasketContratcs.ViewModels;
|
||||
public class OrderViewModel
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
|
||||
public DateTime Date { get; set; }
|
||||
|
||||
public StatusType Status { get; set; }
|
||||
|
||||
public RoomType RoomType { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace TwoFromTheCasketContratcs.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,13 @@
|
||||
namespace TwoFromTheCasketContratcs.ViewModels;
|
||||
|
||||
public class SalaryViewModel
|
||||
{
|
||||
public required string Id { get; set; }
|
||||
public required string MasterId { get; set; }
|
||||
|
||||
public required DateTime SalaryDate { get; set; }
|
||||
|
||||
public required double SalarySize { get; set; }
|
||||
|
||||
public required double Prize { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace TwoFromTheCasketContratcs.ViewModels;
|
||||
|
||||
public class ServiceHistoryViewModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
public string ServiceId { get; set; } = string.Empty;
|
||||
|
||||
public double OldPrice { get; set; }
|
||||
|
||||
public DateTime ChangeDate { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
namespace TwoFromTheCasketContratcs.ViewModels;
|
||||
|
||||
public class ServiceOderViewModel
|
||||
{
|
||||
public required string OrderId { get; set; }
|
||||
|
||||
public required string ServiceId { get; set; }
|
||||
|
||||
public required string MasterId { get; set; }
|
||||
|
||||
public required int TimeOfWorking { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
using TwoFromTheCasketContratcs.Enums;
|
||||
|
||||
namespace TwoFromTheCasketContratcs.ViewModels;
|
||||
|
||||
public class ServiceViewModel
|
||||
{
|
||||
public required string Id { get; set; }
|
||||
|
||||
public required string ServiceName { get; set; }
|
||||
|
||||
public required ServiceType ServiceType { get; set; }
|
||||
|
||||
public required string MasterId { get; set; }
|
||||
|
||||
public required double Price { get; set; }
|
||||
|
||||
public required bool IsDeleted { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
using TwoFromTheCasketContratcs.Enums;
|
||||
|
||||
namespace TwoFromTheCasketContratcs.ViewModels;
|
||||
|
||||
public class ServiceWithHistoryViewModel
|
||||
{
|
||||
public string Id { get; set; } = string.Empty;
|
||||
public string ServiceName { get; set; } = string.Empty;
|
||||
public ServiceType ServiceType { get; set; }
|
||||
public double Price { get; set; }
|
||||
public string MasterId { get; set; } = string.Empty;
|
||||
public DateTime CreatedAt { get; set; }
|
||||
public bool IsDeleted { get; set; }
|
||||
public List<ServiceHistoryViewModel> History { get; set; } = new();
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using TwoFromTheCasketContratcs.Infrastructure;
|
||||
|
||||
namespace TwoFromTheCasketDatabase;
|
||||
|
||||
public class DefaultConfigurationDatabase : IConfigurationDatabase
|
||||
{
|
||||
public string ConnectionString => "";
|
||||
}
|
||||
@@ -0,0 +1,164 @@
|
||||
using AutoMapper;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Npgsql;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Linq;
|
||||
using TwoFromTheCasketContratcs.DataModels;
|
||||
using TwoFromTheCasketContratcs.Exceptions;
|
||||
using TwoFromTheCasketContratcs.StorageContracts;
|
||||
using TwoFromTheCasketDatabase.Models;
|
||||
|
||||
namespace TwoFromTheCasketDatabase.Implementation;
|
||||
|
||||
internal class MasterStorageContract : IMasterStorageContract
|
||||
{
|
||||
private readonly TwoFromTheCasketDbContext _dbContext;
|
||||
|
||||
private readonly Mapper _mapper;
|
||||
public MasterStorageContract(TwoFromTheCasketDbContext twoFromTheCasketDbContext)
|
||||
{
|
||||
_dbContext = twoFromTheCasketDbContext;
|
||||
var config = new MapperConfiguration(cfg =>
|
||||
{
|
||||
cfg.AddMaps(typeof(Master));
|
||||
});
|
||||
_mapper = new Mapper(config);
|
||||
}
|
||||
|
||||
public List<MasterDataModel> GetList(bool onlyActive = true, string? postId = null, DateTime? fromBirthDate = null, DateTime? toBirthDate = null, DateTime? fromEmploymentDate = null, DateTime? toEmploymentDate = null)
|
||||
{
|
||||
try
|
||||
{
|
||||
var query = _dbContext.Masters.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 [.. query.Select(x => _mapper.Map<MasterDataModel>(x))];
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public MasterDataModel? GetElementById(string id)
|
||||
{
|
||||
try
|
||||
{
|
||||
return _mapper.Map<MasterDataModel>(GetMasterById(id));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
}
|
||||
}
|
||||
public MasterDataModel? GetElementByFIO(string name)
|
||||
{
|
||||
try
|
||||
{
|
||||
return _mapper.Map<MasterDataModel>(_dbContext.Masters.FirstOrDefault(x => x.FIO == name));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public MasterDataModel? GetElementByPostId(string postId)
|
||||
{
|
||||
try
|
||||
{
|
||||
return _mapper.Map<MasterDataModel>(_dbContext.Masters.FirstOrDefault(x => x.PostId == postId));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
}
|
||||
}
|
||||
public void AddElement(MasterDataModel masterDataModel)
|
||||
{
|
||||
try
|
||||
{
|
||||
_dbContext.Masters.Add(_mapper.Map<Master>(masterDataModel));
|
||||
_dbContext.SaveChanges();
|
||||
}
|
||||
catch(InvalidOperationException ex) when (ex.TargetSite?.Name == "ThrowIdentityConflict")
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new ElementExistsException("Id", masterDataModel.Id);
|
||||
}
|
||||
catch (DbUpdateException ex) when (ex.InnerException is PostgresException { ConstraintName : "IX_Master_FIO" } )
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new ElementExistsException("FIO", masterDataModel.FIO);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
}
|
||||
}
|
||||
public void UpdElement(MasterDataModel masterDataModel)
|
||||
{
|
||||
try
|
||||
{
|
||||
var element = GetMasterById(masterDataModel.Id) ?? throw new ElementNotFoundException(masterDataModel.Id);
|
||||
_dbContext.Masters.Update(_mapper.Map(masterDataModel,element));
|
||||
_dbContext.SaveChanges();
|
||||
}
|
||||
catch (ElementNotFoundException)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw;
|
||||
}
|
||||
catch (DbUpdateException ex) when (ex.InnerException is PostgresException { ConstraintName: "IX_Master_FIO" })
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new ElementExistsException("FIO", masterDataModel.FIO);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public void DelElement(string id)
|
||||
{
|
||||
try
|
||||
{
|
||||
var element = GetMasterById(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 Master? GetMasterById(string id) => _dbContext.Masters.FirstOrDefault(x => x.Id == id && !x.IsDeleted);
|
||||
}
|
||||
@@ -0,0 +1,202 @@
|
||||
using AutoMapper;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Npgsql;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using TwoFromTheCasketContratcs.DataModels;
|
||||
using TwoFromTheCasketContratcs.Enums;
|
||||
using TwoFromTheCasketContratcs.Exceptions;
|
||||
using TwoFromTheCasketContratcs.StorageContracts;
|
||||
using TwoFromTheCasketDatabase.Models;
|
||||
using static System.Runtime.InteropServices.JavaScript.JSType;
|
||||
|
||||
namespace TwoFromTheCasketDatabase.Implementation;
|
||||
|
||||
internal class OrderStorageContract : IOrderStorageContract
|
||||
{
|
||||
private readonly TwoFromTheCasketDbContext _dbContext;
|
||||
|
||||
private readonly Mapper _mapper;
|
||||
public OrderStorageContract(TwoFromTheCasketDbContext twoFromTheCasketDbContext)
|
||||
{
|
||||
_dbContext = twoFromTheCasketDbContext;
|
||||
|
||||
var config = new MapperConfiguration(cfg =>
|
||||
{
|
||||
|
||||
cfg.CreateMap<Order, OrderDataModel>()
|
||||
.ConstructUsing(src => new OrderDataModel(
|
||||
src.Id.ToString(),
|
||||
src.Date,
|
||||
src.Status,
|
||||
src.RoomType));
|
||||
|
||||
|
||||
cfg.CreateMap<OrderDataModel, Order>()
|
||||
.ForMember(dest => dest.Id, opt => opt.MapFrom(src => Guid.Parse(src.Id)))
|
||||
.ForMember(dest => dest.Date, opt => opt.MapFrom(src => src.Date))
|
||||
.ForMember(dest => dest.Status, opt => opt.MapFrom(src => src.Status))
|
||||
.ForMember(dest => dest.RoomType, opt => opt.MapFrom(src => src.RoomType));
|
||||
|
||||
});
|
||||
|
||||
_mapper = new Mapper(config);
|
||||
}
|
||||
public List<OrderDataModel> GetList()
|
||||
{
|
||||
try
|
||||
{
|
||||
return [.. _dbContext.Orders.Select(x => _mapper.Map<OrderDataModel>(x))];
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
}
|
||||
}
|
||||
public OrderDataModel? GetElementById(string id)
|
||||
{
|
||||
try
|
||||
{
|
||||
return _mapper.Map<OrderDataModel>(GetOrderById(id));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
}
|
||||
}
|
||||
public OrderDataModel? GetElementByDate(DateTime date)
|
||||
{
|
||||
try
|
||||
{
|
||||
return _mapper.Map<OrderDataModel>(_dbContext.Orders.FirstOrDefault(x => x.Date == date));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
}
|
||||
}
|
||||
public OrderDataModel? GetElementByStatus(StatusType status)
|
||||
{
|
||||
try
|
||||
{
|
||||
return _mapper.Map<OrderDataModel>(_dbContext.Orders.FirstOrDefault(x => x.Status == status));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public void AddElement(OrderDataModel orderDataModel)
|
||||
{
|
||||
try
|
||||
{
|
||||
_dbContext.Orders.Add(_mapper.Map<Order>(orderDataModel));
|
||||
_dbContext.SaveChanges();
|
||||
}
|
||||
catch (InvalidOperationException ex) when (ex.TargetSite?.Name == "ThrowIdentityConflict")
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new ElementExistsException("Id", orderDataModel.Id);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
}
|
||||
}
|
||||
public void UpdElement(OrderDataModel orderDataModel)
|
||||
{
|
||||
try
|
||||
{
|
||||
var element = GetOrderById(orderDataModel.Id) ?? throw new ElementNotFoundException(orderDataModel.Id);
|
||||
_dbContext.Orders.Update(_mapper.Map(orderDataModel, 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 = GetOrderById(id) ?? throw new ElementNotFoundException(id);
|
||||
_dbContext.Orders.Remove(element);
|
||||
_dbContext.SaveChanges();
|
||||
}
|
||||
catch (ElementNotFoundException)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
private Order? GetOrderById(string id) => _dbContext.Orders.FirstOrDefault(x => x.Id == id);
|
||||
|
||||
public async Task<List<(string MasterFIO, string ServiceName, int TimeOfWorking, decimal TotalAmount)>> GetOrderDetailsAsync(string orderId, CancellationToken ct)
|
||||
{
|
||||
try
|
||||
{
|
||||
var orderDetails = await _dbContext.ServiceOrders
|
||||
.Where(so => so.OrderId == orderId)
|
||||
.Join(_dbContext.Masters, so => so.MasterId, m => m.Id, (so, m) => new { so, m })
|
||||
.Join(_dbContext.Services, x => x.so.ServiceId, s => s.Id, (x, s) => new
|
||||
{
|
||||
MasterFIO = x.m.FIO,
|
||||
ServiceName = s.ServiceName,
|
||||
TimeOfWorking = x.so.TimeOfWorking,
|
||||
ServicePrice = s.Price
|
||||
})
|
||||
.ToListAsync(ct);
|
||||
|
||||
return orderDetails.Select(x => (
|
||||
x.MasterFIO,
|
||||
x.ServiceName,
|
||||
x.TimeOfWorking,
|
||||
(decimal)(x.ServicePrice * x.TimeOfWorking) // Простой расчет: цена услуги * время работы
|
||||
)).ToList();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<List<OrderDataModel>> GetListAsync(DateTime startDate, DateTime endDate, CancellationToken ct)
|
||||
{
|
||||
try
|
||||
{
|
||||
return [.. await _dbContext.Orders
|
||||
.Where(x => x.Date >= startDate && x.Date <= endDate)
|
||||
.Select(x => _mapper.Map<OrderDataModel>(x))
|
||||
.ToListAsync(ct)];
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,190 @@
|
||||
using AutoMapper;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Npgsql;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using TwoFromTheCasketContratcs.DataModels;
|
||||
using TwoFromTheCasketContratcs.Exceptions;
|
||||
using TwoFromTheCasketContratcs.StorageContracts;
|
||||
using TwoFromTheCasketDatabase.Models;
|
||||
|
||||
namespace TwoFromTheCasketDatabase.Implementation;
|
||||
|
||||
internal class PostStorageContract : IPostStorageContract
|
||||
{
|
||||
private readonly TwoFromTheCasketDbContext _dbContext;
|
||||
private readonly Mapper _mapper;
|
||||
|
||||
public PostStorageContract(TwoFromTheCasketDbContext 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,129 @@
|
||||
using AutoMapper;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using TwoFromTheCasketContratcs.DataModels;
|
||||
using TwoFromTheCasketContratcs.Exceptions;
|
||||
using TwoFromTheCasketContratcs.StorageContracts;
|
||||
using TwoFromTheCasketDatabase.Models;
|
||||
using static System.Runtime.InteropServices.JavaScript.JSType;
|
||||
|
||||
namespace TwoFromTheCasketDatabase.Implementation;
|
||||
|
||||
internal class SalaryStorageContract : ISalaryStorageContract
|
||||
{
|
||||
TwoFromTheCasketDbContext _dbContext;
|
||||
|
||||
Mapper _mapper;
|
||||
|
||||
public SalaryStorageContract(TwoFromTheCasketDbContext twoFromTheCasketDbContext)
|
||||
{
|
||||
_dbContext = twoFromTheCasketDbContext;
|
||||
|
||||
var config = new MapperConfiguration(cfg =>
|
||||
{
|
||||
cfg.CreateMap<Salary, SalaryDataModel>()
|
||||
.ConstructUsing(src => new SalaryDataModel(
|
||||
src.MasterId,
|
||||
src.SalaryDate,
|
||||
src.SalarySize,
|
||||
src.Prize));
|
||||
|
||||
cfg.CreateMap<SalaryDataModel, Salary>()
|
||||
.ForMember(dest => dest.Id, opt => opt.Ignore()) // Игнорируем Id, так как он генерируется автоматически
|
||||
.ForMember(dest => dest.MasterId, opt => opt.MapFrom(src => src.MasterId))
|
||||
.ForMember(dest => dest.SalaryDate, opt => opt.MapFrom(src => src.SalaryDate))
|
||||
.ForMember(dest => dest.SalarySize, opt => opt.MapFrom(src => src.Salary))
|
||||
.ForMember(dest => dest.Prize, opt => opt.MapFrom(src => src.Prize));
|
||||
});
|
||||
|
||||
_mapper = new Mapper(config);
|
||||
}
|
||||
|
||||
public List<SalaryDataModel> GetList(DateTime startDate, DateTime endDate, string? masterId = null)
|
||||
{
|
||||
try
|
||||
{
|
||||
var query = _dbContext.Salaries.Where(x => x.SalaryDate >= startDate && x.SalaryDate <= endDate);
|
||||
if (masterId is not null) query = query.Where(x => x.MasterId == masterId);
|
||||
return [.. query.Select(x => _mapper.Map<SalaryDataModel>(x))];
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public SalaryDataModel? GetElementByMasterId(string masterId)
|
||||
{
|
||||
try
|
||||
{
|
||||
return _mapper.Map<SalaryDataModel>(_dbContext.Salaries.FirstOrDefault(x => x.MasterId == masterId));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public SalaryDataModel? GetElementBySalaryDate(DateTime salaryDate)
|
||||
{
|
||||
try
|
||||
{
|
||||
return _mapper.Map<SalaryDataModel>(_dbContext.Salaries.FirstOrDefault(x => x.SalaryDate == salaryDate));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
}
|
||||
}
|
||||
public void AddElement(SalaryDataModel salaryDataModel)
|
||||
{
|
||||
try
|
||||
{
|
||||
_dbContext.Salaries.Add(_mapper.Map<Salary>(salaryDataModel));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public void SaveChanges()
|
||||
{
|
||||
try
|
||||
{
|
||||
_dbContext.SaveChanges();
|
||||
}
|
||||
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.Master)
|
||||
.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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,240 @@
|
||||
using AutoMapper;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Npgsql;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using TwoFromTheCasketContratcs.DataModels;
|
||||
using TwoFromTheCasketContratcs.Exceptions;
|
||||
using TwoFromTheCasketContratcs.StorageContracts;
|
||||
using TwoFromTheCasketDatabase.Models;
|
||||
|
||||
namespace TwoFromTheCasketDatabase.Implementation;
|
||||
|
||||
internal class ServiceStorageContract : IServiceStorageContract
|
||||
{
|
||||
private readonly TwoFromTheCasketDbContext _dbContext;
|
||||
|
||||
private readonly Mapper _mapper;
|
||||
|
||||
public ServiceStorageContract(TwoFromTheCasketDbContext dbContext)
|
||||
{
|
||||
_dbContext = dbContext;
|
||||
var config = new MapperConfiguration(cfg =>
|
||||
{
|
||||
cfg.CreateMap<Service, ServiceDataModel>();
|
||||
cfg.CreateMap<ServiceDataModel, Service>()
|
||||
.ForMember(x => x.IsDeleted, x => x.MapFrom(src => false));
|
||||
|
||||
|
||||
cfg.CreateMap<ServiceHistory, ServiceHistoryDataModel>();
|
||||
cfg.CreateMap<ServiceHistoryDataModel, ServiceHistory>();
|
||||
});
|
||||
_mapper = new Mapper(config);
|
||||
}
|
||||
|
||||
public List<ServiceDataModel> GetList()
|
||||
{
|
||||
try
|
||||
{
|
||||
return [.. _dbContext.Services.Select(x => _mapper.Map<ServiceDataModel>(x))];
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public ServiceDataModel? GetElementById(string id)
|
||||
{
|
||||
try
|
||||
{
|
||||
return _mapper.Map<ServiceDataModel>(_dbContext.Services.FirstOrDefault(x => x.Id == id && !x.IsDeleted));
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public List<ServiceDataModel>? GetElementByMasterId(string masterId)
|
||||
{
|
||||
try
|
||||
{
|
||||
return [.. _dbContext.Services.Select(x => _mapper.Map<ServiceDataModel>(_dbContext.Services.FirstOrDefault(x => x.MasterId == masterId && !x.IsDeleted)))];
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public List<ServiceDataModel>? GetElementByServiceName(string name)
|
||||
{
|
||||
try
|
||||
{
|
||||
return [.. _dbContext.Services.Select(x => _mapper.Map<ServiceDataModel>(_dbContext.Services.FirstOrDefault(x => x.ServiceName == name && !x.IsDeleted)))];
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public List<ServiceHistoryDataModel> GetHistoryByServiceId(string serviceId)
|
||||
{
|
||||
try
|
||||
{
|
||||
return [.. _dbContext.ServiceHistories.Where(x => x.ServiceId == serviceId).OrderByDescending(x => x.ChangeDate).Select(x => _mapper.Map<ServiceHistoryDataModel>(x))];
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void AddElement(ServiceDataModel serviceDataModel)
|
||||
{
|
||||
try
|
||||
{
|
||||
_dbContext.Services.Add(_mapper.Map<Service>(serviceDataModel));
|
||||
_dbContext.SaveChanges();
|
||||
}
|
||||
catch (InvalidOperationException ex) when (ex.TargetSite?.Name ==
|
||||
"ThrowIdentityConflict")
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new ElementExistsException("Id", serviceDataModel.Id);
|
||||
}
|
||||
catch (DbUpdateException ex) when (ex.InnerException is
|
||||
PostgresException { ConstraintName: "IX_Service_ServiceName_IsDeleted" })
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new ElementExistsException("ServiceName",
|
||||
serviceDataModel.ServiceName);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void UpdElement(ServiceDataModel serviceDataModel)
|
||||
{
|
||||
try
|
||||
{
|
||||
var transaction = _dbContext.Database.BeginTransaction();
|
||||
try
|
||||
{
|
||||
var element = GetServiceById(serviceDataModel.Id) ??
|
||||
throw new ElementNotFoundException(serviceDataModel.Id);
|
||||
if (element.Price != serviceDataModel.Price)
|
||||
{
|
||||
_dbContext.ServiceHistories.Add(new
|
||||
ServiceHistory() { ServiceId = element.Id, OldPrice = element.Price});
|
||||
_dbContext.SaveChanges();
|
||||
}
|
||||
_dbContext.Services.Update(_mapper.Map(serviceDataModel,
|
||||
element));
|
||||
_dbContext.SaveChanges();
|
||||
transaction.Commit();
|
||||
}
|
||||
catch
|
||||
{
|
||||
transaction.Rollback();
|
||||
throw;
|
||||
}
|
||||
|
||||
}
|
||||
catch (DbUpdateException ex) when (ex.InnerException is
|
||||
PostgresException { ConstraintName: "IX_Products_ProductName_IsDeleted" })
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new ElementExistsException("ProductName",
|
||||
serviceDataModel.ServiceName);
|
||||
}
|
||||
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 = GetServiceById(id) ?? throw new
|
||||
ElementNotFoundException(id);
|
||||
element.IsDeleted = true;
|
||||
_dbContext.SaveChanges();
|
||||
}
|
||||
catch (ElementNotFoundException ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
}
|
||||
}
|
||||
private Service? GetServiceById(string id) => _dbContext.Services.FirstOrDefault(x => x.Id == id && !x.IsDeleted);
|
||||
|
||||
public async Task<List<ServiceDataModel>> GetListAsync()
|
||||
{
|
||||
try
|
||||
{
|
||||
return [.. await _dbContext.Services
|
||||
.Include(x => x.ServiceHistory)
|
||||
.Where(x => !x.IsDeleted)
|
||||
.Select(x => _mapper.Map<ServiceDataModel>(x))
|
||||
.ToListAsync()];
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<List<ServiceDataModel>> GetListAsync(DateTime startDate, DateTime endDate, CancellationToken ct)
|
||||
{
|
||||
try
|
||||
{
|
||||
return [.. await _dbContext.Services
|
||||
.Include(x => x.ServiceHistory)
|
||||
.Where(x => !x.IsDeleted)
|
||||
.Select(x => _mapper.Map<ServiceDataModel>(x))
|
||||
.ToListAsync(ct)];
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,219 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace TwoFromTheCasketDatabase.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class FirstMigration : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Masters",
|
||||
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 with time zone", nullable: false),
|
||||
EmploymentDate = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
|
||||
IsDeleted = table.Column<bool>(type: "boolean", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Masters", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Orders",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<string>(type: "text", nullable: false),
|
||||
Date = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
|
||||
Status = table.Column<int>(type: "integer", nullable: false),
|
||||
RoomType = table.Column<int>(type: "integer", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Orders", 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 with time zone", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Posts", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Salaries",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<string>(type: "text", nullable: false),
|
||||
MasterId = table.Column<string>(type: "text", nullable: false),
|
||||
SalaryDate = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
|
||||
SalarySize = table.Column<double>(type: "double precision", nullable: false),
|
||||
Prize = table.Column<double>(type: "double precision", nullable: false),
|
||||
SalaryId = table.Column<string>(type: "text", nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Salaries", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_Salaries_Masters_SalaryId",
|
||||
column: x => x.SalaryId,
|
||||
principalTable: "Masters",
|
||||
principalColumn: "Id");
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "ServiceOrders",
|
||||
columns: table => new
|
||||
{
|
||||
OrderId = table.Column<string>(type: "text", nullable: false),
|
||||
ServiceId = table.Column<string>(type: "text", nullable: false),
|
||||
MasterId = table.Column<string>(type: "text", nullable: false),
|
||||
TimeOfWorking = table.Column<int>(type: "integer", nullable: false),
|
||||
ServiceOrderId = table.Column<string>(type: "text", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_ServiceOrders", x => new { x.ServiceId, x.MasterId, x.OrderId });
|
||||
table.ForeignKey(
|
||||
name: "FK_ServiceOrders_Masters_ServiceOrderId",
|
||||
column: x => x.ServiceOrderId,
|
||||
principalTable: "Masters",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Services",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<string>(type: "text", nullable: false),
|
||||
ServiceName = table.Column<string>(type: "text", nullable: false),
|
||||
ServiceType = table.Column<int>(type: "integer", nullable: false),
|
||||
MasterId = table.Column<string>(type: "text", nullable: false),
|
||||
Price = table.Column<double>(type: "double precision", nullable: false),
|
||||
IsDeleted = table.Column<bool>(type: "boolean", nullable: false),
|
||||
ServiceId = table.Column<string>(type: "text", nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Services", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_Services_Masters_ServiceId",
|
||||
column: x => x.ServiceId,
|
||||
principalTable: "Masters",
|
||||
principalColumn: "Id");
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "ServiceHistories",
|
||||
columns: table => new
|
||||
{
|
||||
ServiceId = table.Column<string>(type: "text", nullable: false),
|
||||
OldPrice = table.Column<double>(type: "double precision", nullable: false),
|
||||
ChangeDate = table.Column<DateTime>(type: "timestamp with time zone", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_ServiceHistories", x => x.ServiceId);
|
||||
table.ForeignKey(
|
||||
name: "FK_ServiceHistories_Services_ServiceId",
|
||||
column: x => x.ServiceId,
|
||||
principalTable: "Services",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Masters_Id_IsDeleted",
|
||||
table: "Masters",
|
||||
columns: new[] { "Id", "IsDeleted" },
|
||||
unique: true,
|
||||
filter: "\"IsDeleted\" = FALSE");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Orders_Id",
|
||||
table: "Orders",
|
||||
column: "Id",
|
||||
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_Salaries_SalaryId",
|
||||
table: "Salaries",
|
||||
column: "SalaryId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_ServiceOrders_ServiceOrderId",
|
||||
table: "ServiceOrders",
|
||||
column: "ServiceOrderId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Services_ServiceId",
|
||||
table: "Services",
|
||||
column: "ServiceId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Services_ServiceName_IsDeleted",
|
||||
table: "Services",
|
||||
columns: new[] { "ServiceName", "IsDeleted" },
|
||||
unique: true,
|
||||
filter: "\"IsDeleted\" = FALSE");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "Orders");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Posts");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Salaries");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "ServiceHistories");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "ServiceOrders");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Services");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Masters");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,277 @@
|
||||
// <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 TwoFromTheCasketDatabase;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace TwoFromTheCasketDatabase.Migrations
|
||||
{
|
||||
[DbContext(typeof(TwoFromTheCasketDbContext))]
|
||||
[Migration("20250907135104_ChangeFieldsInPost")]
|
||||
partial class ChangeFieldsInPost
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "9.0.1")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||
|
||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("TwoFromTheCasketDatabase.Models.Master", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTime>("BirthDate")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<DateTime>("EmploymentDate")
|
||||
.HasColumnType("timestamp with 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.HasIndex("Id", "IsDeleted")
|
||||
.IsUnique()
|
||||
.HasFilter("\"IsDeleted\" = FALSE");
|
||||
|
||||
b.ToTable("Masters");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("TwoFromTheCasketDatabase.Models.Order", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTime>("Date")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<int>("RoomType")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("Status")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("Id")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("Orders");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("TwoFromTheCasketDatabase.Models.Post", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTime>("ChangeDate")
|
||||
.HasColumnType("timestamp with 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("TwoFromTheCasketDatabase.Models.Salary", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("MasterId")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<double>("Prize")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.Property<DateTime>("SalaryDate")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<string>("SalaryId")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<double>("SalarySize")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("SalaryId");
|
||||
|
||||
b.ToTable("Salaries");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("TwoFromTheCasketDatabase.Models.Service", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<bool>("IsDeleted")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<string>("MasterId")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<double>("Price")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.Property<string>("ServiceId")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("ServiceName")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int>("ServiceType")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ServiceId");
|
||||
|
||||
b.HasIndex("ServiceName", "IsDeleted")
|
||||
.IsUnique()
|
||||
.HasFilter("\"IsDeleted\" = FALSE");
|
||||
|
||||
b.ToTable("Services");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("TwoFromTheCasketDatabase.Models.ServiceHistory", b =>
|
||||
{
|
||||
b.Property<string>("ServiceId")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTime>("ChangeDate")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<double>("OldPrice")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.HasKey("ServiceId");
|
||||
|
||||
b.ToTable("ServiceHistories");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("TwoFromTheCasketDatabase.Models.ServiceOrder", b =>
|
||||
{
|
||||
b.Property<string>("ServiceId")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("MasterId")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("OrderId")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("ServiceOrderId")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int>("TimeOfWorking")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("ServiceId", "MasterId", "OrderId");
|
||||
|
||||
b.HasIndex("ServiceOrderId");
|
||||
|
||||
b.ToTable("ServiceOrders");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("TwoFromTheCasketDatabase.Models.Salary", b =>
|
||||
{
|
||||
b.HasOne("TwoFromTheCasketDatabase.Models.Master", "Master")
|
||||
.WithMany("Salaries")
|
||||
.HasForeignKey("SalaryId");
|
||||
|
||||
b.Navigation("Master");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("TwoFromTheCasketDatabase.Models.Service", b =>
|
||||
{
|
||||
b.HasOne("TwoFromTheCasketDatabase.Models.Master", null)
|
||||
.WithMany("Services")
|
||||
.HasForeignKey("ServiceId");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("TwoFromTheCasketDatabase.Models.ServiceHistory", b =>
|
||||
{
|
||||
b.HasOne("TwoFromTheCasketDatabase.Models.Service", "Service")
|
||||
.WithMany("ServiceHistory")
|
||||
.HasForeignKey("ServiceId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Service");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("TwoFromTheCasketDatabase.Models.ServiceOrder", b =>
|
||||
{
|
||||
b.HasOne("TwoFromTheCasketDatabase.Models.Master", null)
|
||||
.WithMany("ServiceOrders")
|
||||
.HasForeignKey("ServiceOrderId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
});
|
||||
|
||||
modelBuilder.Entity("TwoFromTheCasketDatabase.Models.Master", b =>
|
||||
{
|
||||
b.Navigation("Salaries");
|
||||
|
||||
b.Navigation("ServiceOrders");
|
||||
|
||||
b.Navigation("Services");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("TwoFromTheCasketDatabase.Models.Service", b =>
|
||||
{
|
||||
b.Navigation("ServiceHistory");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace TwoFromTheCasketDatabase.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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,280 @@
|
||||
// <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 TwoFromTheCasketDatabase;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace TwoFromTheCasketDatabase.Migrations
|
||||
{
|
||||
[DbContext(typeof(TwoFromTheCasketDbContext))]
|
||||
[Migration("20250907172931_AddDateOfDeleteToMasterAndIdToSalary")]
|
||||
partial class AddDateOfDeleteToMasterAndIdToSalary
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "9.0.1")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||
|
||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("TwoFromTheCasketDatabase.Models.Master", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTime>("BirthDate")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<DateTime?>("DateOfDelete")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<DateTime>("EmploymentDate")
|
||||
.HasColumnType("timestamp with 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.HasIndex("Id", "IsDeleted")
|
||||
.IsUnique()
|
||||
.HasFilter("\"IsDeleted\" = FALSE");
|
||||
|
||||
b.ToTable("Masters");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("TwoFromTheCasketDatabase.Models.Order", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTime>("Date")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<int>("RoomType")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("Status")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("Id")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("Orders");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("TwoFromTheCasketDatabase.Models.Post", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTime>("ChangeDate")
|
||||
.HasColumnType("timestamp with 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("TwoFromTheCasketDatabase.Models.Salary", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("MasterId")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<double>("Prize")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.Property<DateTime>("SalaryDate")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<string>("SalaryId")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<double>("SalarySize")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("SalaryId");
|
||||
|
||||
b.ToTable("Salaries");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("TwoFromTheCasketDatabase.Models.Service", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<bool>("IsDeleted")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<string>("MasterId")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<double>("Price")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.Property<string>("ServiceId")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("ServiceName")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int>("ServiceType")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ServiceId");
|
||||
|
||||
b.HasIndex("ServiceName", "IsDeleted")
|
||||
.IsUnique()
|
||||
.HasFilter("\"IsDeleted\" = FALSE");
|
||||
|
||||
b.ToTable("Services");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("TwoFromTheCasketDatabase.Models.ServiceHistory", b =>
|
||||
{
|
||||
b.Property<string>("ServiceId")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTime>("ChangeDate")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<double>("OldPrice")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.HasKey("ServiceId");
|
||||
|
||||
b.ToTable("ServiceHistories");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("TwoFromTheCasketDatabase.Models.ServiceOrder", b =>
|
||||
{
|
||||
b.Property<string>("ServiceId")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("MasterId")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("OrderId")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("ServiceOrderId")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int>("TimeOfWorking")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("ServiceId", "MasterId", "OrderId");
|
||||
|
||||
b.HasIndex("ServiceOrderId");
|
||||
|
||||
b.ToTable("ServiceOrders");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("TwoFromTheCasketDatabase.Models.Salary", b =>
|
||||
{
|
||||
b.HasOne("TwoFromTheCasketDatabase.Models.Master", "Master")
|
||||
.WithMany("Salaries")
|
||||
.HasForeignKey("SalaryId");
|
||||
|
||||
b.Navigation("Master");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("TwoFromTheCasketDatabase.Models.Service", b =>
|
||||
{
|
||||
b.HasOne("TwoFromTheCasketDatabase.Models.Master", null)
|
||||
.WithMany("Services")
|
||||
.HasForeignKey("ServiceId");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("TwoFromTheCasketDatabase.Models.ServiceHistory", b =>
|
||||
{
|
||||
b.HasOne("TwoFromTheCasketDatabase.Models.Service", "Service")
|
||||
.WithMany("ServiceHistory")
|
||||
.HasForeignKey("ServiceId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Service");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("TwoFromTheCasketDatabase.Models.ServiceOrder", b =>
|
||||
{
|
||||
b.HasOne("TwoFromTheCasketDatabase.Models.Master", null)
|
||||
.WithMany("ServiceOrders")
|
||||
.HasForeignKey("ServiceOrderId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
});
|
||||
|
||||
modelBuilder.Entity("TwoFromTheCasketDatabase.Models.Master", b =>
|
||||
{
|
||||
b.Navigation("Salaries");
|
||||
|
||||
b.Navigation("ServiceOrders");
|
||||
|
||||
b.Navigation("Services");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("TwoFromTheCasketDatabase.Models.Service", b =>
|
||||
{
|
||||
b.Navigation("ServiceHistory");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace TwoFromTheCasketDatabase.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class AddDateOfDeleteToMasterAndIdToSalary : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "FK_Salaries_Masters_MasterId",
|
||||
table: "Salaries");
|
||||
|
||||
migrationBuilder.DropIndex(
|
||||
name: "IX_Salaries_MasterId",
|
||||
table: "Salaries");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Salaries_SalaryId",
|
||||
table: "Salaries",
|
||||
column: "SalaryId");
|
||||
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "FK_Salaries_Masters_SalaryId",
|
||||
table: "Salaries",
|
||||
column: "SalaryId",
|
||||
principalTable: "Masters",
|
||||
principalColumn: "Id");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "FK_Salaries_Masters_SalaryId",
|
||||
table: "Salaries");
|
||||
|
||||
migrationBuilder.DropIndex(
|
||||
name: "IX_Salaries_SalaryId",
|
||||
table: "Salaries");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Salaries_MasterId",
|
||||
table: "Salaries",
|
||||
column: "MasterId");
|
||||
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "FK_Salaries_Masters_MasterId",
|
||||
table: "Salaries",
|
||||
column: "MasterId",
|
||||
principalTable: "Masters",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,285 @@
|
||||
// <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 TwoFromTheCasketDatabase;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace TwoFromTheCasketDatabase.Migrations
|
||||
{
|
||||
[DbContext(typeof(TwoFromTheCasketDbContext))]
|
||||
[Migration("20250907182212_AddSalaryForeignKey")]
|
||||
partial class AddSalaryForeignKey
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "9.0.1")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||
|
||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("TwoFromTheCasketDatabase.Models.Master", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTime>("BirthDate")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<DateTime>("EmploymentDate")
|
||||
.HasColumnType("timestamp with 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.HasIndex("Id", "IsDeleted")
|
||||
.IsUnique()
|
||||
.HasFilter("\"IsDeleted\" = FALSE");
|
||||
|
||||
b.ToTable("Masters");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("TwoFromTheCasketDatabase.Models.Order", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTime>("Date")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<int>("RoomType")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("Status")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("Id")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("Orders");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("TwoFromTheCasketDatabase.Models.Post", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTime>("ChangeDate")
|
||||
.HasColumnType("timestamp with 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("TwoFromTheCasketDatabase.Models.Salary", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("MasterId")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<double>("Prize")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.Property<DateTime>("SalaryDate")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<string>("SalaryId")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<double>("SalarySize")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("MasterId");
|
||||
|
||||
b.HasIndex("SalaryId");
|
||||
|
||||
b.ToTable("Salaries");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("TwoFromTheCasketDatabase.Models.Service", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<bool>("IsDeleted")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<string>("MasterId")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<double>("Price")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.Property<string>("ServiceId")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("ServiceName")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int>("ServiceType")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ServiceId");
|
||||
|
||||
b.HasIndex("ServiceName", "IsDeleted")
|
||||
.IsUnique()
|
||||
.HasFilter("\"IsDeleted\" = FALSE");
|
||||
|
||||
b.ToTable("Services");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("TwoFromTheCasketDatabase.Models.ServiceHistory", b =>
|
||||
{
|
||||
b.Property<string>("ServiceId")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTime>("ChangeDate")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<double>("OldPrice")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.HasKey("ServiceId");
|
||||
|
||||
b.ToTable("ServiceHistories");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("TwoFromTheCasketDatabase.Models.ServiceOrder", b =>
|
||||
{
|
||||
b.Property<string>("ServiceId")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("MasterId")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("OrderId")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("ServiceOrderId")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int>("TimeOfWorking")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("ServiceId", "MasterId", "OrderId");
|
||||
|
||||
b.HasIndex("ServiceOrderId");
|
||||
|
||||
b.ToTable("ServiceOrders");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("TwoFromTheCasketDatabase.Models.Salary", b =>
|
||||
{
|
||||
b.HasOne("TwoFromTheCasketDatabase.Models.Master", "Master")
|
||||
.WithMany()
|
||||
.HasForeignKey("MasterId")
|
||||
.OnDelete(DeleteBehavior.Restrict)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("TwoFromTheCasketDatabase.Models.Master", null)
|
||||
.WithMany("Salaries")
|
||||
.HasForeignKey("SalaryId");
|
||||
|
||||
b.Navigation("Master");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("TwoFromTheCasketDatabase.Models.Service", b =>
|
||||
{
|
||||
b.HasOne("TwoFromTheCasketDatabase.Models.Master", null)
|
||||
.WithMany("Services")
|
||||
.HasForeignKey("ServiceId");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("TwoFromTheCasketDatabase.Models.ServiceHistory", b =>
|
||||
{
|
||||
b.HasOne("TwoFromTheCasketDatabase.Models.Service", "Service")
|
||||
.WithMany("ServiceHistory")
|
||||
.HasForeignKey("ServiceId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Service");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("TwoFromTheCasketDatabase.Models.ServiceOrder", b =>
|
||||
{
|
||||
b.HasOne("TwoFromTheCasketDatabase.Models.Master", null)
|
||||
.WithMany("ServiceOrders")
|
||||
.HasForeignKey("ServiceOrderId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
});
|
||||
|
||||
modelBuilder.Entity("TwoFromTheCasketDatabase.Models.Master", b =>
|
||||
{
|
||||
b.Navigation("Salaries");
|
||||
|
||||
b.Navigation("ServiceOrders");
|
||||
|
||||
b.Navigation("Services");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("TwoFromTheCasketDatabase.Models.Service", b =>
|
||||
{
|
||||
b.Navigation("ServiceHistory");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace TwoFromTheCasketDatabase.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class AddSalaryForeignKey : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Salaries_MasterId",
|
||||
table: "Salaries",
|
||||
column: "MasterId");
|
||||
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "FK_Salaries_Masters_MasterId",
|
||||
table: "Salaries",
|
||||
column: "MasterId",
|
||||
principalTable: "Masters",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Restrict);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "FK_Salaries_Masters_MasterId",
|
||||
table: "Salaries");
|
||||
|
||||
migrationBuilder.DropIndex(
|
||||
name: "IX_Salaries_MasterId",
|
||||
table: "Salaries");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,280 @@
|
||||
// <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 TwoFromTheCasketDatabase;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace TwoFromTheCasketDatabase.Migrations
|
||||
{
|
||||
[DbContext(typeof(TwoFromTheCasketDbContext))]
|
||||
[Migration("20250907183927_FixSalaryForeignKeyConfiguration")]
|
||||
partial class FixSalaryForeignKeyConfiguration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "9.0.1")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||
|
||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("TwoFromTheCasketDatabase.Models.Master", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTime>("BirthDate")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<DateTime>("EmploymentDate")
|
||||
.HasColumnType("timestamp with 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.HasIndex("Id", "IsDeleted")
|
||||
.IsUnique()
|
||||
.HasFilter("\"IsDeleted\" = FALSE");
|
||||
|
||||
b.ToTable("Masters");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("TwoFromTheCasketDatabase.Models.Order", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTime>("Date")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<int>("RoomType")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("Status")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("Id")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("Orders");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("TwoFromTheCasketDatabase.Models.Post", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTime>("ChangeDate")
|
||||
.HasColumnType("timestamp with 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("TwoFromTheCasketDatabase.Models.Salary", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("MasterId")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<double>("Prize")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.Property<DateTime>("SalaryDate")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<string>("SalaryId")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<double>("SalarySize")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("MasterId", "SalaryDate")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("Salaries");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("TwoFromTheCasketDatabase.Models.Service", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<bool>("IsDeleted")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<string>("MasterId")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<double>("Price")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.Property<string>("ServiceId")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("ServiceName")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int>("ServiceType")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ServiceId");
|
||||
|
||||
b.HasIndex("ServiceName", "IsDeleted")
|
||||
.IsUnique()
|
||||
.HasFilter("\"IsDeleted\" = FALSE");
|
||||
|
||||
b.ToTable("Services");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("TwoFromTheCasketDatabase.Models.ServiceHistory", b =>
|
||||
{
|
||||
b.Property<string>("ServiceId")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTime>("ChangeDate")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<double>("OldPrice")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.HasKey("ServiceId");
|
||||
|
||||
b.ToTable("ServiceHistories");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("TwoFromTheCasketDatabase.Models.ServiceOrder", b =>
|
||||
{
|
||||
b.Property<string>("ServiceId")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("MasterId")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("OrderId")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("ServiceOrderId")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int>("TimeOfWorking")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("ServiceId", "MasterId", "OrderId");
|
||||
|
||||
b.HasIndex("ServiceOrderId");
|
||||
|
||||
b.ToTable("ServiceOrders");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("TwoFromTheCasketDatabase.Models.Salary", b =>
|
||||
{
|
||||
b.HasOne("TwoFromTheCasketDatabase.Models.Master", "Master")
|
||||
.WithMany("Salaries")
|
||||
.HasForeignKey("MasterId")
|
||||
.OnDelete(DeleteBehavior.Restrict)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Master");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("TwoFromTheCasketDatabase.Models.Service", b =>
|
||||
{
|
||||
b.HasOne("TwoFromTheCasketDatabase.Models.Master", null)
|
||||
.WithMany("Services")
|
||||
.HasForeignKey("ServiceId");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("TwoFromTheCasketDatabase.Models.ServiceHistory", b =>
|
||||
{
|
||||
b.HasOne("TwoFromTheCasketDatabase.Models.Service", "Service")
|
||||
.WithMany("ServiceHistory")
|
||||
.HasForeignKey("ServiceId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Service");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("TwoFromTheCasketDatabase.Models.ServiceOrder", b =>
|
||||
{
|
||||
b.HasOne("TwoFromTheCasketDatabase.Models.Master", null)
|
||||
.WithMany("ServiceOrders")
|
||||
.HasForeignKey("ServiceOrderId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
});
|
||||
|
||||
modelBuilder.Entity("TwoFromTheCasketDatabase.Models.Master", b =>
|
||||
{
|
||||
b.Navigation("Salaries");
|
||||
|
||||
b.Navigation("ServiceOrders");
|
||||
|
||||
b.Navigation("Services");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("TwoFromTheCasketDatabase.Models.Service", b =>
|
||||
{
|
||||
b.Navigation("ServiceHistory");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace TwoFromTheCasketDatabase.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class FixSalaryForeignKeyConfiguration : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "FK_Salaries_Masters_SalaryId",
|
||||
table: "Salaries");
|
||||
|
||||
migrationBuilder.DropIndex(
|
||||
name: "IX_Salaries_MasterId",
|
||||
table: "Salaries");
|
||||
|
||||
migrationBuilder.DropIndex(
|
||||
name: "IX_Salaries_SalaryId",
|
||||
table: "Salaries");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Salaries_MasterId_SalaryDate",
|
||||
table: "Salaries",
|
||||
columns: new[] { "MasterId", "SalaryDate" },
|
||||
unique: true);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropIndex(
|
||||
name: "IX_Salaries_MasterId_SalaryDate",
|
||||
table: "Salaries");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Salaries_MasterId",
|
||||
table: "Salaries",
|
||||
column: "MasterId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Salaries_SalaryId",
|
||||
table: "Salaries",
|
||||
column: "SalaryId");
|
||||
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "FK_Salaries_Masters_SalaryId",
|
||||
table: "Salaries",
|
||||
column: "SalaryId",
|
||||
principalTable: "Masters",
|
||||
principalColumn: "Id");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,313 @@
|
||||
// <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 TwoFromTheCasketDatabase;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace TwoFromTheCasketDatabase.Migrations
|
||||
{
|
||||
[DbContext(typeof(TwoFromTheCasketDbContext))]
|
||||
[Migration("20250912071637_FixServiceOrderStructure")]
|
||||
partial class FixServiceOrderStructure
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "9.0.1")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||
|
||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("TwoFromTheCasketDatabase.Models.Master", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTime>("BirthDate")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<DateTime>("EmploymentDate")
|
||||
.HasColumnType("timestamp with 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.HasIndex("Id", "IsDeleted")
|
||||
.IsUnique()
|
||||
.HasFilter("\"IsDeleted\" = FALSE");
|
||||
|
||||
b.ToTable("Masters");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("TwoFromTheCasketDatabase.Models.Order", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTime>("Date")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<int>("RoomType")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("Status")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("Id")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("Orders");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("TwoFromTheCasketDatabase.Models.Post", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTime>("ChangeDate")
|
||||
.HasColumnType("timestamp with 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("TwoFromTheCasketDatabase.Models.Salary", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("MasterId")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<double>("Prize")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.Property<DateTime>("SalaryDate")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<string>("SalaryId")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<double>("SalarySize")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("MasterId", "SalaryDate")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("Salaries");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("TwoFromTheCasketDatabase.Models.Service", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<bool>("IsDeleted")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<string>("MasterId")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<double>("Price")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.Property<string>("ServiceId")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("ServiceName")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int>("ServiceType")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ServiceId");
|
||||
|
||||
b.HasIndex("ServiceName", "IsDeleted")
|
||||
.IsUnique()
|
||||
.HasFilter("\"IsDeleted\" = FALSE");
|
||||
|
||||
b.ToTable("Services");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("TwoFromTheCasketDatabase.Models.ServiceHistory", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<DateTime>("ChangeDate")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<double>("OldPrice")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.Property<string>("ServiceId")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ServiceId");
|
||||
|
||||
b.ToTable("ServiceHistories");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("TwoFromTheCasketDatabase.Models.ServiceOrder", b =>
|
||||
{
|
||||
b.Property<string>("ServiceOrderId")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("MasterId")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("OrderId")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("ServiceId")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int>("TimeOfWorking")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("ServiceOrderId");
|
||||
|
||||
b.HasIndex("MasterId");
|
||||
|
||||
b.HasIndex("OrderId");
|
||||
|
||||
b.HasIndex("ServiceId");
|
||||
|
||||
b.ToTable("ServiceOrders");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("TwoFromTheCasketDatabase.Models.Salary", b =>
|
||||
{
|
||||
b.HasOne("TwoFromTheCasketDatabase.Models.Master", "Master")
|
||||
.WithMany("Salaries")
|
||||
.HasForeignKey("MasterId")
|
||||
.OnDelete(DeleteBehavior.Restrict)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Master");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("TwoFromTheCasketDatabase.Models.Service", b =>
|
||||
{
|
||||
b.HasOne("TwoFromTheCasketDatabase.Models.Master", null)
|
||||
.WithMany("Services")
|
||||
.HasForeignKey("ServiceId");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("TwoFromTheCasketDatabase.Models.ServiceHistory", b =>
|
||||
{
|
||||
b.HasOne("TwoFromTheCasketDatabase.Models.Service", "Service")
|
||||
.WithMany("ServiceHistory")
|
||||
.HasForeignKey("ServiceId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Service");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("TwoFromTheCasketDatabase.Models.ServiceOrder", b =>
|
||||
{
|
||||
b.HasOne("TwoFromTheCasketDatabase.Models.Master", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("MasterId")
|
||||
.OnDelete(DeleteBehavior.Restrict)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("TwoFromTheCasketDatabase.Models.Order", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("OrderId")
|
||||
.OnDelete(DeleteBehavior.Restrict)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("TwoFromTheCasketDatabase.Models.Service", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("ServiceId")
|
||||
.OnDelete(DeleteBehavior.Restrict)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("TwoFromTheCasketDatabase.Models.Master", null)
|
||||
.WithMany("ServiceOrders")
|
||||
.HasForeignKey("ServiceOrderId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
});
|
||||
|
||||
modelBuilder.Entity("TwoFromTheCasketDatabase.Models.Master", b =>
|
||||
{
|
||||
b.Navigation("Salaries");
|
||||
|
||||
b.Navigation("ServiceOrders");
|
||||
|
||||
b.Navigation("Services");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("TwoFromTheCasketDatabase.Models.Service", b =>
|
||||
{
|
||||
b.Navigation("ServiceHistory");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,148 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace TwoFromTheCasketDatabase.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class FixServiceOrderStructure : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropPrimaryKey(
|
||||
name: "PK_ServiceOrders",
|
||||
table: "ServiceOrders");
|
||||
|
||||
migrationBuilder.DropIndex(
|
||||
name: "IX_ServiceOrders_ServiceOrderId",
|
||||
table: "ServiceOrders");
|
||||
|
||||
migrationBuilder.DropPrimaryKey(
|
||||
name: "PK_ServiceHistories",
|
||||
table: "ServiceHistories");
|
||||
|
||||
migrationBuilder.AddColumn<int>(
|
||||
name: "Id",
|
||||
table: "ServiceHistories",
|
||||
type: "integer",
|
||||
nullable: false,
|
||||
defaultValue: 0)
|
||||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
|
||||
|
||||
migrationBuilder.AddPrimaryKey(
|
||||
name: "PK_ServiceOrders",
|
||||
table: "ServiceOrders",
|
||||
column: "ServiceOrderId");
|
||||
|
||||
migrationBuilder.AddPrimaryKey(
|
||||
name: "PK_ServiceHistories",
|
||||
table: "ServiceHistories",
|
||||
column: "Id");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_ServiceOrders_MasterId",
|
||||
table: "ServiceOrders",
|
||||
column: "MasterId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_ServiceOrders_OrderId",
|
||||
table: "ServiceOrders",
|
||||
column: "OrderId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_ServiceOrders_ServiceId",
|
||||
table: "ServiceOrders",
|
||||
column: "ServiceId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_ServiceHistories_ServiceId",
|
||||
table: "ServiceHistories",
|
||||
column: "ServiceId");
|
||||
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "FK_ServiceOrders_Masters_MasterId",
|
||||
table: "ServiceOrders",
|
||||
column: "MasterId",
|
||||
principalTable: "Masters",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Restrict);
|
||||
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "FK_ServiceOrders_Orders_OrderId",
|
||||
table: "ServiceOrders",
|
||||
column: "OrderId",
|
||||
principalTable: "Orders",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Restrict);
|
||||
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "FK_ServiceOrders_Services_ServiceId",
|
||||
table: "ServiceOrders",
|
||||
column: "ServiceId",
|
||||
principalTable: "Services",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Restrict);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "FK_ServiceOrders_Masters_MasterId",
|
||||
table: "ServiceOrders");
|
||||
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "FK_ServiceOrders_Orders_OrderId",
|
||||
table: "ServiceOrders");
|
||||
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "FK_ServiceOrders_Services_ServiceId",
|
||||
table: "ServiceOrders");
|
||||
|
||||
migrationBuilder.DropPrimaryKey(
|
||||
name: "PK_ServiceOrders",
|
||||
table: "ServiceOrders");
|
||||
|
||||
migrationBuilder.DropIndex(
|
||||
name: "IX_ServiceOrders_MasterId",
|
||||
table: "ServiceOrders");
|
||||
|
||||
migrationBuilder.DropIndex(
|
||||
name: "IX_ServiceOrders_OrderId",
|
||||
table: "ServiceOrders");
|
||||
|
||||
migrationBuilder.DropIndex(
|
||||
name: "IX_ServiceOrders_ServiceId",
|
||||
table: "ServiceOrders");
|
||||
|
||||
migrationBuilder.DropPrimaryKey(
|
||||
name: "PK_ServiceHistories",
|
||||
table: "ServiceHistories");
|
||||
|
||||
migrationBuilder.DropIndex(
|
||||
name: "IX_ServiceHistories_ServiceId",
|
||||
table: "ServiceHistories");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "Id",
|
||||
table: "ServiceHistories");
|
||||
|
||||
migrationBuilder.AddPrimaryKey(
|
||||
name: "PK_ServiceOrders",
|
||||
table: "ServiceOrders",
|
||||
columns: new[] { "ServiceId", "MasterId", "OrderId" });
|
||||
|
||||
migrationBuilder.AddPrimaryKey(
|
||||
name: "PK_ServiceHistories",
|
||||
table: "ServiceHistories",
|
||||
column: "ServiceId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_ServiceOrders_ServiceOrderId",
|
||||
table: "ServiceOrders",
|
||||
column: "ServiceOrderId");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,310 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
using TwoFromTheCasketDatabase;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace TwoFromTheCasketDatabase.Migrations
|
||||
{
|
||||
[DbContext(typeof(TwoFromTheCasketDbContext))]
|
||||
partial class TwoFromTheCasketDbContextModelSnapshot : ModelSnapshot
|
||||
{
|
||||
protected override void BuildModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "9.0.1")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||
|
||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("TwoFromTheCasketDatabase.Models.Master", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTime>("BirthDate")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<DateTime>("EmploymentDate")
|
||||
.HasColumnType("timestamp with 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.HasIndex("Id", "IsDeleted")
|
||||
.IsUnique()
|
||||
.HasFilter("\"IsDeleted\" = FALSE");
|
||||
|
||||
b.ToTable("Masters");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("TwoFromTheCasketDatabase.Models.Order", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTime>("Date")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<int>("RoomType")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("Status")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("Id")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("Orders");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("TwoFromTheCasketDatabase.Models.Post", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTime>("ChangeDate")
|
||||
.HasColumnType("timestamp with 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("TwoFromTheCasketDatabase.Models.Salary", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("MasterId")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<double>("Prize")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.Property<DateTime>("SalaryDate")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<string>("SalaryId")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<double>("SalarySize")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("MasterId", "SalaryDate")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("Salaries");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("TwoFromTheCasketDatabase.Models.Service", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<bool>("IsDeleted")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<string>("MasterId")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<double>("Price")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.Property<string>("ServiceId")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("ServiceName")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int>("ServiceType")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ServiceId");
|
||||
|
||||
b.HasIndex("ServiceName", "IsDeleted")
|
||||
.IsUnique()
|
||||
.HasFilter("\"IsDeleted\" = FALSE");
|
||||
|
||||
b.ToTable("Services");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("TwoFromTheCasketDatabase.Models.ServiceHistory", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<DateTime>("ChangeDate")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<double>("OldPrice")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.Property<string>("ServiceId")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ServiceId");
|
||||
|
||||
b.ToTable("ServiceHistories");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("TwoFromTheCasketDatabase.Models.ServiceOrder", b =>
|
||||
{
|
||||
b.Property<string>("ServiceOrderId")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("MasterId")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("OrderId")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("ServiceId")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int>("TimeOfWorking")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("ServiceOrderId");
|
||||
|
||||
b.HasIndex("MasterId");
|
||||
|
||||
b.HasIndex("OrderId");
|
||||
|
||||
b.HasIndex("ServiceId");
|
||||
|
||||
b.ToTable("ServiceOrders");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("TwoFromTheCasketDatabase.Models.Salary", b =>
|
||||
{
|
||||
b.HasOne("TwoFromTheCasketDatabase.Models.Master", "Master")
|
||||
.WithMany("Salaries")
|
||||
.HasForeignKey("MasterId")
|
||||
.OnDelete(DeleteBehavior.Restrict)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Master");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("TwoFromTheCasketDatabase.Models.Service", b =>
|
||||
{
|
||||
b.HasOne("TwoFromTheCasketDatabase.Models.Master", null)
|
||||
.WithMany("Services")
|
||||
.HasForeignKey("ServiceId");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("TwoFromTheCasketDatabase.Models.ServiceHistory", b =>
|
||||
{
|
||||
b.HasOne("TwoFromTheCasketDatabase.Models.Service", "Service")
|
||||
.WithMany("ServiceHistory")
|
||||
.HasForeignKey("ServiceId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Service");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("TwoFromTheCasketDatabase.Models.ServiceOrder", b =>
|
||||
{
|
||||
b.HasOne("TwoFromTheCasketDatabase.Models.Master", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("MasterId")
|
||||
.OnDelete(DeleteBehavior.Restrict)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("TwoFromTheCasketDatabase.Models.Order", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("OrderId")
|
||||
.OnDelete(DeleteBehavior.Restrict)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("TwoFromTheCasketDatabase.Models.Service", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("ServiceId")
|
||||
.OnDelete(DeleteBehavior.Restrict)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("TwoFromTheCasketDatabase.Models.Master", null)
|
||||
.WithMany("ServiceOrders")
|
||||
.HasForeignKey("ServiceOrderId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
});
|
||||
|
||||
modelBuilder.Entity("TwoFromTheCasketDatabase.Models.Master", b =>
|
||||
{
|
||||
b.Navigation("Salaries");
|
||||
|
||||
b.Navigation("ServiceOrders");
|
||||
|
||||
b.Navigation("Services");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("TwoFromTheCasketDatabase.Models.Service", b =>
|
||||
{
|
||||
b.Navigation("ServiceHistory");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using AutoMapper;
|
||||
using TwoFromTheCasketContratcs.DataModels;
|
||||
|
||||
namespace TwoFromTheCasketDatabase.Models;
|
||||
|
||||
[AutoMap(typeof(MasterDataModel), ReverseMap = true)]
|
||||
internal class Master
|
||||
{
|
||||
public required string Id { get; set; }
|
||||
|
||||
public required string FIO { get; set; }
|
||||
|
||||
[ForeignKey("PostId")]
|
||||
public required string PostId { get; set; }
|
||||
|
||||
public DateTime BirthDate { get; set; }
|
||||
|
||||
public DateTime EmploymentDate { get; set; }
|
||||
|
||||
public bool IsDeleted { get; set; }
|
||||
[ForeignKey("ServiceId")]
|
||||
public List<Service>? Services { get; set; }
|
||||
|
||||
[ForeignKey("SalaryId")]
|
||||
public List<Salary>? Salaries { get; set; }
|
||||
|
||||
public List<ServiceOrder>? ServiceOrders { get; set; }
|
||||
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
using AutoMapper;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using TwoFromTheCasketContratcs.DataModels;
|
||||
using TwoFromTheCasketContratcs.Enums;
|
||||
|
||||
namespace TwoFromTheCasketDatabase.Models;
|
||||
|
||||
|
||||
internal class Order
|
||||
{
|
||||
public required string Id { get; set; }
|
||||
|
||||
public DateTime Date { get; set; }
|
||||
|
||||
public StatusType Status { get; set; }
|
||||
|
||||
public RoomType RoomType { get; set; }
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using TwoFromTheCasketContratcs.Enums;
|
||||
using TwoFromTheCasketContratcs.Infrastructure.PostConfigurations;
|
||||
|
||||
namespace TwoFromTheCasketDatabase.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; }
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
using AutoMapper;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using TwoFromTheCasketContratcs.DataModels;
|
||||
|
||||
namespace TwoFromTheCasketDatabase.Models;
|
||||
|
||||
[AutoMap(typeof(SalaryDataModel), ReverseMap = true)]
|
||||
internal class Salary
|
||||
{
|
||||
public string Id { get; set; } = Guid.NewGuid().ToString();
|
||||
public required string MasterId { get; set; }
|
||||
|
||||
public DateTime SalaryDate { get; set; }
|
||||
|
||||
public required double SalarySize { get; set; }
|
||||
|
||||
public double Prize { get; set; }
|
||||
|
||||
public Master? Master { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using TwoFromTheCasketContratcs.Enums;
|
||||
|
||||
namespace TwoFromTheCasketDatabase.Models;
|
||||
|
||||
internal class Service
|
||||
{
|
||||
public required string Id { get; set; }
|
||||
|
||||
public required string ServiceName { get; set; }
|
||||
|
||||
public required ServiceType ServiceType { get; set; }
|
||||
|
||||
public required string MasterId { get; set; }
|
||||
|
||||
public required double Price { get; set; }
|
||||
|
||||
public required bool IsDeleted { get; set; }
|
||||
|
||||
[ForeignKey("ServiceId")]
|
||||
public List<ServiceHistory>? ServiceHistory { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace TwoFromTheCasketDatabase.Models;
|
||||
|
||||
internal class ServiceHistory
|
||||
{
|
||||
public string Id { get; set; } = Guid.NewGuid().ToString();
|
||||
|
||||
public required string ServiceId { get; set; }
|
||||
|
||||
public required double OldPrice { get; set; }
|
||||
|
||||
public DateTime ChangeDate { get; set; } = DateTime.UtcNow;
|
||||
|
||||
public Service? Service { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace TwoFromTheCasketDatabase.Models;
|
||||
|
||||
internal class ServiceOrder
|
||||
{
|
||||
public string ServiceOrderId { get; set; } = Guid.NewGuid().ToString();
|
||||
|
||||
public required string OrderId { get; set; }
|
||||
|
||||
public required string ServiceId { get; set; }
|
||||
|
||||
public required string MasterId { get; set; }
|
||||
|
||||
public int TimeOfWorking { 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