Compare commits
21 Commits
Task_1_Mod
...
Task_6_Rep
| Author | SHA1 | Date | |
|---|---|---|---|
| 29d974f2c1 | |||
| 04966ef9e5 | |||
| eff45b4815 | |||
| 9968b6d69e | |||
| b1a49bfde3 | |||
| 9f03eaa09e | |||
| 1b8b1a06f8 | |||
| fddb9c9d83 | |||
| 5e249e488c | |||
| bd0c52b9f1 | |||
| e1e8d23bd0 | |||
| d3bf4eec43 | |||
| abbfe117f9 | |||
| 8bdc9275d5 | |||
| 65a03714a2 | |||
| 2ee47af951 | |||
| cf45ffb67d | |||
| 9c06125d66 | |||
| fda7d01074 | |||
| 46f94f62b9 | |||
| af9e774126 |
@@ -0,0 +1,68 @@
|
||||
using SmallSoftwareContracts.BusinessLogicsContracts;
|
||||
using SmallSoftwareContracts.DataModels;
|
||||
using SmallSoftwareContracts.StoragesContracts;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using SmallSoftwareContracts.Exceptions;
|
||||
using SmallSoftwareContracts.Extensions;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace SmallSoftwareBusinessLogic.Implementations;
|
||||
|
||||
internal class ManufacturerBusinessLogicContract(IManufacturerStorageContract
|
||||
manufacturerStorageContract, ILogger logger) : IManufacturerBusinessLogicContract
|
||||
{
|
||||
private readonly ILogger _logger = logger;
|
||||
private readonly IManufacturerStorageContract _manufacturerStorageContract
|
||||
= manufacturerStorageContract;
|
||||
public List<ManufacturerDataModel> GetAllManufacturers()
|
||||
{
|
||||
_logger.LogInformation("GetAllManufacturers");
|
||||
return _manufacturerStorageContract.GetList() ?? throw new
|
||||
NullListException();
|
||||
}
|
||||
public ManufacturerDataModel GetManufacturerByData(string data)
|
||||
{
|
||||
_logger.LogInformation("Get element by data: {data}", data);
|
||||
if (data.IsEmpty())
|
||||
{
|
||||
throw new ArgumentNullException(nameof(data));
|
||||
}
|
||||
if (data.IsGuid())
|
||||
{
|
||||
return _manufacturerStorageContract.GetElementById(data) ??
|
||||
throw new ElementNotFoundException(data);
|
||||
}
|
||||
return _manufacturerStorageContract.GetElementByName(data) ??
|
||||
_manufacturerStorageContract.GetElementByOldName(data) ??
|
||||
throw new ElementNotFoundException(data);
|
||||
}
|
||||
public void InsertManufacturer(ManufacturerDataModel manufacturerDataModel)
|
||||
{
|
||||
_logger.LogInformation("New data: {json}",
|
||||
JsonSerializer.Serialize(manufacturerDataModel));
|
||||
ArgumentNullException.ThrowIfNull(manufacturerDataModel);
|
||||
manufacturerDataModel.Validate();
|
||||
_manufacturerStorageContract.AddElement(manufacturerDataModel);
|
||||
}
|
||||
public void UpdateManufacturer(ManufacturerDataModel manufacturerDataModel)
|
||||
{
|
||||
_logger.LogInformation("Update data: {json}",
|
||||
JsonSerializer.Serialize(manufacturerDataModel));
|
||||
ArgumentNullException.ThrowIfNull(manufacturerDataModel);
|
||||
manufacturerDataModel.Validate();
|
||||
_manufacturerStorageContract.UpdElement(manufacturerDataModel);
|
||||
}
|
||||
public void DeleteManufacturer(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");
|
||||
}
|
||||
_manufacturerStorageContract.DelElement(id);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using SmallSoftwareContracts.BusinessLogicsContracts;
|
||||
using SmallSoftwareContracts.DataModels;
|
||||
using SmallSoftwareContracts.Enums;
|
||||
using SmallSoftwareContracts.Exceptions;
|
||||
using SmallSoftwareContracts.Extensions;
|
||||
using SmallSoftwareContracts.StoragesContracts;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SmallSoftwareBusinessLogic.Implementations;
|
||||
|
||||
internal class PostBusinessLogicContract(IPostStorageContract
|
||||
postStorageContract, ILogger logger) : IPostBusinessLogicContract
|
||||
{
|
||||
private readonly ILogger _logger = logger;
|
||||
private readonly IPostStorageContract _postStorageContract =
|
||||
postStorageContract;
|
||||
public List<PostDataModel> GetAllPosts()
|
||||
{
|
||||
_logger.LogInformation("GetAllPosts");
|
||||
return _postStorageContract.GetList() ?? throw new NullListException();
|
||||
}
|
||||
public List<PostDataModel> GetAllDataOfPost(string postId)
|
||||
{
|
||||
_logger.LogInformation("GetAllDataOfPost for {postId}", postId);
|
||||
if (postId.IsEmpty())
|
||||
{
|
||||
throw new ArgumentNullException(nameof(postId));
|
||||
}
|
||||
if (!postId.IsGuid())
|
||||
{
|
||||
throw new ValidationException("The value in the field postId is not a unique identifier.");
|
||||
}
|
||||
return _postStorageContract.GetPostWithHistory(postId) ?? throw new
|
||||
NullListException();
|
||||
}
|
||||
public PostDataModel GetPostByData(string data)
|
||||
{
|
||||
_logger.LogInformation("Get element by data: {data}", data);
|
||||
if (data.IsEmpty())
|
||||
{
|
||||
throw new ArgumentNullException(nameof(data));
|
||||
}
|
||||
if (data.IsGuid())
|
||||
{
|
||||
return _postStorageContract.GetElementById(data) ?? throw new
|
||||
ElementNotFoundException(data);
|
||||
}
|
||||
return _postStorageContract.GetElementByName(data) ?? throw new
|
||||
ElementNotFoundException(data);
|
||||
}
|
||||
public void InsertPost(PostDataModel postDataModel)
|
||||
{
|
||||
_logger.LogInformation("New data: {json}",
|
||||
JsonSerializer.Serialize(postDataModel));
|
||||
ArgumentNullException.ThrowIfNull(postDataModel);
|
||||
postDataModel.Validate();
|
||||
_postStorageContract.AddElement(postDataModel);
|
||||
}
|
||||
public void UpdatePost(PostDataModel postDataModel)
|
||||
{
|
||||
_logger.LogInformation("Update data: {json}",
|
||||
JsonSerializer.Serialize(postDataModel));
|
||||
ArgumentNullException.ThrowIfNull(postDataModel);
|
||||
postDataModel.Validate();
|
||||
_postStorageContract.UpdElement(postDataModel);
|
||||
}
|
||||
public void DeletePost(string id)
|
||||
{
|
||||
_logger.LogInformation("Delete by id: {id}", id);
|
||||
if (id.IsEmpty())
|
||||
{
|
||||
throw new ArgumentNullException(nameof(id));
|
||||
}
|
||||
if (!id.IsGuid())
|
||||
{
|
||||
throw new ValidationException("Id is not a unique identifier");
|
||||
}
|
||||
_postStorageContract.DelElement(id);
|
||||
}
|
||||
public void RestorePost(string id)
|
||||
{
|
||||
_logger.LogInformation("Restore by id: {id}", id);
|
||||
if (id.IsEmpty())
|
||||
{
|
||||
throw new ArgumentNullException(nameof(id));
|
||||
}
|
||||
if (!id.IsGuid())
|
||||
{
|
||||
throw new ValidationException("Id is not a unique identifier");
|
||||
}
|
||||
_postStorageContract.ResElement(id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,152 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using SmallSoftwareBusinessLogic.OfficePackage;
|
||||
using SmallSoftwareContracts.BusinessLogicsContracts;
|
||||
using SmallSoftwareContracts.DataModels;
|
||||
using SmallSoftwareContracts.Exceptions;
|
||||
using SmallSoftwareContracts.Extensions;
|
||||
using SmallSoftwareContracts.StoragesContracts;
|
||||
|
||||
namespace SmallSoftwareBusinessLogic.Implementations;
|
||||
|
||||
internal class ReportContract(ISoftwareStorageContract softwareStorageContract,
|
||||
IRequestStorageContract requestStorageContract,
|
||||
ISalaryStorageContract salaryStorageContract,
|
||||
BaseWordBuilder baseWordBuilder,
|
||||
BaseExcelBuilder baseExcelBuilder,
|
||||
BasePdfBuilder basePdfBuilder, ILogger logger) : IReportContract
|
||||
{
|
||||
private readonly ISoftwareStorageContract _softwareStorageContract = softwareStorageContract;
|
||||
private readonly ILogger _logger = logger;
|
||||
private readonly IRequestStorageContract _requestStorageContract = requestStorageContract;
|
||||
private readonly ISalaryStorageContract _salaryStorageContract = salaryStorageContract;
|
||||
private readonly BaseWordBuilder _baseWordBuilder = baseWordBuilder;
|
||||
private readonly BaseExcelBuilder _baseExcelBuilder = baseExcelBuilder;
|
||||
|
||||
private readonly BasePdfBuilder _basePdfBuilder = basePdfBuilder;
|
||||
|
||||
internal static readonly string[] tableHeader = ["Дата", "Сумма", "Товар", "Кол-во"];
|
||||
internal static readonly string[] documentHeader = ["Название ПО", "Старая цена", "Дата"];
|
||||
|
||||
public Task<List<HistoryOfSoftwareDataModel>> GetDataSoftwaresByHistoryAsync(CancellationToken ct)
|
||||
{
|
||||
_logger.LogInformation("Get data SoftwaresByManufacturer");
|
||||
return GetDataBySoftwaresAsync(ct);
|
||||
}
|
||||
private async Task<List<HistoryOfSoftwareDataModel>> GetDataBySoftwaresAsync(CancellationToken ct)
|
||||
=> [.. (await _softwareStorageContract.GetListAsync(ct)).GroupBy(x => x.SoftwareName).Select(x => new HistoryOfSoftwareDataModel {
|
||||
SoftwareName = x.Key, Histories = [.. x.Select(y => y.OldPrice.ToString())], Data = [.. x.Select(y => y.ChangeDate.ToString())] })];
|
||||
|
||||
|
||||
public async Task<Stream> CreateDocumentSoftwaresByHistoryAsync(CancellationToken ct)
|
||||
{
|
||||
_logger.LogInformation("Create report HistoryBySoftware");
|
||||
var data = await GetDataBySoftwaresAsync(ct) ?? throw new InvalidOperationException("No found data");
|
||||
|
||||
var tableData = new List<string[]>
|
||||
{
|
||||
documentHeader
|
||||
};
|
||||
|
||||
foreach (var software in data)
|
||||
{
|
||||
tableData.Add(new string[] { software.SoftwareName, "", "" });
|
||||
|
||||
var pairs = software.Histories.Zip(software.Data,
|
||||
(price, date) => new string[] { "", price, date });
|
||||
|
||||
tableData.AddRange(pairs);
|
||||
}
|
||||
|
||||
return _baseWordBuilder
|
||||
.AddHeader("Истории ПО")
|
||||
.AddParagraph($"Сформировано на дату {DateTime.Now}")
|
||||
.AddTable(
|
||||
widths: new[] { 3000, 3000, 3000 },
|
||||
data: tableData
|
||||
)
|
||||
.Build();
|
||||
}
|
||||
|
||||
public Task<List<RequestDataModel>> GetDataRequestByPeriodAsync(DateTime dateStart, DateTime dateFinish, CancellationToken ct)
|
||||
{
|
||||
_logger.LogInformation("Get data RequestsByPeriod from {dateStart} to {dateFinish}", dateStart, dateFinish);
|
||||
return GetDataByRequestsAsync(dateStart, dateFinish, ct);
|
||||
}
|
||||
|
||||
private async Task<List<RequestDataModel>> GetDataByRequestsAsync(DateTime dateStart, DateTime dateFinish, CancellationToken ct)
|
||||
{
|
||||
if (dateStart.IsDateNotOlder(dateFinish))
|
||||
{
|
||||
throw new IncorrectDatesException(dateStart, dateFinish);
|
||||
}
|
||||
return [.. (await _requestStorageContract.GetListAsync(dateStart, dateFinish, ct)).OrderBy(x => x.RequestDate)];
|
||||
}
|
||||
|
||||
public async Task<Stream> CreateDocumentRequestsByPeriodAsync(DateTime dateStart, DateTime dateFinish, CancellationToken ct)
|
||||
{
|
||||
logger.LogInformation("Create report RequestsByPeriod from {dateStart} to {dateFinish}", dateStart, dateFinish);
|
||||
var data = await GetDataByRequestsAsync(dateStart, dateFinish, ct) ?? throw new InvalidOperationException("No found data");
|
||||
|
||||
var tableHeader = new string[] { "Дата", "Email", "Сумма", "ПО", "Количество" };
|
||||
|
||||
return _baseExcelBuilder
|
||||
.AddHeader("Requests за период", 0, 5)
|
||||
.AddParagraph($"c {dateStart.ToShortDateString()} по {dateFinish.ToShortDateString()}", 2)
|
||||
.AddTable(
|
||||
[10, 10, 10, 10, 10],
|
||||
[.. new List<string[]>() { tableHeader }
|
||||
.Union(data.SelectMany(x =>
|
||||
(new List<string[]>() {
|
||||
new string[] {
|
||||
x.RequestDate.ToShortDateString(),
|
||||
x.Email,
|
||||
x.Sum.ToString("N2"),
|
||||
"",
|
||||
""
|
||||
}
|
||||
})
|
||||
.Union(x.Softwares!.Select(y => new string[] {
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
y.SoftwareName,
|
||||
y.Count.ToString("N2")
|
||||
}))
|
||||
.ToArray()
|
||||
)
|
||||
.Union([[
|
||||
"Всего",
|
||||
"",
|
||||
data.Sum(x => x.Sum).ToString("N2"),
|
||||
"",
|
||||
""
|
||||
]]))
|
||||
])
|
||||
.Build();
|
||||
}
|
||||
|
||||
public Task<List<WorkerSalaryByPeriodDataModel>> GetDataSalaryByPeriodAsync(DateTime dateStart, DateTime dateFinish, CancellationToken ct)
|
||||
{
|
||||
logger.LogInformation("Get data SalaryByPeriod from {dateStart} to { dateFinish}", dateStart, dateFinish);
|
||||
return GetDataBySalaryAsync(dateStart, dateFinish, ct);
|
||||
}
|
||||
|
||||
private async Task<List<WorkerSalaryByPeriodDataModel>> GetDataBySalaryAsync(DateTime dateStart, DateTime dateFinish, CancellationToken ct)
|
||||
{
|
||||
if (dateStart.IsDateNotOlder(dateFinish))
|
||||
{
|
||||
throw new IncorrectDatesException(dateStart, dateFinish);
|
||||
}
|
||||
return [.. (await _salaryStorageContract.GetListAsync(dateStart, dateFinish, ct)).GroupBy(x => x.WorkerFIO).Select(x => new
|
||||
WorkerSalaryByPeriodDataModel { WorkerFIO = x.Key, TotalSalary = x.Sum(y => y.Salary),
|
||||
FromPeriod = x.Min(y => y.SalaryDate), ToPeriod = x.Max(y => y.SalaryDate) }).OrderBy(x => x.WorkerFIO)];
|
||||
}
|
||||
|
||||
public async Task<Stream> CreateDocumentSalaryByPeriodAsync(DateTime dateStart, DateTime dateFinish, CancellationToken ct)
|
||||
{
|
||||
_logger.LogInformation("Create report SalaryByPeriod from {dateStart} to { dateFinish}", dateStart, dateFinish);
|
||||
var data = await GetDataBySalaryAsync(dateStart, dateFinish, ct) ?? throw new InvalidOperationException("No found data");
|
||||
return _basePdfBuilder.AddHeader("Зарплатная ведомость").AddParagraph($"за период с {dateStart.ToShortDateString()} по {dateFinish.ToShortDateString()}")
|
||||
.AddPieChart("Начисления", [.. data.Select(x => (x.WorkerFIO, x.TotalSalary))]).Build();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using SmallSoftwareContracts.BusinessLogicsContracts;
|
||||
using SmallSoftwareContracts.DataModels;
|
||||
using SmallSoftwareContracts.Exceptions;
|
||||
using SmallSoftwareContracts.Extensions;
|
||||
using SmallSoftwareContracts.StoragesContracts;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SmallSoftwareBusinessLogic.Implementations;
|
||||
|
||||
internal class RequestBusinessLogicContract(IRequestStorageContract requestStorageContract, ILogger logger) : IRequestBusinessLogicContract
|
||||
{
|
||||
private readonly ILogger _logger = logger;
|
||||
private readonly IRequestStorageContract _requestStorageContract =
|
||||
requestStorageContract;
|
||||
public List<RequestDataModel> GetAllRequestsByPeriod(DateTime fromDate, DateTime toDate)
|
||||
{
|
||||
_logger.LogInformation("GetAllRequests params: {fromDate}, {toDate}", fromDate, toDate);
|
||||
if (fromDate.IsDateNotOlder(toDate))
|
||||
{
|
||||
throw new IncorrectDatesException(fromDate, toDate);
|
||||
}
|
||||
return _requestStorageContract.GetList(fromDate, toDate) ?? throw new NullListException();
|
||||
|
||||
}
|
||||
public List<RequestDataModel> GetAllRequestsByWorkerByPeriod(string workerId, DateTime fromDate, DateTime toDate)
|
||||
{
|
||||
_logger.LogInformation("GetAllRequests params: {workerId}, {fromDate}, { toDate} ", workerId, fromDate, toDate);
|
||||
if (fromDate.IsDateNotOlder(toDate))
|
||||
{
|
||||
throw new IncorrectDatesException(fromDate, toDate);
|
||||
}
|
||||
if (workerId.IsEmpty())
|
||||
{
|
||||
throw new ArgumentNullException(nameof(workerId));
|
||||
}
|
||||
if (!workerId.IsGuid())
|
||||
{
|
||||
throw new ValidationException("The value in the field workerId is not a unique identifier.");
|
||||
}
|
||||
return _requestStorageContract.GetList(fromDate, toDate, workerId:
|
||||
workerId) ?? throw new NullListException();
|
||||
}
|
||||
|
||||
public List<RequestDataModel> GetAllRequestsBySoftwareByPeriod(string softwareId, DateTime fromDate, DateTime toDate)
|
||||
{
|
||||
_logger.LogInformation("GetAllRequests params: {softwareId}, {fromDate}, { toDate} ", softwareId, fromDate, toDate);
|
||||
if (fromDate.IsDateNotOlder(toDate))
|
||||
{
|
||||
throw new IncorrectDatesException(fromDate, toDate);
|
||||
}
|
||||
if (softwareId.IsEmpty())
|
||||
{
|
||||
throw new ArgumentNullException(nameof(softwareId));
|
||||
}
|
||||
if (!softwareId.IsGuid())
|
||||
{
|
||||
throw new ValidationException("The value in the field softwareId is not a unique identifier.");
|
||||
}
|
||||
return _requestStorageContract.GetList(fromDate, toDate, softwareId:
|
||||
softwareId) ?? throw new NullListException();
|
||||
}
|
||||
|
||||
public RequestDataModel GetRequestByData(string data)
|
||||
{
|
||||
_logger.LogInformation("Get element by data: {data}", data);
|
||||
if (data.IsEmpty())
|
||||
{
|
||||
throw new ArgumentNullException(nameof(data));
|
||||
}
|
||||
if (!data.IsGuid())
|
||||
{
|
||||
throw new ValidationException("Id is not a unique identifier");
|
||||
}
|
||||
return _requestStorageContract.GetElementById(data) ?? throw new ElementNotFoundException(data);
|
||||
|
||||
}
|
||||
public void InsertRequest(RequestDataModel requestDataModel)
|
||||
{
|
||||
_logger.LogInformation("New data: {json}",
|
||||
JsonSerializer.Serialize(requestDataModel));
|
||||
ArgumentNullException.ThrowIfNull(requestDataModel);
|
||||
requestDataModel.Validate();
|
||||
_requestStorageContract.AddElement(requestDataModel);
|
||||
|
||||
}
|
||||
public void CancelRequest(string id)
|
||||
{
|
||||
_logger.LogInformation("Cancel by id: {id}", id);
|
||||
if (id.IsEmpty())
|
||||
{
|
||||
throw new ArgumentNullException(nameof(id));
|
||||
}
|
||||
if (!id.IsGuid())
|
||||
{
|
||||
throw new ValidationException("Id is not a unique identifier");
|
||||
}
|
||||
_requestStorageContract.DelElement(id);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,144 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using SmallSoftwareContracts.BusinessLogicsContracts;
|
||||
using SmallSoftwareContracts.DataModels;
|
||||
using SmallSoftwareContracts.Exceptions;
|
||||
using SmallSoftwareContracts.Extensions;
|
||||
using SmallSoftwareContracts.Infrastructure;
|
||||
using SmallSoftwareContracts.Infrastructure.PostConfigurations;
|
||||
using SmallSoftwareContracts.StoragesContracts;
|
||||
namespace SmallSoftwareBusinessLogic.Implementations;
|
||||
|
||||
|
||||
internal class SalaryBusinessLogicContract(ISalaryStorageContract salaryStorageContract,
|
||||
IRequestStorageContract requestStorageContract, IPostStorageContract postStorageContract,
|
||||
IWorkerStorageContract workerStorageContract, ILogger logger, IConfigurationSalary сonfiguration) : ISalaryBusinessLogicContract
|
||||
{
|
||||
private readonly ILogger _logger = logger;
|
||||
private readonly ISalaryStorageContract _salaryStorageContract = salaryStorageContract;
|
||||
private readonly IRequestStorageContract _requestStorageContract = requestStorageContract;
|
||||
private readonly IPostStorageContract _postStorageContract = postStorageContract;
|
||||
private readonly IWorkerStorageContract _workerStorageContract = workerStorageContract;
|
||||
private readonly IConfigurationSalary _salaryConfiguration = сonfiguration;
|
||||
private readonly Lock _lockObject = new();
|
||||
public List<SalaryDataModel> GetAllSalariesByPeriod(DateTime fromDate,
|
||||
DateTime toDate)
|
||||
{
|
||||
_logger.LogInformation("GetAllSalaries params: {fromDate}, {toDate}",
|
||||
fromDate, toDate);
|
||||
if (fromDate.IsDateNotOlder(toDate))
|
||||
{
|
||||
throw new IncorrectDatesException(fromDate, toDate);
|
||||
}
|
||||
return _salaryStorageContract.GetList(fromDate, toDate) ?? throw new
|
||||
NullListException();
|
||||
}
|
||||
public List<SalaryDataModel> GetAllSalariesByPeriodByWorker(DateTime
|
||||
fromDate, DateTime toDate, string workerId)
|
||||
{
|
||||
if (fromDate.IsDateNotOlder(toDate))
|
||||
{
|
||||
throw new IncorrectDatesException(fromDate, toDate);
|
||||
}
|
||||
if (workerId.IsEmpty())
|
||||
{
|
||||
throw new ArgumentNullException(nameof(workerId));
|
||||
}
|
||||
if (!workerId.IsGuid())
|
||||
{
|
||||
throw new ValidationException("The value in the field workerId is not a unique identifier.");
|
||||
}
|
||||
_logger.LogInformation("GetAllSalaries params: {fromDate}, {toDate}, { workerId} ", fromDate, toDate, workerId);
|
||||
return _salaryStorageContract.GetList(fromDate, toDate, workerId) ??
|
||||
throw new NullListException();
|
||||
}
|
||||
|
||||
|
||||
public void CalculateSalaryByMonth(DateTime date)
|
||||
{
|
||||
_logger.LogInformation("CalculateSalaryByMounth: {date}", date);
|
||||
var startDate = new DateTime(date.Year, date.Month, 1);
|
||||
var finishDate = new DateTime(date.Year, date.Month, DateTime.DaysInMonth(date.Year, date.Month));
|
||||
var workers = _workerStorageContract.GetList() ?? throw new NullListException();
|
||||
foreach (var worker in workers)
|
||||
{
|
||||
var requests = _requestStorageContract.GetList(startDate, finishDate, workerId: worker.Id) ?? throw new NullListException();
|
||||
var post = _postStorageContract.GetElementById(worker.PostId) ??
|
||||
throw new NullListException();
|
||||
var salary = worker.ConfigurationModel switch
|
||||
{
|
||||
null => 0,
|
||||
CashierPostConfiguration cpc => CalculateSalaryForCashier(requests, startDate, finishDate, cpc),
|
||||
SupervisorPostConfiguration spc => CalculateSalaryForSupervisor(startDate, finishDate, spc),
|
||||
PostConfiguration pc => pc.Rate,
|
||||
};
|
||||
_logger.LogDebug("The employee {workerId} was paid a salary of {salary}", worker.Id, salary);
|
||||
_salaryStorageContract.AddElement(new SalaryDataModel(worker.Id, finishDate, salary));
|
||||
}
|
||||
}
|
||||
private double CalculateSalaryForCashier(List<RequestDataModel> requests, DateTime startDate, DateTime finishDate, CashierPostConfiguration config)
|
||||
{
|
||||
var parallelOptions = new ParallelOptions
|
||||
{
|
||||
MaxDegreeOfParallelism = _salaryConfiguration.MaxConcurrentThreads
|
||||
};
|
||||
|
||||
double calcPercent = 0.0;
|
||||
var dates = new List<DateTime>();
|
||||
|
||||
for (var date = startDate; date < finishDate; date = date.AddDays(1))
|
||||
{
|
||||
dates.Add(date);
|
||||
}
|
||||
|
||||
Parallel.ForEach(dates, parallelOptions, date =>
|
||||
{
|
||||
var requestsInDay = requests.Where(x => x.RequestDate >= date && x.RequestDate < date.AddDays(1)).ToArray();
|
||||
if (requestsInDay.Length > 0)
|
||||
{
|
||||
double dailySum = requestsInDay.Sum(x => x.Sum);
|
||||
double dailyAverage = dailySum / requestsInDay.Length;
|
||||
double dailyPercent = dailyAverage * config.SalePercent;
|
||||
|
||||
lock (_lockObject)
|
||||
{
|
||||
calcPercent += dailyPercent;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
double bonus = 0;
|
||||
try
|
||||
{
|
||||
bonus = requests
|
||||
.AsParallel()
|
||||
.WithDegreeOfParallelism(_salaryConfiguration.MaxConcurrentThreads)
|
||||
.Where(x => x.Sum > _salaryConfiguration.ExtraSaleSum)
|
||||
.Sum(x => x.Sum * config.BonusForExtraSales);
|
||||
}
|
||||
catch (AggregateException agEx)
|
||||
{
|
||||
foreach (var ex in agEx.InnerExceptions)
|
||||
{
|
||||
_logger.LogError(ex, "Error calculating bonus in cashier payroll");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
return config.Rate + calcPercent + bonus;
|
||||
}
|
||||
|
||||
private double CalculateSalaryForSupervisor(DateTime startDate, DateTime finishDate, SupervisorPostConfiguration config)
|
||||
{
|
||||
try
|
||||
{
|
||||
return config.Rate + config.PersonalCountTrendPremium *
|
||||
_workerStorageContract.GetWorkerTrend(startDate, finishDate);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error in the supervisor payroll process");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,100 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using SmallSoftwareContracts.BusinessLogicsContracts;
|
||||
using SmallSoftwareContracts.DataModels;
|
||||
using SmallSoftwareContracts.Enums;
|
||||
using SmallSoftwareContracts.Exceptions;
|
||||
using SmallSoftwareContracts.Extensions;
|
||||
using SmallSoftwareContracts.StoragesContracts;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace SmallSoftwareBusinessLogic.Implementations;
|
||||
|
||||
internal class SoftwareBusinessLogicContract(ISoftwareStorageContract
|
||||
softwareStorageContract, ILogger logger) : ISoftwareBusinessLogicContract
|
||||
{
|
||||
private readonly ILogger _logger = logger;
|
||||
private readonly ISoftwareStorageContract _softwareStorageContract =
|
||||
softwareStorageContract;
|
||||
public List<SoftwareDataModel> GetAllSoftwares(bool onlyActive)
|
||||
{
|
||||
_logger.LogInformation("GetAllSoftwares params: {onlyActive}", onlyActive);
|
||||
return _softwareStorageContract.GetList(onlyActive) ?? throw new
|
||||
NullListException();
|
||||
}
|
||||
public List<SoftwareDataModel> GetAllSoftwaresByManufacturer(string
|
||||
manufacturerId, bool onlyActive = true)
|
||||
{
|
||||
if (manufacturerId.IsEmpty())
|
||||
{
|
||||
throw new ArgumentNullException(nameof(manufacturerId));
|
||||
}
|
||||
if (!manufacturerId.IsGuid())
|
||||
{
|
||||
throw new ValidationException("The value in the field manufacturerId is not a unique identifier.");
|
||||
}
|
||||
_logger.LogInformation("GetAllSoftwares params: {manufacturerId}, { onlyActive} ", manufacturerId, onlyActive);
|
||||
return _softwareStorageContract.GetList(onlyActive, manufacturerId) ??
|
||||
throw new NullListException();
|
||||
}
|
||||
public List<SoftwareHistoryDataModel> GetSoftwareHistoryBySoftware(string softwareId)
|
||||
{
|
||||
_logger.LogInformation("GetSoftwareHistoryBySoftware for {softwareId}", softwareId);
|
||||
if (softwareId.IsEmpty())
|
||||
{
|
||||
throw new ArgumentNullException(nameof(softwareId));
|
||||
}
|
||||
if (!softwareId.IsGuid())
|
||||
{
|
||||
throw new ValidationException("The value in the field softwareId is not a unique identifier.");
|
||||
}
|
||||
return _softwareStorageContract.GetHistoryBySoftwareId(softwareId) ??
|
||||
throw new NullListException();
|
||||
|
||||
}
|
||||
public SoftwareDataModel GetSoftwareByData(string data)
|
||||
{
|
||||
_logger.LogInformation("Get element by data: {data}", data);
|
||||
if (data.IsEmpty())
|
||||
{
|
||||
throw new ArgumentNullException(nameof(data));
|
||||
}
|
||||
if (data.IsGuid())
|
||||
{
|
||||
return _softwareStorageContract.GetElementById(data) ?? throw
|
||||
new ElementNotFoundException(data);
|
||||
}
|
||||
return _softwareStorageContract.GetElementByName(data) ?? throw new
|
||||
ElementNotFoundException(data);
|
||||
}
|
||||
public void InsertSoftware(SoftwareDataModel softwareDataModel)
|
||||
{
|
||||
_logger.LogInformation("New data: {json}",
|
||||
JsonSerializer.Serialize(softwareDataModel));
|
||||
ArgumentNullException.ThrowIfNull(softwareDataModel);
|
||||
softwareDataModel.Validate();
|
||||
_softwareStorageContract.AddElement(softwareDataModel);
|
||||
}
|
||||
public void UpdateSoftware(SoftwareDataModel softwareDataModel)
|
||||
{
|
||||
_logger.LogInformation("Update data: {json}",
|
||||
JsonSerializer.Serialize(softwareDataModel));
|
||||
ArgumentNullException.ThrowIfNull(softwareDataModel);
|
||||
softwareDataModel.Validate();
|
||||
_softwareStorageContract.UpdElement(softwareDataModel);
|
||||
|
||||
}
|
||||
public void DeleteSoftware(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");
|
||||
}
|
||||
_softwareStorageContract.DelElement(id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,110 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using SmallSoftwareContracts.BusinessLogicsContracts;
|
||||
using SmallSoftwareContracts.DataModels;
|
||||
using SmallSoftwareContracts.Exceptions;
|
||||
using SmallSoftwareContracts.Extensions;
|
||||
using SmallSoftwareContracts.StoragesContracts;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SmallSoftwareBusinessLogic.Implementations;
|
||||
|
||||
internal class WorkerBusinessLogicContract(IWorkerStorageContract
|
||||
workerStorageContract, ILogger logger) : IWorkerBusinessLogicContract
|
||||
{
|
||||
private readonly ILogger _logger = logger;
|
||||
private readonly IWorkerStorageContract _workerStorageContract =
|
||||
workerStorageContract;
|
||||
public List<WorkerDataModel> GetAllWorkers(bool onlyActive = true)
|
||||
{
|
||||
_logger.LogInformation("GetAllWorkers params: {onlyActive}",
|
||||
onlyActive);
|
||||
return _workerStorageContract.GetList(onlyActive) ?? throw new
|
||||
NullListException();
|
||||
}
|
||||
public List<WorkerDataModel> GetAllWorkersByPost(string postId, bool
|
||||
onlyActive = true)
|
||||
{
|
||||
_logger.LogInformation("GetAllWorkers params: {postId}, { onlyActive},", postId, onlyActive);
|
||||
if (postId.IsEmpty())
|
||||
{
|
||||
throw new ArgumentNullException(nameof(postId));
|
||||
}
|
||||
if (!postId.IsGuid())
|
||||
{
|
||||
throw new ValidationException("The value in the field postId is not a unique identifier.");
|
||||
}
|
||||
return _workerStorageContract.GetList(onlyActive, postId) ?? throw
|
||||
new NullListException();
|
||||
}
|
||||
public List<WorkerDataModel> GetAllWorkersByBirthDate(DateTime fromDate,
|
||||
DateTime toDate, bool onlyActive = true)
|
||||
{
|
||||
_logger.LogInformation("GetAllWorkers params: {onlyActive}, { fromDate}, { toDate} ", onlyActive, fromDate, toDate);
|
||||
if (fromDate.IsDateNotOlder(toDate))
|
||||
{
|
||||
throw new IncorrectDatesException(fromDate, toDate);
|
||||
}
|
||||
return _workerStorageContract.GetList(onlyActive, fromBirthDate:
|
||||
fromDate, toBirthDate: toDate) ?? throw new NullListException();
|
||||
}
|
||||
public List<WorkerDataModel> GetAllWorkersByEmploymentDate(DateTime
|
||||
fromDate, DateTime toDate, bool onlyActive = true)
|
||||
{
|
||||
_logger.LogInformation("GetAllWorkers params: {onlyActive}, { fromDate}, { toDate} ", onlyActive, fromDate, toDate);
|
||||
if (fromDate.IsDateNotOlder(toDate))
|
||||
{
|
||||
throw new IncorrectDatesException(fromDate, toDate);
|
||||
}
|
||||
return _workerStorageContract.GetList(onlyActive, fromEmploymentDate:
|
||||
fromDate, toEmploymentDate: toDate) ?? throw new NullListException();
|
||||
}
|
||||
public WorkerDataModel GetWorkerByData(string data)
|
||||
{
|
||||
_logger.LogInformation("Get element by data: {data}", data);
|
||||
if (data.IsEmpty())
|
||||
{
|
||||
throw new ArgumentNullException(nameof(data));
|
||||
}
|
||||
if (data.IsGuid())
|
||||
{
|
||||
return _workerStorageContract.GetElementById(data) ?? throw
|
||||
new ElementNotFoundException(data);
|
||||
}
|
||||
return _workerStorageContract.GetElementByFIO(data) ?? throw new
|
||||
ElementNotFoundException(data);
|
||||
}
|
||||
public void InsertWorker(WorkerDataModel workerDataModel)
|
||||
{
|
||||
_logger.LogInformation("New data: {json}",
|
||||
JsonSerializer.Serialize(workerDataModel));
|
||||
ArgumentNullException.ThrowIfNull(workerDataModel);
|
||||
workerDataModel.Validate();
|
||||
_workerStorageContract.AddElement(workerDataModel);
|
||||
}
|
||||
public void UpdateWorker(WorkerDataModel workerDataModel)
|
||||
{
|
||||
_logger.LogInformation("Update data: {json}",
|
||||
JsonSerializer.Serialize(workerDataModel));
|
||||
ArgumentNullException.ThrowIfNull(workerDataModel);
|
||||
workerDataModel.Validate();
|
||||
_workerStorageContract.UpdElement(workerDataModel);
|
||||
}
|
||||
public void DeleteWorker(string id)
|
||||
{
|
||||
_logger.LogInformation("Delete by id: {id}", id);
|
||||
if (id.IsEmpty())
|
||||
{
|
||||
throw new ArgumentNullException(nameof(id));
|
||||
}
|
||||
if (!id.IsGuid())
|
||||
{
|
||||
throw new ValidationException("Id is not a unique identifier");
|
||||
}
|
||||
_workerStorageContract.DelElement(id);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace SmallSoftwareBusinessLogic.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,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SmallSoftwareBusinessLogic.OfficePackage;
|
||||
|
||||
public abstract class BasePdfBuilder
|
||||
{
|
||||
public abstract BasePdfBuilder AddHeader(string header);
|
||||
public abstract BasePdfBuilder AddParagraph(string text);
|
||||
public abstract BasePdfBuilder AddPieChart(string title, List<(string Caption, double Value)> data);
|
||||
public abstract Stream Build();
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace SmallSoftwareBusinessLogic.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,76 @@
|
||||
using MigraDoc.DocumentObjectModel;
|
||||
using MigraDoc.DocumentObjectModel.Shapes.Charts;
|
||||
using MigraDoc.Rendering;
|
||||
using System.Text;
|
||||
|
||||
namespace SmallSoftwareBusinessLogic.OfficePackage;
|
||||
|
||||
|
||||
public class MigraDocPdfBuilder : BasePdfBuilder
|
||||
{
|
||||
private readonly Document _document;
|
||||
|
||||
public MigraDocPdfBuilder()
|
||||
{
|
||||
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
|
||||
_document = new Document();
|
||||
DefineStyles();
|
||||
}
|
||||
|
||||
public override BasePdfBuilder AddHeader(string header)
|
||||
{
|
||||
_document.AddSection().AddParagraph(header, "NormalBold");
|
||||
return this;
|
||||
}
|
||||
|
||||
public override BasePdfBuilder AddParagraph(string text)
|
||||
{
|
||||
_document.LastSection.AddParagraph(text, "Normal");
|
||||
return this;
|
||||
}
|
||||
|
||||
public override BasePdfBuilder AddPieChart(string title, List<(string Caption, double Value)> data)
|
||||
{
|
||||
if (data == null || data.Count == 0)
|
||||
{
|
||||
return this;
|
||||
}
|
||||
var chart = new Chart(ChartType.Pie2D);
|
||||
var series = chart.SeriesCollection.AddSeries();
|
||||
series.Add(data.Select(x => x.Value).ToArray());
|
||||
var xseries = chart.XValues.AddXSeries();
|
||||
xseries.Add(data.Select(x => x.Caption).ToArray());
|
||||
chart.DataLabel.Type = DataLabelType.Percent;
|
||||
chart.DataLabel.Position = DataLabelPosition.OutsideEnd;
|
||||
chart.Width = Unit.FromCentimeter(16);
|
||||
chart.Height = Unit.FromCentimeter(12);
|
||||
chart.TopArea.AddParagraph(title);
|
||||
chart.XAxis.MajorTickMark = TickMarkType.Outside;
|
||||
chart.YAxis.MajorTickMark = TickMarkType.Outside;
|
||||
chart.YAxis.HasMajorGridlines = true;
|
||||
chart.PlotArea.LineFormat.Width = 1;
|
||||
chart.PlotArea.LineFormat.Visible = true;
|
||||
chart.TopArea.AddLegend();
|
||||
_document.LastSection.Add(chart);
|
||||
return this;
|
||||
}
|
||||
|
||||
public override Stream Build()
|
||||
{
|
||||
var stream = new MemoryStream();
|
||||
var renderer = new PdfDocumentRenderer(true)
|
||||
{
|
||||
Document = _document
|
||||
};
|
||||
renderer.RenderDocument();
|
||||
renderer.PdfDocument.Save(stream);
|
||||
return stream;
|
||||
}
|
||||
|
||||
private void DefineStyles()
|
||||
{
|
||||
var headerStyle = _document.Styles.AddStyle("NormalBold", "Normal");
|
||||
headerStyle.Font.Bold = true;
|
||||
headerStyle.Font.Size = 14;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,308 @@
|
||||
using DocumentFormat.OpenXml.Packaging;
|
||||
using DocumentFormat.OpenXml.Spreadsheet;
|
||||
using DocumentFormat.OpenXml;
|
||||
|
||||
namespace SmallSoftwareBusinessLogic.OfficePackage;
|
||||
|
||||
public 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.BoldTextWithBorders);
|
||||
for (int i = startIndex + 1; i < startIndex + count; ++i)
|
||||
{
|
||||
CreateCell(i, _rowIndex, "", StyleIndex.BoldTextWithBorders);
|
||||
}
|
||||
_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.BoldTextWithBorders);
|
||||
}
|
||||
_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.SimpleTextWithBorders);
|
||||
}
|
||||
_rowIndex++;
|
||||
}
|
||||
|
||||
for (var j = 0; j < data.Last().Length; ++j)
|
||||
{
|
||||
CreateCell(j, _rowIndex, data.Last()[j], StyleIndex.BoldTextWithBorders);
|
||||
}
|
||||
_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);
|
||||
|
||||
var fills = new Fills() { Count = 1 };
|
||||
fills.Append(new Fill
|
||||
{
|
||||
PatternFill = new PatternFill()
|
||||
{
|
||||
PatternType = new EnumValue<PatternValues>(PatternValues.None)
|
||||
}
|
||||
});
|
||||
workbookStylesPart.Stylesheet.Append(fills);
|
||||
|
||||
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 },
|
||||
DiagonalBorder = new DiagonalBorder()
|
||||
});
|
||||
workbookStylesPart.Stylesheet.Append(borders);
|
||||
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.Left,
|
||||
Vertical = VerticalAlignmentValues.Center,
|
||||
WrapText = true
|
||||
}
|
||||
});
|
||||
cellFormats.Append(new CellFormat
|
||||
{
|
||||
NumberFormatId = 0,
|
||||
FormatId = 0,
|
||||
FontId = 1,
|
||||
BorderId = 1,
|
||||
FillId = 0,
|
||||
Alignment = new Alignment()
|
||||
{
|
||||
Horizontal = HorizontalAlignmentValues.Left,
|
||||
Vertical = VerticalAlignmentValues.Center,
|
||||
WrapText = true
|
||||
}
|
||||
});
|
||||
workbookStylesPart.Stylesheet.Append(cellFormats);
|
||||
}
|
||||
|
||||
private enum StyleIndex
|
||||
{
|
||||
SimpleTextWithoutBorder = 0,
|
||||
SimpleTextWithBorders = 1,
|
||||
BoldTextWithoutBorders = 2,
|
||||
BoldTextWithBorders = 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,116 @@
|
||||
using DocumentFormat.OpenXml;
|
||||
using DocumentFormat.OpenXml.Packaging;
|
||||
using DocumentFormat.OpenXml.Wordprocessing;
|
||||
|
||||
namespace SmallSoftwareBusinessLogic.OfficePackage;
|
||||
|
||||
public 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());
|
||||
|
||||
var runProperties = new RunProperties();
|
||||
runProperties.AppendChild(new Bold());
|
||||
run.AppendChild(runProperties);
|
||||
|
||||
run.AppendChild(new Text(header));
|
||||
return this;
|
||||
}
|
||||
|
||||
public override BaseWordBuilder AddParagraph(string text)
|
||||
{
|
||||
var paragraph = _body.AppendChild(new Paragraph());
|
||||
var run = paragraph.AppendChild(new Run());
|
||||
run.AppendChild(new Text(text));
|
||||
return this;
|
||||
}
|
||||
|
||||
public override BaseWordBuilder AddTable(int[] widths, List<string[]> data)
|
||||
{
|
||||
if (widths == null || widths.Length == 0)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(widths));
|
||||
}
|
||||
if (data == null || data.Count == 0)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(data));
|
||||
}
|
||||
if (data.Any(x => x.Length != widths.Length))
|
||||
{
|
||||
throw new InvalidOperationException("widths.Length != data.Length");
|
||||
}
|
||||
var table = new Table();
|
||||
table.AppendChild(new TableProperties(
|
||||
new TableBorders(
|
||||
new TopBorder()
|
||||
{
|
||||
Val = new EnumValue<BorderValues>(BorderValues.Single),
|
||||
Size = 12
|
||||
},
|
||||
new BottomBorder()
|
||||
{
|
||||
Val = new EnumValue<BorderValues>(BorderValues.Single),
|
||||
Size = 12
|
||||
},
|
||||
new LeftBorder()
|
||||
{
|
||||
Val = new EnumValue<BorderValues>(BorderValues.Single),
|
||||
Size = 12
|
||||
},
|
||||
new RightBorder()
|
||||
{
|
||||
Val = new EnumValue<BorderValues>(BorderValues.Single),
|
||||
Size = 12
|
||||
},
|
||||
new InsideHorizontalBorder()
|
||||
{
|
||||
Val = new EnumValue<BorderValues>(BorderValues.Single),
|
||||
Size = 12
|
||||
},
|
||||
new InsideVerticalBorder()
|
||||
{
|
||||
Val = new EnumValue<BorderValues>(BorderValues.Single),
|
||||
Size = 12
|
||||
}
|
||||
)
|
||||
));
|
||||
var tr = new TableRow();
|
||||
for (var j = 0; j < widths.Length; ++j)
|
||||
{
|
||||
tr.Append(new TableCell(
|
||||
new TableCellProperties(new TableCellWidth()
|
||||
{
|
||||
Width =
|
||||
widths[j].ToString()
|
||||
}),
|
||||
new Paragraph(new Run(new RunProperties(new Bold()), new Text(data.First()[j])))));
|
||||
}
|
||||
table.Append(tr);
|
||||
table.Append(data.Skip(1).Select(x =>
|
||||
new TableRow(x.Select(y => new TableCell(new Paragraph(new
|
||||
Run(new Text(y))))))));
|
||||
_body.Append(table);
|
||||
return this;
|
||||
}
|
||||
|
||||
public override Stream Build()
|
||||
{
|
||||
var stream = new MemoryStream();
|
||||
using var wordDocument = WordprocessingDocument.Create(stream, WordprocessingDocumentType.Document);
|
||||
var mainPart = wordDocument.AddMainDocumentPart();
|
||||
mainPart.Document = _document;
|
||||
return stream;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="DocumentFormat.OpenXml" Version="3.3.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging" Version="9.0.2" />
|
||||
<PackageReference Include="PdfSharp.MigraDoc.Standard" Version="1.51.15" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<InternalsVisibleTo Include="SmallSoftwareTests" />
|
||||
<InternalsVisibleTo Include="SmallSoftwareWebApi" />
|
||||
<InternalsVisibleTo Include="DynamicProxyGenAssembly2" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\SmallSoftwareContracts\SmallSoftwareContracts.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,18 @@
|
||||
using SmallSoftwareContracts.AdapterContracts.OperationResponses;
|
||||
using SmallSoftwareContracts.BindingModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SmallSoftwareContracts.AdapterContracts;
|
||||
|
||||
public interface IManufacturerAdapter
|
||||
{
|
||||
ManufacturerOperationResponse GetList();
|
||||
ManufacturerOperationResponse GetElement(string data);
|
||||
ManufacturerOperationResponse RegisterManufacturer(ManufacturerBindingModel manufacturerModel);
|
||||
ManufacturerOperationResponse ChangeManufacturerInfo(ManufacturerBindingModel manufacturerModel);
|
||||
ManufacturerOperationResponse RemoveManufacturer(string id);
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
using SmallSoftwareContracts.AdapterContracts.OperationResponses;
|
||||
using SmallSoftwareContracts.BindingModels;
|
||||
|
||||
namespace SmallSoftwareContracts.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,13 @@
|
||||
using SmallSoftwareContracts.AdapterContracts.OperationResponses;
|
||||
|
||||
namespace SmallSoftwareContracts.AdapterContracts;
|
||||
|
||||
public interface IReportAdapter
|
||||
{
|
||||
Task<ReportOperationResponse> GetDataSoftwaresByManufacturerAsync(CancellationToken ct);
|
||||
Task<ReportOperationResponse> CreateDocumentSoftwaresByManufacturerAsync(CancellationToken ct);
|
||||
Task<ReportOperationResponse> GetDataRequestByPeriodAsync(DateTime dateStart, DateTime dateFinish, CancellationToken ct);
|
||||
Task<ReportOperationResponse> CreateDocumentRequestsByPeriodAsync(DateTime dateStart, DateTime dateFinish, CancellationToken ct);
|
||||
Task<ReportOperationResponse> GetDataSalaryByPeriodAsync(DateTime dateStart, DateTime dateFinish, CancellationToken ct);
|
||||
Task<ReportOperationResponse> CreateDocumentSalaryByPeriodAsync(DateTime dateStart, DateTime dateFinish, CancellationToken ct);
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
using SmallSoftwareContracts.AdapterContracts.OperationResponses;
|
||||
using SmallSoftwareContracts.BindingModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SmallSoftwareContracts.AdapterContracts;
|
||||
|
||||
public interface IRequestAdapter
|
||||
{
|
||||
|
||||
RequestOperationResponse GetList(DateTime fromDate, DateTime toDate);
|
||||
RequestOperationResponse GetWorkerList(string id, DateTime fromDate, DateTime
|
||||
toDate);
|
||||
RequestOperationResponse GetSoftwareList(string id, DateTime fromDate, DateTime
|
||||
toDate);
|
||||
RequestOperationResponse GetElement(string id);
|
||||
RequestOperationResponse MakeRequest(RequestBindingModel saleModel);
|
||||
RequestOperationResponse CancelRequest(string id);
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
using SmallSoftwareContracts.AdapterContracts.OperationResponses;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SmallSoftwareContracts.AdapterContracts;
|
||||
|
||||
public interface ISalaryAdapter
|
||||
{
|
||||
SalaryOperationResponse GetListByPeriod(DateTime fromDate, DateTime toDate);
|
||||
SalaryOperationResponse GetListByPeriodByWorker(DateTime fromDate, DateTime toDate, string workerId);
|
||||
SalaryOperationResponse CalculateSalary(DateTime date);
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
using SmallSoftwareContracts.AdapterContracts.OperationResponses;
|
||||
using SmallSoftwareContracts.BindingModels;
|
||||
|
||||
namespace SmallSoftwareContracts.AdapterContracts;
|
||||
|
||||
public interface ISoftwareAdapter
|
||||
{
|
||||
SoftwareOperationResponse GetList(bool includeDeleted);
|
||||
SoftwareOperationResponse GetManufacturerList(string id, bool
|
||||
includeDeleted);
|
||||
SoftwareOperationResponse GetHistory(string id);
|
||||
SoftwareOperationResponse GetElement(string data);
|
||||
SoftwareOperationResponse RegisterSoftware(SoftwareBindingModel productModel);
|
||||
SoftwareOperationResponse ChangeSoftwareInfo(SoftwareBindingModel
|
||||
productModel);
|
||||
SoftwareOperationResponse RemoveSoftware(string id);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
using SmallSoftwareContracts.AdapterContracts.OperationResponses;
|
||||
using SmallSoftwareContracts.BindingModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SmallSoftwareContracts.AdapterContracts;
|
||||
|
||||
public interface IWorkerAdapter
|
||||
{
|
||||
WorkerOperationResponse GetList(bool includeDeleted);
|
||||
WorkerOperationResponse GetPostList(string id, bool includeDeleted);
|
||||
WorkerOperationResponse GetListByBirthDate(DateTime fromDate, DateTime toDate, bool includeDeleted);
|
||||
WorkerOperationResponse GetListByEmploymentDate(DateTime fromDate, DateTime
|
||||
toDate, bool includeDeleted);
|
||||
WorkerOperationResponse GetElement(string data);
|
||||
WorkerOperationResponse RegisterWorker(WorkerBindingModel workerModel);
|
||||
WorkerOperationResponse ChangeWorkerInfo(WorkerBindingModel workerModel);
|
||||
WorkerOperationResponse RemoveWorker(string id);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
using SmallSoftwareContracts.Infrastructure;
|
||||
using SmallSoftwareContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SmallSoftwareContracts.AdapterContracts.OperationResponses;
|
||||
|
||||
public class ManufacturerOperationResponse : OperationResponse
|
||||
{
|
||||
public static ManufacturerOperationResponse OK(List<ManufacturerViewModel>
|
||||
data) => OK<ManufacturerOperationResponse, List<ManufacturerViewModel>>(data);
|
||||
public static ManufacturerOperationResponse OK(ManufacturerViewModel data)
|
||||
=> OK<ManufacturerOperationResponse, ManufacturerViewModel>(data);
|
||||
public static ManufacturerOperationResponse NoContent() =>
|
||||
NoContent<ManufacturerOperationResponse>();
|
||||
public static ManufacturerOperationResponse NotFound(string message) =>
|
||||
NotFound<ManufacturerOperationResponse>(message);
|
||||
public static ManufacturerOperationResponse BadRequest(string message) =>
|
||||
BadRequest<ManufacturerOperationResponse>(message);
|
||||
public static ManufacturerOperationResponse InternalServerError(string
|
||||
message) => InternalServerError<ManufacturerOperationResponse>(message);
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
using SmallSoftwareContracts.Infrastructure;
|
||||
using SmallSoftwareContracts.ViewModels;
|
||||
|
||||
namespace SmallSoftwareContracts.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,15 @@
|
||||
using SmallSoftwareContracts.DataModels;
|
||||
using SmallSoftwareContracts.Infrastructure;
|
||||
using SmallSoftwareContracts.ViewModels;
|
||||
|
||||
namespace SmallSoftwareContracts.AdapterContracts.OperationResponses;
|
||||
|
||||
public class ReportOperationResponse : OperationResponse
|
||||
{
|
||||
public static ReportOperationResponse OK(List<HistoryOfSoftwareViewModel> data) => OK<ReportOperationResponse, List<HistoryOfSoftwareViewModel>>(data);
|
||||
public static ReportOperationResponse OK(List<RequestViewModel> data) => OK<ReportOperationResponse, List<RequestViewModel>>(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);
|
||||
public static ReportOperationResponse OK(List<WorkerSalaryByPeriodViewModel> data) => OK<ReportOperationResponse, List<WorkerSalaryByPeriodViewModel>>(data);
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
using SmallSoftwareContracts.Infrastructure;
|
||||
using SmallSoftwareContracts.ViewModels;
|
||||
|
||||
namespace SmallSoftwareContracts.AdapterContracts.OperationResponses;
|
||||
public class RequestOperationResponse : OperationResponse
|
||||
{
|
||||
public static RequestOperationResponse OK(List<RequestViewModel> data) =>
|
||||
OK<RequestOperationResponse, List<RequestViewModel>>(data);
|
||||
public static RequestOperationResponse OK(RequestViewModel data) =>
|
||||
OK<RequestOperationResponse, RequestViewModel>(data);
|
||||
public static RequestOperationResponse NoContent() =>
|
||||
NoContent<RequestOperationResponse>();
|
||||
public static RequestOperationResponse NotFound(string message) =>
|
||||
NotFound<RequestOperationResponse>(message);
|
||||
public static RequestOperationResponse BadRequest(string message) =>
|
||||
BadRequest<RequestOperationResponse>(message);
|
||||
public static RequestOperationResponse InternalServerError(string message) =>
|
||||
InternalServerError<RequestOperationResponse>(message);
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
using SmallSoftwareContracts.Infrastructure;
|
||||
using SmallSoftwareContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SmallSoftwareContracts.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,22 @@
|
||||
using SmallSoftwareContracts.Infrastructure;
|
||||
using SmallSoftwareContracts.ViewModels;
|
||||
|
||||
namespace SmallSoftwareContracts.AdapterContracts.OperationResponses;
|
||||
|
||||
public class SoftwareOperationResponse : OperationResponse
|
||||
{
|
||||
public static SoftwareOperationResponse OK(List<SoftwareViewModel> data) =>
|
||||
OK<SoftwareOperationResponse, List<SoftwareViewModel>>(data);
|
||||
public static SoftwareOperationResponse OK(List<SoftwareHistoryViewModel>
|
||||
data) => OK<SoftwareOperationResponse, List<SoftwareHistoryViewModel>>(data);
|
||||
public static SoftwareOperationResponse OK(SoftwareViewModel data) =>
|
||||
OK<SoftwareOperationResponse, SoftwareViewModel>(data);
|
||||
public static SoftwareOperationResponse NoContent() =>
|
||||
NoContent<SoftwareOperationResponse>();
|
||||
public static SoftwareOperationResponse NotFound(string message) =>
|
||||
NotFound<SoftwareOperationResponse>(message);
|
||||
public static SoftwareOperationResponse BadRequest(string message) =>
|
||||
BadRequest<SoftwareOperationResponse>(message);
|
||||
public static SoftwareOperationResponse InternalServerError(string message)
|
||||
=> InternalServerError<SoftwareOperationResponse>(message);
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
using SmallSoftwareContracts.Infrastructure;
|
||||
using SmallSoftwareContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SmallSoftwareContracts.AdapterContracts.OperationResponses;
|
||||
public class WorkerOperationResponse : OperationResponse
|
||||
{
|
||||
public static WorkerOperationResponse OK(List<WorkerViewModel> data) =>
|
||||
OK<WorkerOperationResponse, List<WorkerViewModel>>(data);
|
||||
public static WorkerOperationResponse OK(WorkerViewModel data) =>
|
||||
OK<WorkerOperationResponse, WorkerViewModel>(data);
|
||||
public static WorkerOperationResponse NoContent() =>
|
||||
NoContent<WorkerOperationResponse>();
|
||||
public static WorkerOperationResponse NotFound(string message) =>
|
||||
NotFound<WorkerOperationResponse>(message);
|
||||
public static WorkerOperationResponse BadRequest(string message) =>
|
||||
BadRequest<WorkerOperationResponse>(message);
|
||||
public static WorkerOperationResponse InternalServerError(string message)
|
||||
=> InternalServerError<WorkerOperationResponse>(message);
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
namespace SmallSoftwareContracts.BindingModels;
|
||||
|
||||
public class InstallationRequestBindingModel
|
||||
|
||||
{
|
||||
|
||||
public string? SoftwareId { get; set; }
|
||||
public string? RequestId { get; set; }
|
||||
public int Count { get; set; }
|
||||
public double Price { get; set; }
|
||||
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SmallSoftwareContracts.BindingModels;
|
||||
|
||||
public class ManufacturerBindingModel
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? ManufacturerName { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SmallSoftwareContracts.BindingModels;
|
||||
|
||||
public class PostBindingModel
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? PostId => Id;
|
||||
public string? PostName { get; set; }
|
||||
public string? PostType { get; set; }
|
||||
public double Salary { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
using SmallSoftwareContracts.DataModels;
|
||||
|
||||
namespace SmallSoftwareContracts.BindingModels;
|
||||
|
||||
public class RequestBindingModel
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? WorkerId { get; set; }
|
||||
public List<InstallationRequestBindingModel>? Softwares { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
using SmallSoftwareContracts.Enums;
|
||||
|
||||
namespace SmallSoftwareContracts.BindingModels;
|
||||
|
||||
public class SoftwareBindingModel
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? SoftwareName { get; set; }
|
||||
public string? SoftwareType { get; set; }
|
||||
public string? ManufacturerId { get; set; }
|
||||
public double Price { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SmallSoftwareContracts.BindingModels;
|
||||
public class WorkerBindingModel
|
||||
{
|
||||
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 string? ConfigurationJson { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
using SmallSoftwareContracts.DataModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SmallSoftwareContracts.BusinessLogicsContracts;
|
||||
|
||||
public interface IManufacturerBusinessLogicContract
|
||||
{
|
||||
List<ManufacturerDataModel> GetAllManufacturers();
|
||||
ManufacturerDataModel GetManufacturerByData(string data);
|
||||
void InsertManufacturer(ManufacturerDataModel manufacturerDataModel);
|
||||
void UpdateManufacturer(ManufacturerDataModel manufacturerDataModel);
|
||||
void DeleteManufacturer(string id);
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
using SmallSoftwareContracts.DataModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SmallSoftwareContracts.BusinessLogicsContracts;
|
||||
|
||||
public interface IPostBusinessLogicContract
|
||||
{
|
||||
List<PostDataModel> GetAllPosts();
|
||||
List<PostDataModel> GetAllDataOfPost(string postId);
|
||||
PostDataModel GetPostByData(string data);
|
||||
void InsertPost(PostDataModel postDataModel);
|
||||
void UpdatePost(PostDataModel postDataModel);
|
||||
void DeletePost(string id);
|
||||
void RestorePost(string id);
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using SmallSoftwareContracts.DataModels;
|
||||
|
||||
namespace SmallSoftwareContracts.BusinessLogicsContracts;
|
||||
|
||||
public interface IReportContract
|
||||
{
|
||||
Task<List<HistoryOfSoftwareDataModel>> GetDataSoftwaresByHistoryAsync(CancellationToken ct);
|
||||
Task<List<RequestDataModel>> GetDataRequestByPeriodAsync(DateTime dateStart, DateTime dateFinish, CancellationToken ct);
|
||||
Task<Stream> CreateDocumentSoftwaresByHistoryAsync(CancellationToken ct);
|
||||
Task<Stream> CreateDocumentRequestsByPeriodAsync(DateTime dateStart, DateTime dateFinish, CancellationToken ct);
|
||||
Task<List<WorkerSalaryByPeriodDataModel>> GetDataSalaryByPeriodAsync(DateTime dateStart, DateTime dateFinish, CancellationToken ct);
|
||||
Task<Stream> CreateDocumentSalaryByPeriodAsync(DateTime dateStart, DateTime dateFinish, CancellationToken ct);
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
using SmallSoftwareContracts.DataModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SmallSoftwareContracts.BusinessLogicsContracts;
|
||||
|
||||
public interface IRequestBusinessLogicContract
|
||||
{
|
||||
|
||||
List<RequestDataModel> GetAllRequestsByPeriod(DateTime fromDate, DateTime toDate);
|
||||
List<RequestDataModel> GetAllRequestsByWorkerByPeriod(string workerId, DateTime fromDate, DateTime toDate);
|
||||
List<RequestDataModel> GetAllRequestsBySoftwareByPeriod(string softwareId, DateTime fromDate, DateTime toDate);
|
||||
RequestDataModel GetRequestByData(string data);
|
||||
void InsertRequest(RequestDataModel requestDataModel);
|
||||
void CancelRequest(string id);
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
|
||||
using SmallSoftwareContracts.DataModels;
|
||||
|
||||
namespace SmallSoftwareContracts.BusinessLogicsContracts;
|
||||
|
||||
public interface ISalaryBusinessLogicContract
|
||||
{
|
||||
List<SalaryDataModel> GetAllSalariesByPeriod(DateTime fromDate, DateTime toDate);
|
||||
List<SalaryDataModel> GetAllSalariesByPeriodByWorker(DateTime fromDate, DateTime toDate, string workerId);
|
||||
void CalculateSalaryByMonth(DateTime date);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
using SmallSoftwareContracts.DataModels;
|
||||
|
||||
namespace SmallSoftwareContracts.BusinessLogicsContracts;
|
||||
|
||||
public interface ISoftwareBusinessLogicContract
|
||||
{
|
||||
List<SoftwareDataModel> GetAllSoftwares(bool onlyActive = true);
|
||||
List<SoftwareDataModel> GetAllSoftwaresByManufacturer(string manufacturerId,
|
||||
bool onlyActive = true);
|
||||
List<SoftwareHistoryDataModel> GetSoftwareHistoryBySoftware(string softwareId);
|
||||
SoftwareDataModel GetSoftwareByData(string data);
|
||||
void InsertSoftware(SoftwareDataModel softwareDataModel);
|
||||
void UpdateSoftware(SoftwareDataModel softwareDataModel);
|
||||
void DeleteSoftware(string id);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
using SmallSoftwareContracts.DataModels;
|
||||
|
||||
namespace SmallSoftwareContracts.BusinessLogicsContracts;
|
||||
|
||||
public interface IWorkerBusinessLogicContract
|
||||
{
|
||||
List<WorkerDataModel> GetAllWorkers(bool onlyActive = true);
|
||||
List<WorkerDataModel> GetAllWorkersByPost(string postId, bool onlyActive = true);
|
||||
List<WorkerDataModel> GetAllWorkersByBirthDate(DateTime fromDate, DateTime toDate, bool onlyActive = true);
|
||||
List<WorkerDataModel> GetAllWorkersByEmploymentDate(DateTime fromDate,
|
||||
DateTime toDate, bool onlyActive = true);
|
||||
WorkerDataModel GetWorkerByData(string data);
|
||||
void InsertWorker(WorkerDataModel workerDataModel);
|
||||
void UpdateWorker(WorkerDataModel workerDataModel);
|
||||
void DeleteWorker(string id);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace SmallSoftwareContracts.DataModels;
|
||||
|
||||
public class HistoryOfSoftwareDataModel
|
||||
{
|
||||
public required string SoftwareName { get; set; }
|
||||
public required List<string> Histories { get; set; }
|
||||
public required List<string> Data { get; set; }
|
||||
}
|
||||
@@ -4,11 +4,22 @@ using SmallSoftwareContracts.Infrastructure;
|
||||
|
||||
namespace SmallSoftwareContracts.DataModels;
|
||||
|
||||
public class InstallationRequestDataModel(string softwareId, string requestId, int count) : IValidation
|
||||
public class InstallationRequestDataModel(string softwareId, string requestId, int count, double price) : IValidation
|
||||
{
|
||||
private readonly SoftwareDataModel? _software;
|
||||
|
||||
public string SoftwareId { get; private set; } = softwareId;
|
||||
public string RequestId { get; private set; } = requestId;
|
||||
public int Count { get; private set; } = count;
|
||||
public int Count { get; private set; } = count;
|
||||
public double Price { get; private set; } = price;
|
||||
|
||||
public string SoftwareName => _software?.SoftwareName ?? string.Empty;
|
||||
public InstallationRequestDataModel(string saleId, string softwareId, int count, double price, SoftwareDataModel software) : this(saleId, softwareId, count, price)
|
||||
{
|
||||
_software = software;
|
||||
}
|
||||
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
if (SoftwareId.IsEmpty())
|
||||
@@ -21,5 +32,7 @@ public class InstallationRequestDataModel(string softwareId, string requestId, i
|
||||
throw new ValidationException("The value in the field RequestId is not a unique identifier");
|
||||
if (Count <= 0)
|
||||
throw new ValidationException("Field Count is less than or equal to 0");
|
||||
if (Price <= 0)
|
||||
throw new ValidationException("Field Price is less than or equal to 0");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,9 @@ prevManufacturerName, string? prevPrevManufacturerName) : IValidation
|
||||
prevManufacturerName;
|
||||
public string? PrevPrevManufacturerName { get; private set; } =
|
||||
prevPrevManufacturerName;
|
||||
|
||||
public ManufacturerDataModel(string id, string manufacturerName) : this(id, manufacturerName, null, null){ }
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
if (Id.IsEmpty())
|
||||
|
||||
@@ -5,37 +5,24 @@ using SmallSoftwareContracts.Infrastructure;
|
||||
|
||||
namespace SmallSoftwareContracts.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, double salary) : 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 bool IsActual { get; private set; } = isActual;
|
||||
public DateTime ChangeDate { get; private set; } = changeDate;
|
||||
public void Validate()
|
||||
{
|
||||
if (Id.IsEmpty())
|
||||
throw new ValidationException("Field Id is empty");
|
||||
|
||||
if (!Id.IsGuid())
|
||||
throw new ValidationException("The value in the field Id is not a unique identifier");
|
||||
|
||||
if (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");
|
||||
|
||||
if (PostType == PostType.None)
|
||||
throw new ValidationException("Field PostType is empty");
|
||||
|
||||
if (Salary <= 0)
|
||||
throw new ValidationException("Field Salary is empty");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,21 +2,42 @@
|
||||
using SmallSoftwareContracts.Extensions;
|
||||
using SmallSoftwareContracts.Infrastructure;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Xml;
|
||||
|
||||
|
||||
namespace SmallSoftwareContracts.DataModels;
|
||||
|
||||
|
||||
public class RequestDataModel(string id, string workerId, string email, double sum,
|
||||
bool isCancel, List<InstallationRequestDataModel> softwares) : IValidation
|
||||
public class RequestDataModel : IValidation
|
||||
{
|
||||
public string Id { get; private set; } = id;
|
||||
public string WorkerId { get; private set; } = workerId;
|
||||
private readonly WorkerDataModel? _worker;
|
||||
public string Id { get; private set; }
|
||||
public string WorkerId { get; private set; }
|
||||
public DateTime RequestDate { get; private set; } = DateTime.UtcNow;
|
||||
public string Email { get; private set; } = email;
|
||||
public double Sum { get; private set; } = sum;
|
||||
public bool IsCancel { get; private set; } = isCancel;
|
||||
public List<InstallationRequestDataModel> Softwares { get; private set; } = softwares;
|
||||
public string Email { get; private set; }
|
||||
public double Sum { get; private set; }
|
||||
public bool IsCancel { get; private set; }
|
||||
public List<InstallationRequestDataModel>? Softwares { get; private set; }
|
||||
public string WorkerFIO => _worker?.FIO ?? string.Empty;
|
||||
public RequestDataModel(string id, string workerId, string email, bool isCancel, List<InstallationRequestDataModel> installationRequests, DateTime requestDate)
|
||||
{
|
||||
Id = id;
|
||||
WorkerId = workerId;
|
||||
Email = email;
|
||||
IsCancel = isCancel;
|
||||
Softwares = installationRequests;
|
||||
Sum = Softwares?.Sum(x => x.Price * x.Count) ?? 0;
|
||||
}
|
||||
|
||||
public RequestDataModel(string id, string workerId, string email, double sum, bool isCancel,
|
||||
List<InstallationRequestDataModel> installationRequests, WorkerDataModel worker, DateTime requestDate)
|
||||
: this(id, workerId, email, isCancel, installationRequests, requestDate)
|
||||
{
|
||||
Sum = sum;
|
||||
_worker = worker;
|
||||
}
|
||||
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
if (Id.IsEmpty())
|
||||
@@ -26,14 +47,14 @@ public class RequestDataModel(string id, string workerId, string email, double s
|
||||
if (WorkerId.IsEmpty())
|
||||
throw new ValidationException("Field WorkerId is empty");
|
||||
if (!WorkerId.IsGuid())
|
||||
throw new ValidationException("The value in the field WorkerId is not a unique identifier");
|
||||
if (Email.IsEmpty())
|
||||
throw new ValidationException("Worker Email is empty");
|
||||
if (!Regex.IsMatch(Email, @"^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$"))
|
||||
throw new ValidationException("Field Email is not a email");
|
||||
throw new ValidationException("The value in the field WorkerId is not a unique identifier");
|
||||
if (Sum <= 0)
|
||||
throw new ValidationException("Field Sum is less than or equal to 0");
|
||||
if ((Softwares?.Count ?? 0) == 0)
|
||||
throw new ValidationException("The sale must include Softwares");
|
||||
throw new ValidationException("The request must include products");
|
||||
if (!Regex.IsMatch(Email, @"^[^@\s]+@[^@\s]+\.[^@\s]+$"))
|
||||
{
|
||||
throw new ValidationException("Invalid email format");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,20 +1,23 @@
|
||||
using SmallSoftwareContracts.Exceptions;
|
||||
using SmallSoftwareContracts.Extensions;
|
||||
using SmallSoftwareContracts.Infrastructure;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SmallSoftwareContracts.DataModels;
|
||||
|
||||
public class SalaryDataModel(string workerId, DateTime salaryDate, double
|
||||
workerSalary) : IValidation
|
||||
{
|
||||
private readonly WorkerDataModel? _worker;
|
||||
public string WorkerId { get; private set; } = workerId;
|
||||
public DateTime SalaryDate { get; private set; } = salaryDate;
|
||||
public double Salary { get; private set; } = workerSalary;
|
||||
public string WorkerFIO => _worker?.FIO ?? string.Empty;
|
||||
|
||||
public SalaryDataModel(string workerId, DateTime salaryDate, double workerSalary, WorkerDataModel worker) : this(workerId, salaryDate, workerSalary)
|
||||
{
|
||||
_worker = worker;
|
||||
}
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
if (WorkerId.IsEmpty())
|
||||
|
||||
@@ -13,12 +13,28 @@ namespace SmallSoftwareContracts.DataModels;
|
||||
|
||||
public class SoftwareDataModel(string id, string softwareName, SoftwareType softwareType, string manufacturerId, double price, bool isDeleted) : IValidation
|
||||
{
|
||||
private readonly ManufacturerDataModel? _manufacturer;
|
||||
public string Id { get; private set; } = id;
|
||||
public string SoftwareName { get; private set; } = softwareName;
|
||||
public SoftwareType SoftwareType { get; private set; } = softwareType;
|
||||
public string ManufacturerId { get; private set; } = manufacturerId;
|
||||
public double Price { get; private set; } = price;
|
||||
public bool IsDeleted { get; private set; } = isDeleted;
|
||||
public string ManufacturerName => _manufacturer?.ManufacturerName ?? string.Empty;
|
||||
|
||||
public SoftwareDataModel(string id, string softwareName, SoftwareType
|
||||
softwareType, string manufacturerId, double price, bool isDeleted,
|
||||
ManufacturerDataModel manufacturer) : this(id, softwareName, softwareType,
|
||||
manufacturerId, price, isDeleted)
|
||||
{
|
||||
_manufacturer = manufacturer;
|
||||
}
|
||||
public SoftwareDataModel(string id, string softwareName, SoftwareType
|
||||
softwareType, string manufacturerId, double price) : this(id, softwareName,
|
||||
softwareType, manufacturerId, price, false)
|
||||
{ }
|
||||
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
if (Id.IsEmpty())
|
||||
|
||||
@@ -11,9 +11,19 @@ namespace SmallSoftwareContracts.DataModels;
|
||||
|
||||
public class SoftwareHistoryDataModel(string softwareId, double oldPrice) : IValidation
|
||||
{
|
||||
private readonly SoftwareDataModel? _software;
|
||||
public string SoftwareId { get; private set; } = softwareId;
|
||||
public double OldPrice { get; private set; } = oldPrice;
|
||||
public DateTime ChangeDate { get; private set; } = DateTime.UtcNow;
|
||||
|
||||
public string SoftwareName => _software?.SoftwareName ?? string.Empty;
|
||||
public SoftwareHistoryDataModel(string softwareId, double oldPrice, DateTime
|
||||
changeDate, SoftwareDataModel software) : this(softwareId, oldPrice)
|
||||
{
|
||||
ChangeDate = changeDate;
|
||||
_software = software;
|
||||
}
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
if (SoftwareId.IsEmpty())
|
||||
|
||||
@@ -1,18 +1,51 @@
|
||||
using SmallSoftwareContracts.Exceptions;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Newtonsoft.Json;
|
||||
using SmallSoftwareContracts.Exceptions;
|
||||
using SmallSoftwareContracts.Extensions;
|
||||
using SmallSoftwareContracts.Infrastructure;
|
||||
using SmallSoftwareContracts.Infrastructure.PostConfigurations;
|
||||
|
||||
namespace SmallSoftwareContracts.DataModels;
|
||||
|
||||
public class WorkerDataModel(string id, string fio, string postId, DateTime
|
||||
birthDate, DateTime employmentDate, bool isDeleted) : IValidation
|
||||
public class WorkerDataModel(string id, string fio, string postId, DateTime birthDate, DateTime employmentDate, bool isDeleted, PostConfiguration configuration) : IValidation
|
||||
{
|
||||
private readonly PostDataModel? _post;
|
||||
public string Id { get; private set; } = id;
|
||||
public string FIO { get; private set; } = fio;
|
||||
public string PostId { get; private set; } = postId;
|
||||
public DateTime BirthDate { get; private set; } = birthDate;
|
||||
public DateTime EmploymentDate { get; private set; } = employmentDate;
|
||||
public bool IsDeleted { get; private set; } = isDeleted;
|
||||
public string PostName => _post?.PostName ?? string.Empty;
|
||||
public PostConfiguration ConfigurationModel { get; private set; } = configuration;
|
||||
|
||||
public WorkerDataModel(string id, string fio, string postId, DateTime
|
||||
birthDate, DateTime employmentDate, bool isDeleted, PostDataModel post) :
|
||||
this(id, fio, postId, birthDate, employmentDate, isDeleted, new PostConfiguration { Rate = 10 })
|
||||
{
|
||||
_post = post;
|
||||
}
|
||||
|
||||
public WorkerDataModel(string id, string fio, string postId, DateTime birthDate, DateTime employmentDate)
|
||||
: this(id, fio, postId, birthDate, employmentDate, false, new PostConfiguration { Rate = 10 })
|
||||
{ }
|
||||
|
||||
public WorkerDataModel(string id, string fio, string postId, DateTime
|
||||
birthDate, DateTime employmentDate, string configurationJson) :
|
||||
this(id, fio, postId, birthDate, employmentDate, false, new PostConfiguration { Rate = 10 })
|
||||
{
|
||||
var obj = JToken.Parse(configurationJson);
|
||||
if (obj is not null)
|
||||
{
|
||||
ConfigurationModel = obj.Value<string>("Type") switch
|
||||
{
|
||||
nameof(CashierPostConfiguration) => JsonConvert.DeserializeObject<CashierPostConfiguration>(configurationJson)!,
|
||||
nameof(SupervisorPostConfiguration) => JsonConvert.DeserializeObject<SupervisorPostConfiguration>(configurationJson)!,
|
||||
_ => JsonConvert.DeserializeObject<PostConfiguration>(configurationJson)!,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
if (Id.IsEmpty())
|
||||
@@ -31,6 +64,9 @@ birthDate, DateTime employmentDate, bool isDeleted) : IValidation
|
||||
throw new ValidationException("The date of employment cannot be less than the date of birth");
|
||||
if ((EmploymentDate - BirthDate).TotalDays / 365 < 16)
|
||||
throw new ValidationException($"Minors cannot be hired (EmploymentDate - { EmploymentDate.ToShortDateString() }, BirthDate - { BirthDate.ToShortDateString()})");
|
||||
|
||||
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,10 @@
|
||||
namespace SmallSoftwareContracts.DataModels;
|
||||
|
||||
public class WorkerSalaryByPeriodDataModel
|
||||
{
|
||||
public required string WorkerFIO { get; set; }
|
||||
public double TotalSalary { get; set; }
|
||||
public DateTime FromPeriod { get; set; }
|
||||
public DateTime ToPeriod { get; set; }
|
||||
}
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
namespace SmallSoftwareContracts.Exceptions;
|
||||
public class ElementDeletedException : Exception
|
||||
{
|
||||
public ElementDeletedException(string id) : base($"Cannot modify a deleted item(id: { id})") { }
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
|
||||
namespace SmallSoftwareContracts.Exceptions;
|
||||
public class ElementExistsException : Exception
|
||||
{
|
||||
public string ParamName { get; private set; }
|
||||
public string ParamValue { get; private set; }
|
||||
public ElementExistsException(string paramName, string paramValue) :
|
||||
base($"There is already an element with value{paramValue} of parameter { paramName}")
|
||||
{
|
||||
ParamName = paramName;
|
||||
ParamValue = paramValue;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
namespace SmallSoftwareContracts.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,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using static System.Runtime.InteropServices.JavaScript.JSType;
|
||||
|
||||
namespace SmallSoftwareContracts.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,7 @@
|
||||
|
||||
namespace SmallSoftwareContracts.Exceptions;
|
||||
|
||||
public class NullListException : Exception
|
||||
{
|
||||
public NullListException() : base("The returned list is null") { }
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
|
||||
|
||||
namespace SmallSoftwareContracts.Exceptions;
|
||||
|
||||
public class StorageException : Exception
|
||||
{
|
||||
public StorageException(Exception ex) : base($"Error while working in storage: { ex.Message}", ex) { }
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SmallSoftwareContracts.Extensions;
|
||||
|
||||
public static class DateTimeExtensions
|
||||
{
|
||||
public static bool IsDateNotOlder(this DateTime date, DateTime olderDate)
|
||||
{
|
||||
return date >= olderDate;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace SmallSoftwareContracts.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 SmallSoftwareContracts.Infrastructure;
|
||||
|
||||
public interface IConfigurationSalary
|
||||
{
|
||||
double ExtraSaleSum { get; }
|
||||
int MaxConcurrentThreads { get; }
|
||||
}
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.Net;
|
||||
|
||||
namespace SmallSoftwareContracts.Infrastructure;
|
||||
|
||||
public class OperationResponse
|
||||
{
|
||||
protected HttpStatusCode StatusCode { get; set; }
|
||||
|
||||
protected object? Result { get; set; }
|
||||
|
||||
protected string? FileName { get; set; }
|
||||
|
||||
public IActionResult GetResponse(HttpRequest request, HttpResponse response)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(request);
|
||||
ArgumentNullException.ThrowIfNull(response);
|
||||
response.StatusCode = (int)StatusCode;
|
||||
if (Result is null)
|
||||
{
|
||||
return new StatusCodeResult((int)StatusCode);
|
||||
}
|
||||
if (Result is Stream stream)
|
||||
{
|
||||
return new FileStreamResult(stream, "application/octetstream")
|
||||
{
|
||||
FileDownloadName = FileName
|
||||
};
|
||||
}
|
||||
return new ObjectResult(Result);
|
||||
}
|
||||
|
||||
protected static TResult OK<TResult, TData>(TData data) where TResult : OperationResponse, new() => new() { StatusCode = HttpStatusCode.OK, Result = data };
|
||||
|
||||
protected static TResult OK<TResult, TData>(TData data, string fileName) where TResult : OperationResponse, new() => new()
|
||||
{
|
||||
StatusCode = HttpStatusCode.OK,
|
||||
Result = data,
|
||||
FileName = fileName
|
||||
};
|
||||
|
||||
protected static TResult NoContent<TResult>() where TResult :
|
||||
OperationResponse, new() => new() { StatusCode = HttpStatusCode.NoContent };
|
||||
protected static TResult BadRequest<TResult>(string? errorMessage = null)
|
||||
where TResult : OperationResponse, new() => new()
|
||||
{
|
||||
StatusCode =
|
||||
HttpStatusCode.BadRequest,
|
||||
Result = errorMessage
|
||||
};
|
||||
protected static TResult NotFound<TResult>(string? errorMessage = null)
|
||||
where TResult : OperationResponse, new() => new()
|
||||
{
|
||||
StatusCode =
|
||||
HttpStatusCode.NotFound,
|
||||
Result = errorMessage
|
||||
};
|
||||
protected static TResult InternalServerError<TResult>(string? errorMessage
|
||||
= null) where TResult : OperationResponse, new() => new()
|
||||
{
|
||||
StatusCode =
|
||||
HttpStatusCode.InternalServerError,
|
||||
Result = errorMessage
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace SmallSoftwareContracts.Infrastructure.PostConfigurations;
|
||||
|
||||
public class CashierPostConfiguration : PostConfiguration
|
||||
{
|
||||
public override string Type => nameof(CashierPostConfiguration);
|
||||
public double SalePercent { get; set; }
|
||||
public double BonusForExtraSales { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace SmallSoftwareContracts.Infrastructure.PostConfigurations;
|
||||
public class PostConfiguration
|
||||
{
|
||||
public virtual string Type => nameof(PostConfiguration);
|
||||
public double Rate { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace SmallSoftwareContracts.Infrastructure.PostConfigurations;
|
||||
|
||||
public class SupervisorPostConfiguration : PostConfiguration
|
||||
{
|
||||
public override string Type => nameof(SupervisorPostConfiguration);
|
||||
public double PersonalCountTrendPremium { get; set; }
|
||||
}
|
||||
@@ -6,4 +6,9 @@
|
||||
<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" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
using SmallSoftwareContracts.DataModels;
|
||||
|
||||
namespace SmallSoftwareContracts.StoragesContracts;
|
||||
|
||||
public interface IManufacturerStorageContract
|
||||
{
|
||||
List<ManufacturerDataModel> GetList();
|
||||
ManufacturerDataModel? GetElementById(string id);
|
||||
ManufacturerDataModel? GetElementByName(string name);
|
||||
ManufacturerDataModel? GetElementByOldName(string name);
|
||||
void AddElement(ManufacturerDataModel manufacturerDataModel);
|
||||
void UpdElement(ManufacturerDataModel manufacturerDataModel);
|
||||
void DelElement(string id);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
using SmallSoftwareContracts.DataModels;
|
||||
|
||||
namespace SmallSoftwareContracts.StoragesContracts;
|
||||
|
||||
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,14 @@
|
||||
using SmallSoftwareContracts.DataModels;
|
||||
|
||||
namespace SmallSoftwareContracts.StoragesContracts;
|
||||
|
||||
public interface IRequestStorageContract
|
||||
{
|
||||
Task<List<RequestDataModel>> GetListAsync(DateTime startDate, DateTime endDate, CancellationToken ct);
|
||||
|
||||
List<RequestDataModel> GetList(DateTime? startDate = null,
|
||||
DateTime? endDate = null, string? workerId = null, string? softwareId = null);
|
||||
RequestDataModel? GetElementById(string id);
|
||||
void AddElement(RequestDataModel requestDataModel);
|
||||
void DelElement(string id);
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
using SmallSoftwareContracts.DataModels;
|
||||
|
||||
namespace SmallSoftwareContracts.StoragesContracts;
|
||||
|
||||
public interface ISalaryStorageContract
|
||||
{
|
||||
List<SalaryDataModel> GetList(DateTime startDate, DateTime endDate, string? workerId = null);
|
||||
void AddElement(SalaryDataModel salaryDataModel);
|
||||
Task<List<SalaryDataModel>> GetListAsync(DateTime startDate, DateTime endDate, CancellationToken ct);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
using SmallSoftwareContracts.DataModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SmallSoftwareContracts.StoragesContracts;
|
||||
|
||||
public interface ISoftwareStorageContract
|
||||
{
|
||||
Task<List<SoftwareHistoryDataModel>> GetListAsync(CancellationToken ct);
|
||||
List<SoftwareDataModel> GetList(bool onlyActive = true, string? manufacturerId = null);
|
||||
List<SoftwareHistoryDataModel> GetHistoryBySoftwareId(string softwareId);
|
||||
SoftwareDataModel? GetElementById(string id);
|
||||
SoftwareDataModel? GetElementByName(string name);
|
||||
void AddElement(SoftwareDataModel softwareDataModel);
|
||||
void UpdElement(SoftwareDataModel softwareDataModel);
|
||||
void DelElement(string id);
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
using SmallSoftwareContracts.DataModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SmallSoftwareContracts.StoragesContracts;
|
||||
|
||||
public interface IWorkerStorageContract
|
||||
{
|
||||
List<WorkerDataModel> GetList(bool onlyActive = true, string? postId =
|
||||
null, DateTime? fromBirthDate = null, DateTime? toBirthDate = null, DateTime?
|
||||
fromEmploymentDate = null, DateTime? toEmploymentDate = null);
|
||||
WorkerDataModel? GetElementById(string id);
|
||||
WorkerDataModel? GetElementByFIO(string fio);
|
||||
void AddElement(WorkerDataModel workerDataModel);
|
||||
void UpdElement(WorkerDataModel workerDataModel);
|
||||
void DelElement(string id);
|
||||
int GetWorkerTrend(DateTime fromPeriod, DateTime toPeriod);
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace SmallSoftwareContracts.ViewModels;
|
||||
|
||||
public class HistoryOfSoftwareViewModel
|
||||
{
|
||||
public required string SoftwareName { get; set; }
|
||||
public required List<string> Histories { get; set; }
|
||||
public required List<string> Data { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SmallSoftwareContracts.ViewModels;
|
||||
|
||||
public class InstallationRequestViewModel
|
||||
{
|
||||
public required string SoftwareId { get; set; }
|
||||
public required string SoftwareName { get; set; }
|
||||
public int Count { get; set; }
|
||||
public double Price { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SmallSoftwareContracts.ViewModels;
|
||||
|
||||
public class ManufacturerViewModel
|
||||
{
|
||||
public required string Id { get; set; }
|
||||
public required string ManufacturerName { get; set; }
|
||||
public string? PrevManufacturerName { get; set; }
|
||||
public string? PrevPrevManufacturerName { get; set; }
|
||||
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
|
||||
namespace SmallSoftwareContracts.ViewModels;
|
||||
|
||||
public class PostViewModel
|
||||
{
|
||||
public required string Id { get; set; }
|
||||
public required string PostName { get; set; }
|
||||
public required string PostType { get; set; }
|
||||
public double Salary { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
|
||||
namespace SmallSoftwareContracts.ViewModels;
|
||||
|
||||
public class RequestViewModel
|
||||
{
|
||||
public required string Id { get; set; }
|
||||
public required string WorkerId { get; set; }
|
||||
public required string WorkerFIO { get; set; }
|
||||
public DateTime RequestDate { get; set; }
|
||||
public double Sum { get; set; }
|
||||
public bool IsCancel { get; set; }
|
||||
public required List<InstallationRequestViewModel> Softwares { get; set; }
|
||||
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SmallSoftwareContracts.ViewModels;
|
||||
|
||||
public class SalaryViewModel
|
||||
{
|
||||
public required string WorkerId { get; set; }
|
||||
public required string WorkerFIO { get; set; }
|
||||
public DateTime SalaryDate { get; set; }
|
||||
public double Salary { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SmallSoftwareContracts.ViewModels;
|
||||
|
||||
public class SoftwareHistoryViewModel
|
||||
{
|
||||
public required string SoftwareName { get; set; }
|
||||
public double OldPrice { get; set; }
|
||||
public DateTime ChangeDate { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
namespace SmallSoftwareContracts.ViewModels;
|
||||
|
||||
public class SoftwareViewModel
|
||||
{
|
||||
public required string Id { get; set; }
|
||||
public required string SoftwareName { get; set; }
|
||||
public required string ManufacturerId { get; set; }
|
||||
public required string ManufacturerName { get; set; }
|
||||
public required string SoftwareType { get; set; }
|
||||
public double Price { get; set; }
|
||||
public bool IsDeleted { get; set; }
|
||||
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace SmallSoftwareContracts.ViewModels;
|
||||
|
||||
public class WorkerSalaryByPeriodViewModel
|
||||
{
|
||||
public required string WorkerFIO { get; set; }
|
||||
public double TotalSalary { get; set; }
|
||||
public DateTime FromPeriod { get; set; }
|
||||
public DateTime ToPeriod { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SmallSoftwareContracts.ViewModels;
|
||||
|
||||
public class WorkerViewModel
|
||||
{
|
||||
public required string Id { get; set; }
|
||||
public required string FIO { get; set; }
|
||||
public required string PostId { get; set; }
|
||||
public required string PostName { get; set; }
|
||||
public bool IsDeleted { get; set; }
|
||||
public DateTime BirthDate { get; set; }
|
||||
public DateTime EmploymentDate { get; set; }
|
||||
public required string Configuration { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using SmallSoftwareContracts.Infrastructure;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SmallSoftwareDatabase;
|
||||
|
||||
class DefaultConfigurationDatabase : IConfigurationDatabase
|
||||
{
|
||||
public string ConnectionString => "";
|
||||
}
|
||||
@@ -0,0 +1,166 @@
|
||||
using AutoMapper;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Npgsql;
|
||||
using SmallSoftwareContracts.DataModels;
|
||||
using SmallSoftwareContracts.Exceptions;
|
||||
using SmallSoftwareContracts.StoragesContracts;
|
||||
using SmallSoftwareDatabase.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SmallSoftwareDatabase.Implementations;
|
||||
internal class ManufacturerStorageContract : IManufacturerStorageContract
|
||||
{
|
||||
private readonly SmallSoftwareDbContext _dbContext;
|
||||
private readonly Mapper _mapper;
|
||||
public ManufacturerStorageContract(SmallSoftwareDbContext dbContext)
|
||||
{
|
||||
_dbContext = dbContext;
|
||||
var config = new MapperConfiguration(cfg =>
|
||||
{
|
||||
cfg.AddMaps(typeof(Manufacturer));
|
||||
});
|
||||
_mapper = new Mapper(config);
|
||||
}
|
||||
public List<ManufacturerDataModel> GetList()
|
||||
{
|
||||
try
|
||||
{
|
||||
return [.. _dbContext.Manufacturers.Select(x => _mapper.Map<ManufacturerDataModel>(x))];
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
}
|
||||
}
|
||||
public ManufacturerDataModel? GetElementById(string id)
|
||||
{
|
||||
try
|
||||
{
|
||||
return
|
||||
_mapper.Map<ManufacturerDataModel>(GetManufacturerById(id));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
}
|
||||
}
|
||||
public ManufacturerDataModel? GetElementByName(string name)
|
||||
{
|
||||
try
|
||||
{
|
||||
return
|
||||
_mapper.Map<ManufacturerDataModel>(_dbContext.Manufacturers.FirstOrDefault(x => x.ManufacturerName == name));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
}
|
||||
}
|
||||
public ManufacturerDataModel? GetElementByOldName(string name)
|
||||
{
|
||||
try
|
||||
{
|
||||
return
|
||||
_mapper.Map<ManufacturerDataModel>(_dbContext.Manufacturers.FirstOrDefault(x =>
|
||||
x.PrevManufacturerName == name ||
|
||||
x.PrevPrevManufacturerName == name));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
}
|
||||
}
|
||||
public void AddElement(ManufacturerDataModel manufacturerDataModel)
|
||||
{
|
||||
try
|
||||
{
|
||||
_dbContext.Manufacturers.Add(_mapper.Map<Manufacturer>(manufacturerDataModel));
|
||||
_dbContext.SaveChanges();
|
||||
}
|
||||
catch (InvalidOperationException ex) when (ex.TargetSite?.Name ==
|
||||
"ThrowIdentityConflict")
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new ElementExistsException("Id",
|
||||
manufacturerDataModel.Id);
|
||||
}
|
||||
catch (DbUpdateException ex) when (ex.InnerException is
|
||||
PostgresException { ConstraintName: "IX_Manufacturers_ManufacturerName" })
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new ElementExistsException("ManufacturerName",
|
||||
manufacturerDataModel.ManufacturerName);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
}
|
||||
}
|
||||
public void UpdElement(ManufacturerDataModel manufacturerDataModel)
|
||||
{
|
||||
try
|
||||
{
|
||||
var element = GetManufacturerById(manufacturerDataModel.Id) ??
|
||||
throw new ElementNotFoundException(manufacturerDataModel.Id);
|
||||
if (element.ManufacturerName !=
|
||||
manufacturerDataModel.ManufacturerName)
|
||||
{
|
||||
element.PrevPrevManufacturerName =
|
||||
element.PrevManufacturerName;
|
||||
element.PrevManufacturerName = element.ManufacturerName;
|
||||
element.ManufacturerName =
|
||||
manufacturerDataModel.ManufacturerName;
|
||||
}
|
||||
_dbContext.Manufacturers.Update(element);
|
||||
_dbContext.SaveChanges();
|
||||
}
|
||||
catch (ElementNotFoundException)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw;
|
||||
}
|
||||
catch (DbUpdateException ex) when (ex.InnerException is
|
||||
PostgresException { ConstraintName: "IX_Manufacturers_ManufacturerName" })
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new ElementExistsException("ManufacturerName",
|
||||
manufacturerDataModel.ManufacturerName);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
}
|
||||
}
|
||||
public void DelElement(string id)
|
||||
{
|
||||
try
|
||||
{
|
||||
var element = GetManufacturerById(id) ?? throw new
|
||||
ElementNotFoundException(id);
|
||||
_dbContext.Manufacturers.Remove(element);
|
||||
_dbContext.SaveChanges();
|
||||
}
|
||||
catch (ElementNotFoundException)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
}
|
||||
}
|
||||
private Manufacturer? GetManufacturerById(string id) =>
|
||||
_dbContext.Manufacturers.FirstOrDefault(x => x.Id == id);
|
||||
}
|
||||
@@ -0,0 +1,192 @@
|
||||
using AutoMapper;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Npgsql;
|
||||
using SmallSoftwareContracts.DataModels;
|
||||
using SmallSoftwareContracts.Exceptions;
|
||||
using SmallSoftwareContracts.StoragesContracts;
|
||||
using SmallSoftwareDatabase.Models;
|
||||
|
||||
namespace SmallSoftwareDatabase.Implementations;
|
||||
|
||||
internal class PostStorageContract : IPostStorageContract
|
||||
{
|
||||
private readonly SmallSoftwareDbContext _dbContext;
|
||||
private readonly Mapper _mapper;
|
||||
public PostStorageContract(SmallSoftwareDbContext 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));
|
||||
|
||||
});
|
||||
_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,134 @@
|
||||
using AutoMapper;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using SmallSoftwareContracts.DataModels;
|
||||
using SmallSoftwareContracts.Exceptions;
|
||||
using SmallSoftwareContracts.StoragesContracts;
|
||||
using SmallSoftwareDatabase.Models;
|
||||
|
||||
namespace SmallSoftwareDatabase.Implementations;
|
||||
|
||||
internal class RequestStorageContract : IRequestStorageContract
|
||||
{
|
||||
private readonly SmallSoftwareDbContext _dbContext;
|
||||
private readonly Mapper _mapper;
|
||||
|
||||
public RequestStorageContract(SmallSoftwareDbContext dbContext)
|
||||
{
|
||||
_dbContext = dbContext;
|
||||
var config = new MapperConfiguration(cfg =>
|
||||
{
|
||||
cfg.CreateMap<Manufacturer, ManufacturerDataModel>();
|
||||
cfg.CreateMap<Software, SoftwareDataModel>();
|
||||
cfg.CreateMap<Worker, WorkerDataModel>();
|
||||
cfg.CreateMap<InstallationRequest, InstallationRequestDataModel>();
|
||||
cfg.CreateMap<InstallationRequestDataModel, InstallationRequest>()
|
||||
.ForMember(x => x.SoftwareId, x => x.MapFrom(src => src.SoftwareId));
|
||||
cfg.CreateMap<Request, RequestDataModel>();
|
||||
cfg.CreateMap<RequestDataModel, Request>()
|
||||
.ForMember(x => x.IsCancel, x => x.MapFrom(src => false))
|
||||
.ForMember(x => x.InstallationRequests, x => x.MapFrom(src => src.Softwares))
|
||||
.ForMember(x => x.Worker, x => x.Ignore())
|
||||
.ForMember(dest => dest.RequestDate, opt => opt.MapFrom(src => src.RequestDate))
|
||||
.ForMember(dest => dest.RequestDate, opt => opt.MapFrom(src => src.RequestDate));
|
||||
});
|
||||
_mapper = new Mapper(config);
|
||||
}
|
||||
|
||||
public List<RequestDataModel> GetList(DateTime? startDate = null, DateTime? endDate = null, string? workerId = null, string? softwareId = null)
|
||||
{
|
||||
try
|
||||
{
|
||||
var query = _dbContext.Requests.Include(x => x.Worker).Include(x => x.InstallationRequests).AsQueryable();
|
||||
if (workerId is not null)
|
||||
{
|
||||
query = query.Where(x => x.WorkerId == workerId);
|
||||
}
|
||||
if (softwareId is not null)
|
||||
{
|
||||
query = query.Where(x => x.InstallationRequests!.Any(y => y.SoftwareId == softwareId));
|
||||
}
|
||||
return [.. query.Select(x => _mapper.Map<RequestDataModel>(x))];
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public RequestDataModel? GetElementById(string id)
|
||||
{
|
||||
try
|
||||
{
|
||||
return _mapper.Map<RequestDataModel>(GetRequestById(id));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public void AddElement(RequestDataModel requestDataModel)
|
||||
{
|
||||
try
|
||||
{
|
||||
_dbContext.Requests.Add(_mapper.Map<Request>(requestDataModel));
|
||||
_dbContext.SaveChanges();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public void DelElement(string id)
|
||||
{
|
||||
try
|
||||
{
|
||||
var element = GetRequestById(id) ?? throw new ElementNotFoundException(id);
|
||||
|
||||
if (element.IsCancel)
|
||||
{
|
||||
throw new ElementDeletedException(id);
|
||||
}
|
||||
|
||||
element.IsCancel = true;
|
||||
_dbContext.SaveChanges();
|
||||
}
|
||||
catch (Exception ex) when (ex is ElementDeletedException || ex is ElementNotFoundException)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
private Request? GetRequestById(string id) =>
|
||||
_dbContext.Requests
|
||||
.Include(x => x.Worker)
|
||||
.Include(x => x.InstallationRequests)!
|
||||
.ThenInclude(x => x.Software)
|
||||
.FirstOrDefault(x => x.Id == id);
|
||||
|
||||
public async Task<List<RequestDataModel>> GetListAsync(DateTime startDate, DateTime endDate, CancellationToken ct)
|
||||
{
|
||||
try
|
||||
{
|
||||
return [.. await _dbContext.Requests
|
||||
.Include(x => x.InstallationRequests)!.ThenInclude(x => x.Software)
|
||||
.Where(x => x.RequestDate >= startDate && x.RequestDate < endDate).Select(x => _mapper.Map<RequestDataModel>(x)).ToListAsync(ct)];
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
using AutoMapper;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using SmallSoftwareContracts.DataModels;
|
||||
using SmallSoftwareContracts.Exceptions;
|
||||
using SmallSoftwareContracts.StoragesContracts;
|
||||
using SmallSoftwareDatabase.Models;
|
||||
|
||||
namespace SmallSoftwareDatabase.Implementations;
|
||||
|
||||
internal class SalaryStorageContract : ISalaryStorageContract
|
||||
{
|
||||
private readonly SmallSoftwareDbContext _dbContext;
|
||||
private readonly Mapper _mapper;
|
||||
public SalaryStorageContract(SmallSoftwareDbContext dbContext)
|
||||
{
|
||||
_dbContext = dbContext;
|
||||
var config = new MapperConfiguration(cfg =>
|
||||
{
|
||||
cfg.CreateMap<Worker, WorkerDataModel>();
|
||||
cfg.CreateMap<Salary, SalaryDataModel>();
|
||||
cfg.CreateMap<SalaryDataModel, Salary>()
|
||||
.ForMember(dest => dest.WorkerSalary, opt => opt.MapFrom(src => src.Salary));
|
||||
});
|
||||
_mapper = new Mapper(config);
|
||||
}
|
||||
public List<SalaryDataModel> GetList(DateTime startDate, DateTime endDate, string? workerId = null)
|
||||
{
|
||||
try
|
||||
{
|
||||
var query = _dbContext.Salaries.Include(x => x.Worker).Where(x => x.SalaryDate >= startDate && x.SalaryDate <= endDate);
|
||||
if (workerId is not null)
|
||||
{
|
||||
query = query.Where(x => x.WorkerId == workerId);
|
||||
}
|
||||
return [.. query.Select(x => _mapper.Map<SalaryDataModel>(x))];
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
}
|
||||
}
|
||||
public void AddElement(SalaryDataModel salaryDataModel)
|
||||
{
|
||||
try
|
||||
{
|
||||
_dbContext.Salaries.Add(_mapper.Map<Salary>(salaryDataModel));
|
||||
_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.Worker).Where(x => x.SalaryDate >= startDate && x.SalaryDate <= endDate).Select(x => _mapper.Map<SalaryDataModel>(x)).ToListAsync(ct)];
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,203 @@
|
||||
using AutoMapper;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Npgsql;
|
||||
using SmallSoftwareContracts.DataModels;
|
||||
using SmallSoftwareContracts.Exceptions;
|
||||
using SmallSoftwareContracts.StoragesContracts;
|
||||
using SmallSoftwareDatabase.Models;
|
||||
|
||||
namespace SmallSoftwareDatabase.Implementations;
|
||||
|
||||
internal class SoftwareStorageContract : ISoftwareStorageContract
|
||||
{
|
||||
private readonly SmallSoftwareDbContext _dbContext;
|
||||
private readonly Mapper _mapper;
|
||||
public SoftwareStorageContract(SmallSoftwareDbContext dbContext)
|
||||
{
|
||||
_dbContext = dbContext;
|
||||
var config = new MapperConfiguration(cfg =>
|
||||
{
|
||||
cfg.CreateMap<Manufacturer, ManufacturerDataModel>();
|
||||
cfg.CreateMap<Software, SoftwareDataModel>();
|
||||
cfg.CreateMap<SoftwareDataModel, Software>()
|
||||
.ForMember(x => x.IsDeleted, x => x.MapFrom(src => false));
|
||||
cfg.CreateMap<SoftwareHistory, SoftwareHistoryDataModel>();
|
||||
});
|
||||
_mapper = new Mapper(config);
|
||||
}
|
||||
|
||||
public async Task<List<SoftwareHistoryDataModel>> GetListAsync(CancellationToken ct)
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
return [.. await _dbContext.SoftwareHistories.Include(x => x.Software).Select(x => _mapper.Map<SoftwareHistoryDataModel>(x)).ToListAsync(ct)];
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public List<SoftwareDataModel> GetList(bool onlyActive = true, string? manufacturerId = null)
|
||||
{
|
||||
try
|
||||
{
|
||||
var query = _dbContext.Softwares.Include(x => x.Manufacturer).AsQueryable();
|
||||
if (onlyActive)
|
||||
{
|
||||
query = query.Where(x => !x.IsDeleted);
|
||||
}
|
||||
if (manufacturerId is not null)
|
||||
{
|
||||
query = query.Where(x => x.ManufacturerId ==
|
||||
manufacturerId);
|
||||
}
|
||||
return [.. query.Select(x => _mapper.Map<SoftwareDataModel>(x))];
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
}
|
||||
}
|
||||
public List<SoftwareHistoryDataModel> GetHistoryBySoftwareId(string
|
||||
softwareId)
|
||||
{
|
||||
try
|
||||
{
|
||||
return [.. _dbContext.SoftwareHistories.Include(x => x.Software).Where(x => x.SoftwareId == softwareId)
|
||||
.OrderByDescending(x => x.ChangeDate)
|
||||
.Select(x => _mapper.Map<SoftwareHistoryDataModel>(x))];
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
}
|
||||
}
|
||||
public SoftwareDataModel? GetElementById(string id)
|
||||
{
|
||||
try
|
||||
{
|
||||
return _mapper.Map<SoftwareDataModel>(GetSoftwareById(id));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
}
|
||||
}
|
||||
public SoftwareDataModel? GetElementByName(string name)
|
||||
{
|
||||
try
|
||||
{
|
||||
return
|
||||
_mapper.Map<SoftwareDataModel>(_dbContext.Softwares.Include(x => x.Manufacturer).FirstOrDefault(x =>
|
||||
x.SoftwareName == name && !x.IsDeleted));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
}
|
||||
}
|
||||
public void AddElement(SoftwareDataModel softwareDataModel)
|
||||
{
|
||||
try
|
||||
{
|
||||
_dbContext.Softwares.Add(_mapper.Map<Software>(softwareDataModel));
|
||||
_dbContext.SaveChanges();
|
||||
}
|
||||
catch (InvalidOperationException ex) when (ex.TargetSite?.Name ==
|
||||
"ThrowIdentityConflict")
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new ElementExistsException("Id", softwareDataModel.Id);
|
||||
}
|
||||
catch (DbUpdateException ex) when (ex.InnerException is
|
||||
PostgresException { ConstraintName: "IX_Softwares_SoftwareName_IsDeleted" })
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new ElementExistsException("SoftwareName",
|
||||
softwareDataModel.SoftwareName);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
}
|
||||
}
|
||||
public void UpdElement(SoftwareDataModel softwareDataModel)
|
||||
{
|
||||
try
|
||||
{
|
||||
var transaction = _dbContext.Database.BeginTransaction();
|
||||
try
|
||||
{
|
||||
var element = GetSoftwareById(softwareDataModel.Id) ??
|
||||
throw new ElementNotFoundException(softwareDataModel.Id);
|
||||
if (element.Price != softwareDataModel.Price)
|
||||
{
|
||||
_dbContext.SoftwareHistories.Add(new
|
||||
SoftwareHistory()
|
||||
{ SoftwareId = element.Id, OldPrice = element.Price });
|
||||
_dbContext.SaveChanges();
|
||||
}
|
||||
_dbContext.Softwares.Update(_mapper.Map(softwareDataModel,
|
||||
element));
|
||||
_dbContext.SaveChanges();
|
||||
transaction.Commit();
|
||||
}
|
||||
catch
|
||||
{
|
||||
transaction.Rollback();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
catch (DbUpdateException ex) when (ex.InnerException is
|
||||
PostgresException { ConstraintName: "IX_Softwares_SoftwareName_IsDeleted" })
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new ElementExistsException("SoftwareName",
|
||||
softwareDataModel.SoftwareName);
|
||||
}
|
||||
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 = GetSoftwareById(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 Software? GetSoftwareById(string id) =>
|
||||
_dbContext.Softwares.Include(x => x.Manufacturer).FirstOrDefault(x => x.Id == id && !x.IsDeleted);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,177 @@
|
||||
using AutoMapper;
|
||||
using SmallSoftwareContracts.DataModels;
|
||||
using SmallSoftwareContracts.Exceptions;
|
||||
using SmallSoftwareContracts.StoragesContracts;
|
||||
using SmallSoftwareDatabase.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SmallSoftwareDatabase.Implementations;
|
||||
|
||||
internal class WorkerStorageContract : IWorkerStorageContract
|
||||
{
|
||||
private readonly SmallSoftwareDbContext _dbContext;
|
||||
private readonly Mapper _mapper;
|
||||
public WorkerStorageContract(SmallSoftwareDbContext dbContext)
|
||||
{
|
||||
_dbContext = dbContext;
|
||||
var config = new MapperConfiguration(cfg =>
|
||||
{
|
||||
cfg.CreateMap<Post, PostDataModel>()
|
||||
.ForMember(x => x.Id, x => x.MapFrom(src =>
|
||||
src.PostId));
|
||||
cfg.CreateMap<Worker, WorkerDataModel>();
|
||||
cfg.CreateMap<WorkerDataModel, Worker>()
|
||||
.ForMember(x => x.Post, x => x.Ignore())
|
||||
.ForMember(x => x.Configuration, x => x.MapFrom(src => src.ConfigurationModel));
|
||||
});
|
||||
_mapper = new Mapper(config);
|
||||
}
|
||||
public List<WorkerDataModel> GetList(bool onlyActive = true, string? postId
|
||||
= null, DateTime? fromBirthDate = null, DateTime? toBirthDate = null, DateTime?
|
||||
fromEmploymentDate = null, DateTime? toEmploymentDate = null)
|
||||
{
|
||||
try
|
||||
{
|
||||
var query = _dbContext.Workers.AsQueryable();
|
||||
if (onlyActive)
|
||||
{
|
||||
query = query.Where(x => !x.IsDeleted);
|
||||
}
|
||||
if (postId is not null)
|
||||
{
|
||||
query = query.Where(x => x.PostId == postId);
|
||||
}
|
||||
if (fromBirthDate is not null && toBirthDate is not null)
|
||||
{
|
||||
query = query.Where(x => x.BirthDate >= fromBirthDate &&
|
||||
x.BirthDate <= toBirthDate);
|
||||
}
|
||||
if (fromEmploymentDate is not null && toEmploymentDate is not
|
||||
null)
|
||||
{
|
||||
query = query.Where(x => x.EmploymentDate >=
|
||||
fromEmploymentDate && x.EmploymentDate <= toEmploymentDate);
|
||||
}
|
||||
return [.. JoinPost(query).Select(x => _mapper.Map<WorkerDataModel>(x))];
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
}
|
||||
}
|
||||
public WorkerDataModel? GetElementById(string id)
|
||||
{
|
||||
try
|
||||
{
|
||||
return _mapper.Map<WorkerDataModel>(GetWorkerById(id));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
}
|
||||
}
|
||||
public WorkerDataModel? GetElementByFIO(string fio)
|
||||
{
|
||||
try
|
||||
{
|
||||
return
|
||||
_mapper.Map<WorkerDataModel>(AddPost(_dbContext.Workers.FirstOrDefault(x => x.FIO == fio && !x.IsDeleted)));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
}
|
||||
}
|
||||
public void AddElement(WorkerDataModel workerDataModel)
|
||||
{
|
||||
try
|
||||
{
|
||||
_dbContext.Workers.Add(_mapper.Map<Worker>(workerDataModel));
|
||||
_dbContext.SaveChanges();
|
||||
}
|
||||
catch (InvalidOperationException ex) when (ex.TargetSite?.Name == "ThrowIdentityConflict")
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new ElementExistsException("Id", workerDataModel.Id);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
}
|
||||
}
|
||||
public void UpdElement(WorkerDataModel workerDataModel)
|
||||
{
|
||||
try
|
||||
{
|
||||
var element = GetWorkerById(workerDataModel.Id) ?? throw new
|
||||
ElementNotFoundException(workerDataModel.Id);
|
||||
_dbContext.Workers.Update(_mapper.Map(workerDataModel,
|
||||
element));
|
||||
_dbContext.SaveChanges();
|
||||
}
|
||||
catch (ElementNotFoundException)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
}
|
||||
}
|
||||
public void DelElement(string id)
|
||||
{
|
||||
try
|
||||
{
|
||||
var element = GetWorkerById(id) ?? throw new
|
||||
ElementNotFoundException(id);
|
||||
element.IsDeleted = true;
|
||||
element.DateOfDelete = DateTime.UtcNow;
|
||||
_dbContext.SaveChanges();
|
||||
}
|
||||
catch (ElementNotFoundException)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public int GetWorkerTrend(DateTime fromPeriod, DateTime toPeriod)
|
||||
{
|
||||
try
|
||||
{
|
||||
var countWorkersOnBegining = _dbContext.Workers.Count(x =>
|
||||
x.EmploymentDate < fromPeriod && (!x.IsDeleted || x.DateOfDelete > fromPeriod));
|
||||
var countWorkersOnEnding = _dbContext.Workers.Count(x =>
|
||||
x.EmploymentDate < toPeriod && (!x.IsDeleted || x.DateOfDelete > toPeriod));
|
||||
return countWorkersOnEnding - countWorkersOnBegining;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private Worker? GetWorkerById(string id) => AddPost(_dbContext.Workers.FirstOrDefault(x => x.Id == id && !x.IsDeleted));
|
||||
private IQueryable<Worker> JoinPost(IQueryable<Worker> query) => query.GroupJoin(_dbContext.Posts.Where(x => x.IsActual), x =>
|
||||
x.PostId, y => y.PostId, (x, y) => new { Worker = x, Post = y }).SelectMany(xy => xy.Post.DefaultIfEmpty(), (x, y) => x.Worker.AddPost(y));
|
||||
private Worker? AddPost(Worker? worker) => worker?.AddPost(_dbContext.Posts.FirstOrDefault(x => x.PostId == worker.PostId && x.IsActual));
|
||||
|
||||
|
||||
}
|
||||
338
SmallSoftwareProject/SmallSoftwareDatabase/Migrations/20250417140247_FirstMigration.Designer.cs
generated
Normal file
338
SmallSoftwareProject/SmallSoftwareDatabase/Migrations/20250417140247_FirstMigration.Designer.cs
generated
Normal file
@@ -0,0 +1,338 @@
|
||||
// <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 SmallSoftwareDatabase;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace SmallSoftwareDatabase.Migrations
|
||||
{
|
||||
[DbContext(typeof(SmallSoftwareDbContext))]
|
||||
[Migration("20250417140247_FirstMigration")]
|
||||
partial class FirstMigration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "9.0.2")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||
|
||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("SmallSoftwareDatabase.Models.InstallationRequest", b =>
|
||||
{
|
||||
b.Property<string>("RequestId")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("SoftwareId")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<double>("Price")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.HasKey("RequestId", "SoftwareId");
|
||||
|
||||
b.HasIndex("SoftwareId");
|
||||
|
||||
b.ToTable("InstallationRequests");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SmallSoftwareDatabase.Models.Manufacturer", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("ManufacturerName")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("PrevManufacturerName")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("PrevPrevManufacturerName")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ManufacturerName")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("Manufacturers");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SmallSoftwareDatabase.Models.Post", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTime>("ChangeDate")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.Property<bool>("IsActual")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<string>("PostId")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("PostName")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int>("PostType")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<double>("Salary")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("PostId", "IsActual")
|
||||
.IsUnique()
|
||||
.HasFilter("\"IsActual\" = TRUE");
|
||||
|
||||
b.HasIndex("PostName", "IsActual")
|
||||
.IsUnique()
|
||||
.HasFilter("\"IsActual\" = TRUE");
|
||||
|
||||
b.ToTable("Posts");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SmallSoftwareDatabase.Models.Request", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("Email")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<bool>("IsCancel")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<DateTime>("RequestDate")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.Property<double>("Sum")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.Property<string>("WorkerId")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("WorkerId");
|
||||
|
||||
b.ToTable("Requests");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SmallSoftwareDatabase.Models.Salary", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTime>("SalaryDate")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.Property<string>("WorkerId")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<double>("WorkerSalary")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("WorkerId");
|
||||
|
||||
b.ToTable("Salaries");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SmallSoftwareDatabase.Models.Software", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<bool>("IsDeleted")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<string>("ManufacturerId")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("PrevPrevSoftwareName")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("PrevSoftwareName")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<double>("Price")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.Property<string>("SoftwareName")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int>("SoftwareType")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ManufacturerId");
|
||||
|
||||
b.HasIndex("SoftwareName", "IsDeleted")
|
||||
.IsUnique()
|
||||
.HasFilter("\"IsDeleted\" = FALSE");
|
||||
|
||||
b.ToTable("Softwares");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SmallSoftwareDatabase.Models.SoftwareHistory", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTime>("ChangeDate")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.Property<double>("OldPrice")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.Property<string>("SoftwareId")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("SoftwareId");
|
||||
|
||||
b.ToTable("SoftwareHistories");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SmallSoftwareDatabase.Models.Worker", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTime>("BirthDate")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.Property<DateTime>("EmploymentDate")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.Property<string>("FIO")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<bool>("IsDeleted")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<string>("PostId")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Workers");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SmallSoftwareDatabase.Models.InstallationRequest", b =>
|
||||
{
|
||||
b.HasOne("SmallSoftwareDatabase.Models.Request", "Request")
|
||||
.WithMany("InstallationRequests")
|
||||
.HasForeignKey("RequestId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("SmallSoftwareDatabase.Models.Software", "Software")
|
||||
.WithMany("InstallationRequests")
|
||||
.HasForeignKey("SoftwareId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Request");
|
||||
|
||||
b.Navigation("Software");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SmallSoftwareDatabase.Models.Request", b =>
|
||||
{
|
||||
b.HasOne("SmallSoftwareDatabase.Models.Worker", "Worker")
|
||||
.WithMany("Requests")
|
||||
.HasForeignKey("WorkerId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Worker");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SmallSoftwareDatabase.Models.Salary", b =>
|
||||
{
|
||||
b.HasOne("SmallSoftwareDatabase.Models.Worker", "Worker")
|
||||
.WithMany("Salaries")
|
||||
.HasForeignKey("WorkerId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Worker");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SmallSoftwareDatabase.Models.Software", b =>
|
||||
{
|
||||
b.HasOne("SmallSoftwareDatabase.Models.Manufacturer", "Manufacturer")
|
||||
.WithMany("Softwares")
|
||||
.HasForeignKey("ManufacturerId")
|
||||
.OnDelete(DeleteBehavior.Restrict)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Manufacturer");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SmallSoftwareDatabase.Models.SoftwareHistory", b =>
|
||||
{
|
||||
b.HasOne("SmallSoftwareDatabase.Models.Software", "Software")
|
||||
.WithMany("SoftwareHistories")
|
||||
.HasForeignKey("SoftwareId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Software");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SmallSoftwareDatabase.Models.Manufacturer", b =>
|
||||
{
|
||||
b.Navigation("Softwares");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SmallSoftwareDatabase.Models.Request", b =>
|
||||
{
|
||||
b.Navigation("InstallationRequests");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SmallSoftwareDatabase.Models.Software", b =>
|
||||
{
|
||||
b.Navigation("InstallationRequests");
|
||||
|
||||
b.Navigation("SoftwareHistories");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SmallSoftwareDatabase.Models.Worker", b =>
|
||||
{
|
||||
b.Navigation("Requests");
|
||||
|
||||
b.Navigation("Salaries");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,254 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace SmallSoftwareDatabase.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class FirstMigration : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Manufacturers",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<string>(type: "text", nullable: false),
|
||||
ManufacturerName = table.Column<string>(type: "text", nullable: false),
|
||||
PrevManufacturerName = table.Column<string>(type: "text", nullable: true),
|
||||
PrevPrevManufacturerName = table.Column<string>(type: "text", nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Manufacturers", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Posts",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<string>(type: "text", nullable: false),
|
||||
PostId = table.Column<string>(type: "text", nullable: false),
|
||||
PostName = table.Column<string>(type: "text", nullable: false),
|
||||
PostType = table.Column<int>(type: "integer", nullable: false),
|
||||
Salary = table.Column<double>(type: "double precision", nullable: false),
|
||||
IsActual = table.Column<bool>(type: "boolean", nullable: false),
|
||||
ChangeDate = table.Column<DateTime>(type: "timestamp without time zone", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Posts", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Workers",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<string>(type: "text", nullable: false),
|
||||
FIO = table.Column<string>(type: "text", nullable: false),
|
||||
PostId = table.Column<string>(type: "text", nullable: false),
|
||||
BirthDate = table.Column<DateTime>(type: "timestamp without time zone", nullable: false),
|
||||
EmploymentDate = table.Column<DateTime>(type: "timestamp without time zone", nullable: false),
|
||||
IsDeleted = table.Column<bool>(type: "boolean", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Workers", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Softwares",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<string>(type: "text", nullable: false),
|
||||
SoftwareName = table.Column<string>(type: "text", nullable: false),
|
||||
SoftwareType = table.Column<int>(type: "integer", nullable: false),
|
||||
ManufacturerId = table.Column<string>(type: "text", nullable: false),
|
||||
Price = table.Column<double>(type: "double precision", nullable: false),
|
||||
IsDeleted = table.Column<bool>(type: "boolean", nullable: false),
|
||||
PrevSoftwareName = table.Column<string>(type: "text", nullable: true),
|
||||
PrevPrevSoftwareName = table.Column<string>(type: "text", nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Softwares", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_Softwares_Manufacturers_ManufacturerId",
|
||||
column: x => x.ManufacturerId,
|
||||
principalTable: "Manufacturers",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Restrict);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Requests",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<string>(type: "text", nullable: false),
|
||||
WorkerId = table.Column<string>(type: "text", nullable: false),
|
||||
RequestDate = table.Column<DateTime>(type: "timestamp without time zone", nullable: false),
|
||||
Email = table.Column<string>(type: "text", nullable: false),
|
||||
Sum = table.Column<double>(type: "double precision", nullable: false),
|
||||
IsCancel = table.Column<bool>(type: "boolean", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Requests", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_Requests_Workers_WorkerId",
|
||||
column: x => x.WorkerId,
|
||||
principalTable: "Workers",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Salaries",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<string>(type: "text", nullable: false),
|
||||
WorkerId = table.Column<string>(type: "text", nullable: false),
|
||||
WorkerSalary = table.Column<double>(type: "double precision", nullable: false),
|
||||
SalaryDate = table.Column<DateTime>(type: "timestamp without time zone", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Salaries", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_Salaries_Workers_WorkerId",
|
||||
column: x => x.WorkerId,
|
||||
principalTable: "Workers",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "SoftwareHistories",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<string>(type: "text", nullable: false),
|
||||
SoftwareId = table.Column<string>(type: "text", nullable: false),
|
||||
OldPrice = table.Column<double>(type: "double precision", nullable: false),
|
||||
ChangeDate = table.Column<DateTime>(type: "timestamp without time zone", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_SoftwareHistories", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_SoftwareHistories_Softwares_SoftwareId",
|
||||
column: x => x.SoftwareId,
|
||||
principalTable: "Softwares",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "InstallationRequests",
|
||||
columns: table => new
|
||||
{
|
||||
SoftwareId = table.Column<string>(type: "text", nullable: false),
|
||||
RequestId = table.Column<string>(type: "text", nullable: false),
|
||||
Count = table.Column<int>(type: "integer", nullable: false),
|
||||
Price = table.Column<double>(type: "double precision", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_InstallationRequests", x => new { x.RequestId, x.SoftwareId });
|
||||
table.ForeignKey(
|
||||
name: "FK_InstallationRequests_Requests_RequestId",
|
||||
column: x => x.RequestId,
|
||||
principalTable: "Requests",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
table.ForeignKey(
|
||||
name: "FK_InstallationRequests_Softwares_SoftwareId",
|
||||
column: x => x.SoftwareId,
|
||||
principalTable: "Softwares",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_InstallationRequests_SoftwareId",
|
||||
table: "InstallationRequests",
|
||||
column: "SoftwareId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Manufacturers_ManufacturerName",
|
||||
table: "Manufacturers",
|
||||
column: "ManufacturerName",
|
||||
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_Requests_WorkerId",
|
||||
table: "Requests",
|
||||
column: "WorkerId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Salaries_WorkerId",
|
||||
table: "Salaries",
|
||||
column: "WorkerId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_SoftwareHistories_SoftwareId",
|
||||
table: "SoftwareHistories",
|
||||
column: "SoftwareId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Softwares_ManufacturerId",
|
||||
table: "Softwares",
|
||||
column: "ManufacturerId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Softwares_SoftwareName_IsDeleted",
|
||||
table: "Softwares",
|
||||
columns: new[] { "SoftwareName", "IsDeleted" },
|
||||
unique: true,
|
||||
filter: "\"IsDeleted\" = FALSE");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "InstallationRequests");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Posts");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Salaries");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "SoftwareHistories");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Requests");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Softwares");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Workers");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Manufacturers");
|
||||
}
|
||||
}
|
||||
}
|
||||
345
SmallSoftwareProject/SmallSoftwareDatabase/Migrations/20250417185242_ChangeFieldsInWorker.Designer.cs
generated
Normal file
345
SmallSoftwareProject/SmallSoftwareDatabase/Migrations/20250417185242_ChangeFieldsInWorker.Designer.cs
generated
Normal file
@@ -0,0 +1,345 @@
|
||||
// <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 SmallSoftwareDatabase;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace SmallSoftwareDatabase.Migrations
|
||||
{
|
||||
[DbContext(typeof(SmallSoftwareDbContext))]
|
||||
[Migration("20250417185242_ChangeFieldsInWorker")]
|
||||
partial class ChangeFieldsInWorker
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "9.0.2")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||
|
||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("SmallSoftwareDatabase.Models.InstallationRequest", b =>
|
||||
{
|
||||
b.Property<string>("RequestId")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("SoftwareId")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<double>("Price")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.HasKey("RequestId", "SoftwareId");
|
||||
|
||||
b.HasIndex("SoftwareId");
|
||||
|
||||
b.ToTable("InstallationRequests");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SmallSoftwareDatabase.Models.Manufacturer", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("ManufacturerName")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("PrevManufacturerName")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("PrevPrevManufacturerName")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ManufacturerName")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("Manufacturers");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SmallSoftwareDatabase.Models.Post", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTime>("ChangeDate")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.Property<bool>("IsActual")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<string>("PostId")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("PostName")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int>("PostType")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<double>("Salary")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("PostId", "IsActual")
|
||||
.IsUnique()
|
||||
.HasFilter("\"IsActual\" = TRUE");
|
||||
|
||||
b.HasIndex("PostName", "IsActual")
|
||||
.IsUnique()
|
||||
.HasFilter("\"IsActual\" = TRUE");
|
||||
|
||||
b.ToTable("Posts");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SmallSoftwareDatabase.Models.Request", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("Email")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<bool>("IsCancel")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<DateTime>("RequestDate")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.Property<double>("Sum")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.Property<string>("WorkerId")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("WorkerId");
|
||||
|
||||
b.ToTable("Requests");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SmallSoftwareDatabase.Models.Salary", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTime>("SalaryDate")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.Property<string>("WorkerId")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<double>("WorkerSalary")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("WorkerId");
|
||||
|
||||
b.ToTable("Salaries");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SmallSoftwareDatabase.Models.Software", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<bool>("IsDeleted")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<string>("ManufacturerId")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("PrevPrevSoftwareName")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("PrevSoftwareName")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<double>("Price")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.Property<string>("SoftwareName")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int>("SoftwareType")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ManufacturerId");
|
||||
|
||||
b.HasIndex("SoftwareName", "IsDeleted")
|
||||
.IsUnique()
|
||||
.HasFilter("\"IsDeleted\" = FALSE");
|
||||
|
||||
b.ToTable("Softwares");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SmallSoftwareDatabase.Models.SoftwareHistory", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTime>("ChangeDate")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.Property<double>("OldPrice")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.Property<string>("SoftwareId")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("SoftwareId");
|
||||
|
||||
b.ToTable("SoftwareHistories");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SmallSoftwareDatabase.Models.Worker", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTime>("BirthDate")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.Property<string>("Configuration")
|
||||
.IsRequired()
|
||||
.HasColumnType("jsonb");
|
||||
|
||||
b.Property<DateTime?>("DateOfDelete")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.Property<DateTime>("EmploymentDate")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.Property<string>("FIO")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<bool>("IsDeleted")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<string>("PostId")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Workers");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SmallSoftwareDatabase.Models.InstallationRequest", b =>
|
||||
{
|
||||
b.HasOne("SmallSoftwareDatabase.Models.Request", "Request")
|
||||
.WithMany("InstallationRequests")
|
||||
.HasForeignKey("RequestId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("SmallSoftwareDatabase.Models.Software", "Software")
|
||||
.WithMany("InstallationRequests")
|
||||
.HasForeignKey("SoftwareId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Request");
|
||||
|
||||
b.Navigation("Software");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SmallSoftwareDatabase.Models.Request", b =>
|
||||
{
|
||||
b.HasOne("SmallSoftwareDatabase.Models.Worker", "Worker")
|
||||
.WithMany("Requests")
|
||||
.HasForeignKey("WorkerId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Worker");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SmallSoftwareDatabase.Models.Salary", b =>
|
||||
{
|
||||
b.HasOne("SmallSoftwareDatabase.Models.Worker", "Worker")
|
||||
.WithMany("Salaries")
|
||||
.HasForeignKey("WorkerId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Worker");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SmallSoftwareDatabase.Models.Software", b =>
|
||||
{
|
||||
b.HasOne("SmallSoftwareDatabase.Models.Manufacturer", "Manufacturer")
|
||||
.WithMany("Softwares")
|
||||
.HasForeignKey("ManufacturerId")
|
||||
.OnDelete(DeleteBehavior.Restrict)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Manufacturer");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SmallSoftwareDatabase.Models.SoftwareHistory", b =>
|
||||
{
|
||||
b.HasOne("SmallSoftwareDatabase.Models.Software", "Software")
|
||||
.WithMany("SoftwareHistories")
|
||||
.HasForeignKey("SoftwareId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Software");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SmallSoftwareDatabase.Models.Manufacturer", b =>
|
||||
{
|
||||
b.Navigation("Softwares");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SmallSoftwareDatabase.Models.Request", b =>
|
||||
{
|
||||
b.Navigation("InstallationRequests");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SmallSoftwareDatabase.Models.Software", b =>
|
||||
{
|
||||
b.Navigation("InstallationRequests");
|
||||
|
||||
b.Navigation("SoftwareHistories");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SmallSoftwareDatabase.Models.Worker", b =>
|
||||
{
|
||||
b.Navigation("Requests");
|
||||
|
||||
b.Navigation("Salaries");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace SmallSoftwareDatabase.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class ChangeFieldsInWorker : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AddColumn<string>(
|
||||
name: "Configuration",
|
||||
table: "Workers",
|
||||
type: "jsonb",
|
||||
nullable: false,
|
||||
defaultValue: "{\"Rate\": 0, \"Type\": \"PostConfiguration\"}");
|
||||
|
||||
migrationBuilder.AddColumn<DateTime>(
|
||||
name: "DateOfDelete",
|
||||
table: "Workers",
|
||||
type: "timestamp without time zone",
|
||||
nullable: true);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropColumn(
|
||||
name: "Configuration",
|
||||
table: "Workers");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "DateOfDelete",
|
||||
table: "Workers");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,342 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
using SmallSoftwareDatabase;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace SmallSoftwareDatabase.Migrations
|
||||
{
|
||||
[DbContext(typeof(SmallSoftwareDbContext))]
|
||||
partial class SmallSoftwareDbContextModelSnapshot : ModelSnapshot
|
||||
{
|
||||
protected override void BuildModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "9.0.2")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||
|
||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("SmallSoftwareDatabase.Models.InstallationRequest", b =>
|
||||
{
|
||||
b.Property<string>("RequestId")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("SoftwareId")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<double>("Price")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.HasKey("RequestId", "SoftwareId");
|
||||
|
||||
b.HasIndex("SoftwareId");
|
||||
|
||||
b.ToTable("InstallationRequests");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SmallSoftwareDatabase.Models.Manufacturer", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("ManufacturerName")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("PrevManufacturerName")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("PrevPrevManufacturerName")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ManufacturerName")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("Manufacturers");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SmallSoftwareDatabase.Models.Post", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTime>("ChangeDate")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.Property<bool>("IsActual")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<string>("PostId")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("PostName")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int>("PostType")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<double>("Salary")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("PostId", "IsActual")
|
||||
.IsUnique()
|
||||
.HasFilter("\"IsActual\" = TRUE");
|
||||
|
||||
b.HasIndex("PostName", "IsActual")
|
||||
.IsUnique()
|
||||
.HasFilter("\"IsActual\" = TRUE");
|
||||
|
||||
b.ToTable("Posts");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SmallSoftwareDatabase.Models.Request", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("Email")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<bool>("IsCancel")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<DateTime>("RequestDate")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.Property<double>("Sum")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.Property<string>("WorkerId")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("WorkerId");
|
||||
|
||||
b.ToTable("Requests");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SmallSoftwareDatabase.Models.Salary", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTime>("SalaryDate")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.Property<string>("WorkerId")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<double>("WorkerSalary")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("WorkerId");
|
||||
|
||||
b.ToTable("Salaries");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SmallSoftwareDatabase.Models.Software", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<bool>("IsDeleted")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<string>("ManufacturerId")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("PrevPrevSoftwareName")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("PrevSoftwareName")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<double>("Price")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.Property<string>("SoftwareName")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int>("SoftwareType")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ManufacturerId");
|
||||
|
||||
b.HasIndex("SoftwareName", "IsDeleted")
|
||||
.IsUnique()
|
||||
.HasFilter("\"IsDeleted\" = FALSE");
|
||||
|
||||
b.ToTable("Softwares");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SmallSoftwareDatabase.Models.SoftwareHistory", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTime>("ChangeDate")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.Property<double>("OldPrice")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.Property<string>("SoftwareId")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("SoftwareId");
|
||||
|
||||
b.ToTable("SoftwareHistories");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SmallSoftwareDatabase.Models.Worker", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTime>("BirthDate")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.Property<string>("Configuration")
|
||||
.IsRequired()
|
||||
.HasColumnType("jsonb");
|
||||
|
||||
b.Property<DateTime?>("DateOfDelete")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.Property<DateTime>("EmploymentDate")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.Property<string>("FIO")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<bool>("IsDeleted")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<string>("PostId")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Workers");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SmallSoftwareDatabase.Models.InstallationRequest", b =>
|
||||
{
|
||||
b.HasOne("SmallSoftwareDatabase.Models.Request", "Request")
|
||||
.WithMany("InstallationRequests")
|
||||
.HasForeignKey("RequestId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("SmallSoftwareDatabase.Models.Software", "Software")
|
||||
.WithMany("InstallationRequests")
|
||||
.HasForeignKey("SoftwareId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Request");
|
||||
|
||||
b.Navigation("Software");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SmallSoftwareDatabase.Models.Request", b =>
|
||||
{
|
||||
b.HasOne("SmallSoftwareDatabase.Models.Worker", "Worker")
|
||||
.WithMany("Requests")
|
||||
.HasForeignKey("WorkerId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Worker");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SmallSoftwareDatabase.Models.Salary", b =>
|
||||
{
|
||||
b.HasOne("SmallSoftwareDatabase.Models.Worker", "Worker")
|
||||
.WithMany("Salaries")
|
||||
.HasForeignKey("WorkerId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Worker");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SmallSoftwareDatabase.Models.Software", b =>
|
||||
{
|
||||
b.HasOne("SmallSoftwareDatabase.Models.Manufacturer", "Manufacturer")
|
||||
.WithMany("Softwares")
|
||||
.HasForeignKey("ManufacturerId")
|
||||
.OnDelete(DeleteBehavior.Restrict)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Manufacturer");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SmallSoftwareDatabase.Models.SoftwareHistory", b =>
|
||||
{
|
||||
b.HasOne("SmallSoftwareDatabase.Models.Software", "Software")
|
||||
.WithMany("SoftwareHistories")
|
||||
.HasForeignKey("SoftwareId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Software");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SmallSoftwareDatabase.Models.Manufacturer", b =>
|
||||
{
|
||||
b.Navigation("Softwares");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SmallSoftwareDatabase.Models.Request", b =>
|
||||
{
|
||||
b.Navigation("InstallationRequests");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SmallSoftwareDatabase.Models.Software", b =>
|
||||
{
|
||||
b.Navigation("InstallationRequests");
|
||||
|
||||
b.Navigation("SoftwareHistories");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SmallSoftwareDatabase.Models.Worker", b =>
|
||||
{
|
||||
b.Navigation("Requests");
|
||||
|
||||
b.Navigation("Salaries");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SmallSoftwareDatabase.Models;
|
||||
|
||||
internal class InstallationRequest
|
||||
{
|
||||
public required string SoftwareId { get; set; }
|
||||
public required string RequestId { get; set; }
|
||||
public int Count { get; set; }
|
||||
public double Price { get; set; }
|
||||
public Request? Request { get; set; }
|
||||
public Software? Software { get; set; }
|
||||
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
using AutoMapper;
|
||||
using SmallSoftwareContracts.DataModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SmallSoftwareDatabase.Models;
|
||||
|
||||
[AutoMap(typeof(ManufacturerDataModel), ReverseMap = true)]
|
||||
internal class Manufacturer
|
||||
{
|
||||
public required string Id { get; set; }
|
||||
public required string ManufacturerName { get; set; }
|
||||
public string? PrevManufacturerName { get; set; }
|
||||
public string? PrevPrevManufacturerName { get; set; }
|
||||
|
||||
[ForeignKey("ManufacturerId")]
|
||||
public List<Software>? Softwares { get; set; }
|
||||
|
||||
}
|
||||
14
SmallSoftwareProject/SmallSoftwareDatabase/Models/Post.cs
Normal file
14
SmallSoftwareProject/SmallSoftwareDatabase/Models/Post.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using SmallSoftwareContracts.Enums;
|
||||
|
||||
namespace SmallSoftwareDatabase.Models;
|
||||
|
||||
internal class Post
|
||||
{
|
||||
public 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 double Salary { get; set; }
|
||||
public bool IsActual { get; set; }
|
||||
public DateTime ChangeDate { get; set; }
|
||||
}
|
||||
17
SmallSoftwareProject/SmallSoftwareDatabase/Models/Request.cs
Normal file
17
SmallSoftwareProject/SmallSoftwareDatabase/Models/Request.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace SmallSoftwareDatabase.Models;
|
||||
|
||||
internal class Request
|
||||
{
|
||||
public string Id { get; set; } = Guid.NewGuid().ToString();
|
||||
public required string WorkerId { get; set; }
|
||||
public DateTime RequestDate { get; set; }
|
||||
public required string Email { get; set; }
|
||||
public double Sum { get; set; }
|
||||
public bool IsCancel { get; set; }
|
||||
public Worker? Worker { get; set; }
|
||||
|
||||
[ForeignKey("RequestId")]
|
||||
public List<InstallationRequest>? InstallationRequests { get; set; }
|
||||
}
|
||||
11
SmallSoftwareProject/SmallSoftwareDatabase/Models/Salary.cs
Normal file
11
SmallSoftwareProject/SmallSoftwareDatabase/Models/Salary.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
namespace SmallSoftwareDatabase.Models;
|
||||
|
||||
internal class Salary
|
||||
{
|
||||
public string Id { get; set; } = Guid.NewGuid().ToString();
|
||||
public required string WorkerId { get; set; }
|
||||
public double WorkerSalary { get; set; }
|
||||
public DateTime SalaryDate { get; set; }
|
||||
public Worker? Worker { get; set; }
|
||||
}
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
using SmallSoftwareContracts.Enums;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace SmallSoftwareDatabase.Models;
|
||||
|
||||
internal class Software
|
||||
{
|
||||
public required string Id { get; set; }
|
||||
public required string SoftwareName { get; set; }
|
||||
public SoftwareType SoftwareType { get; set; }
|
||||
public required string ManufacturerId { get; set; }
|
||||
public double Price { get; set; }
|
||||
public bool IsDeleted { get; set; }
|
||||
public string? PrevSoftwareName { get; set; }
|
||||
public string? PrevPrevSoftwareName { get; set; }
|
||||
public Manufacturer? Manufacturer { get; set; }
|
||||
|
||||
[ForeignKey("SoftwareId")]
|
||||
public List<SoftwareHistory>? SoftwareHistories { get; set; }
|
||||
|
||||
[ForeignKey("SoftwareId")]
|
||||
public List<InstallationRequest>? InstallationRequests { get; set; }
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
namespace SmallSoftwareDatabase.Models;
|
||||
|
||||
internal class SoftwareHistory
|
||||
{
|
||||
public string Id { get; set; } = Guid.NewGuid().ToString();
|
||||
public required string SoftwareId { get; set; }
|
||||
public double OldPrice { get; set; }
|
||||
public DateTime ChangeDate { get; set; } = DateTime.UtcNow;
|
||||
|
||||
public Software? Software { 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