Сделал все до тестов
This commit is contained in:
@@ -1,16 +1,19 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using TwoFromTheCasketContracts.BusinessLogicsContracts;
|
||||
using TwoFromTheCasketContracts.DataModels;
|
||||
using TwoFromTheCasketContracts.Exceptions;
|
||||
using TwoFromTheCasketContracts.Resources;
|
||||
using TwoFromTheCasketContracts.StorageContracts;
|
||||
using static System.Runtime.InteropServices.JavaScript.JSType;
|
||||
|
||||
namespace TwoFromTheCasketBusinessLogic.Implementation;
|
||||
|
||||
internal class ComplitedWorkBusinessLogicContract(IComplitedWorkStorageContract _complitedWorkStorageContract, ILogger _logger) : IComplitedWorkBusinessLogicContract
|
||||
internal class ComplitedWorkBusinessLogicContract(IComplitedWorkStorageContract _complitedWorkStorageContract, ILogger _logger, IStringLocalizer<Messages> localizer) : IComplitedWorkBusinessLogicContract
|
||||
{
|
||||
private IComplitedWorkStorageContract complitedWorkStorageContract = _complitedWorkStorageContract;
|
||||
private ILogger logger = _logger;
|
||||
private readonly IStringLocalizer<Messages> _localizer = localizer;
|
||||
|
||||
public List<ComplitedWorkDataModel> GetComplitedWorksByPeriod(DateTime fromDate, DateTime toDate)
|
||||
{
|
||||
@@ -19,15 +22,10 @@ internal class ComplitedWorkBusinessLogicContract(IComplitedWorkStorageContract
|
||||
if (fromDate >= toDate)
|
||||
{
|
||||
_logger.LogError("Invalid date range: fromDate ({FromDate}) must be earlier than toDate ({ToDate}).", fromDate, toDate);
|
||||
throw new IncorrectDatesException(fromDate, toDate);
|
||||
throw new IncorrectDatesException(fromDate, toDate, _localizer);
|
||||
}
|
||||
|
||||
var result = complitedWorkStorageContract.GetList(fromDate, toDate);
|
||||
if (result == null)
|
||||
{
|
||||
logger.LogError("No completed works found in the specified period.");
|
||||
throw new NullListException();
|
||||
}
|
||||
|
||||
logger.LogInformation("Fetched {Count} completed works in the specified period.", result.Count);
|
||||
return result;
|
||||
@@ -40,14 +38,14 @@ internal class ComplitedWorkBusinessLogicContract(IComplitedWorkStorageContract
|
||||
if (string.IsNullOrWhiteSpace(complitedWorkId) || !Guid.TryParse(complitedWorkId, out _))
|
||||
{
|
||||
logger.LogError("Invalid completed work ID: {WorkId}", complitedWorkId);
|
||||
throw new ValidationException("Invalid completed work ID.");
|
||||
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageNotAId"], "WorkId"));
|
||||
}
|
||||
|
||||
var result = complitedWorkStorageContract.GetElementById(complitedWorkId);
|
||||
if (result == null)
|
||||
{
|
||||
logger.LogError("Completed work with ID {WorkId} not found.", complitedWorkId);
|
||||
throw new ElementNotFoundException($"Completed work with ID {complitedWorkId} not found.");
|
||||
throw new ElementNotFoundException($"Completed work with ID {complitedWorkId} not found.", _localizer);
|
||||
}
|
||||
|
||||
logger.LogInformation("Fetched completed work {WorkId}.", result.Id);
|
||||
@@ -67,23 +65,17 @@ internal class ComplitedWorkBusinessLogicContract(IComplitedWorkStorageContract
|
||||
if (!Guid.TryParse(roomId, out _))
|
||||
{
|
||||
logger.LogError("Invalid Room ID format: {RoomId}.", roomId);
|
||||
throw new ValidationException("Invalid Room ID.");
|
||||
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageNotAId"], "RoomId"));
|
||||
}
|
||||
|
||||
if (fromDate >= toDate)
|
||||
{
|
||||
logger.LogError("Invalid date range: From {FromDate} To {ToDate}.", fromDate, toDate);
|
||||
throw new IncorrectDatesException(fromDate,toDate);
|
||||
throw new IncorrectDatesException(fromDate,toDate, _localizer);
|
||||
}
|
||||
|
||||
var result = complitedWorkStorageContract.GetList(fromDate, toDate, roomId, null, null);
|
||||
|
||||
if (result is null)
|
||||
{
|
||||
logger.LogError("Storage returned null list for room {RoomId}.", roomId);
|
||||
throw new NullListException();
|
||||
}
|
||||
|
||||
logger.LogInformation("Found {Count} completed works for room {RoomId}.", result.Count, roomId);
|
||||
return result;
|
||||
}
|
||||
@@ -104,13 +96,13 @@ internal class ComplitedWorkBusinessLogicContract(IComplitedWorkStorageContract
|
||||
if (!Guid.TryParse(workId, out _))
|
||||
{
|
||||
logger.LogError("Invalid Work ID format: {WorkId}.", workId);
|
||||
throw new ValidationException("Invalid work ID.");
|
||||
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageNotAId"], "WorkId"));
|
||||
}
|
||||
|
||||
if (fromDate >= toDate)
|
||||
{
|
||||
logger.LogError("Invalid date range: From {FromDate} To {ToDate}.", fromDate, toDate);
|
||||
throw new IncorrectDatesException(fromDate,toDate);
|
||||
throw new IncorrectDatesException(fromDate,toDate, _localizer);
|
||||
}
|
||||
|
||||
var result = complitedWorkStorageContract.GetList(fromDate, toDate, null, workId, null);
|
||||
@@ -118,7 +110,7 @@ internal class ComplitedWorkBusinessLogicContract(IComplitedWorkStorageContract
|
||||
if (result is null)
|
||||
{
|
||||
logger.LogError("Storage returned null list for worker {WorkId}.", workId);
|
||||
throw new NullListException();
|
||||
throw new NullListException(_localizer);
|
||||
}
|
||||
|
||||
logger.LogInformation("Found {Count} completed works for work type {WorkId}.", result.Count, workId);
|
||||
@@ -139,23 +131,17 @@ internal class ComplitedWorkBusinessLogicContract(IComplitedWorkStorageContract
|
||||
if (!Guid.TryParse(workerId, out _))
|
||||
{
|
||||
logger.LogError("Invalid Worker ID format: {WorkerId}.", workerId);
|
||||
throw new ValidationException("Invalid worker ID.");
|
||||
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageNotAId"], "WorkId"));
|
||||
}
|
||||
|
||||
if (fromDate >= toDate)
|
||||
{
|
||||
logger.LogError("Invalid date range: From {FromDate} To {ToDate}.", fromDate, toDate);
|
||||
throw new IncorrectDatesException(fromDate,toDate);
|
||||
throw new IncorrectDatesException(fromDate,toDate, _localizer);
|
||||
}
|
||||
|
||||
var result = complitedWorkStorageContract.GetList(fromDate, toDate, null, null, workerId);
|
||||
|
||||
if (result is null)
|
||||
{
|
||||
logger.LogError("Storage returned null list for worker {WorkerId}.", workerId);
|
||||
throw new NullListException();
|
||||
}
|
||||
|
||||
logger.LogInformation("Found {Count} completed works for worker {WorkerId}.", result.Count, workerId);
|
||||
return result;
|
||||
}
|
||||
@@ -165,29 +151,7 @@ internal class ComplitedWorkBusinessLogicContract(IComplitedWorkStorageContract
|
||||
{
|
||||
logger.LogInformation("Inserting completed work: {ComplitedWorkId}", complitedWorkDataModel.Id);
|
||||
|
||||
if (!Guid.TryParse(complitedWorkDataModel.Id, out _))
|
||||
{
|
||||
logger.LogError("Invalid completed work ID format: {ComplitedWorkId}", complitedWorkDataModel.Id);
|
||||
throw new ValidationException("Invalid completed work ID.");
|
||||
}
|
||||
|
||||
if (!Guid.TryParse(complitedWorkDataModel.WorkId, out _))
|
||||
{
|
||||
logger.LogError("Invalid work ID format: {WorkId}", complitedWorkDataModel.WorkId);
|
||||
throw new ValidationException("Invalid work ID.");
|
||||
}
|
||||
|
||||
if (!Guid.TryParse(complitedWorkDataModel.RoomId, out _))
|
||||
{
|
||||
logger.LogError("Invalid room ID format: {RoomId}", complitedWorkDataModel.RoomId);
|
||||
throw new ValidationException("Invalid room ID.");
|
||||
}
|
||||
|
||||
if (complitedWorkDataModel.Workers is null)
|
||||
{
|
||||
logger.LogError("Attempted to insert completed work without assigned workers.");
|
||||
throw new ValidationException("Completed work must have at least one assigned worker.");
|
||||
}
|
||||
complitedWorkDataModel.Validate(_localizer);
|
||||
|
||||
logger.LogInformation("Completed work {ComplitedWorkId} has been validated successfully.", complitedWorkDataModel.Id);
|
||||
complitedWorkStorageContract.AddElement(complitedWorkDataModel);
|
||||
@@ -207,7 +171,7 @@ internal class ComplitedWorkBusinessLogicContract(IComplitedWorkStorageContract
|
||||
if (string.IsNullOrWhiteSpace(complitedWorkId) || !Guid.TryParse(complitedWorkId, out _))
|
||||
{
|
||||
logger.LogError("Invalid completed work ID: {WorkId}", complitedWorkId);
|
||||
throw new ValidationException("Invalid completed work ID.");
|
||||
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageNotAId"], "WorkId"));
|
||||
}
|
||||
|
||||
complitedWorkStorageContract.DelElement(complitedWorkId);
|
||||
|
||||
@@ -1,31 +1,50 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using TwoFromTheCasketBusinessLogic.OfficePackage;
|
||||
using TwoFromTheCasketContracts.BusinessLogicsContracts;
|
||||
using TwoFromTheCasketContracts.DataModels;
|
||||
using TwoFromTheCasketContracts.Exceptions;
|
||||
using TwoFromTheCasketContracts.Infastructure.SalaryConfiguration;
|
||||
using TwoFromTheCasketContracts.Resources;
|
||||
using TwoFromTheCasketContracts.StorageContracts;
|
||||
using TwoFromTheCasketContracts.ViewModels;
|
||||
|
||||
namespace TwoFromTheCasketBusinessLogic.Implementation;
|
||||
|
||||
internal class ReportContract(
|
||||
internal class ReportContract : IReportContract
|
||||
{
|
||||
private readonly IRoomStorageContract _roomStorageContract;
|
||||
private readonly IRoomHistoryStorageContract _roomHistoryStorageContract;
|
||||
private readonly IComplitedWorkStorageContract _complitedWorkStorageContract ;
|
||||
private readonly ISalaryStorageContract _salaryStorageContract ;
|
||||
private readonly IWorkStorageContract _workStorageContract;
|
||||
private readonly IWorkerStorageContract _workerStorageContract;
|
||||
private readonly ILogger _logger;
|
||||
private readonly BaseWordBuilder _baseWordBuilder;
|
||||
private readonly BaseExcelBuilder _baseExcelBuilder;
|
||||
private readonly BasePdfBuilder _basePdfBuilder;
|
||||
private readonly IStringLocalizer<Messages> _localizer;
|
||||
|
||||
public ReportContract(
|
||||
IRoomStorageContract roomStorageContract, IRoomHistoryStorageContract roomHistoryStorageContract,
|
||||
IComplitedWorkStorageContract complitedWorkStorageContract, IWorkStorageContract workStorageContract,
|
||||
IWorkerStorageContract workerStorageContract, ISalaryStorageContract salaryStorageContract,
|
||||
ILogger logger, BaseWordBuilder baseWordBuilder,
|
||||
BaseExcelBuilder baseExcelBuilder, BasePdfBuilder basePdfBuilder) : IReportContract
|
||||
{
|
||||
private readonly IRoomStorageContract _roomStorageContract = roomStorageContract;
|
||||
private readonly IRoomHistoryStorageContract _roomHistoryStorageContract = roomHistoryStorageContract;
|
||||
private readonly IComplitedWorkStorageContract _complitedWorkStorageContract = complitedWorkStorageContract;
|
||||
private readonly ISalaryStorageContract _salaryStorageContract = salaryStorageContract;
|
||||
private readonly IWorkStorageContract _workStorageContract = workStorageContract;
|
||||
private readonly IWorkerStorageContract _workerStorageContract = workerStorageContract;
|
||||
private readonly ILogger _logger = logger;
|
||||
private readonly BaseWordBuilder _baseWordBuilder = baseWordBuilder;
|
||||
private readonly BaseExcelBuilder _baseExcelBuilder = baseExcelBuilder;
|
||||
private readonly BasePdfBuilder _basePdfBuilder = basePdfBuilder;
|
||||
BaseExcelBuilder baseExcelBuilder, BasePdfBuilder basePdfBuilder,
|
||||
IStringLocalizer<Messages> localizer)
|
||||
{
|
||||
_roomStorageContract = roomStorageContract;
|
||||
_roomHistoryStorageContract = roomHistoryStorageContract;
|
||||
_complitedWorkStorageContract = complitedWorkStorageContract;
|
||||
_salaryStorageContract = salaryStorageContract;
|
||||
_workStorageContract = workStorageContract;
|
||||
_workerStorageContract = workerStorageContract;
|
||||
_logger = logger;
|
||||
_baseWordBuilder = baseWordBuilder;
|
||||
_baseExcelBuilder = baseExcelBuilder;
|
||||
_basePdfBuilder = basePdfBuilder;
|
||||
_localizer = localizer;
|
||||
}
|
||||
|
||||
public async Task<List<RoomWithHistoryDataModel>> GetRoomHistoryGroupedAsync(CancellationToken ct)
|
||||
{
|
||||
@@ -67,8 +86,8 @@ internal class ReportContract(
|
||||
return new List<string[]> { baseRow }.Union(historyRows);
|
||||
}).ToList();
|
||||
var res = _baseWordBuilder
|
||||
.AddHeader("История изменений помещений")
|
||||
.AddParagraph($"Сформировано: {DateTime.Now:dd.MM.yyyy HH:mm}")
|
||||
.AddHeader(_localizer["DocumentDocHeader"])
|
||||
.AddParagraph(string.Format(_localizer["DocumentSubHeader"], DateTime.Now))
|
||||
.AddTable([100, 30, 20, 25], header.Concat(rows).ToList())
|
||||
.Build();
|
||||
res.Position = 0;
|
||||
@@ -78,7 +97,7 @@ internal class ReportContract(
|
||||
public async Task<List<ComplitedWorkReportViewModel>> GetComplitedWorksByPeriodAsync(DateTime from, DateTime to, CancellationToken ct)
|
||||
{
|
||||
if (from >= to)
|
||||
throw new IncorrectDatesException(from, to);
|
||||
throw new IncorrectDatesException(from, to, _localizer);
|
||||
var complitedWorks = await _complitedWorkStorageContract.GetListAsync(from, to, ct);
|
||||
var works = await _workStorageContract.GetListAsync(ct);
|
||||
var rooms = await _roomStorageContract.GetListAsync(ct);
|
||||
@@ -146,7 +165,7 @@ internal class ReportContract(
|
||||
|
||||
tableData.AddRange(data.Select(x => new[]
|
||||
{
|
||||
x.Date.ToString("yyyy-MM-dd HH:mm"),
|
||||
x.Date.ToLocalTime().ToShortDateString(),
|
||||
x.WorkerFIO,
|
||||
x.RoomAddress,
|
||||
x.WorkDescription,
|
||||
@@ -157,8 +176,8 @@ internal class ReportContract(
|
||||
tableData.Add(new[] { "", "", "", "Итого:", totalSum.ToString("F2") });
|
||||
|
||||
var result = _baseExcelBuilder
|
||||
.AddHeader("Отчет по выполненным работам за период", 0, 5)
|
||||
.AddParagraph($"Период: с {from:yyyy-MM-dd} по {to:yyyy-MM-dd}", 2)
|
||||
.AddHeader(_localizer["DocumentDocExcelHeader"], 0, 5)
|
||||
.AddParagraph(string.Format(_localizer["DocumentSubExcelHeader"], from.ToLocalTime().ToShortDateString(), to.ToLocalTime().ToShortDateString()), 2)
|
||||
.AddTable(new[] { 20, 25, 30, 30, 15 }, tableData)
|
||||
.Build();
|
||||
|
||||
@@ -174,7 +193,7 @@ internal class ReportContract(
|
||||
if (!Guid.TryParse(workerId, out _))
|
||||
throw new ValidationException("Invalid worker ID format.");
|
||||
if (from >= to)
|
||||
throw new IncorrectDatesException(from, to);
|
||||
throw new IncorrectDatesException(from, to, _localizer);
|
||||
|
||||
var salaries = await _salaryStorageContract.GetListAsync(from, to, ct, workerId)
|
||||
?? throw new NullReferenceException("No salary data found.");
|
||||
@@ -203,9 +222,9 @@ internal class ReportContract(
|
||||
string fio = data.First().WorkerFIO;
|
||||
|
||||
return _basePdfBuilder
|
||||
.AddHeader($"Зарплатная ведомость у {fio}")
|
||||
.AddParagraph($"за период с {from.ToShortDateString()} по {to.ToShortDateString()}")
|
||||
.AddPieChart("Начисления", [.. data.Select(x => (x.Date.ToShortDateString(), x.Amount))])
|
||||
.AddHeader(string.Format(_localizer["DocumentSalaryHeader"], fio))
|
||||
.AddParagraph(string.Format(_localizer["DocumentSubExcelHeader"], from.ToLocalTime().ToShortTimeString(), to.ToLocalTime().ToShortTimeString()))
|
||||
.AddPieChart(_localizer["DocumentSalaryChartTitle"], [.. data.Select(x => (x.Date.ToLocalTime().ToShortTimeString(), x.Amount))])
|
||||
.Build();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,26 +1,24 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using TwoFromTheCasketContracts.BusinessLogicsContracts;
|
||||
using TwoFromTheCasketContracts.DataModels;
|
||||
using TwoFromTheCasketContracts.Exceptions;
|
||||
using TwoFromTheCasketContracts.Resources;
|
||||
using TwoFromTheCasketContracts.StorageContracts;
|
||||
|
||||
namespace TwoFromTheCasketBusinessLogic.Implementation;
|
||||
|
||||
internal class RoomBusinessLogicContract(IRoomStorageContract _roomStorageContract, ILogger _logger) : IRoomBusinessLogicContract
|
||||
internal class RoomBusinessLogicContract(IRoomStorageContract _roomStorageContract, ILogger _logger, IStringLocalizer<Messages> localizer) : IRoomBusinessLogicContract
|
||||
{
|
||||
private IRoomStorageContract roomStorageContract = _roomStorageContract;
|
||||
private ILogger logger = _logger;
|
||||
private readonly IStringLocalizer<Messages> _localizer = localizer;
|
||||
|
||||
public List<RoomDataModel> GetAllRooms()
|
||||
{
|
||||
logger.LogInformation("Retrieving all rooms.");
|
||||
var rooms = roomStorageContract.GetList();
|
||||
|
||||
if (rooms == null)
|
||||
{
|
||||
logger.LogError("Room list is null.");
|
||||
throw new NullListException();
|
||||
}
|
||||
|
||||
logger.LogInformation("Successfully retrieved {Count} rooms.", rooms.Count);
|
||||
return rooms;
|
||||
}
|
||||
@@ -36,11 +34,6 @@ internal class RoomBusinessLogicContract(IRoomStorageContract _roomStorageContra
|
||||
}
|
||||
|
||||
var rooms = roomStorageContract.GetListByOwner(ownerFIO);
|
||||
if (rooms == null)
|
||||
{
|
||||
logger.LogError("No rooms found for owner FIO: {ownerFIO}", ownerFIO);
|
||||
throw new NullListException();
|
||||
}
|
||||
|
||||
logger.LogInformation("Found {Count} rooms for owner FIO: {ownerFIO}", rooms.Count, ownerFIO);
|
||||
return rooms;
|
||||
@@ -57,11 +50,6 @@ internal class RoomBusinessLogicContract(IRoomStorageContract _roomStorageContra
|
||||
}
|
||||
|
||||
var rooms = roomStorageContract.GetListByAddress(address);
|
||||
if (rooms == null)
|
||||
{
|
||||
logger.LogError("No rooms found at address: {Address}", address);
|
||||
throw new NullListException();
|
||||
}
|
||||
|
||||
logger.LogInformation("Found {Count} rooms at address: {Address}", rooms.Count, address);
|
||||
return rooms;
|
||||
@@ -80,14 +68,14 @@ internal class RoomBusinessLogicContract(IRoomStorageContract _roomStorageContra
|
||||
if (!Guid.TryParse(roomId, out _))
|
||||
{
|
||||
logger.LogError("Invalid room ID format: {RoomId}", roomId);
|
||||
throw new ValidationException("Invalid room ID.");
|
||||
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageEmptyField"], "RoomId"));
|
||||
}
|
||||
|
||||
var room = roomStorageContract.GetElementById(roomId);
|
||||
if (room == null)
|
||||
{
|
||||
logger.LogError("Room not found: {RoomId}", roomId);
|
||||
throw new ElementNotFoundException(roomId);
|
||||
throw new ElementNotFoundException(roomId, _localizer);
|
||||
}
|
||||
|
||||
logger.LogInformation("Successfully retrieved room: {RoomId}", roomId);
|
||||
@@ -98,29 +86,7 @@ internal class RoomBusinessLogicContract(IRoomStorageContract _roomStorageContra
|
||||
{
|
||||
logger.LogInformation("Inserting new room.");
|
||||
|
||||
if (roomDataModel == null)
|
||||
{
|
||||
logger.LogError("Attempted to insert a null room.");
|
||||
throw new ArgumentNullException(nameof(roomDataModel));
|
||||
}
|
||||
|
||||
if (!Guid.TryParse(roomDataModel.Id, out _))
|
||||
{
|
||||
logger.LogError("Invalid room ID: {RoomId}", roomDataModel.Id);
|
||||
throw new ValidationException("Invalid room ID.");
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(roomDataModel.Address))
|
||||
{
|
||||
logger.LogError("Invalid room address.");
|
||||
throw new ValidationException("Room address cannot be empty.");
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(roomDataModel.OwnerFIO))
|
||||
{
|
||||
logger.LogError("Invalid owner FIO: {OwnerFIO}", roomDataModel.OwnerFIO);
|
||||
throw new ValidationException("Room OwnerFIO cannot be empty.");
|
||||
}
|
||||
roomDataModel.Validate(_localizer);
|
||||
|
||||
roomStorageContract.AddElement(roomDataModel);
|
||||
logger.LogInformation("Room {RoomId} inserted successfully.", roomDataModel.Id);
|
||||
@@ -130,23 +96,7 @@ internal class RoomBusinessLogicContract(IRoomStorageContract _roomStorageContra
|
||||
{
|
||||
logger.LogInformation("Updating room: {RoomId}", roomDataModel.Id);
|
||||
|
||||
if (!Guid.TryParse(roomDataModel.Id, out _))
|
||||
{
|
||||
logger.LogError("Invalid room ID: {RoomId}", roomDataModel.Id);
|
||||
throw new ValidationException("Invalid room ID.");
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(roomDataModel.Address))
|
||||
{
|
||||
logger.LogError("Invalid room address.");
|
||||
throw new ValidationException("Room address cannot be empty.");
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(roomDataModel.OwnerFIO))
|
||||
{
|
||||
logger.LogError("Invalid owner FIO: {OwnerFIO}", roomDataModel.OwnerFIO);
|
||||
throw new ValidationException("Room OwnerFIO cannot be empty.");
|
||||
}
|
||||
roomDataModel.Validate(_localizer);
|
||||
|
||||
roomStorageContract.UpdElement(roomDataModel);
|
||||
logger.LogInformation("Room {RoomId} updated successfully.", roomDataModel.Id);
|
||||
@@ -165,7 +115,7 @@ internal class RoomBusinessLogicContract(IRoomStorageContract _roomStorageContra
|
||||
if (!Guid.TryParse(roomId, out _))
|
||||
{
|
||||
logger.LogError("Invalid room ID format: {RoomId}", roomId);
|
||||
throw new ValidationException("Invalid room ID.");
|
||||
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageNotAId"], "RoomId"));
|
||||
}
|
||||
|
||||
roomStorageContract.DelElement(roomId);
|
||||
|
||||
@@ -1,15 +1,19 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using TwoFromTheCasketContracts.BusinessLogicsContracts;
|
||||
using TwoFromTheCasketContracts.DataModels;
|
||||
using TwoFromTheCasketContracts.Exceptions;
|
||||
using TwoFromTheCasketContracts.Resources;
|
||||
using TwoFromTheCasketContracts.StorageContracts;
|
||||
|
||||
namespace TwoFromTheCasketBusinessLogic.Implementation;
|
||||
|
||||
internal class RoomHistoryBusinessLogicContract(IRoomHistoryStorageContract _roomHistoryStorageContract, ILogger _logger) : IRoomHistoryBusinessLogicContract
|
||||
internal class RoomHistoryBusinessLogicContract(IRoomHistoryStorageContract _roomHistoryStorageContract, ILogger _logger, IStringLocalizer<Messages> localizer) : IRoomHistoryBusinessLogicContract
|
||||
{
|
||||
private IRoomHistoryStorageContract roomHistoryStorageContract = _roomHistoryStorageContract;
|
||||
private ILogger logger = _logger;
|
||||
private readonly IStringLocalizer<Messages> _localizer = localizer;
|
||||
|
||||
public List<RoomHistoryDataModel> GetRoomHistory(string roomId)
|
||||
{
|
||||
logger.LogInformation("Retrieving history for room: {RoomId}", roomId);
|
||||
@@ -23,17 +27,11 @@ internal class RoomHistoryBusinessLogicContract(IRoomHistoryStorageContract _roo
|
||||
if (!Guid.TryParse(roomId, out _))
|
||||
{
|
||||
logger.LogError("Invalid room ID format: {RoomId}", roomId);
|
||||
throw new ValidationException("Invalid room ID.");
|
||||
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageNotAId"], "RoomId"));
|
||||
}
|
||||
|
||||
var history = roomHistoryStorageContract.GetList(roomId);
|
||||
|
||||
if (history == null)
|
||||
{
|
||||
logger.LogError("No history found for room ID: {RoomId}", roomId);
|
||||
throw new NullListException();
|
||||
}
|
||||
|
||||
logger.LogInformation("Retrieved {Count} history records for room ID: {RoomId}", history.Count, roomId);
|
||||
return history;
|
||||
}
|
||||
@@ -51,23 +49,13 @@ internal class RoomHistoryBusinessLogicContract(IRoomHistoryStorageContract _roo
|
||||
if (!Guid.TryParse(roomId, out _))
|
||||
{
|
||||
logger.LogError("Invalid room ID format: {RoomId}", roomId);
|
||||
throw new ValidationException("Invalid room ID.");
|
||||
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageNotAId"], "RoomId"));
|
||||
}
|
||||
|
||||
var historyRecords = roomHistoryStorageContract.GetList(roomId);
|
||||
|
||||
if (historyRecords == null || historyRecords.Count == 0)
|
||||
{
|
||||
logger.LogError("No history records found for room ID: {RoomId}", roomId);
|
||||
throw new NullListException();
|
||||
}
|
||||
|
||||
var latestHistory = historyRecords.MaxBy(h => h.DateChange);
|
||||
if (latestHistory == null)
|
||||
{
|
||||
logger.LogError("Failed to determine latest history record for room ID: {RoomId}", roomId);
|
||||
throw new NullListException();
|
||||
}
|
||||
|
||||
logger.LogInformation("Retrieved latest history record for room ID: {RoomId}", roomId);
|
||||
return latestHistory;
|
||||
@@ -86,15 +74,8 @@ internal class RoomHistoryBusinessLogicContract(IRoomHistoryStorageContract _roo
|
||||
if (!Guid.TryParse(roomHistoryDataModel.RoomId, out _))
|
||||
{
|
||||
logger.LogError("Invalid room ID: {RoomId}", roomHistoryDataModel.RoomId);
|
||||
throw new ValidationException("Invalid room ID.");
|
||||
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageNotAId"], "RoomId"));
|
||||
}
|
||||
|
||||
if (roomHistoryDataModel.DateChange == default)
|
||||
{
|
||||
logger.LogError("Invalid change date.");
|
||||
throw new ValidationException("Invalid change date.");
|
||||
}
|
||||
|
||||
roomHistoryStorageContract.AddElement(roomHistoryDataModel);
|
||||
logger.LogInformation("Room history added successfully for room: {RoomId}", roomHistoryDataModel.RoomId);
|
||||
}
|
||||
|
||||
@@ -1,16 +1,19 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using TwoFromTheCasketContracts.BusinessLogicsContracts;
|
||||
using TwoFromTheCasketContracts.DataModels;
|
||||
using TwoFromTheCasketContracts.Exceptions;
|
||||
using TwoFromTheCasketContracts.Infastructure;
|
||||
using TwoFromTheCasketContracts.Infastructure.SalaryConfiguration;
|
||||
using TwoFromTheCasketContracts.Resources;
|
||||
using TwoFromTheCasketContracts.StorageContracts;
|
||||
|
||||
namespace TwoFromTheCasketBusinessLogic.Implementation;
|
||||
|
||||
internal class SalaryBusinessLogicContract(ISalaryStorageContract _salaryStorageContract, IWorkerStorageContract _workerStorageContract,
|
||||
IComplitedWorkStorageContract _сomplitedWorkStorageContract, ISpecializationStorageContract _specializationStorageContract, ILogger _logger, IConfigurationSalary configuration) : ISalaryBusinessLogicContract
|
||||
IComplitedWorkStorageContract _сomplitedWorkStorageContract, ISpecializationStorageContract _specializationStorageContract, ILogger _logger, IConfigurationSalary configuration
|
||||
, IStringLocalizer<Messages> localizer) : ISalaryBusinessLogicContract
|
||||
{
|
||||
private ISalaryStorageContract salaryStorageContract = _salaryStorageContract;
|
||||
private IWorkerStorageContract workerStorageContract = _workerStorageContract;
|
||||
@@ -18,6 +21,7 @@ internal class SalaryBusinessLogicContract(ISalaryStorageContract _salaryStorage
|
||||
private ISpecializationStorageContract specializationStorageContract = _specializationStorageContract;
|
||||
private IConfigurationSalary configurationSalary = configuration;
|
||||
private ILogger logger = _logger;
|
||||
private readonly IStringLocalizer<Messages> _localizer = localizer;
|
||||
|
||||
public List<SalaryDataModel> GetSalariesByWorkerByPeriod(string workerId, DateTime fromDate, DateTime toDate)
|
||||
{
|
||||
@@ -25,14 +29,14 @@ internal class SalaryBusinessLogicContract(ISalaryStorageContract _salaryStorage
|
||||
throw new ArgumentNullException(nameof(workerId), "Worker ID cannot be null or empty.");
|
||||
|
||||
if (!Guid.TryParse(workerId, out _))
|
||||
throw new ValidationException("Invalid worker ID format.");
|
||||
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageNotAId"], "workerId"));
|
||||
|
||||
if (fromDate >= toDate)
|
||||
throw new IncorrectDatesException(fromDate,toDate);
|
||||
throw new IncorrectDatesException(fromDate,toDate, _localizer);
|
||||
|
||||
_logger.LogInformation("Fetching salaries for worker {WorkerId} from {FromDate} to {ToDate}", workerId, fromDate, toDate);
|
||||
|
||||
var salaries = _salaryStorageContract.GetList(fromDate, toDate, workerId) ?? throw new NullListException();
|
||||
var salaries = _salaryStorageContract.GetList(fromDate, toDate, workerId);
|
||||
|
||||
return salaries;
|
||||
}
|
||||
@@ -40,11 +44,11 @@ internal class SalaryBusinessLogicContract(ISalaryStorageContract _salaryStorage
|
||||
public List<SalaryDataModel> GetSalariesByPeriod(DateTime fromDate, DateTime toDate)
|
||||
{
|
||||
if (fromDate >= toDate)
|
||||
throw new IncorrectDatesException(fromDate,toDate);
|
||||
throw new IncorrectDatesException(fromDate,toDate, _localizer);
|
||||
|
||||
_logger.LogInformation("Fetching salaries from {FromDate} to {ToDate}", fromDate, toDate);
|
||||
|
||||
var salaries = _salaryStorageContract.GetList(fromDate, toDate, null) ?? throw new NullListException();
|
||||
var salaries = _salaryStorageContract.GetList(fromDate, toDate, null);
|
||||
|
||||
return salaries;
|
||||
}
|
||||
@@ -62,13 +66,13 @@ internal class SalaryBusinessLogicContract(ISalaryStorageContract _salaryStorage
|
||||
DateTimeKind.Utc);
|
||||
|
||||
var workers = workerStorageContract.GetList()
|
||||
?? throw new StorageException(new InvalidOperationException("Failed to load workers"));
|
||||
?? throw new StorageException(new InvalidOperationException("Failed to load workers"), _localizer);
|
||||
|
||||
foreach (var worker in workers)
|
||||
{
|
||||
var completed = сomplitedWorkStorageContract
|
||||
.GetList(startDate, finishDate, worker.Id)
|
||||
?? throw new StorageException(new InvalidOperationException("Failed to load completed works"));
|
||||
?? throw new StorageException(new InvalidOperationException("Failed to load completed works"), _localizer);
|
||||
|
||||
var totalUnits = completed
|
||||
.SelectMany(cw => cw.Workers)
|
||||
@@ -76,8 +80,7 @@ internal class SalaryBusinessLogicContract(ISalaryStorageContract _salaryStorage
|
||||
.Sum(wcw => wcw.NumberOfWorkingHours);
|
||||
|
||||
var specialization = specializationStorageContract
|
||||
.GetElementById(worker.SpecializationId)
|
||||
?? throw new NullListException();
|
||||
.GetElementById(worker.SpecializationId);
|
||||
|
||||
var cfg = worker.ConfigurationModel;
|
||||
double salaryToPay;
|
||||
|
||||
@@ -1,22 +1,23 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using TwoFromTheCasketContracts.BusinessLogicsContracts;
|
||||
using TwoFromTheCasketContracts.DataModels;
|
||||
using TwoFromTheCasketContracts.Exceptions;
|
||||
using TwoFromTheCasketContracts.Resources;
|
||||
using TwoFromTheCasketContracts.StorageContracts;
|
||||
|
||||
namespace TwoFromTheCasketBusinessLogic.Implementation;
|
||||
|
||||
internal class SpecializationBusinessLogicContract(ISpecializationStorageContract _specializationStorageContract, ILogger _logger) : ISpecializationBusinessLogicContract
|
||||
internal class SpecializationBusinessLogicContract(ISpecializationStorageContract _specializationStorageContract, ILogger _logger, IStringLocalizer<Messages> localizer) : ISpecializationBusinessLogicContract
|
||||
{
|
||||
private ISpecializationStorageContract specializationStorageContract = _specializationStorageContract;
|
||||
private ILogger logger = _logger;
|
||||
|
||||
private readonly IStringLocalizer<Messages> _localizer = localizer;
|
||||
public List<SpecializationDataModel> GetAllSpecializations()
|
||||
{
|
||||
logger.LogInformation("Retrieving all specializations");
|
||||
|
||||
var specializations = _specializationStorageContract.GetList()
|
||||
?? throw new NullListException();
|
||||
var specializations = _specializationStorageContract.GetList();
|
||||
|
||||
return specializations;
|
||||
}
|
||||
@@ -25,8 +26,7 @@ internal class SpecializationBusinessLogicContract(ISpecializationStorageContrac
|
||||
{
|
||||
logger.LogInformation("Retrieving all specializations (only actual: {OnlyActual})", onlyActual);
|
||||
|
||||
var specializations = _specializationStorageContract.GetList()
|
||||
?? throw new NullListException();
|
||||
var specializations = _specializationStorageContract.GetList();
|
||||
|
||||
return onlyActual
|
||||
? specializations.Where(s => s.IsActual).ToList()
|
||||
@@ -39,12 +39,12 @@ internal class SpecializationBusinessLogicContract(ISpecializationStorageContrac
|
||||
throw new ArgumentNullException(nameof(specializationId), "Specialization ID cannot be null or empty");
|
||||
|
||||
if (!Guid.TryParse(specializationId, out _))
|
||||
throw new ValidationException("Invalid specialization ID format");
|
||||
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageNotAId"], "specializationId"));
|
||||
|
||||
logger.LogInformation("Retrieving latest specialization by ID: {SpecializationId}", specializationId);
|
||||
|
||||
var specialization = _specializationStorageContract.GetElementById(specializationId)
|
||||
?? throw new ElementNotFoundException($"Specialization with ID '{specializationId}' not found");
|
||||
?? throw new ElementNotFoundException($"Specialization with ID '{specializationId}' not found", _localizer);
|
||||
|
||||
return specialization;
|
||||
}
|
||||
@@ -69,10 +69,6 @@ internal class SpecializationBusinessLogicContract(ISpecializationStorageContrac
|
||||
throw;
|
||||
}
|
||||
|
||||
if (specializations == null)
|
||||
{
|
||||
throw new NullListException();
|
||||
}
|
||||
|
||||
var latestSpecialization = specializations
|
||||
.Where(s => s.SpecializationName == specializationName)
|
||||
@@ -81,7 +77,7 @@ internal class SpecializationBusinessLogicContract(ISpecializationStorageContrac
|
||||
|
||||
if (latestSpecialization == null)
|
||||
{
|
||||
throw new ElementNotFoundException($"No specialization found with name: {specializationName}");
|
||||
throw new ElementNotFoundException($"No specialization found with name: {specializationName}", _localizer);
|
||||
}
|
||||
|
||||
return latestSpecialization;
|
||||
@@ -91,18 +87,12 @@ internal class SpecializationBusinessLogicContract(ISpecializationStorageContrac
|
||||
public void AddSpecialization(SpecializationDataModel specialization)
|
||||
{
|
||||
|
||||
if (specialization == null ||
|
||||
string.IsNullOrWhiteSpace(specialization.Id) ||
|
||||
string.IsNullOrWhiteSpace(specialization.SpecializationName) ||
|
||||
specialization.Salary <= 0)
|
||||
{
|
||||
throw new ValidationException("Invalid specialization data.");
|
||||
}
|
||||
specialization.Validate(_localizer);
|
||||
|
||||
logger.LogInformation("Adding new specialization: {SpecializationName}", specialization.SpecializationName);
|
||||
|
||||
if (_specializationStorageContract.GetList()?.Any(s => s.SpecializationName.Equals(specialization.SpecializationName, StringComparison.OrdinalIgnoreCase)) == true)
|
||||
throw new ElementExistsException("Specialization", specialization.SpecializationName);
|
||||
throw new ElementExistsException("Specialization", specialization.SpecializationName, _localizer);
|
||||
|
||||
_specializationStorageContract.AddElement(specialization);
|
||||
}
|
||||
@@ -113,12 +103,12 @@ internal class SpecializationBusinessLogicContract(ISpecializationStorageContrac
|
||||
throw new ArgumentNullException(nameof(specializationId), "Specialization ID cannot be null or empty");
|
||||
|
||||
if (!Guid.TryParse(specializationId, out _))
|
||||
throw new ValidationException("Invalid specialization ID format");
|
||||
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageNotAId"], "specializationId"));
|
||||
|
||||
logger.LogInformation("Deactivating specialization: {SpecializationId}", specializationId);
|
||||
|
||||
var specialization = _specializationStorageContract.GetElementById(specializationId)
|
||||
?? throw new ElementNotFoundException($"Specialization with ID {specializationId} not found");
|
||||
?? throw new ElementNotFoundException($"Specialization with ID {specializationId} not found", _localizer);
|
||||
|
||||
if (!specialization.IsActual)
|
||||
throw new ValidationException("Specialization is already deactivated");
|
||||
@@ -132,12 +122,12 @@ internal class SpecializationBusinessLogicContract(ISpecializationStorageContrac
|
||||
throw new ArgumentNullException(nameof(specializationId), "Specialization ID cannot be null or empty");
|
||||
|
||||
if (!Guid.TryParse(specializationId, out _))
|
||||
throw new ValidationException("Invalid specialization ID format");
|
||||
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageNotAId"], "specializationId"));
|
||||
|
||||
logger.LogInformation("Restoring specialization: {SpecializationId}", specializationId);
|
||||
|
||||
var specialization = _specializationStorageContract.GetElementById(specializationId)
|
||||
?? throw new ElementNotFoundException($"Specialization with ID {specializationId} not found");
|
||||
?? throw new ElementNotFoundException($"Specialization with ID {specializationId} not found", _localizer);
|
||||
|
||||
if (specialization.IsActual)
|
||||
throw new ValidationException("Specialization is already active");
|
||||
|
||||
@@ -1,27 +1,25 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using TwoFromTheCasketContracts.BusinessLogicsContracts;
|
||||
using TwoFromTheCasketContracts.DataModels;
|
||||
using TwoFromTheCasketContracts.Enums;
|
||||
using TwoFromTheCasketContracts.Exceptions;
|
||||
using TwoFromTheCasketContracts.Resources;
|
||||
using TwoFromTheCasketContracts.StorageContracts;
|
||||
|
||||
namespace TwoFromTheCasketBusinessLogic.Implementation;
|
||||
|
||||
internal class WorkBusinessLogicContract(IWorkStorageContract _workStorageContract, ILogger _logger) : IWorkBusinessLogicContract
|
||||
internal class WorkBusinessLogicContract(IWorkStorageContract _workStorageContract, ILogger _logger, IStringLocalizer<Messages> localizer) : IWorkBusinessLogicContract
|
||||
{
|
||||
private IWorkStorageContract workStorageContract = _workStorageContract;
|
||||
private ILogger logger = _logger;
|
||||
private readonly IStringLocalizer<Messages> _localizer = localizer;
|
||||
public List<WorkDataModel> GetAllWorks()
|
||||
{
|
||||
_logger.LogInformation("Fetching all works.");
|
||||
|
||||
var works = _workStorageContract.GetList();
|
||||
|
||||
if (works == null)
|
||||
{
|
||||
throw new NullListException();
|
||||
}
|
||||
|
||||
_logger.LogInformation("Fetched {Count} works.", works.Count);
|
||||
return works;
|
||||
}
|
||||
@@ -31,22 +29,11 @@ internal class WorkBusinessLogicContract(IWorkStorageContract _workStorageContra
|
||||
{
|
||||
_logger.LogInformation("InsertWork: {@work}", work);
|
||||
|
||||
if (work == null)
|
||||
throw new ArgumentNullException(nameof(work));
|
||||
|
||||
if(string.IsNullOrWhiteSpace(work.Description))
|
||||
{
|
||||
throw new ValidationException(nameof(work));
|
||||
}
|
||||
|
||||
if (!Guid.TryParse(work.Id, out _))
|
||||
{
|
||||
throw new ValidationException("Invalid work ID format.");
|
||||
}
|
||||
work.Validate(_localizer);
|
||||
|
||||
var existingWork = _workStorageContract.GetElementById(work.Id);
|
||||
if (existingWork != null)
|
||||
throw new ElementExistsException($"Work", work.Id);
|
||||
throw new ElementExistsException($"Work", work.Id, _localizer);
|
||||
|
||||
_workStorageContract.AddElement(work);
|
||||
}
|
||||
@@ -58,25 +45,12 @@ internal class WorkBusinessLogicContract(IWorkStorageContract _workStorageContra
|
||||
{
|
||||
_logger.LogInformation("Updating work: {@work}", work);
|
||||
|
||||
if (work == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(work), "Work cannot be null.");
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(work.Description))
|
||||
{
|
||||
throw new ValidationException("Work description cannot be empty.");
|
||||
}
|
||||
|
||||
if (!Guid.TryParse(work.Id, out _))
|
||||
{
|
||||
throw new ValidationException("Invalid work ID format.");
|
||||
}
|
||||
work.Validate(_localizer);
|
||||
|
||||
var existingWork = _workStorageContract.GetElementById(work.Id);
|
||||
if (existingWork == null)
|
||||
{
|
||||
throw new ElementNotFoundException($"Work with ID {work.Id} not found.");
|
||||
throw new ElementNotFoundException($"Work with ID {work.Id} not found.", _localizer);
|
||||
}
|
||||
|
||||
try
|
||||
@@ -86,7 +60,7 @@ internal class WorkBusinessLogicContract(IWorkStorageContract _workStorageContra
|
||||
}
|
||||
catch (Exception ex) when (!(ex is ElementNotFoundException))
|
||||
{
|
||||
throw new StorageException(ex);
|
||||
throw new StorageException(ex, _localizer);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -102,11 +76,11 @@ internal class WorkBusinessLogicContract(IWorkStorageContract _workStorageContra
|
||||
throw new ArgumentNullException(nameof(workId));
|
||||
|
||||
if (!Guid.TryParse(workId, out _))
|
||||
throw new ValidationException("Invalid work ID format.");
|
||||
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageNotAId"], "workId"));
|
||||
|
||||
var existingWork = _workStorageContract.GetElementById(workId);
|
||||
if (existingWork == null)
|
||||
throw new ElementNotFoundException($"Work with ID {workId} not found.");
|
||||
throw new ElementNotFoundException($"Work with ID {workId} not found.", _localizer);
|
||||
|
||||
try
|
||||
{
|
||||
@@ -114,7 +88,7 @@ internal class WorkBusinessLogicContract(IWorkStorageContract _workStorageContra
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new StorageException(ex);
|
||||
throw new StorageException(ex, _localizer);
|
||||
}
|
||||
}
|
||||
public WorkDataModel GetWorkByData(DateTime dataFrom, DateTime dataTo)
|
||||
@@ -123,26 +97,21 @@ internal class WorkBusinessLogicContract(IWorkStorageContract _workStorageContra
|
||||
|
||||
if (dataFrom >= dataTo)
|
||||
{
|
||||
throw new IncorrectDatesException(dataFrom, dataTo);
|
||||
throw new IncorrectDatesException(dataFrom, dataTo, _localizer);
|
||||
}
|
||||
|
||||
var works = _workStorageContract.GetList(dataFrom, dataTo);
|
||||
|
||||
if (works == null)
|
||||
{
|
||||
throw new NullListException();
|
||||
}
|
||||
|
||||
if (works.Count == 0)
|
||||
{
|
||||
throw new ElementNotFoundException($"No works found in the period from {dataFrom} to {dataTo}.");
|
||||
throw new ElementNotFoundException($"No works found in the period from {dataFrom} to {dataTo}.", _localizer);
|
||||
}
|
||||
|
||||
var latestWork = works.MaxBy(w => w.Date);
|
||||
|
||||
if (latestWork == null)
|
||||
{
|
||||
throw new ElementNotFoundException($"No work found in the given period.");
|
||||
throw new ElementNotFoundException($"No work found in the given period.", _localizer);
|
||||
}
|
||||
|
||||
_logger.LogInformation("Found work: {WorkDescription} (ID: {WorkId})", latestWork.Description, latestWork.Id);
|
||||
|
||||
@@ -4,19 +4,21 @@ using TwoFromTheCasketContracts.DataModels;
|
||||
using TwoFromTheCasketContracts.Exceptions;
|
||||
using TwoFromTheCasketContracts.StorageContracts;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using TwoFromTheCasketContracts.Resources;
|
||||
|
||||
namespace TwoFromTheCasketBusinessLogic.Implementation;
|
||||
|
||||
internal class WorkerBusinessLogicContract(IWorkerStorageContract _workerStorageContract, ILogger _logger) : IWorkerBusinessLogicContract
|
||||
internal class WorkerBusinessLogicContract(IWorkerStorageContract _workerStorageContract, ILogger _logger, IStringLocalizer<Messages> localizer) : IWorkerBusinessLogicContract
|
||||
{
|
||||
private IWorkerStorageContract workerStorageContract = _workerStorageContract;
|
||||
private ILogger logger = _logger;
|
||||
private readonly IStringLocalizer<Messages> _localizer = localizer;
|
||||
|
||||
public List<WorkerDataModel> GetAllWorkers(bool onlyActive = true)
|
||||
{
|
||||
logger.LogInformation("Retrieving all workers (onlyActive: {onlyActive})", onlyActive);
|
||||
var workers = workerStorageContract.GetList(onlyActive, null, null, null, null, null)
|
||||
?? throw new NullListException();
|
||||
var workers = workerStorageContract.GetList(onlyActive, null, null, null, null, null);
|
||||
return workers;
|
||||
}
|
||||
|
||||
@@ -25,10 +27,9 @@ internal class WorkerBusinessLogicContract(IWorkerStorageContract _workerStorage
|
||||
logger.LogInformation("Retrieving workers born between {fromDate} and {toDate}", fromDate, toDate);
|
||||
|
||||
if (fromDate >= toDate)
|
||||
throw new IncorrectDatesException(fromDate, toDate);
|
||||
throw new IncorrectDatesException(fromDate, toDate, _localizer);
|
||||
|
||||
var workers = workerStorageContract.GetList(onlyActive, null, fromDate, toDate, null, null)
|
||||
?? throw new NullListException();
|
||||
var workers = workerStorageContract.GetList(onlyActive, null, fromDate, toDate, null, null);
|
||||
|
||||
return workers;
|
||||
}
|
||||
@@ -38,10 +39,9 @@ internal class WorkerBusinessLogicContract(IWorkerStorageContract _workerStorage
|
||||
logger.LogInformation("Retrieving workers employed between {fromDate} and {toDate}", fromDate, toDate);
|
||||
|
||||
if (fromDate >= toDate)
|
||||
throw new IncorrectDatesException(fromDate, toDate);
|
||||
throw new IncorrectDatesException(fromDate, toDate, _localizer);
|
||||
|
||||
var workers = workerStorageContract.GetList(onlyActive, null, null, null, fromDate, toDate)
|
||||
?? throw new NullListException();
|
||||
var workers = workerStorageContract.GetList(onlyActive, null, null, null, fromDate, toDate);
|
||||
|
||||
return workers;
|
||||
}
|
||||
@@ -54,10 +54,9 @@ internal class WorkerBusinessLogicContract(IWorkerStorageContract _workerStorage
|
||||
throw new ArgumentNullException(nameof(specializationId));
|
||||
|
||||
if (!Guid.TryParse(specializationId, out _))
|
||||
throw new ValidationException("Specialization ID is not a valid GUID.");
|
||||
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageNotAId"], "specializationId"));
|
||||
|
||||
var workers = workerStorageContract.GetList(onlyActive, specializationId, null, null, null, null)
|
||||
?? throw new NullListException();
|
||||
var workers = workerStorageContract.GetList(onlyActive, specializationId, null, null, null, null);
|
||||
|
||||
return workers;
|
||||
}
|
||||
@@ -79,7 +78,7 @@ internal class WorkerBusinessLogicContract(IWorkerStorageContract _workerStorage
|
||||
worker = workerStorageContract.GetElementByFIO(data);
|
||||
}
|
||||
|
||||
return worker ?? throw new ElementNotFoundException(data);
|
||||
return worker ?? throw new ElementNotFoundException(data, _localizer);
|
||||
}
|
||||
|
||||
public void InsertWorker(WorkerDataModel workerDataModel)
|
||||
@@ -89,8 +88,7 @@ internal class WorkerBusinessLogicContract(IWorkerStorageContract _workerStorage
|
||||
|
||||
logger.LogInformation("Inserting new worker: {workerId}", workerDataModel.Id);
|
||||
|
||||
if (!Guid.TryParse(workerDataModel.Id, out _))
|
||||
throw new ValidationException("Worker ID is not a valid GUID.");
|
||||
workerDataModel.Validate(_localizer);
|
||||
|
||||
try
|
||||
{
|
||||
@@ -105,7 +103,7 @@ internal class WorkerBusinessLogicContract(IWorkerStorageContract _workerStorage
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, "Unhandled exception");
|
||||
throw new StorageException(ex);
|
||||
throw new StorageException(ex, _localizer);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -118,8 +116,7 @@ internal class WorkerBusinessLogicContract(IWorkerStorageContract _workerStorage
|
||||
|
||||
logger.LogInformation("Updating worker: {workerId}", workerDataModel.Id);
|
||||
|
||||
if (!Guid.TryParse(workerDataModel.Id, out _))
|
||||
throw new ValidationException("Worker ID is not a valid GUID.");
|
||||
workerDataModel.Validate(_localizer);
|
||||
|
||||
try
|
||||
{
|
||||
@@ -146,7 +143,7 @@ internal class WorkerBusinessLogicContract(IWorkerStorageContract _workerStorage
|
||||
throw new ArgumentNullException(nameof(id));
|
||||
|
||||
if (!Guid.TryParse(id, out _))
|
||||
throw new ValidationException("Worker ID is not a valid GUID.");
|
||||
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageNotAId"], "id"));
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
@@ -1,27 +1,25 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using TwoFromTheCasketContracts.BusinessLogicsContracts;
|
||||
using TwoFromTheCasketContracts.DataModels;
|
||||
using TwoFromTheCasketContracts.Exceptions;
|
||||
using TwoFromTheCasketContracts.Resources;
|
||||
using TwoFromTheCasketContracts.StorageContracts;
|
||||
|
||||
namespace TwoFromTheCasketBusinessLogic.Implementation;
|
||||
|
||||
internal class WorkerComplitedWorkBusinessLogicContract(IWorkerComplitedWorkStorageContract _complitedWorkStorageContract,
|
||||
ILogger _logger) : IWorkerComplitedWorkBusinessLogicContract
|
||||
ILogger _logger, IStringLocalizer<Messages> localizer) : IWorkerComplitedWorkBusinessLogicContract
|
||||
{
|
||||
private IWorkerComplitedWorkStorageContract complitedWorkStorageContract = _complitedWorkStorageContract;
|
||||
private ILogger logger = _logger;
|
||||
private readonly IStringLocalizer<Messages> _localizer = localizer;
|
||||
|
||||
public List<WorkerComplitedWorkDataModel> GetAllWorkerComplitedWorks()
|
||||
{
|
||||
logger.LogInformation("Fetching all worker completed works.");
|
||||
|
||||
var result = complitedWorkStorageContract.GetList();
|
||||
if (result is null)
|
||||
{
|
||||
logger.LogError("No worker completed works found.");
|
||||
throw new NullListException();
|
||||
}
|
||||
|
||||
logger.LogInformation("Fetched {Count} worker completed works.", result.Count);
|
||||
return result;
|
||||
@@ -40,15 +38,10 @@ internal class WorkerComplitedWorkBusinessLogicContract(IWorkerComplitedWorkStor
|
||||
if (!Guid.TryParse(workId, out _))
|
||||
{
|
||||
logger.LogError("Invalid work ID format: {workId}", workId);
|
||||
throw new ValidationException("Invalid work ID format.");
|
||||
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageNotAId"], "workId"));
|
||||
}
|
||||
|
||||
var result = complitedWorkStorageContract.GetList(complitedWorkId: workId);
|
||||
if (result is null)
|
||||
{
|
||||
logger.LogError("No completed works found for work ID: {workId}", workId);
|
||||
throw new NullListException();
|
||||
}
|
||||
|
||||
logger.LogInformation("Fetched {Count} worker completed works for workId: {workId}", result.Count, workId);
|
||||
return result;
|
||||
@@ -66,15 +59,10 @@ internal class WorkerComplitedWorkBusinessLogicContract(IWorkerComplitedWorkStor
|
||||
if (!Guid.TryParse(workerId, out _))
|
||||
{
|
||||
logger.LogError("Invalid worker ID format: {workerId}", workerId);
|
||||
throw new ValidationException("Invalid worker ID format.");
|
||||
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageNotAId"], "workerId"));
|
||||
}
|
||||
|
||||
var result = complitedWorkStorageContract.GetList(workerId: workerId);
|
||||
if (result is null)
|
||||
{
|
||||
logger.LogError("No completed works found for worker ID: {workerId}", workerId);
|
||||
throw new NullListException();
|
||||
}
|
||||
|
||||
logger.LogInformation("Fetched {Count} worker completed works for workerId: {workerId}", result.Count, workerId);
|
||||
return result;
|
||||
@@ -90,14 +78,7 @@ internal class WorkerComplitedWorkBusinessLogicContract(IWorkerComplitedWorkStor
|
||||
throw new ArgumentNullException(nameof(workerComplitedWork));
|
||||
}
|
||||
|
||||
if (!Guid.TryParse(workerComplitedWork.WorkerId, out _))
|
||||
throw new ValidationException("Invalid worker ID format.");
|
||||
|
||||
if (!Guid.TryParse(workerComplitedWork.ComplitedWorkId, out _))
|
||||
throw new ValidationException("Invalid completed work ID format.");
|
||||
|
||||
if (workerComplitedWork.NumberOfWorkingHours <= 0)
|
||||
throw new ValidationException("Number of working hours must be greater than zero.");
|
||||
workerComplitedWork.Validate(_localizer);
|
||||
|
||||
complitedWorkStorageContract.AddElement(workerComplitedWork);
|
||||
_logger.LogInformation("Worker completed work inserted successfully: {workerComplitedWork}", workerComplitedWork);
|
||||
@@ -113,14 +94,7 @@ internal class WorkerComplitedWorkBusinessLogicContract(IWorkerComplitedWorkStor
|
||||
throw new ArgumentNullException(nameof(workerComplitedWork));
|
||||
}
|
||||
|
||||
if (!Guid.TryParse(workerComplitedWork.WorkerId, out _))
|
||||
throw new ValidationException("Invalid worker ID format.");
|
||||
|
||||
if (!Guid.TryParse(workerComplitedWork.ComplitedWorkId, out _))
|
||||
throw new ValidationException("Invalid completed work ID format.");
|
||||
|
||||
if (workerComplitedWork.NumberOfWorkingHours <= 0)
|
||||
throw new ValidationException("Number of working hours must be greater than zero.");
|
||||
workerComplitedWork.Validate(_localizer);
|
||||
|
||||
complitedWorkStorageContract.UpdElement(workerComplitedWork);
|
||||
logger.LogInformation("Worker completed work updated successfully: {workerComplitedWork}", workerComplitedWork);
|
||||
@@ -139,7 +113,7 @@ internal class WorkerComplitedWorkBusinessLogicContract(IWorkerComplitedWorkStor
|
||||
if (!Guid.TryParse(workerComplitedWorkId, out _))
|
||||
{
|
||||
logger.LogError("Invalid worker completed work ID format: {workerComplitedWorkId}", workerComplitedWorkId);
|
||||
throw new ValidationException("Invalid worker completed work ID format.");
|
||||
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageNotAId"], "workerComplitedWorkId"));
|
||||
}
|
||||
|
||||
complitedWorkStorageContract.DelElement(workerComplitedWorkId);
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
<PackageReference Include="PDFsharp-MigraDoc" Version="6.1.1" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\TwoFromTheCasketContracts\TwoFromTheCasketContracts.csproj" />
|
||||
<InternalsVisibleTo Include="TwoFromTheCasketTests" />
|
||||
<InternalsVisibleTo Include="TwoFromTheCasketWebApi" />
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using TwoFromTheCasketContracts.DataModels;
|
||||
namespace TwoFromTheCasketContracts.BusinessLogicsContracts;
|
||||
public interface IComplitedWorkBusinessLogicContract
|
||||
internal interface IComplitedWorkBusinessLogicContract
|
||||
{
|
||||
List<ComplitedWorkDataModel> GetComplitedWorksByPeriod(DateTime fromDate, DateTime toDate);
|
||||
List<ComplitedWorkDataModel> GetComplitedWorksByRoomByPeriod(string roomId, DateTime fromDate, DateTime toDate);
|
||||
|
||||
@@ -5,7 +5,7 @@ using TwoFromTheCasketContracts.ViewModels;
|
||||
|
||||
namespace TwoFromTheCasketContracts.BusinessLogicsContracts;
|
||||
|
||||
public interface IReportContract
|
||||
internal interface IReportContract
|
||||
{
|
||||
Task<List<RoomWithHistoryDataModel>> GetRoomHistoryGroupedAsync(CancellationToken ct);
|
||||
Task<List<ComplitedWorkReportViewModel>> GetComplitedWorksByPeriodAsync(DateTime from, DateTime to, CancellationToken ct);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using TwoFromTheCasketContracts.DataModels;
|
||||
namespace TwoFromTheCasketContracts.BusinessLogicsContracts;
|
||||
public interface IRoomBusinessLogicContract
|
||||
internal interface IRoomBusinessLogicContract
|
||||
{
|
||||
List<RoomDataModel> GetAllRooms();
|
||||
List<RoomDataModel> GetRoomsByOwner(string ownerName);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using TwoFromTheCasketContracts.DataModels;
|
||||
namespace TwoFromTheCasketContracts.BusinessLogicsContracts;
|
||||
public interface IRoomHistoryBusinessLogicContract
|
||||
internal interface IRoomHistoryBusinessLogicContract
|
||||
{
|
||||
List<RoomHistoryDataModel> GetRoomHistory(string roomId);
|
||||
RoomHistoryDataModel GetLatestRoomHistory(string roomId);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using TwoFromTheCasketContracts.DataModels;
|
||||
namespace TwoFromTheCasketContracts.BusinessLogicsContracts;
|
||||
public interface ISalaryBusinessLogicContract
|
||||
internal interface ISalaryBusinessLogicContract
|
||||
{
|
||||
List<SalaryDataModel> GetSalariesByPeriod(DateTime fromDate, DateTime toDate);
|
||||
List<SalaryDataModel> GetSalariesByWorkerByPeriod(string workerId, DateTime fromDate, DateTime toDate);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using TwoFromTheCasketContracts.DataModels;
|
||||
namespace TwoFromTheCasketContracts.BusinessLogicsContracts;
|
||||
public interface ISpecializationBusinessLogicContract
|
||||
internal interface ISpecializationBusinessLogicContract
|
||||
{
|
||||
List<SpecializationDataModel> GetAllSpecializations(bool onlyActual = true);
|
||||
SpecializationDataModel GetLatestSpecializationById(string specializationId);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using TwoFromTheCasketContracts.DataModels;
|
||||
namespace TwoFromTheCasketContracts.BusinessLogicsContracts;
|
||||
public interface IWorkBusinessLogicContract
|
||||
internal interface IWorkBusinessLogicContract
|
||||
{
|
||||
List<WorkDataModel> GetAllWorks();
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using TwoFromTheCasketContracts.DataModels;
|
||||
|
||||
namespace TwoFromTheCasketContracts.BusinessLogicsContracts;
|
||||
public interface IWorkerBusinessLogicContract
|
||||
internal interface IWorkerBusinessLogicContract
|
||||
{
|
||||
List<WorkerDataModel> GetAllWorkers(bool onlyActive = true);
|
||||
List<WorkerDataModel> GetWorkersBySpecialization(string specializationId, bool onlyActive = true);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using TwoFromTheCasketContracts.DataModels;
|
||||
namespace TwoFromTheCasketContracts.BusinessLogicsContracts;
|
||||
public interface IWorkerComplitedWorkBusinessLogicContract
|
||||
internal interface IWorkerComplitedWorkBusinessLogicContract
|
||||
{
|
||||
List<WorkerComplitedWorkDataModel> GetWorkerComplitedWorksByWorker(string workerId);
|
||||
List<WorkerComplitedWorkDataModel> GetWorkerComplitedWorksByWork(string workId);
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
using TwoFromTheCasketContracts.Extensions;
|
||||
using TwoFromTheCasketContracts.Exceptions;
|
||||
using TwoFromTheCasketContracts.Infastructure;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using TwoFromTheCasketContracts.Resources;
|
||||
namespace TwoFromTheCasketContracts.DataModels;
|
||||
|
||||
public class ComplitedWorkDataModel(string id, string workId, string roomId, List<WorkerComplitedWorkDataModel> workers ) :IValidation
|
||||
internal class ComplitedWorkDataModel(string id, string workId, string roomId, List<WorkerComplitedWorkDataModel> workers ) :IValidation
|
||||
{
|
||||
public string Id { get; private set; } = id;
|
||||
public string WorkId { get; private set; } = workId;
|
||||
@@ -12,22 +14,22 @@ public class ComplitedWorkDataModel(string id, string workId, string roomId, Lis
|
||||
public List<WorkerComplitedWorkDataModel> Workers { get; private set; } = workers;
|
||||
|
||||
|
||||
public void Validate()
|
||||
public void Validate(IStringLocalizer<Messages> localizer)
|
||||
{
|
||||
if (Id.IsEmpty())
|
||||
throw new ValidationException("Field Id is empty");
|
||||
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageEmptyField"], "Id"));
|
||||
if (!Id.IsGuid())
|
||||
throw new ValidationException("The value in the field Id is not a unique identifier");
|
||||
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageNotAId"], "Id"));
|
||||
if (WorkId.IsEmpty())
|
||||
throw new ValidationException("Field WorkId is empty");
|
||||
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageEmptyField"], "WorkId"));
|
||||
if (!WorkId.IsGuid())
|
||||
throw new ValidationException("The value in the field WorkId is not a unique identifier");
|
||||
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageNotAId"], "WorkId"));
|
||||
if (RoomId.IsEmpty())
|
||||
throw new ValidationException("Field RoomId is empty");
|
||||
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageEmptyField"], "RoomId"));
|
||||
if (!RoomId.IsGuid())
|
||||
throw new ValidationException("The value in the field RoomId is not a unique identifier");
|
||||
if((Workers?.Count ?? 0) == 0)
|
||||
throw new ValidationException("The value in the Workers must include workers");
|
||||
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageNotAId"], "RoomId"));
|
||||
if ((Workers?.Count ?? 0) == 0)
|
||||
throw new ValidationException(localizer["ValidationExceptionMessageNoWorkerInComplitedWorks"]);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
using System.Text.RegularExpressions;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using System.Text.RegularExpressions;
|
||||
using TwoFromTheCasketContracts.Enums;
|
||||
using TwoFromTheCasketContracts.Exceptions;
|
||||
using TwoFromTheCasketContracts.Extensions;
|
||||
using TwoFromTheCasketContracts.Infastructure;
|
||||
using TwoFromTheCasketContracts.Resources;
|
||||
|
||||
namespace TwoFromTheCasketContracts.DataModels;
|
||||
|
||||
public class RoomDataModel(string id, string ownerFIO, string address, double space, TypeRoom type) : IValidation
|
||||
internal class RoomDataModel(string id, string ownerFIO, string address, double space, TypeRoom type) : IValidation
|
||||
{
|
||||
public string Id { get; private set; } = id;
|
||||
public string OwnerFIO { get; private set; } = ownerFIO;
|
||||
@@ -14,21 +16,21 @@ public class RoomDataModel(string id, string ownerFIO, string address, double sp
|
||||
public double Space { get; private set; } = space;
|
||||
public TypeRoom Type { get; private set; } = type;
|
||||
|
||||
public void Validate()
|
||||
public void Validate(IStringLocalizer<Messages> localizer)
|
||||
{
|
||||
if(Id.IsEmpty())
|
||||
throw new ValidationException("Field Id is empty");
|
||||
if (Id.IsEmpty())
|
||||
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageEmptyField"], "Id"));
|
||||
if (!Id.IsGuid())
|
||||
throw new ValidationException("The value in the field Id is not a unique identifier");
|
||||
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageNotAId"], "Id"));
|
||||
if (OwnerFIO.IsEmpty())
|
||||
throw new ValidationException("Field OwnerFIO is empty");
|
||||
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageEmptyField"], "OwnerFIO"));
|
||||
if (Address.IsEmpty())
|
||||
throw new ValidationException("Field Address is empty");
|
||||
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageEmptyField"], "Address"));
|
||||
if (!Regex.IsMatch(Address, @"^([А-ЯЁа-яё0-9\s.,-]+),\s?д\.\s?\d+(,\s?кв\.\s?\d+)?$"))
|
||||
throw new ValidationException("Field Address is not address");
|
||||
throw new ValidationException(localizer["ValidationExceptionMessageInvalidAddress"]);
|
||||
if (Space <= 0)
|
||||
throw new ValidationException("Field Space is empty");
|
||||
if(Type == TypeRoom.None)
|
||||
throw new ValidationException("Field Type is empty");
|
||||
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageInvalidRange"], "Space"));
|
||||
if (Type == TypeRoom.None)
|
||||
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageEmptyField"], "Type"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
using TwoFromTheCasketContracts.Enums;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using TwoFromTheCasketContracts.Enums;
|
||||
using TwoFromTheCasketContracts.Exceptions;
|
||||
using TwoFromTheCasketContracts.Extensions;
|
||||
using TwoFromTheCasketContracts.Infastructure;
|
||||
using TwoFromTheCasketContracts.Resources;
|
||||
|
||||
namespace TwoFromTheCasketContracts.DataModels;
|
||||
|
||||
public class RoomHistoryDataModel : IValidation
|
||||
internal class RoomHistoryDataModel : IValidation
|
||||
{
|
||||
public string RoomId { get; private set; }
|
||||
public string OwnerFIO { get; private set; }
|
||||
@@ -18,18 +20,18 @@ public class RoomHistoryDataModel : IValidation
|
||||
RoomId = roomId;
|
||||
OwnerFIO = ownerFIO;
|
||||
Type = type;
|
||||
DateChange = dateChange;
|
||||
DateChange = dateChange.ToUniversalTime();
|
||||
}
|
||||
|
||||
public void Validate()
|
||||
public void Validate(IStringLocalizer<Messages> localizer)
|
||||
{
|
||||
if (RoomId.IsEmpty())
|
||||
throw new ValidationException("Field RoomId is empty");
|
||||
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageEmptyField"], "RoomId"));
|
||||
if (!RoomId.IsGuid())
|
||||
throw new ValidationException("The value in the field RoomId is not a unique identifier");
|
||||
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageNotAId"], "RoomId"));
|
||||
if (OwnerFIO.IsEmpty())
|
||||
throw new ValidationException("Field OwnerFIO is empty");
|
||||
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageEmptyField"], "OwnerFIO"));
|
||||
if (Type == TypeRoom.None)
|
||||
throw new ValidationException("Field Type is empty");
|
||||
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageEmptyField"], "Type"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
namespace TwoFromTheCasketContracts.DataModels;
|
||||
|
||||
public class RoomWithHistoryDataModel
|
||||
internal class RoomWithHistoryDataModel
|
||||
{
|
||||
public RoomDataModel Room { get; set; }
|
||||
public List<RoomHistoryDataModel> History { get; set; }
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
using TwoFromTheCasketContracts.Extensions;
|
||||
using TwoFromTheCasketContracts.Exceptions;
|
||||
using TwoFromTheCasketContracts.Infastructure;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using TwoFromTheCasketContracts.Resources;
|
||||
|
||||
namespace TwoFromTheCasketContracts.DataModels;
|
||||
|
||||
public class SalaryDataModel(string id, string workerId, double sum, WorkDataModel? emploee = null) : IValidation
|
||||
internal class SalaryDataModel(string id, string workerId, double sum, WorkDataModel? emploee = null) : IValidation
|
||||
{
|
||||
public string Id { get; private set; } = id;
|
||||
public string WorkerId { get; private set; } = workerId;
|
||||
@@ -12,18 +14,18 @@ public class SalaryDataModel(string id, string workerId, double sum, WorkDataMod
|
||||
public WorkDataModel Emploee { get; private set; } = emploee;
|
||||
public DateTime Date { get; private set; } = DateTime.UtcNow;
|
||||
|
||||
public void Validate()
|
||||
public void Validate(IStringLocalizer<Messages> localizer)
|
||||
{
|
||||
if (Id.IsEmpty())
|
||||
throw new ValidationException("Field Id is empty");
|
||||
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageEmptyField"], "Id"));
|
||||
if (!Id.IsGuid())
|
||||
throw new ValidationException("The value in the field Id is not a unique identifier");
|
||||
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageNotAId"], "Id"));
|
||||
if (WorkerId.IsEmpty())
|
||||
throw new ValidationException("Field WorkerId is empty");
|
||||
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageEmptyField"], "WorkerId"));
|
||||
if (!WorkerId.IsGuid())
|
||||
throw new ValidationException("The value in the field WorkerId is not a unique identifier");
|
||||
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageNotAId"], "WorkerId"));
|
||||
if (Sum <= 0)
|
||||
throw new ValidationException("Field Sum is empty");
|
||||
|
||||
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageInvalidRange"], "Sum"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,27 +1,30 @@
|
||||
using TwoFromTheCasketContracts.Extensions;
|
||||
using TwoFromTheCasketContracts.Exceptions;
|
||||
using TwoFromTheCasketContracts.Infastructure;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using TwoFromTheCasketContracts.Resources;
|
||||
|
||||
namespace TwoFromTheCasketContracts.DataModels;
|
||||
|
||||
public class SpecializationDataModel(string id, string specializationName, double salary,
|
||||
internal class SpecializationDataModel(string id, string specializationName, double salary,
|
||||
bool isActual, DateTime changeDate) : IValidation
|
||||
{
|
||||
public string Id { get; private set; } = id;
|
||||
public string SpecializationName { get; private set; } = specializationName;
|
||||
public double Salary { get; private set; } = salary;
|
||||
public bool IsActual { get; private set; } = isActual;
|
||||
public DateTime ChangeDate { get; private set; } = changeDate;
|
||||
public void Validate()
|
||||
public DateTime ChangeDate { get; private set; } = changeDate.ToUniversalTime();
|
||||
public void Validate(IStringLocalizer<Messages> localizer)
|
||||
{
|
||||
if (Id.IsEmpty())
|
||||
throw new ValidationException("Field Id is empty");
|
||||
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageEmptyField"], "Id"));
|
||||
if (!Id.IsGuid())
|
||||
throw new ValidationException("The value in the field Id is not a unique identifier");
|
||||
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageNotAId"], "Id"));
|
||||
if (SpecializationName.IsEmpty())
|
||||
throw new ValidationException("Field SpecializationName is empty");
|
||||
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageEmptyField"], "SpecializationName"));
|
||||
if (Salary <= 0)
|
||||
throw new ValidationException("Field Salary is empty");
|
||||
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageInvalidRange"], "Salary"));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,30 +1,31 @@
|
||||
using TwoFromTheCasketContracts.Enums;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using TwoFromTheCasketContracts.Enums;
|
||||
using TwoFromTheCasketContracts.Exceptions;
|
||||
using TwoFromTheCasketContracts.Extensions;
|
||||
using TwoFromTheCasketContracts.Infastructure;
|
||||
using TwoFromTheCasketContracts.Resources;
|
||||
|
||||
namespace TwoFromTheCasketContracts.DataModels;
|
||||
|
||||
public class WorkDataModel(string id, TypeWork type, string description, DateTime date) : IValidation
|
||||
internal class WorkDataModel(string id, TypeWork type, string description, DateTime date) : IValidation
|
||||
{
|
||||
public string Id { get; private set; } = id;
|
||||
public TypeWork Type { get; private set; } = type;
|
||||
public string Description { get; private set; } = description;
|
||||
public DateTime Date { get; private set; } = date;
|
||||
public DateTime Date { get; private set; } = date.ToUniversalTime();
|
||||
|
||||
public void Validate()
|
||||
public void Validate(IStringLocalizer<Messages> localizer)
|
||||
{
|
||||
if (Id.IsEmpty())
|
||||
throw new ValidationException("Field Id is empty");
|
||||
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageEmptyField"], "Id"));
|
||||
if (!Id.IsGuid())
|
||||
throw new ValidationException("The value in the field Id is not a unique identifier");
|
||||
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageNotAId"], "Id"));
|
||||
if (Type == TypeWork.None)
|
||||
throw new ValidationException("Field Type is empty");
|
||||
if(Description.IsEmpty())
|
||||
throw new ValidationException("Field Description is empty");
|
||||
if (Date < DateTime.Now)
|
||||
throw new ValidationException("Field Date is earlier than today");
|
||||
|
||||
|
||||
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageEmptyField"], "Type"));
|
||||
if (Description.IsEmpty())
|
||||
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageEmptyField"], "Description"));
|
||||
if (Date < DateTime.UtcNow)
|
||||
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageDateInPast"], "Date"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,27 +1,30 @@
|
||||
using TwoFromTheCasketContracts.Exceptions;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using TwoFromTheCasketContracts.Exceptions;
|
||||
using TwoFromTheCasketContracts.Extensions;
|
||||
using TwoFromTheCasketContracts.Infastructure;
|
||||
using TwoFromTheCasketContracts.Resources;
|
||||
|
||||
namespace TwoFromTheCasketContracts.DataModels;
|
||||
|
||||
public class WorkerComplitedWorkDataModel(string workerId, string complitedWorkId, double numberOfWorkingHours) : IValidation
|
||||
internal class WorkerComplitedWorkDataModel(string workerId, string complitedWorkId, double numberOfWorkingHours) : IValidation
|
||||
{
|
||||
public string WorkerId { get; private set; } = workerId;
|
||||
public string ComplitedWorkId { get; private set; } = complitedWorkId;
|
||||
|
||||
public double NumberOfWorkingHours { get; private set; } = numberOfWorkingHours;
|
||||
|
||||
public void Validate()
|
||||
public void Validate(IStringLocalizer<Messages> localizer)
|
||||
{
|
||||
if (WorkerId.IsEmpty())
|
||||
throw new ValidationException("Field WorkerId is empty");
|
||||
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageEmptyField"], "WorkerId"));
|
||||
if (!WorkerId.IsGuid())
|
||||
throw new ValidationException("The value in the field WorkerId is not a unique identifier");
|
||||
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageNotAId"], "WorkerId"));
|
||||
if (ComplitedWorkId.IsEmpty())
|
||||
throw new ValidationException("Field ComplitedWorkId is empty");
|
||||
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageEmptyField"], "ComplitedWorkId"));
|
||||
if (!ComplitedWorkId.IsGuid())
|
||||
throw new ValidationException("The value in the field ComplitedWorkId is not a unique identifier");
|
||||
if(NumberOfWorkingHours <= 0)
|
||||
throw new ValidationException("Field NumberOfWorkingHours is empty");
|
||||
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageNotAId"], "ComplitedWorkId"));
|
||||
if (NumberOfWorkingHours <= 0)
|
||||
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageInvalidRange"], "NumberOfWorkingHours"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -5,17 +5,19 @@ using System.Text.RegularExpressions;
|
||||
using TwoFromTheCasketContracts.Infastructure.SalaryConfiguration;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Newtonsoft.Json;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using TwoFromTheCasketContracts.Resources;
|
||||
|
||||
namespace TwoFromTheCasketContracts.DataModels;
|
||||
|
||||
public class WorkerDataModel(string id, string fio, string specializationId, string phoneNumber, DateTime dateBirthday, SalaryConfiguration configuration, SpecializationDataModel? _specializationDataModel = null) : IValidation
|
||||
internal class WorkerDataModel(string id, string fio, string specializationId, string phoneNumber, DateTime dateBirthday, SalaryConfiguration configuration, SpecializationDataModel? _specializationDataModel = null) : IValidation
|
||||
{
|
||||
public string Id { get; private set; } = id;
|
||||
public string FIO { get; private set; } = fio;
|
||||
public string SpecializationId { get; private set; } = specializationId;
|
||||
public SalaryConfiguration ConfigurationModel { get; private set; } = configuration;
|
||||
public string PhoneNumber { get; private set; } = phoneNumber;
|
||||
public DateTime DateBirthDay { get; private set; } = dateBirthday;
|
||||
public DateTime DateBirthDay { get; private set; } = dateBirthday.ToUniversalTime();
|
||||
public DateTime ValidFrom { get; private set; } = DateTime.UtcNow;
|
||||
public SpecializationDataModel? SpecializationDataModel { get; private set; } = _specializationDataModel;
|
||||
public bool IsCurrent { get; private set; } = true;
|
||||
@@ -35,28 +37,28 @@ public class WorkerDataModel(string id, string fio, string specializationId, str
|
||||
}
|
||||
}
|
||||
|
||||
public void Validate()
|
||||
public void Validate(IStringLocalizer<Messages> localizer)
|
||||
{
|
||||
if (Id.IsEmpty())
|
||||
throw new ValidationException("Field Id is empty");
|
||||
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageEmptyField"], "Id"));
|
||||
if (!Id.IsGuid())
|
||||
throw new ValidationException("The value in the field Id is not a unique identifier");
|
||||
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageNotAId"], "Id"));
|
||||
if (FIO.IsEmpty())
|
||||
throw new ValidationException("Field FIO is empty");
|
||||
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageEmptyField"], "FIO"));
|
||||
if (SpecializationId.IsEmpty())
|
||||
throw new ValidationException("Field SpecializationId is empty");
|
||||
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageEmptyField"], "SpecializationId"));
|
||||
if (!SpecializationId.IsGuid())
|
||||
throw new ValidationException("The value in the field SpecializationId is not a unique identifier");
|
||||
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageNotAId"], "SpecializationId"));
|
||||
if (PhoneNumber.IsEmpty())
|
||||
throw new ValidationException("Field PhoneNumber is empty");
|
||||
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageEmptyField"], "PhoneNumber"));
|
||||
if (!Regex.IsMatch(PhoneNumber, @"^((8|\+7)[\- ]?)?(\(?\d{3}\)?[\-]?)?[\d\- ]{7,10}$"))
|
||||
throw new ValidationException("Field PhoneNumber is not a phone number");
|
||||
if (DateBirthDay.Date > DateTime.Now.AddYears(-16).Date)
|
||||
throw new ValidationException($"Minors cannot be hired (DateBirthDay = { DateBirthDay.ToShortDateString() })");
|
||||
throw new ValidationException(localizer["ValidationExceptionMessageInvalidPhoneNumber"]);
|
||||
if (DateBirthDay.Date > DateTime.UtcNow.AddYears(-16).Date)
|
||||
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageTooYoung"], DateBirthDay.ToShortDateString()));
|
||||
if (ConfigurationModel is null)
|
||||
throw new ValidationException($"Field Configuration is not initialized");
|
||||
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageEmptyField"], "Configuration"));
|
||||
if (ConfigurationModel!.Rate <= 0)
|
||||
throw new ValidationException("Field Sum is less or equal zero");
|
||||
|
||||
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageInvalidRange"], "Configuration.Rate"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
|
||||
using Microsoft.Extensions.Localization;
|
||||
using TwoFromTheCasketContracts.Resources;
|
||||
|
||||
namespace TwoFromTheCasketContracts.Exceptions;
|
||||
|
||||
public class ElementDeletedException : Exception
|
||||
internal class ElementDeletedException : Exception
|
||||
{
|
||||
public ElementDeletedException(string id) : base($"Cannot modify a deleted item (id: {id})") { }
|
||||
public ElementDeletedException(string id, IStringLocalizer<Messages> localizer) : base(string.Format(localizer["ElementDeletedExceptionCaption"], id)) { }
|
||||
}
|
||||
|
||||
@@ -1,14 +1,17 @@
|
||||
namespace TwoFromTheCasketContracts.Exceptions;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using TwoFromTheCasketContracts.Resources;
|
||||
|
||||
public class ElementExistsException : Exception
|
||||
namespace TwoFromTheCasketContracts.Exceptions;
|
||||
|
||||
internal class ElementExistsException : Exception
|
||||
{
|
||||
public string ParamName { get; private set; }
|
||||
public string ParamName { get; private set; }
|
||||
public string ParamValue { 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;
|
||||
}
|
||||
public ElementExistsException(string paramName, string paramValue, IStringLocalizer<Messages> localizer)
|
||||
: base(string.Format(localizer["ElementExistsExceptionCaption"], paramName, paramValue))
|
||||
{
|
||||
ParamName = paramName;
|
||||
ParamValue = paramValue;
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,15 @@
|
||||
namespace TwoFromTheCasketContracts.Exceptions;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using TwoFromTheCasketContracts.Resources;
|
||||
|
||||
public class ElementNotFoundException : Exception
|
||||
namespace TwoFromTheCasketContracts.Exceptions;
|
||||
|
||||
internal class ElementNotFoundException : Exception
|
||||
{
|
||||
public string Value { get; private set; }
|
||||
|
||||
public ElementNotFoundException(string value) : base($"Element not found at value = {value}")
|
||||
{
|
||||
Value = value;
|
||||
}
|
||||
public ElementNotFoundException(string value, IStringLocalizer<Messages> localizer)
|
||||
: base(string.Format(localizer["ElementNotFoundExceptionCaption"], value))
|
||||
{
|
||||
Value = value;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,10 @@
|
||||
namespace TwoFromTheCasketContracts.Exceptions;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using TwoFromTheCasketContracts.Resources;
|
||||
|
||||
public class IncorrectDatesException : Exception
|
||||
namespace TwoFromTheCasketContracts.Exceptions;
|
||||
|
||||
internal 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}") { }
|
||||
public IncorrectDatesException(DateTime start, DateTime end, IStringLocalizer<Messages> localizer)
|
||||
: base(string.Format(localizer["IncorrectDatesExceptionCaption"], start, end)) { }
|
||||
}
|
||||
@@ -1,6 +1,10 @@
|
||||
namespace TwoFromTheCasketContracts.Exceptions;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using TwoFromTheCasketContracts.Resources;
|
||||
|
||||
public class NullListException : Exception
|
||||
namespace TwoFromTheCasketContracts.Exceptions;
|
||||
|
||||
internal class NullListException : Exception
|
||||
{
|
||||
public NullListException() : base("The returned list is null") { }
|
||||
public NullListException(IStringLocalizer<Messages> localizer)
|
||||
: base(localizer["NullListExceptionCaption"]) { }
|
||||
}
|
||||
@@ -1,6 +1,10 @@
|
||||
namespace TwoFromTheCasketContracts.Exceptions;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using TwoFromTheCasketContracts.Resources;
|
||||
|
||||
public class StorageException : Exception
|
||||
namespace TwoFromTheCasketContracts.Exceptions;
|
||||
|
||||
internal class StorageException : Exception
|
||||
{
|
||||
public StorageException(Exception ex) : base($"Error while working in storage: {ex.Message}", ex) { }
|
||||
public StorageException(Exception ex, IStringLocalizer<Messages> localizer)
|
||||
: base(string.Format(localizer["StorageExceptionCaption"], ex.Message), ex) { }
|
||||
}
|
||||
@@ -1,6 +1,9 @@
|
||||
namespace TwoFromTheCasketContracts.Infastructure;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using TwoFromTheCasketContracts.Resources;
|
||||
|
||||
public interface IValidation
|
||||
namespace TwoFromTheCasketContracts.Infastructure;
|
||||
|
||||
internal interface IValidation
|
||||
{
|
||||
void Validate();
|
||||
void Validate(IStringLocalizer<Messages> localizer);
|
||||
}
|
||||
|
||||
@@ -7,5 +7,5 @@ public class SalaryConfiguration
|
||||
public virtual string Type => nameof(SalaryConfiguration);
|
||||
public double Rate { get; set; }
|
||||
|
||||
public string CultureNAme { get; set; } = CultureInfo.CurrentCulture.Name;
|
||||
public string CultureName { get; set; } = CultureInfo.CurrentCulture.Name;
|
||||
}
|
||||
|
||||
333
TwoFromTheCasketContracts/TwoFromTheCasketContracts/Resources/Messages.Designer.cs
generated
Normal file
333
TwoFromTheCasketContracts/TwoFromTheCasketContracts/Resources/Messages.Designer.cs
generated
Normal file
@@ -0,0 +1,333 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// Этот код создан программой.
|
||||
// Исполняемая версия:4.0.30319.42000
|
||||
//
|
||||
// Изменения в этом файле могут привести к неправильной работе и будут потеряны в случае
|
||||
// повторной генерации кода.
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace TwoFromTheCasketContracts.Resources {
|
||||
using System;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Класс ресурса со строгой типизацией для поиска локализованных строк и т.д.
|
||||
/// </summary>
|
||||
// Этот класс создан автоматически классом StronglyTypedResourceBuilder
|
||||
// с помощью такого средства, как ResGen или Visual Studio.
|
||||
// Чтобы добавить или удалить член, измените файл .ResX и снова запустите ResGen
|
||||
// с параметром /str или перестройте свой проект VS.
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||
internal class Messages {
|
||||
|
||||
private static global::System.Resources.ResourceManager resourceMan;
|
||||
|
||||
private static global::System.Globalization.CultureInfo resourceCulture;
|
||||
|
||||
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
|
||||
internal Messages() {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Возвращает кэшированный экземпляр ResourceManager, использованный этим классом.
|
||||
/// </summary>
|
||||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||
internal static global::System.Resources.ResourceManager ResourceManager {
|
||||
get {
|
||||
if (object.ReferenceEquals(resourceMan, null)) {
|
||||
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("TwoFromTheCasketContracts.Resources.Messages", typeof(Messages).Assembly);
|
||||
resourceMan = temp;
|
||||
}
|
||||
return resourceMan;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Перезаписывает свойство CurrentUICulture текущего потока для всех
|
||||
/// обращений к ресурсу с помощью этого класса ресурса со строгой типизацией.
|
||||
/// </summary>
|
||||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||
internal static global::System.Globalization.CultureInfo Culture {
|
||||
get {
|
||||
return resourceCulture;
|
||||
}
|
||||
set {
|
||||
resourceCulture = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ищет локализованную строку, похожую на Параметр не должен быть пустым.
|
||||
/// </summary>
|
||||
internal static string AdapterMessageArgumentNullException {
|
||||
get {
|
||||
return ResourceManager.GetString("AdapterMessageArgumentNullException", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ищет локализованную строку, похожую на Элемент с параметром {0} и значением {1} уже существует.
|
||||
/// </summary>
|
||||
internal static string AdapterMessageElementExists {
|
||||
get {
|
||||
return ResourceManager.GetString("AdapterMessageElementExists", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ищет локализованную строку, похожую на Элемент со значением {0} не найден.
|
||||
/// </summary>
|
||||
internal static string AdapterMessageElementNotFound {
|
||||
get {
|
||||
return ResourceManager.GetString("AdapterMessageElementNotFound", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ищет локализованную строку, похожую на Некорректные даты: {0}.
|
||||
/// </summary>
|
||||
internal static string AdapterMessageIncorrectDates {
|
||||
get {
|
||||
return ResourceManager.GetString("AdapterMessageIncorrectDates", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ищет локализованную строку, похожую на Ошибка при выполнении операции: {0}.
|
||||
/// </summary>
|
||||
internal static string AdapterMessageInvalidOperationException {
|
||||
get {
|
||||
return ResourceManager.GetString("AdapterMessageInvalidOperationException", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ищет локализованную строку, похожую на Не найдено помещений по указанному адресу.
|
||||
/// </summary>
|
||||
internal static string AdapterMessageNoRoomsForAddress {
|
||||
get {
|
||||
return ResourceManager.GetString("AdapterMessageNoRoomsForAddress", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ищет локализованную строку, похожую на Данные о зарплате не найдены.
|
||||
/// </summary>
|
||||
internal static string AdapterMessageSalaryDataNotFound {
|
||||
get {
|
||||
return ResourceManager.GetString("AdapterMessageSalaryDataNotFound", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ищет локализованную строку, похожую на Ошибка при работе с хранилищем данных: {0}.
|
||||
/// </summary>
|
||||
internal static string AdapterMessageStorageException {
|
||||
get {
|
||||
return ResourceManager.GetString("AdapterMessageStorageException", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ищет локализованную строку, похожую на Внутренняя ошибка: {0}.
|
||||
/// </summary>
|
||||
internal static string AdapterMessageUnhandledException {
|
||||
get {
|
||||
return ResourceManager.GetString("AdapterMessageUnhandledException", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ищет локализованную строку, похожую на Переданы некорректные данные: {0}.
|
||||
/// </summary>
|
||||
internal static string AdapterMessageValidationException {
|
||||
get {
|
||||
return ResourceManager.GetString("AdapterMessageValidationException", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ищет локализованную строку, похожую на Отчёт по выполненным работам за период.
|
||||
/// </summary>
|
||||
internal static string DocumentDocExcelHeader {
|
||||
get {
|
||||
return ResourceManager.GetString("DocumentDocExcelHeader", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ищет локализованную строку, похожую на История изменений помещений.
|
||||
/// </summary>
|
||||
internal static string DocumentDocHeader {
|
||||
get {
|
||||
return ResourceManager.GetString("DocumentDocHeader", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ищет локализованную строку, похожую на Начисления.
|
||||
/// </summary>
|
||||
internal static string DocumentSalaryChartTitle {
|
||||
get {
|
||||
return ResourceManager.GetString("DocumentSalaryChartTitle", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ищет локализованную строку, похожую на Зарплатная ведомость у {0}.
|
||||
/// </summary>
|
||||
internal static string DocumentSalaryHeader {
|
||||
get {
|
||||
return ResourceManager.GetString("DocumentSalaryHeader", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ищет локализованную строку, похожую на Период: с {0} по {1}.
|
||||
/// </summary>
|
||||
internal static string DocumentSubExcelHeader {
|
||||
get {
|
||||
return ResourceManager.GetString("DocumentSubExcelHeader", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ищет локализованную строку, похожую на Сформировано {0}.
|
||||
/// </summary>
|
||||
internal static string DocumentSubHeader {
|
||||
get {
|
||||
return ResourceManager.GetString("DocumentSubHeader", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ищет локализованную строку, похожую на Нельзя изменить удаленный элемент(идентификатор: {0}).
|
||||
/// </summary>
|
||||
internal static string ElementDeletedExceptionCaption {
|
||||
get {
|
||||
return ResourceManager.GetString("ElementDeletedExceptionCaption", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ищет локализованную строку, похожую на Элемент с параметром {0} и значением {1} уже существует.
|
||||
/// </summary>
|
||||
internal static string ElementExistsExceptionCaption {
|
||||
get {
|
||||
return ResourceManager.GetString("ElementExistsExceptionCaption", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ищет локализованную строку, похожую на Элемент со значением {0} не найден.
|
||||
/// </summary>
|
||||
internal static string ElementNotFoundExceptionCaption {
|
||||
get {
|
||||
return ResourceManager.GetString("ElementNotFoundExceptionCaption", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ищет локализованную строку, похожую на Дата окончания должна быть позже даты начала. Дата начала: {0}, Дата конца: {1}.
|
||||
/// </summary>
|
||||
internal static string IncorrectDatesExceptionCaption {
|
||||
get {
|
||||
return ResourceManager.GetString("IncorrectDatesExceptionCaption", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ищет локализованную строку, похожую на Полученный список равен null.
|
||||
/// </summary>
|
||||
internal static string NullListExceptionCaption {
|
||||
get {
|
||||
return ResourceManager.GetString("NullListExceptionCaption", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ищет локализованную строку, похожую на Ошибка при работе с хранилищем: {0}.
|
||||
/// </summary>
|
||||
internal static string StorageExceptionCaption {
|
||||
get {
|
||||
return ResourceManager.GetString("StorageExceptionCaption", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ищет локализованную строку, похожую на Значение поля {0} не может быть в прошлом.
|
||||
/// </summary>
|
||||
internal static string ValidationExceptionMessageDateInPast {
|
||||
get {
|
||||
return ResourceManager.GetString("ValidationExceptionMessageDateInPast", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ищет локализованную строку, похожую на Значение в поле {0}, пусто.
|
||||
/// </summary>
|
||||
internal static string ValidationExceptionMessageEmptyField {
|
||||
get {
|
||||
return ResourceManager.GetString("ValidationExceptionMessageEmptyField", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ищет локализованную строку, похожую на Поле адрес заполнено некорректно.
|
||||
/// </summary>
|
||||
internal static string ValidationExceptionMessageInvalidAddress {
|
||||
get {
|
||||
return ResourceManager.GetString("ValidationExceptionMessageInvalidAddress", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ищет локализованную строку, похожую на Поле PhoneNumber заполнено некорректно.
|
||||
/// </summary>
|
||||
internal static string ValidationExceptionMessageInvalidPhoneNumber {
|
||||
get {
|
||||
return ResourceManager.GetString("ValidationExceptionMessageInvalidPhoneNumber", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ищет локализованную строку, похожую на Значение поля {0} должно быть больше нуля.
|
||||
/// </summary>
|
||||
internal static string ValidationExceptionMessageInvalidRange {
|
||||
get {
|
||||
return ResourceManager.GetString("ValidationExceptionMessageInvalidRange", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ищет локализованную строку, похожую на Значение в поле {0} не является типом уникального идентификатора.
|
||||
/// </summary>
|
||||
internal static string ValidationExceptionMessageNotAId {
|
||||
get {
|
||||
return ResourceManager.GetString("ValidationExceptionMessageNotAId", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ищет локализованную строку, похожую на В работе должен быть задействован хотябы один рабочий.
|
||||
/// </summary>
|
||||
internal static string ValidationExceptionMessageNoWorkerInComplitedWorks {
|
||||
get {
|
||||
return ResourceManager.GetString("ValidationExceptionMessageNoWorkerInComplitedWorks", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ищет локализованную строку, похожую на Несовершеннолетние не могут быть приняты на работу (DateBirthDay = {0}).
|
||||
/// </summary>
|
||||
internal static string ValidationExceptionMessageTooYoung {
|
||||
get {
|
||||
return ResourceManager.GetString("ValidationExceptionMessageTooYoung", resourceCulture);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,210 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<data name="AdapterMessageArgumentNullException" xml:space="preserve">
|
||||
<value>Параметр не должен быть пустым</value>
|
||||
</data>
|
||||
<data name="AdapterMessageElementExists" xml:space="preserve">
|
||||
<value>Элемент с параметром {0} и значением {1} уже существует</value>
|
||||
</data>
|
||||
<data name="AdapterMessageElementNotFound" xml:space="preserve">
|
||||
<value>Элемент со значением {0} не найден</value>
|
||||
</data>
|
||||
<data name="AdapterMessageIncorrectDates" xml:space="preserve">
|
||||
<value>Некорректные даты: {0}</value>
|
||||
</data>
|
||||
<data name="AdapterMessageInvalidOperationException" xml:space="preserve">
|
||||
<value>Ошибка при выполнении операции: {0}</value>
|
||||
</data>
|
||||
<data name="AdapterMessageNoRoomsForAddress" xml:space="preserve">
|
||||
<value>Не найдено помещений по указанному адресу</value>
|
||||
</data>
|
||||
<data name="AdapterMessageSalaryDataNotFound" xml:space="preserve">
|
||||
<value>Данные о зарплате не найдены</value>
|
||||
</data>
|
||||
<data name="AdapterMessageStorageException" xml:space="preserve">
|
||||
<value>Ошибка при работе с хранилищем данных: {0}</value>
|
||||
</data>
|
||||
<data name="AdapterMessageUnhandledException" xml:space="preserve">
|
||||
<value>Внутренняя ошибка: {0}</value>
|
||||
</data>
|
||||
<data name="AdapterMessageValidationException" xml:space="preserve">
|
||||
<value>Переданы некорректные данные: {0}</value>
|
||||
</data>
|
||||
<data name="DocumentDocExcelHeader" xml:space="preserve">
|
||||
<value>Отчёт по выполненным работам за период</value>
|
||||
</data>
|
||||
<data name="DocumentDocHeader" xml:space="preserve">
|
||||
<value>История изменений помещений</value>
|
||||
</data>
|
||||
<data name="DocumentSalaryChartTitle" xml:space="preserve">
|
||||
<value>Начисления</value>
|
||||
</data>
|
||||
<data name="DocumentSalaryHeader" xml:space="preserve">
|
||||
<value>Зарплатная ведомость у {0}</value>
|
||||
</data>
|
||||
<data name="DocumentSubExcelHeader" xml:space="preserve">
|
||||
<value>Период: с {0} по {1}</value>
|
||||
</data>
|
||||
<data name="DocumentSubHeader" xml:space="preserve">
|
||||
<value>Сформировано {0}</value>
|
||||
</data>
|
||||
<data name="ElementDeletedExceptionCaption" xml:space="preserve">
|
||||
<value>Нельзя изменить удаленный элемент(идентификатор: {0})</value>
|
||||
</data>
|
||||
<data name="ElementExistsExceptionCaption" xml:space="preserve">
|
||||
<value>Элемент с параметром {0} и значением {1} уже существует</value>
|
||||
</data>
|
||||
<data name="ElementNotFoundExceptionCaption" xml:space="preserve">
|
||||
<value>Элемент со значением {0} не найден</value>
|
||||
</data>
|
||||
<data name="IncorrectDatesExceptionCaption" xml:space="preserve">
|
||||
<value>Дата окончания должна быть позже даты начала. Дата начала: {0}, Дата конца: {1}</value>
|
||||
</data>
|
||||
<data name="NullListExceptionCaption" xml:space="preserve">
|
||||
<value>Полученный список равен null</value>
|
||||
</data>
|
||||
<data name="StorageExceptionCaption" xml:space="preserve">
|
||||
<value>Ошибка при работе с хранилищем: {0}</value>
|
||||
</data>
|
||||
<data name="ValidationExceptionMessageDateInPast" xml:space="preserve">
|
||||
<value>Значение поля {0} не может быть в прошлом</value>
|
||||
</data>
|
||||
<data name="ValidationExceptionMessageEmptyField" xml:space="preserve">
|
||||
<value>Значение в поле {0}, пусто</value>
|
||||
</data>
|
||||
<data name="ValidationExceptionMessageInvalidAddress" xml:space="preserve">
|
||||
<value>Поле адрес заполнено некорректно</value>
|
||||
</data>
|
||||
<data name="ValidationExceptionMessageInvalidPhoneNumber" xml:space="preserve">
|
||||
<value>Поле PhoneNumber заполнено некорректно</value>
|
||||
</data>
|
||||
<data name="ValidationExceptionMessageInvalidRange" xml:space="preserve">
|
||||
<value>Значение поля {0} должно быть больше нуля</value>
|
||||
</data>
|
||||
<data name="ValidationExceptionMessageNotAId" xml:space="preserve">
|
||||
<value>Значение в поле {0} не является типом уникального идентификатора</value>
|
||||
</data>
|
||||
<data name="ValidationExceptionMessageNoWorkerInComplitedWorks" xml:space="preserve">
|
||||
<value>В работе должен быть задействован хотябы один рабочий</value>
|
||||
</data>
|
||||
<data name="ValidationExceptionMessageTooYoung" xml:space="preserve">
|
||||
<value>Несовершеннолетние не могут быть приняты на работу (DateBirthDay = {0})</value>
|
||||
</data>
|
||||
</root>
|
||||
@@ -1,6 +1,6 @@
|
||||
using TwoFromTheCasketContracts.DataModels;
|
||||
namespace TwoFromTheCasketContracts.StorageContracts;
|
||||
public interface IComplitedWorkStorageContract
|
||||
internal interface IComplitedWorkStorageContract
|
||||
{
|
||||
List<ComplitedWorkDataModel> GetList(DateTime? startTime, DateTime? endTime, string? RoomId = null, string? WorkId = null, string? WorkerId = null);
|
||||
Task<List<ComplitedWorkDataModel>> GetListAsync(DateTime? startTime, DateTime? endTime, CancellationToken ct);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using TwoFromTheCasketContracts.DataModels;
|
||||
namespace TwoFromTheCasketContracts.StorageContracts;
|
||||
public interface IRoomHistoryStorageContract
|
||||
internal interface IRoomHistoryStorageContract
|
||||
{
|
||||
List<RoomHistoryDataModel> GetList(string roomId);
|
||||
Task<List<RoomHistoryDataModel>> GetListAsync(CancellationToken ct);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using TwoFromTheCasketContracts.DataModels;
|
||||
namespace TwoFromTheCasketContracts.StorageContracts;
|
||||
public interface IRoomStorageContract
|
||||
internal interface IRoomStorageContract
|
||||
{
|
||||
List<RoomDataModel> GetList();
|
||||
Task<List<RoomDataModel>> GetListAsync(CancellationToken ct);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using TwoFromTheCasketContracts.DataModels;
|
||||
namespace TwoFromTheCasketContracts.StorageContracts;
|
||||
public interface ISalaryStorageContract
|
||||
internal interface ISalaryStorageContract
|
||||
{
|
||||
List<SalaryDataModel> GetList(DateTime startDate, DateTime endDate, string? workerId = null);
|
||||
Task<List<SalaryDataModel>> GetListAsync(DateTime startDate, DateTime endDate, CancellationToken ct, string? workerId = null);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using TwoFromTheCasketContracts.DataModels;
|
||||
namespace TwoFromTheCasketContracts.StorageContracts;
|
||||
public interface ISpecializationStorageContract
|
||||
internal interface ISpecializationStorageContract
|
||||
{
|
||||
List<SpecializationDataModel> GetList(bool onlyActive = true);
|
||||
SpecializationDataModel? GetElementById(string id);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using TwoFromTheCasketContracts.DataModels;
|
||||
namespace TwoFromTheCasketContracts.StorageContracts;
|
||||
public interface IWorkStorageContract
|
||||
internal interface IWorkStorageContract
|
||||
{
|
||||
List<WorkDataModel> GetList(DateTime? fromEndDate = null, DateTime? toEndDate = null);
|
||||
Task<List<WorkDataModel>> GetListAsync(CancellationToken ct);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using TwoFromTheCasketContracts.DataModels;
|
||||
namespace TwoFromTheCasketContracts.StorageContracts;
|
||||
public interface IWorkerComplitedWorkStorageContract
|
||||
internal interface IWorkerComplitedWorkStorageContract
|
||||
{
|
||||
List<WorkerComplitedWorkDataModel> GetList(string? workerId = null, string? complitedWorkId = null);
|
||||
WorkerComplitedWorkDataModel? GetElementById(string id);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using TwoFromTheCasketContracts.DataModels;
|
||||
namespace TwoFromTheCasketContracts.StorageContracts;
|
||||
public interface IWorkerStorageContract
|
||||
internal interface IWorkerStorageContract
|
||||
{
|
||||
List<WorkerDataModel> GetList(bool onlyActive = true, string? SpecializationId = null, DateTime? fromBirthDate = null, DateTime? toBirthDate = null, DateTime? fromEmploymentDate = null, DateTime? toEmploymentDate = null);
|
||||
Task<List<WorkerDataModel>> GetListAsync(CancellationToken ct);
|
||||
|
||||
@@ -9,6 +9,30 @@
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Abstractions" Version="2.3.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="2.3.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Localization.Abstractions" Version="9.0.4" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Update="Resources\Messages.Designer.cs">
|
||||
<DesignTime>True</DesignTime>
|
||||
<AutoGen>True</AutoGen>
|
||||
<DependentUpon>Messages.resx</DependentUpon>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Update="Resources\Messages.resx">
|
||||
<Generator>ResXFileCodeGenerator</Generator>
|
||||
<LastGenOutput>Messages.Designer.cs</LastGenOutput>
|
||||
</EmbeddedResource>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<InternalsVisibleTo Include="TwoFromTheCasketBusinessLogic" />
|
||||
<InternalsVisibleTo Include="TwoFromTheCasketTests" />
|
||||
<InternalsVisibleTo Include="TwoFromTheCasketDatabase" />
|
||||
<InternalsVisibleTo Include="TwoFromTheCasketWebApi" />
|
||||
<InternalsVisibleTo Include="DynamicProxyGenAssembly2" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -4,6 +4,6 @@ namespace TwoFromTheCasketContracts.ViewModels;
|
||||
|
||||
public class RoomWithHistoryViewModel
|
||||
{
|
||||
public required RoomDataModel Room { get; set; }
|
||||
public required List<RoomHistoryDataModel> History { get; set; }
|
||||
public required string Room { get; set; }
|
||||
public required List<string> History { get; set; }
|
||||
}
|
||||
|
||||
@@ -3,19 +3,23 @@ using Microsoft.EntityFrameworkCore;
|
||||
using Npgsql;
|
||||
using TwoFromTheCasketContracts.DataModels;
|
||||
using TwoFromTheCasketContracts.Exceptions;
|
||||
using TwoFromTheCasketContracts.Resources;
|
||||
using TwoFromTheCasketContracts.StorageContracts;
|
||||
using TwoFromTheCasketDatabase.Models;
|
||||
using Microsoft.Extensions.Localization;
|
||||
|
||||
namespace TwoFromTheCasketDatabase.Implementations;
|
||||
|
||||
public class ComplitedWorkStorageContract : IComplitedWorkStorageContract
|
||||
internal class ComplitedWorkStorageContract : IComplitedWorkStorageContract
|
||||
{
|
||||
private readonly TwoFromTheCasketDbContext _dbContext;
|
||||
private readonly Mapper _mapper;
|
||||
private IStringLocalizer<Messages> _localizer;
|
||||
|
||||
public ComplitedWorkStorageContract(TwoFromTheCasketDbContext context)
|
||||
public ComplitedWorkStorageContract(TwoFromTheCasketDbContext context, IStringLocalizer<Messages> localizer)
|
||||
{
|
||||
_dbContext = context;
|
||||
_localizer = localizer;
|
||||
var conf = new MapperConfiguration(cfg =>
|
||||
{
|
||||
cfg.CreateMap<ComplitedWork, ComplitedWorkDataModel>()
|
||||
@@ -53,7 +57,7 @@ public class ComplitedWorkStorageContract : IComplitedWorkStorageContract
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
throw new StorageException(ex, _localizer);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -92,7 +96,7 @@ public class ComplitedWorkStorageContract : IComplitedWorkStorageContract
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
throw new StorageException(ex, _localizer);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -106,7 +110,7 @@ public class ComplitedWorkStorageContract : IComplitedWorkStorageContract
|
||||
catch (Exception e)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(e);
|
||||
throw new StorageException(e, _localizer);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -121,7 +125,7 @@ public class ComplitedWorkStorageContract : IComplitedWorkStorageContract
|
||||
|
||||
if (!_dbContext.Rooms.Any(x => x.Id == complitedWorkDataModel.RoomId))
|
||||
{
|
||||
throw new ElementNotFoundException($"Room with ID {complitedWorkDataModel.RoomId} not found.");
|
||||
throw new ElementNotFoundException($"Room with ID {complitedWorkDataModel.RoomId} not found.", _localizer);
|
||||
}
|
||||
|
||||
var complitedWork = _mapper.Map<ComplitedWork>(complitedWorkDataModel);
|
||||
@@ -150,12 +154,12 @@ public class ComplitedWorkStorageContract : IComplitedWorkStorageContract
|
||||
catch (DbUpdateException ex) when (ex.InnerException is PostgresException { ConstraintName: "PK_ComplitedWorks" })
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new ElementExistsException("Id", complitedWorkDataModel.Id);
|
||||
throw new ElementExistsException("Id", complitedWorkDataModel.Id, _localizer);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(e);
|
||||
throw new StorageException(e, _localizer);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -168,7 +172,7 @@ public class ComplitedWorkStorageContract : IComplitedWorkStorageContract
|
||||
try
|
||||
{
|
||||
var element = _dbContext.ComplitedWorks.FirstOrDefault(x => x.Id == id)
|
||||
?? throw new ElementNotFoundException(id);
|
||||
?? throw new ElementNotFoundException(id, _localizer);
|
||||
|
||||
_dbContext.ComplitedWorks.Remove(element);
|
||||
_dbContext.SaveChanges();
|
||||
@@ -181,7 +185,7 @@ public class ComplitedWorkStorageContract : IComplitedWorkStorageContract
|
||||
catch (Exception e)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(e);
|
||||
throw new StorageException(e, _localizer);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,20 +1,23 @@
|
||||
using AutoMapper;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using TwoFromTheCasketContracts.DataModels;
|
||||
using TwoFromTheCasketContracts.Exceptions;
|
||||
using TwoFromTheCasketContracts.Resources;
|
||||
using TwoFromTheCasketContracts.StorageContracts;
|
||||
using TwoFromTheCasketDatabase.Models;
|
||||
|
||||
namespace TwoFromTheCasketDatabase.Implementations;
|
||||
|
||||
public class RoomHistoryStorageContract : IRoomHistoryStorageContract
|
||||
internal class RoomHistoryStorageContract : IRoomHistoryStorageContract
|
||||
{
|
||||
private readonly TwoFromTheCasketDbContext _dbContext;
|
||||
private readonly Mapper _mapper;
|
||||
|
||||
public RoomHistoryStorageContract(TwoFromTheCasketDbContext context)
|
||||
private IStringLocalizer<Messages> _localizer;
|
||||
public RoomHistoryStorageContract(TwoFromTheCasketDbContext context, IStringLocalizer<Messages> localizer)
|
||||
{
|
||||
_dbContext = context;
|
||||
_localizer = localizer;
|
||||
var conf = new MapperConfiguration(cfg =>
|
||||
{
|
||||
cfg.CreateMap<RoomHistoryDataModel, RoomHistory>();
|
||||
@@ -40,7 +43,7 @@ public class RoomHistoryStorageContract : IRoomHistoryStorageContract
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
throw new StorageException(ex, _localizer);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,7 +63,7 @@ public class RoomHistoryStorageContract : IRoomHistoryStorageContract
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
throw new StorageException(ex, _localizer);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,7 +82,7 @@ public class RoomHistoryStorageContract : IRoomHistoryStorageContract
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
throw new StorageException(ex, _localizer);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -89,7 +92,7 @@ public class RoomHistoryStorageContract : IRoomHistoryStorageContract
|
||||
{
|
||||
var roomExists = _dbContext.Rooms.Any(x => x.Id == roomHistoryDataModel.RoomId);
|
||||
if (!roomExists)
|
||||
throw new ElementNotFoundException($"Room with Id {roomHistoryDataModel.RoomId} not found.");
|
||||
throw new ElementNotFoundException($"Room with Id {roomHistoryDataModel.RoomId} not found.", _localizer);
|
||||
|
||||
var entity = _mapper.Map<RoomHistory>(roomHistoryDataModel);
|
||||
_dbContext.RoomHistories.Add(entity);
|
||||
@@ -100,12 +103,12 @@ public class RoomHistoryStorageContract : IRoomHistoryStorageContract
|
||||
catch (DbUpdateException ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
throw new StorageException(ex, _localizer);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
throw new StorageException(ex, _localizer);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,17 +5,21 @@ using TwoFromTheCasketContracts.Exceptions;
|
||||
using TwoFromTheCasketContracts.StorageContracts;
|
||||
using TwoFromTheCasketDatabase.Models;
|
||||
using AutoMapper;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using TwoFromTheCasketContracts.Resources;
|
||||
|
||||
namespace TwoFromTheCasketDatabase.Implementations;
|
||||
|
||||
public class RoomStorageContract : IRoomStorageContract
|
||||
internal class RoomStorageContract : IRoomStorageContract
|
||||
{
|
||||
private readonly TwoFromTheCasketDbContext _dbContext;
|
||||
private readonly IMapper _mapper;
|
||||
private IStringLocalizer<Messages> _localizer;
|
||||
|
||||
public RoomStorageContract(TwoFromTheCasketDbContext dbContext)
|
||||
public RoomStorageContract(TwoFromTheCasketDbContext dbContext, IStringLocalizer<Messages> localizer)
|
||||
{
|
||||
_dbContext = dbContext;
|
||||
_localizer = localizer;
|
||||
var conf = new MapperConfiguration(cfg =>
|
||||
{
|
||||
cfg.CreateMap<Room, RoomDataModel>();
|
||||
@@ -34,7 +38,7 @@ public class RoomStorageContract : IRoomStorageContract
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
throw new StorageException(ex, _localizer);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,7 +57,7 @@ public class RoomStorageContract : IRoomStorageContract
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
throw new StorageException(ex, _localizer);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,7 +71,7 @@ public class RoomStorageContract : IRoomStorageContract
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
throw new StorageException(ex, _localizer);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,7 +85,7 @@ public class RoomStorageContract : IRoomStorageContract
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
throw new StorageException(ex, _localizer);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -95,7 +99,7 @@ public class RoomStorageContract : IRoomStorageContract
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
throw new StorageException(ex, _localizer);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -108,7 +112,7 @@ public class RoomStorageContract : IRoomStorageContract
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
throw new StorageException(ex, _localizer);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -122,12 +126,12 @@ public class RoomStorageContract : IRoomStorageContract
|
||||
catch (DbUpdateException ex) when (ex.InnerException is PostgresException { ConstraintName: "IX_Rooms_Address" })
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new ElementExistsException("Address", roomDataModel.Address);
|
||||
throw new ElementExistsException("Address", roomDataModel.Address, _localizer);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
throw new StorageException(ex, _localizer);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -136,7 +140,7 @@ public class RoomStorageContract : IRoomStorageContract
|
||||
try
|
||||
{
|
||||
var element = _dbContext.Rooms.FirstOrDefault(x => x.Id == roomDataModel.Id)
|
||||
?? throw new ElementNotFoundException(roomDataModel.Id);
|
||||
?? throw new ElementNotFoundException(roomDataModel.Id, _localizer);
|
||||
|
||||
_dbContext.Rooms.Update(_mapper.Map(roomDataModel, element));
|
||||
_dbContext.SaveChanges();
|
||||
@@ -149,12 +153,12 @@ public class RoomStorageContract : IRoomStorageContract
|
||||
catch (DbUpdateException ex) when (ex.InnerException is PostgresException { ConstraintName: "IX_Rooms_Address" })
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new ElementExistsException("Address", roomDataModel.Address);
|
||||
throw new ElementExistsException("Address", roomDataModel.Address, _localizer);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
throw new StorageException(ex, _localizer);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -163,7 +167,7 @@ public class RoomStorageContract : IRoomStorageContract
|
||||
try
|
||||
{
|
||||
var room = _dbContext.Rooms.FirstOrDefault(x => x.Id == id)
|
||||
?? throw new ElementNotFoundException(id);
|
||||
?? throw new ElementNotFoundException(id, _localizer);
|
||||
|
||||
_dbContext.Rooms.Remove(room);
|
||||
_dbContext.SaveChanges();
|
||||
@@ -176,7 +180,7 @@ public class RoomStorageContract : IRoomStorageContract
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
throw new StorageException(ex, _localizer);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,17 +4,21 @@ using TwoFromTheCasketContracts.DataModels;
|
||||
using TwoFromTheCasketContracts.Exceptions;
|
||||
using TwoFromTheCasketContracts.StorageContracts;
|
||||
using TwoFromTheCasketDatabase.Models;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using TwoFromTheCasketContracts.Resources;
|
||||
|
||||
namespace TwoFromTheCasketDatabase.Implementations;
|
||||
|
||||
public class SalaryStorageContract : ISalaryStorageContract
|
||||
internal class SalaryStorageContract : ISalaryStorageContract
|
||||
{
|
||||
private readonly TwoFromTheCasketDbContext _dbContext;
|
||||
private readonly Mapper _mapper;
|
||||
private IStringLocalizer<Messages> _localizer;
|
||||
|
||||
public SalaryStorageContract(TwoFromTheCasketDbContext context)
|
||||
public SalaryStorageContract(TwoFromTheCasketDbContext context, IStringLocalizer<Messages> localizer)
|
||||
{
|
||||
_dbContext = context;
|
||||
_localizer = localizer;
|
||||
var conf = new MapperConfiguration(cfg =>
|
||||
{
|
||||
cfg.CreateMap<SalaryDataModel, Salary>();
|
||||
@@ -38,7 +42,7 @@ public class SalaryStorageContract : ISalaryStorageContract
|
||||
catch (Exception e)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(e);
|
||||
throw new StorageException(e, _localizer);
|
||||
}
|
||||
}
|
||||
public async Task<List<SalaryDataModel>> GetListAsync(DateTime startDate, DateTime endDate, CancellationToken ct, string? workerId)
|
||||
@@ -65,7 +69,7 @@ public class SalaryStorageContract : ISalaryStorageContract
|
||||
catch (Exception e)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(e);
|
||||
throw new StorageException(e, _localizer);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,7 +81,7 @@ public class SalaryStorageContract : ISalaryStorageContract
|
||||
var workerExists = _dbContext.Workers.Any(x => x.Id == salaryDataModel.WorkerId);
|
||||
if (!workerExists)
|
||||
{
|
||||
throw new ElementNotFoundException($"Worker with id {salaryDataModel.WorkerId} not found.");
|
||||
throw new ElementNotFoundException($"Worker with id {salaryDataModel.WorkerId} not found.", _localizer);
|
||||
}
|
||||
|
||||
_dbContext.Salaries.Add(_mapper.Map<Salary>(salaryDataModel));
|
||||
@@ -91,12 +95,12 @@ public class SalaryStorageContract : ISalaryStorageContract
|
||||
catch (DbUpdateException ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
throw new StorageException(ex, _localizer);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
throw new StorageException(ex, _localizer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,22 +1,25 @@
|
||||
using AutoMapper;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using Npgsql;
|
||||
using System.Xml.Linq;
|
||||
using TwoFromTheCasketContracts.DataModels;
|
||||
using TwoFromTheCasketContracts.Exceptions;
|
||||
using TwoFromTheCasketContracts.Resources;
|
||||
using TwoFromTheCasketContracts.StorageContracts;
|
||||
using TwoFromTheCasketDatabase.Models;
|
||||
|
||||
namespace TwoFromTheCasketDatabase.Implementations;
|
||||
|
||||
public class SpecializationStorageContract : ISpecializationStorageContract
|
||||
internal class SpecializationStorageContract : ISpecializationStorageContract
|
||||
{
|
||||
private readonly TwoFromTheCasketDbContext _dbContext;
|
||||
private readonly Mapper _mapper;
|
||||
|
||||
public SpecializationStorageContract(TwoFromTheCasketDbContext context)
|
||||
private IStringLocalizer<Messages> _localizer;
|
||||
public SpecializationStorageContract(TwoFromTheCasketDbContext context, IStringLocalizer<Messages> localizer)
|
||||
{
|
||||
_dbContext = context;
|
||||
_localizer = localizer;
|
||||
var conf = new MapperConfiguration(cfg =>
|
||||
{
|
||||
cfg.CreateMap<TwoFromTheCasketContracts.DataModels.SpecializationDataModel, TwoFromTheCasketDatabase.Models.Specialization>()
|
||||
@@ -40,7 +43,7 @@ public class SpecializationStorageContract : ISpecializationStorageContract
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
throw new StorageException(ex, _localizer);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,7 +57,7 @@ public class SpecializationStorageContract : ISpecializationStorageContract
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
throw new StorageException(ex, _localizer);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,7 +72,7 @@ public class SpecializationStorageContract : ISpecializationStorageContract
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
throw new StorageException(ex, _localizer);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,7 +81,7 @@ public class SpecializationStorageContract : ISpecializationStorageContract
|
||||
try
|
||||
{
|
||||
if (_dbContext.Specializations.Any(x => x.Id == specialization.Id))
|
||||
throw new ElementExistsException("Id", specialization.Id);
|
||||
throw new ElementExistsException("Id", specialization.Id, _localizer);
|
||||
|
||||
var entity = _mapper.Map<Specialization>(specialization);
|
||||
entity.Id = specialization.Id;
|
||||
@@ -91,12 +94,12 @@ public class SpecializationStorageContract : ISpecializationStorageContract
|
||||
catch (DbUpdateException ex) when (ex.InnerException is PostgresException { ConstraintName: "IX_Specializations_SpecializationName_IsActual" })
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new ElementExistsException("SpecializationName", specialization.SpecializationName);
|
||||
throw new ElementExistsException("SpecializationName", specialization.SpecializationName, _localizer);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
throw new StorageException(ex, _localizer);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -109,11 +112,11 @@ public class SpecializationStorageContract : ISpecializationStorageContract
|
||||
{
|
||||
var existing = _dbContext.Specializations
|
||||
.FirstOrDefault(x => x.Id == specialization.Id)
|
||||
?? throw new ElementNotFoundException(specialization.Id);
|
||||
?? throw new ElementNotFoundException(specialization.Id, _localizer);
|
||||
|
||||
if (!existing.IsActual)
|
||||
{
|
||||
throw new ElementDeletedException(specialization.Id);
|
||||
throw new ElementDeletedException(specialization.Id, _localizer);
|
||||
}
|
||||
|
||||
existing.IsActual = false;
|
||||
@@ -142,12 +145,12 @@ public class SpecializationStorageContract : ISpecializationStorageContract
|
||||
catch (DbUpdateException ex) when (ex.InnerException is PostgresException { ConstraintName: "IX_Specializations_SpecializationName_IsActual" })
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new ElementExistsException("SpecializationName", specialization.SpecializationName);
|
||||
throw new ElementExistsException("SpecializationName", specialization.SpecializationName, _localizer);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
throw new StorageException(ex, _localizer);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -157,7 +160,7 @@ public class SpecializationStorageContract : ISpecializationStorageContract
|
||||
{
|
||||
var element = _dbContext.Specializations
|
||||
.FirstOrDefault(x => x.Id == id && x.IsActual)
|
||||
?? throw new ElementNotFoundException(id);
|
||||
?? throw new ElementNotFoundException(id, _localizer);
|
||||
|
||||
element.IsActual = false;
|
||||
element.ChangeDate = DateTime.UtcNow;
|
||||
@@ -171,7 +174,7 @@ public class SpecializationStorageContract : ISpecializationStorageContract
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
throw new StorageException(ex, _localizer);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -181,7 +184,7 @@ public class SpecializationStorageContract : ISpecializationStorageContract
|
||||
{
|
||||
var element = _dbContext.Specializations
|
||||
.FirstOrDefault(x => x.Id == id && !x.IsActual)
|
||||
?? throw new ElementNotFoundException(id);
|
||||
?? throw new ElementNotFoundException(id, _localizer);
|
||||
|
||||
element.IsActual = true;
|
||||
element.ChangeDate = DateTime.UtcNow;
|
||||
@@ -195,7 +198,7 @@ public class SpecializationStorageContract : ISpecializationStorageContract
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
throw new StorageException(ex, _localizer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,20 +1,23 @@
|
||||
using AutoMapper;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using TwoFromTheCasketContracts.DataModels;
|
||||
using TwoFromTheCasketContracts.Exceptions;
|
||||
using TwoFromTheCasketContracts.Resources;
|
||||
using TwoFromTheCasketContracts.StorageContracts;
|
||||
using TwoFromTheCasketDatabase.Models;
|
||||
|
||||
namespace TwoFromTheCasketDatabase.Implementations;
|
||||
|
||||
public class WorkStorageContract : IWorkStorageContract
|
||||
internal class WorkStorageContract : IWorkStorageContract
|
||||
{
|
||||
private readonly TwoFromTheCasketDbContext _dbContext;
|
||||
private readonly Mapper _mapper;
|
||||
|
||||
public WorkStorageContract(TwoFromTheCasketDbContext context)
|
||||
private IStringLocalizer<Messages> _localizer;
|
||||
public WorkStorageContract(TwoFromTheCasketDbContext context, IStringLocalizer<Messages> localizer)
|
||||
{
|
||||
_dbContext = context;
|
||||
_localizer = localizer;
|
||||
var conf = new MapperConfiguration(cfg =>
|
||||
{
|
||||
cfg.AddMaps(typeof(TwoFromTheCasketDbContext).Assembly);
|
||||
@@ -39,7 +42,7 @@ public class WorkStorageContract : IWorkStorageContract
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
throw new StorageException(ex, _localizer);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,7 +61,7 @@ public class WorkStorageContract : IWorkStorageContract
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
throw new StorageException(ex, _localizer);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,7 +76,7 @@ public class WorkStorageContract : IWorkStorageContract
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
throw new StorageException(ex, _localizer);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,12 +90,12 @@ public class WorkStorageContract : IWorkStorageContract
|
||||
catch (DbUpdateException ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
throw new StorageException(ex, _localizer);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
throw new StorageException(ex, _localizer);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -101,7 +104,7 @@ public class WorkStorageContract : IWorkStorageContract
|
||||
try
|
||||
{
|
||||
var existingWork = _dbContext.Works.FirstOrDefault(x => x.Id == workDataModel.Id)
|
||||
?? throw new ElementNotFoundException(workDataModel.Id);
|
||||
?? throw new ElementNotFoundException(workDataModel.Id, _localizer);
|
||||
|
||||
_dbContext.Works.Update(_mapper.Map(workDataModel, existingWork));
|
||||
_dbContext.SaveChanges();
|
||||
@@ -114,7 +117,7 @@ public class WorkStorageContract : IWorkStorageContract
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
throw new StorageException(ex, _localizer);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -123,7 +126,7 @@ public class WorkStorageContract : IWorkStorageContract
|
||||
try
|
||||
{
|
||||
var work = _dbContext.Works.FirstOrDefault(x => x.Id == id)
|
||||
?? throw new ElementNotFoundException(id);
|
||||
?? throw new ElementNotFoundException(id, _localizer);
|
||||
|
||||
_dbContext.Works.Remove(work);
|
||||
_dbContext.SaveChanges();
|
||||
@@ -136,7 +139,7 @@ public class WorkStorageContract : IWorkStorageContract
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
throw new StorageException(ex, _localizer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,20 +1,24 @@
|
||||
using AutoMapper;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using TwoFromTheCasketContracts.DataModels;
|
||||
using TwoFromTheCasketContracts.Exceptions;
|
||||
using TwoFromTheCasketContracts.Resources;
|
||||
using TwoFromTheCasketContracts.StorageContracts;
|
||||
using TwoFromTheCasketDatabase.Models;
|
||||
|
||||
namespace TwoFromTheCasketDatabase.Implementations;
|
||||
|
||||
public class WorkerComplitedWorkStorageContract : IWorkerComplitedWorkStorageContract
|
||||
internal class WorkerComplitedWorkStorageContract : IWorkerComplitedWorkStorageContract
|
||||
{
|
||||
private readonly TwoFromTheCasketDbContext _dbContext;
|
||||
private readonly Mapper _mapper;
|
||||
private IStringLocalizer<Messages> _localizer;
|
||||
|
||||
public WorkerComplitedWorkStorageContract(TwoFromTheCasketDbContext context)
|
||||
public WorkerComplitedWorkStorageContract(TwoFromTheCasketDbContext context, IStringLocalizer<Messages> localizer)
|
||||
{
|
||||
_dbContext = context;
|
||||
_localizer = localizer;
|
||||
var conf = new MapperConfiguration(cfg =>
|
||||
{
|
||||
cfg.CreateMap<WorkerComplitedWork, WorkerComplitedWorkDataModel>();
|
||||
@@ -40,7 +44,7 @@ public class WorkerComplitedWorkStorageContract : IWorkerComplitedWorkStorageCon
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
throw new StorageException(ex, _localizer);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,7 +58,7 @@ public class WorkerComplitedWorkStorageContract : IWorkerComplitedWorkStorageCon
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
throw new StorageException(ex, _localizer);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,12 +72,12 @@ public class WorkerComplitedWorkStorageContract : IWorkerComplitedWorkStorageCon
|
||||
catch (DbUpdateException ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
throw new StorageException(ex, _localizer);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
throw new StorageException(ex, _localizer);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,7 +87,7 @@ public class WorkerComplitedWorkStorageContract : IWorkerComplitedWorkStorageCon
|
||||
{
|
||||
var existing = _dbContext.WorkerComplitedWorks.FirstOrDefault(x =>
|
||||
x.WorkerId == workerComplitedWorkDataModel.WorkerId && x.ComplitedWorkId == workerComplitedWorkDataModel.ComplitedWorkId)
|
||||
?? throw new ElementNotFoundException($"{workerComplitedWorkDataModel.WorkerId}-{workerComplitedWorkDataModel.ComplitedWorkId}");
|
||||
?? throw new ElementNotFoundException($"{workerComplitedWorkDataModel.WorkerId}-{workerComplitedWorkDataModel.ComplitedWorkId}", _localizer);
|
||||
|
||||
existing.NumberOfWorkingHours = workerComplitedWorkDataModel.NumberOfWorkingHours;
|
||||
_dbContext.SaveChanges();
|
||||
@@ -96,7 +100,7 @@ public class WorkerComplitedWorkStorageContract : IWorkerComplitedWorkStorageCon
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
throw new StorageException(ex, _localizer);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -105,7 +109,7 @@ public class WorkerComplitedWorkStorageContract : IWorkerComplitedWorkStorageCon
|
||||
try
|
||||
{
|
||||
var element = _dbContext.WorkerComplitedWorks.FirstOrDefault(x => x.ComplitedWorkId == id)
|
||||
?? throw new ElementNotFoundException(id);
|
||||
?? throw new ElementNotFoundException(id, _localizer);
|
||||
|
||||
_dbContext.WorkerComplitedWorks.Remove(element);
|
||||
_dbContext.SaveChanges();
|
||||
@@ -118,7 +122,7 @@ public class WorkerComplitedWorkStorageContract : IWorkerComplitedWorkStorageCon
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
throw new StorageException(ex, _localizer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,21 +1,25 @@
|
||||
using AutoMapper;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using Npgsql;
|
||||
using TwoFromTheCasketContracts.DataModels;
|
||||
using TwoFromTheCasketContracts.Exceptions;
|
||||
using TwoFromTheCasketContracts.Resources;
|
||||
using TwoFromTheCasketContracts.StorageContracts;
|
||||
using TwoFromTheCasketDatabase.Models;
|
||||
|
||||
namespace TwoFromTheCasketDatabase.Implementations;
|
||||
|
||||
public class WorkerStorageContract : IWorkerStorageContract
|
||||
internal class WorkerStorageContract : IWorkerStorageContract
|
||||
{
|
||||
private readonly TwoFromTheCasketDbContext _dbContext;
|
||||
private readonly Mapper _mapper;
|
||||
private IStringLocalizer<Messages> _localizer;
|
||||
|
||||
public WorkerStorageContract(TwoFromTheCasketDbContext context)
|
||||
public WorkerStorageContract(TwoFromTheCasketDbContext context, IStringLocalizer<Messages> localizer)
|
||||
{
|
||||
_dbContext = context;
|
||||
_localizer = localizer;
|
||||
var conf = new MapperConfiguration(cfg =>
|
||||
{
|
||||
cfg.AddMaps(typeof(TwoFromTheCasketDbContext).Assembly);
|
||||
@@ -57,7 +61,7 @@ public class WorkerStorageContract : IWorkerStorageContract
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
throw new StorageException(ex, _localizer);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,7 +82,7 @@ public class WorkerStorageContract : IWorkerStorageContract
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
throw new StorageException(ex, _localizer);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -92,7 +96,7 @@ public class WorkerStorageContract : IWorkerStorageContract
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
throw new StorageException(ex, _localizer);
|
||||
}
|
||||
}
|
||||
public async Task<WorkerDataModel?> GetElementByIdAsync(string id, CancellationToken ct)
|
||||
@@ -107,7 +111,7 @@ public class WorkerStorageContract : IWorkerStorageContract
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
throw new StorageException(ex, _localizer);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -121,7 +125,7 @@ public class WorkerStorageContract : IWorkerStorageContract
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
throw new StorageException(ex, _localizer);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -135,7 +139,7 @@ public class WorkerStorageContract : IWorkerStorageContract
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
throw new StorageException(ex, _localizer);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -143,7 +147,7 @@ public class WorkerStorageContract : IWorkerStorageContract
|
||||
{
|
||||
try
|
||||
{
|
||||
workerDataModel.Validate();
|
||||
workerDataModel.Validate(_localizer);
|
||||
|
||||
var entity = _mapper.Map<Worker>(workerDataModel);
|
||||
entity.Configuration = workerDataModel.ConfigurationModel;
|
||||
@@ -158,7 +162,7 @@ public class WorkerStorageContract : IWorkerStorageContract
|
||||
if (ex.InnerException is PostgresException pg &&
|
||||
pg.ConstraintName == "IX_Workers_PhoneNumber")
|
||||
{
|
||||
throw new ElementExistsException("PhoneNumber", workerDataModel.PhoneNumber);
|
||||
throw new ElementExistsException("PhoneNumber", workerDataModel.PhoneNumber, _localizer);
|
||||
}
|
||||
|
||||
throw;
|
||||
@@ -166,7 +170,7 @@ public class WorkerStorageContract : IWorkerStorageContract
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
throw new StorageException(ex, _localizer);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -176,7 +180,7 @@ public class WorkerStorageContract : IWorkerStorageContract
|
||||
{
|
||||
var existing = _dbContext.Workers
|
||||
.FirstOrDefault(x => x.Id == workerDataModel.Id)
|
||||
?? throw new ElementNotFoundException(workerDataModel.Id);
|
||||
?? throw new ElementNotFoundException(workerDataModel.Id, _localizer);
|
||||
_mapper.Map(workerDataModel, existing);
|
||||
existing.Configuration = workerDataModel.ConfigurationModel;
|
||||
|
||||
@@ -190,12 +194,12 @@ public class WorkerStorageContract : IWorkerStorageContract
|
||||
catch (DbUpdateException ex) when (ex.InnerException is PostgresException { ConstraintName: "IX_Workers_PhoneNumber" })
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new ElementExistsException("PhoneNumber", workerDataModel.PhoneNumber);
|
||||
throw new ElementExistsException("PhoneNumber", workerDataModel.PhoneNumber, _localizer);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
throw new StorageException(ex, _localizer);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -204,7 +208,7 @@ public class WorkerStorageContract : IWorkerStorageContract
|
||||
try
|
||||
{
|
||||
var worker = _dbContext.Workers.FirstOrDefault(x => x.Id == id)
|
||||
?? throw new ElementNotFoundException(id);
|
||||
?? throw new ElementNotFoundException(id, _localizer);
|
||||
|
||||
worker.IsCurrent = 0;
|
||||
|
||||
@@ -220,7 +224,7 @@ public class WorkerStorageContract : IWorkerStorageContract
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
throw new StorageException(ex, _localizer);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -21,5 +21,12 @@
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\TwoFromTheCasketContracts\TwoFromTheCasketContracts.csproj" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<InternalsVisibleTo Include="TwoFromTheCasketBusinessLogic" />
|
||||
<InternalsVisibleTo Include="TwoFromTheCasketTests" />
|
||||
<InternalsVisibleTo Include="TwoFromTheCasketDatabase" />
|
||||
<InternalsVisibleTo Include="TwoFromTheCasketWebApi" />
|
||||
<InternalsVisibleTo Include="DynamicProxyGenAssembly2" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -274,12 +274,12 @@ public class ReportContractTests
|
||||
Assert.That(actualTableData[2][0], Is.EqualTo(""));
|
||||
Assert.That(actualTableData[2][1], Is.EqualTo("Иванов"));
|
||||
Assert.That(actualTableData[2][2], Is.EqualTo("Office"));
|
||||
Assert.That(actualTableData[2][3], Is.EqualTo("2023-01-01 00:00"));
|
||||
Assert.That(actualTableData[2][3], Is.EqualTo("2022-12-31 20:00"));
|
||||
|
||||
Assert.That(actualTableData[3][0], Is.EqualTo(""));
|
||||
Assert.That(actualTableData[3][1], Is.EqualTo("Иванов И.И."));
|
||||
Assert.That(actualTableData[3][2], Is.EqualTo("Office"));
|
||||
Assert.That(actualTableData[3][3], Is.EqualTo("2023-01-02 00:00"));
|
||||
Assert.That(actualTableData[3][3], Is.EqualTo("2023-01-01 20:00"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -320,7 +320,7 @@ public class ReportContractTests
|
||||
|
||||
// Assert
|
||||
Assert.That(actualTableData, Is.Not.Null);
|
||||
Assert.That(actualTableData.Count, Is.EqualTo(2));
|
||||
Assert.That(actualTableData.Count, Is.EqualTo(3));
|
||||
|
||||
Assert.That(actualTableData[0], Is.EqualTo(new[] { "Дата", "Исполнитель", "Адрес помещения", "Описание работы", "Стоимость" }));
|
||||
Assert.That(actualTableData[1][1], Is.EqualTo("Иванов"));
|
||||
|
||||
@@ -25,8 +25,8 @@ public class ComplitedWorkControllerTests : BaseWebApiControllerTest
|
||||
var room = TwoFromTheCasketDb.InsertRoomToDatabaseAndReturn();
|
||||
var complited = TwoFromTheCasketDb.InsertComplitedWorkToDatabaseAndReturn(date: date, roomId: room.Id, workId: work.Id);
|
||||
|
||||
var from = date.AddDays(-1).ToString("o");
|
||||
var to = date.AddDays(1).ToString("o");
|
||||
var from = date.AddDays(-1).ToString("MM/dd/yyyy");
|
||||
var to = date.AddDays(1).ToString("MM/dd/yyyy");
|
||||
|
||||
var response = await HttpClient.GetAsync($"api/ComplitedWork/GetListByPeriod/{from}/{to}");
|
||||
Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.OK));
|
||||
@@ -47,8 +47,8 @@ public class ComplitedWorkControllerTests : BaseWebApiControllerTest
|
||||
[Test]
|
||||
public async Task Try_GetListByPeriod_WhenIncorrectDateRange_Test()
|
||||
{
|
||||
var from = new DateTime(2025, 1, 2, 0, 0, 0, DateTimeKind.Utc).ToString("o");
|
||||
var to = new DateTime(2024, 1, 1, 0, 0, 0, DateTimeKind.Utc).ToString("o");
|
||||
var from = new DateTime(2025, 1, 2, 0, 0, 0, DateTimeKind.Utc).ToString("MM/dd/yyyy");
|
||||
var to = new DateTime(2024, 1, 1, 0, 0, 0, DateTimeKind.Utc).ToString("MM/dd/yyyy");
|
||||
|
||||
var response = await HttpClient.GetAsync($"api/ComplitedWork/GetListByPeriod/{from}/{to}");
|
||||
Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.BadRequest));
|
||||
@@ -62,8 +62,8 @@ public class ComplitedWorkControllerTests : BaseWebApiControllerTest
|
||||
var work = TwoFromTheCasketDb.InsertWorkToDatabaseAndReturn(date: date);
|
||||
var complited = TwoFromTheCasketDb.InsertComplitedWorkToDatabaseAndReturn(roomId: room.Id, workId: work.Id, date: date);
|
||||
|
||||
var from = date.AddDays(-1).ToString("o");
|
||||
var to = date.AddDays(1).ToString("o");
|
||||
var from = date.AddDays(-1).ToString("MM/dd/yyyy");
|
||||
var to = date.AddDays(1).ToString("MM/dd/yyyy");
|
||||
|
||||
var response = await HttpClient.GetAsync($"api/ComplitedWork/GetListByRoom/{room.Id}/{from}/{to}");
|
||||
Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.OK));
|
||||
@@ -77,8 +77,8 @@ public class ComplitedWorkControllerTests : BaseWebApiControllerTest
|
||||
[Test]
|
||||
public async Task Try_GetListByRoom_WhenEmptyRoomId_Test()
|
||||
{
|
||||
var from = DateTime.UtcNow.AddDays(-1).ToString("o");
|
||||
var to = DateTime.UtcNow.AddDays(1).ToString("o");
|
||||
var from = DateTime.UtcNow.AddDays(-1).ToString("MM/dd/yyyy");
|
||||
var to = DateTime.UtcNow.AddDays(1).ToString("MM/dd/yyyy");
|
||||
|
||||
var response = await HttpClient.GetAsync($"api/ComplitedWork/GetListByRoom/lol/{from}/{to}");
|
||||
Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.BadRequest));
|
||||
@@ -94,8 +94,8 @@ public class ComplitedWorkControllerTests : BaseWebApiControllerTest
|
||||
[Test]
|
||||
public async Task Try_GetListByRoom_WhenIncorrectDateRange_Test()
|
||||
{
|
||||
var from = new DateTime(2025, 1, 1, 0, 0, 0, DateTimeKind.Utc).ToString("o");
|
||||
var to = new DateTime(2024, 1, 1, 0, 0, 0, DateTimeKind.Utc).ToString("o");
|
||||
var from = new DateTime(2025, 1, 1, 0, 0, 0, DateTimeKind.Utc).ToString("MM/dd/yyyy");
|
||||
var to = new DateTime(2024, 1, 1, 0, 0, 0, DateTimeKind.Utc).ToString("MM/dd/yyyy");
|
||||
|
||||
var response = await HttpClient.GetAsync($"api/ComplitedWork/GetListByRoom/room1/{from}/{to}");
|
||||
Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.BadRequest));
|
||||
@@ -109,8 +109,8 @@ public class ComplitedWorkControllerTests : BaseWebApiControllerTest
|
||||
var work = TwoFromTheCasketDb.InsertWorkToDatabaseAndReturn(date: date);
|
||||
var complited = TwoFromTheCasketDb.InsertComplitedWorkToDatabaseAndReturn(roomId: room.Id, workId: work.Id, date: date);
|
||||
|
||||
var from = date.AddDays(-1).ToString("o");
|
||||
var to = date.AddDays(1).ToString("o");
|
||||
var from = date.AddDays(-1).ToString("MM/dd/yyyy");
|
||||
var to = date.AddDays(1).ToString("MM/dd/yyyy");
|
||||
|
||||
var response = await HttpClient.GetAsync($"api/ComplitedWork/GetListByWork/{work.Id}/{from}/{to}");
|
||||
Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.OK));
|
||||
@@ -124,8 +124,8 @@ public class ComplitedWorkControllerTests : BaseWebApiControllerTest
|
||||
[Test]
|
||||
public async Task Try_GetListByWork_WhenEmptyWorkId_Test()
|
||||
{
|
||||
var from = DateTime.UtcNow.AddDays(-1).ToString("o");
|
||||
var to = DateTime.UtcNow.AddDays(1).ToString("o");
|
||||
var from = DateTime.UtcNow.AddDays(-1).ToString("MM/dd/yyyy");
|
||||
var to = DateTime.UtcNow.AddDays(1).ToString("MM/dd/yyyy");
|
||||
|
||||
var response = await HttpClient.GetAsync($"api/ComplitedWork/GetListByWork/ /{from}/{to}");
|
||||
Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.BadRequest));
|
||||
@@ -135,8 +135,8 @@ public class ComplitedWorkControllerTests : BaseWebApiControllerTest
|
||||
public async Task Try_GetListByWork_WhenInvalidDateRange_Test()
|
||||
{
|
||||
var workId = Guid.NewGuid().ToString();
|
||||
var from = new DateTime(2025, 1, 1).ToString("o");
|
||||
var to = new DateTime(2020, 1, 1).ToString("o");
|
||||
var from = new DateTime(2025, 1, 1).ToString("MM/dd/yyyy");
|
||||
var to = new DateTime(2020, 1, 1).ToString("MM/dd/yyyy");
|
||||
|
||||
var response = await HttpClient.GetAsync($"api/ComplitedWork/GetListByWork/{workId}/{from}/{to}");
|
||||
Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.BadRequest));
|
||||
@@ -162,8 +162,8 @@ public class ComplitedWorkControllerTests : BaseWebApiControllerTest
|
||||
var worker = TwoFromTheCasketDb.InsertWorkerToDatabaseAndReturn(specializationId: spec.Id);
|
||||
TwoFromTheCasketDb.InsertWorkerComplitedWorkToDatabaseAndReturn(workerId: worker.Id, complitedWorkId: complited.Id, numberOfWorkingHour: 5);
|
||||
|
||||
var from = date.AddDays(-1).ToString("o");
|
||||
var to = date.AddDays(1).ToString("o");
|
||||
var from = date.AddDays(-1).ToString("MM/dd/yyyy");
|
||||
var to = date.AddDays(1).ToString("MM/dd/yyyy");
|
||||
|
||||
var response = await HttpClient.GetAsync($"api/ComplitedWork/GetListByWorker/{worker.Id}/{from}/{to}");
|
||||
Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.OK));
|
||||
@@ -177,8 +177,8 @@ public class ComplitedWorkControllerTests : BaseWebApiControllerTest
|
||||
[Test]
|
||||
public async Task Try_GetListByWorker_WhenEmptyWorkerId_Test()
|
||||
{
|
||||
var from = DateTime.UtcNow.AddDays(-1).ToString("o");
|
||||
var to = DateTime.UtcNow.AddDays(1).ToString("o");
|
||||
var from = DateTime.UtcNow.AddDays(-1).ToString("MM/dd/yyyy");
|
||||
var to = DateTime.UtcNow.AddDays(1).ToString("MM/dd/yyyy");
|
||||
|
||||
var response = await HttpClient.GetAsync($"api/ComplitedWork/GetListByWorker/ /{from}/{to}");
|
||||
Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.BadRequest));
|
||||
@@ -187,8 +187,8 @@ public class ComplitedWorkControllerTests : BaseWebApiControllerTest
|
||||
[Test]
|
||||
public async Task Try_GetListByWorker_WhenInvalidGuid_Test()
|
||||
{
|
||||
var from = DateTime.UtcNow.AddDays(-1).ToString("o");
|
||||
var to = DateTime.UtcNow.AddDays(1).ToString("o");
|
||||
var from = DateTime.UtcNow.AddDays(-1).ToString("MM/dd/yyyy");
|
||||
var to = DateTime.UtcNow.AddDays(1).ToString("MM/dd/yyyy");
|
||||
|
||||
var response = await HttpClient.GetAsync($"api/ComplitedWork/GetListByWorker/invalid-guid/{from}/{to}");
|
||||
Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.BadRequest));
|
||||
@@ -198,8 +198,8 @@ public class ComplitedWorkControllerTests : BaseWebApiControllerTest
|
||||
public async Task Try_GetListByWorker_WhenInvalidDateRange_Test()
|
||||
{
|
||||
var workerId = Guid.NewGuid().ToString();
|
||||
var from = new DateTime(2025, 1, 1).ToString("o");
|
||||
var to = new DateTime(2020, 1, 1).ToString("o");
|
||||
var from = new DateTime(2025, 1, 1).ToString("MM/dd/yyyy");
|
||||
var to = new DateTime(2020, 1, 1).ToString("MM/dd/yyyy");
|
||||
|
||||
var response = await HttpClient.GetAsync($"api/ComplitedWork/GetListByWorker/{workerId}/{from}/{to}");
|
||||
Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.BadRequest));
|
||||
|
||||
@@ -85,8 +85,8 @@ public class ReportControllerTests : BaseWebApiControllerTest
|
||||
TwoFromTheCasketDb.InsertWorkerComplitedWorkToDatabaseAndReturn(complitedWorkId: complitedWork.Id, workerId: workerId, numberOfWorkingHour: 10);
|
||||
|
||||
// Act
|
||||
var fromDate = DateTime.UtcNow.AddDays(-2).ToString("yyyy-MM-dd");
|
||||
var toDate = DateTime.UtcNow.ToString("yyyy-MM-dd");
|
||||
var fromDate = DateTime.Now.AddDays(-2).ToString("MM/dd/yyyy");
|
||||
var toDate = DateTime.Now.ToString("MM/dd/yyyy");
|
||||
var response = await HttpClient.GetAsync($"/api/Report/GetComplitedWork?fromDate={fromDate}&toDate={toDate}");
|
||||
|
||||
// Assert
|
||||
@@ -99,8 +99,8 @@ public class ReportControllerTests : BaseWebApiControllerTest
|
||||
[Test]
|
||||
public async Task GetComplitedWork_WhenInvalidDates_ShouldReturnBadRequest_Test()
|
||||
{
|
||||
var fromDate = DateTime.UtcNow.ToString("yyyy-MM-dd");
|
||||
var toDate = DateTime.UtcNow.AddDays(-2).ToString("yyyy-MM-dd");
|
||||
var fromDate = DateTime.Now.ToString("MM/dd/yyyy");
|
||||
var toDate = DateTime.Now.AddDays(-2).ToString("MM/dd/yyyy");
|
||||
|
||||
var response = await HttpClient.GetAsync($"/api/Report/GetComplitedWork?fromDate={fromDate}&toDate={toDate}");
|
||||
|
||||
@@ -123,7 +123,7 @@ public class ReportControllerTests : BaseWebApiControllerTest
|
||||
TwoFromTheCasketDb.InsertWorkerComplitedWorkToDatabaseAndReturn(workerId: worker.Id, complitedWorkId: complited2.Id, numberOfWorkingHour: 100);
|
||||
|
||||
// Act
|
||||
var response = await HttpClient.GetAsync($"/api/report/LoadComplitedWork?fromDate={date.AddDays(-3):yyyy-MM-dd}&toDate={date.AddDays(3):yyyy-MM-dd}");
|
||||
var response = await HttpClient.GetAsync($"/api/report/LoadComplitedWork?fromDate={date.AddDays(-3):MM/dd/yyyy}&toDate={date.AddDays(3):MM/dd/yyyy}");
|
||||
|
||||
// Assert
|
||||
Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.OK));
|
||||
@@ -140,7 +140,7 @@ public class ReportControllerTests : BaseWebApiControllerTest
|
||||
public async Task LoadComplitedWork_ShouldReturnFileStreamResult_WhenDataIsinvalid()
|
||||
{
|
||||
// Act
|
||||
var response = await HttpClient.GetAsync($"/api/report/LoadComplitedWork?fromDate={DateTime.UtcNow:yyyy-MM-dd}&toDate={DateTime.UtcNow:yyyy-MM-dd}");
|
||||
var response = await HttpClient.GetAsync($"/api/report/LoadComplitedWork?fromDate={DateTime.Now:MM/dd/yyyy}&toDate={DateTime.Now:MM/dd/yyyy}");
|
||||
|
||||
// Assert
|
||||
Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.BadRequest));
|
||||
@@ -154,8 +154,8 @@ public class ReportControllerTests : BaseWebApiControllerTest
|
||||
var salary1 = TwoFromTheCasketDb.InsertSalaryToDatabaseAndReturn(workerId: worker.Id, sum: 1000, date: DateTime.UtcNow.AddDays(-10));
|
||||
var salary2 = TwoFromTheCasketDb.InsertSalaryToDatabaseAndReturn(workerId: worker.Id, sum: 1500, date: DateTime.UtcNow.AddDays(-5));
|
||||
|
||||
var fromDate = DateTime.UtcNow.AddDays(-15).ToString("O");
|
||||
var toDate = DateTime.UtcNow.ToString("O");
|
||||
var fromDate = DateTime.Now.AddDays(-15).ToString("MM/dd/yyyy");
|
||||
var toDate = DateTime.Now.ToString("MM/dd/yyyy");
|
||||
|
||||
var response = await HttpClient.GetAsync($"/api/report/GetWorkerSalaries?workerId={worker.Id}&fromDate={fromDate}&toDate={toDate}");
|
||||
|
||||
@@ -177,8 +177,8 @@ public class ReportControllerTests : BaseWebApiControllerTest
|
||||
TwoFromTheCasketDb.InsertSalaryToDatabaseAndReturn(workerId: worker.Id, sum: 1000);
|
||||
TwoFromTheCasketDb.InsertSalaryToDatabaseAndReturn(workerId: worker.Id, sum: 5000);
|
||||
|
||||
var from = DateTime.UtcNow.AddDays(-10).ToString("yyyy-MM-dd");
|
||||
var to = DateTime.UtcNow.AddDays(10).ToString("yyyy-MM-dd");
|
||||
var from = DateTime.Now.AddDays(-10).ToString("MM/dd/yyyy");
|
||||
var to = DateTime.Now.AddDays(10).ToString("MM/dd/yyyy");
|
||||
|
||||
var response = await HttpClient.GetAsync($"/api/report/LoadWorkerSalaries?workerId={worker.Id}&fromDate={from}&toDate={to}");
|
||||
|
||||
|
||||
@@ -76,7 +76,7 @@ public class SalaryControllerTest : BaseWebApiControllerTest
|
||||
[Test]
|
||||
public async Task Try_Calculate_WithOvertimeConfiguration_Test()
|
||||
{
|
||||
var dateValid = new DateTime(2024, 1, 1, 0, 0, 0, DateTimeKind.Utc);
|
||||
var dateValid = DateTime.UtcNow.AddYears(-1);
|
||||
var overtime = new OvertimeSalaryConfiguration { Rate = 100, OvertimeMultiplier = 1.75 };
|
||||
|
||||
var w = TwoFromTheCasketDb.Workers.First(x => x.Id == _worker.Id);
|
||||
@@ -96,7 +96,7 @@ public class SalaryControllerTest : BaseWebApiControllerTest
|
||||
workerId: _worker.Id,
|
||||
numberOfWorkingHour: 10);
|
||||
|
||||
var resp = await HttpClient.GetAsync($"/api/Salary/Calculate/{dateValid:O}");
|
||||
var resp = await HttpClient.GetAsync($"/api/Salary/Calculate/{dateValid:MM/dd/yyyy}");
|
||||
Assert.That(resp.StatusCode, Is.EqualTo(HttpStatusCode.NoContent));
|
||||
|
||||
var sal = TwoFromTheCasketDb.Salaries.First(x => x.WorkerId == _worker.Id);
|
||||
@@ -129,7 +129,7 @@ public class SalaryControllerTest : BaseWebApiControllerTest
|
||||
numberOfWorkingHour: 8
|
||||
);
|
||||
|
||||
var resp = await HttpClient.GetAsync($"/api/Salary/Calculate/{date:O}");
|
||||
var resp = await HttpClient.GetAsync($"/api/Salary/Calculate/{date:MM/dd/yyyy}");
|
||||
Assert.That(resp.StatusCode, Is.EqualTo(HttpStatusCode.NoContent));
|
||||
|
||||
var sal = TwoFromTheCasketDb.Salaries.First(x => x.WorkerId == _worker.Id);
|
||||
@@ -140,7 +140,7 @@ public class SalaryControllerTest : BaseWebApiControllerTest
|
||||
[Test]
|
||||
public async Task Try_Calculate_WhenNoCompletedWork_Test()
|
||||
{
|
||||
var date = new DateTime(2024, 1, 1, 0, 0, 0, DateTimeKind.Utc).ToString("o");
|
||||
var date = DateTime.Now.AddYears(-1).ToString("MM/dd/yyyy");
|
||||
var response = await HttpClient.GetAsync($"api/Salary/Calculate/{date}");
|
||||
|
||||
Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.NoContent));
|
||||
@@ -161,7 +161,7 @@ public class SalaryControllerTest : BaseWebApiControllerTest
|
||||
public async Task Try_Calculate_WhenNoCompletedWorker_Test()
|
||||
{
|
||||
TwoFromTheCasketDb.ClearTables();
|
||||
var date = new DateTime(2024, 1, 1, 0, 0, 0, DateTimeKind.Utc).ToString("o");
|
||||
var date = DateTime.Now.AddYears(-1).ToString("MM/dd/yyyy");
|
||||
var response = await HttpClient.GetAsync($"api/Salary/Calculate/{date}");
|
||||
|
||||
Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.NoContent));
|
||||
@@ -176,8 +176,8 @@ public class SalaryControllerTest : BaseWebApiControllerTest
|
||||
TwoFromTheCasketDb.InsertSalaryToDatabaseAndReturn(workerId: _worker.Id);
|
||||
TwoFromTheCasketDb.InsertSalaryToDatabaseAndReturn(workerId: _worker.Id);
|
||||
|
||||
var from = new DateTime(2000, 1, 1, 0, 0, 0, DateTimeKind.Utc).ToString("o");
|
||||
var to = new DateTime(2100, 1, 1, 0, 0, 0, DateTimeKind.Utc).ToString("o");
|
||||
var from = DateTime.Now.AddYears(-35).ToString("MM/dd/yyyy");
|
||||
var to = DateTime.Now.AddYears(35).ToString("MM/dd/yyyy");
|
||||
|
||||
var response = await HttpClient.GetAsync($"api/Salary/GetListByWorkerByPeriod/{_worker.Id}/{from}/{to}");
|
||||
var list = await GetModelFromResponseAsync<List<SalaryViewModel>>(response);
|
||||
@@ -189,8 +189,8 @@ public class SalaryControllerTest : BaseWebApiControllerTest
|
||||
[Test]
|
||||
public async Task Try_GetListByWorkerByPeriod_WhenInvalidGuid_Test()
|
||||
{
|
||||
var from = new DateTime(2000, 1, 1, 0, 0, 0, DateTimeKind.Utc).ToString("o");
|
||||
var to = new DateTime(2100, 1, 1, 0, 0, 0, DateTimeKind.Utc).ToString("o");
|
||||
var from = DateTime.Now.AddYears(-35).ToString("MM/dd/yyyy");
|
||||
var to = DateTime.Now.AddYears(35).ToString("MM/dd/yyyy");
|
||||
|
||||
var response = await HttpClient.GetAsync($"api/Salary/GetListByWorkerByPeriod/none/{to}/{from}");
|
||||
Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.BadRequest));
|
||||
@@ -199,8 +199,8 @@ public class SalaryControllerTest : BaseWebApiControllerTest
|
||||
[Test]
|
||||
public async Task Try_GetListByWorkerByPeriod_WhenInvalidDates_Test()
|
||||
{
|
||||
var from = new DateTime(2100, 1, 1, 0, 0, 0, DateTimeKind.Utc).ToString("o");
|
||||
var to = new DateTime(2000, 1, 1, 0, 0, 0, DateTimeKind.Utc).ToString("o");
|
||||
var from = DateTime.Now.AddYears(35).ToString("MM/dd/yyyy");
|
||||
var to = DateTime.Now.AddYears(-35).ToString("MM/dd/yyyy");
|
||||
|
||||
var response = await HttpClient.GetAsync($"api/Salary/GetListByWorkerByPeriod/{_worker.Id}/{from}/{to}");
|
||||
Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.BadRequest));
|
||||
@@ -212,8 +212,8 @@ public class SalaryControllerTest : BaseWebApiControllerTest
|
||||
var date = DateTime.SpecifyKind(DateTime.UtcNow, DateTimeKind.Utc);
|
||||
TwoFromTheCasketDb.InsertSalaryToDatabaseAndReturn(workerId: _worker.Id, date: date);
|
||||
|
||||
var from = new DateTime(2000, 1, 1, 0, 0, 0, DateTimeKind.Utc).ToString("o");
|
||||
var to = new DateTime(2100, 1, 1, 0, 0, 0, DateTimeKind.Utc).ToString("o");
|
||||
var from = DateTime.Now.AddYears(-35).ToString("MM/dd/yyyy");
|
||||
var to = DateTime.Now.AddYears(35).ToString("MM/dd/yyyy");
|
||||
|
||||
var response = await HttpClient.GetAsync($"api/Salary/GetListByPeriod/{from}/{to}");
|
||||
|
||||
@@ -228,8 +228,8 @@ public class SalaryControllerTest : BaseWebApiControllerTest
|
||||
[Test]
|
||||
public async Task Try_GetListByPeriod_WhenInvalidDates_Test()
|
||||
{
|
||||
var from = new DateTime(2100, 1, 1, 0, 0, 0, DateTimeKind.Utc).ToString("o");
|
||||
var to = new DateTime(2000, 1, 1, 0, 0, 0, DateTimeKind.Utc).ToString("o");
|
||||
var from = DateTime.Now.AddYears(35).ToString("MM/dd/yyyy");
|
||||
var to = DateTime.Now.AddYears(-35).ToString("MM/dd/yyyy");
|
||||
|
||||
var response = await HttpClient.GetAsync($"api/Salary/GetListByPeriod/{from}/{to}");
|
||||
Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.BadRequest));
|
||||
|
||||
@@ -48,8 +48,8 @@ public class WorkControllerTests : BaseWebApiControllerTest
|
||||
[Test]
|
||||
public async Task Try_GetWorkByData_WhenInvalidRange_Test()
|
||||
{
|
||||
var from = new DateTime(2025, 12, 31).ToString("yyyy-MM-dd");
|
||||
var to = new DateTime(2025, 1, 1).ToString("yyyy-MM-dd");
|
||||
var from = new DateTime(2025, 12, 31).ToString("MM/dd/yyyy");
|
||||
var to = new DateTime(2025, 1, 1).ToString("MM/dd/yyyy");
|
||||
|
||||
var response = await HttpClient.GetAsync($"api/Work/GetWorkByData/{from}/{to}");
|
||||
Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.BadRequest));
|
||||
@@ -58,7 +58,7 @@ public class WorkControllerTests : BaseWebApiControllerTest
|
||||
[Test]
|
||||
public async Task Try_GetElementByDate_WhenNotFound_Test()
|
||||
{
|
||||
var dateStr = new DateTime(2000, 1, 1).ToString("yyyy-MM-dd");
|
||||
var dateStr = new DateTime(2000, 1, 1).ToString("MM/dd/yyyy");
|
||||
var response = await HttpClient.GetAsync($"api/Work/GetWorkByData/{dateStr}");
|
||||
Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.NotFound));
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ internal class WorkDataModelTests
|
||||
Assert.That(work.Id, Is.EqualTo(id));
|
||||
Assert.That(work.Type, Is.EqualTo(type));
|
||||
Assert.That(work.Description, Is.EqualTo(description));
|
||||
Assert.That(work.Date, Is.EqualTo(date));
|
||||
Assert.That(work.Date, Is.EqualTo(date.ToUniversalTime()));
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ using TwoFromTheCasketContracts.DataModels;
|
||||
using TwoFromTheCasketContracts.Exceptions;
|
||||
using TwoFromTheCasketContracts.Enums;
|
||||
using TwoFromTheCasketContracts.Infastructure.SalaryConfiguration;
|
||||
using System.Globalization;
|
||||
|
||||
namespace TwoFromTheCasketTests.DataModelsTests
|
||||
{
|
||||
@@ -239,6 +240,7 @@ namespace TwoFromTheCasketTests.DataModelsTests
|
||||
var birthday = DateTime.Now.AddYears(-25);
|
||||
var config = new SalaryConfiguration { Rate = 150 };
|
||||
|
||||
|
||||
var worker = CreateDataModel(
|
||||
id,
|
||||
fio,
|
||||
@@ -256,10 +258,11 @@ namespace TwoFromTheCasketTests.DataModelsTests
|
||||
Assert.That(worker.FIO, Is.EqualTo(fio));
|
||||
Assert.That(worker.SpecializationId, Is.EqualTo(specId));
|
||||
Assert.That(worker.PhoneNumber, Is.EqualTo(phone));
|
||||
Assert.That(worker.DateBirthDay, Is.EqualTo(birthday));
|
||||
Assert.That(worker.DateBirthDay, Is.EqualTo(birthday.ToUniversalTime()));
|
||||
Assert.That(worker.ConfigurationModel, Is.EqualTo(config));
|
||||
Assert.That(worker.ConfigurationModel.Rate, Is.EqualTo(config.Rate));
|
||||
Assert.That(worker.SpecializationDataModel, Is.EqualTo(specModel));
|
||||
Assert.That(worker.ConfigurationModel.CultureName, Is.Not.Empty);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -9,5 +9,5 @@ namespace TwoFromTheCasketTests.Infrastructure;
|
||||
|
||||
public class ConfigurationDatabaseTest : IConfigurationDatabase
|
||||
{
|
||||
public string ConnectionString => "Host=localhost;Port=5432;Database=TwoFromTheCasketDb;Username=postgres;Password=1234";
|
||||
public string ConnectionString => "Host=localhost;Port=5432;Database=TwoFromTheCasketDb;Username=postgres;Password=123456";
|
||||
}
|
||||
@@ -1,21 +1,23 @@
|
||||
using AutoMapper;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using TwoFromTheCasketContracts.AdapterContracts;
|
||||
using TwoFromTheCasketContracts.AdapterContracts.OperationResponses;
|
||||
using TwoFromTheCasketContracts.BindingModels;
|
||||
using TwoFromTheCasketContracts.BusinessLogicsContracts;
|
||||
using TwoFromTheCasketContracts.DataModels;
|
||||
using TwoFromTheCasketContracts.Exceptions;
|
||||
using TwoFromTheCasketContracts.Resources;
|
||||
using TwoFromTheCasketContracts.ViewModels;
|
||||
|
||||
namespace TwoFromTheCasketWebApi.Adapters;
|
||||
|
||||
public class ComplitedWorkAdapter : IComplitedWorkAdapter
|
||||
internal class ComplitedWorkAdapter : IComplitedWorkAdapter
|
||||
{
|
||||
private readonly IComplitedWorkBusinessLogicContract _complitedWorkBusinessLogic;
|
||||
private readonly ILogger _logger;
|
||||
private readonly Mapper _mapper;
|
||||
|
||||
public ComplitedWorkAdapter(IComplitedWorkBusinessLogicContract complitedWorkBusinessLogic, ILogger<ComplitedWorkAdapter> logger)
|
||||
private readonly IStringLocalizer<Messages> _localizer;
|
||||
public ComplitedWorkAdapter(IComplitedWorkBusinessLogicContract complitedWorkBusinessLogic, ILogger<ComplitedWorkAdapter> logger, IStringLocalizer<Messages> localizer)
|
||||
{
|
||||
_complitedWorkBusinessLogic = complitedWorkBusinessLogic;
|
||||
_logger = logger;
|
||||
@@ -28,6 +30,7 @@ public class ComplitedWorkAdapter : IComplitedWorkAdapter
|
||||
cfg.CreateMap<WorkerComplitedWorkDataModel, WorkerComplitedWorkViewModel>();
|
||||
});
|
||||
|
||||
_localizer = localizer;
|
||||
_mapper = new Mapper(config);
|
||||
}
|
||||
|
||||
@@ -35,28 +38,28 @@ public class ComplitedWorkAdapter : IComplitedWorkAdapter
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = _complitedWorkBusinessLogic.GetComplitedWorksByPeriod(fromDate, toDate);
|
||||
var result = _complitedWorkBusinessLogic.GetComplitedWorksByPeriod(fromDate.ToUniversalTime(), toDate.ToUniversalTime());
|
||||
return ComplitedWorkOperationResponse.OK(result.Select(x => _mapper.Map<ComplitedWorkViewModel>(x)).ToList());
|
||||
}
|
||||
catch (IncorrectDatesException ex)
|
||||
{
|
||||
_logger.LogError(ex, "IncorrectDatesException");
|
||||
return ComplitedWorkOperationResponse.BadRequest($"Incorrect dates: {ex.Message}");
|
||||
return ComplitedWorkOperationResponse.BadRequest(_localizer["AdapterMessageIncorrectDates", ex.Message]);
|
||||
}
|
||||
catch (NullListException)
|
||||
{
|
||||
_logger.LogError("NullListException");
|
||||
return ComplitedWorkOperationResponse.NotFound("The list is not initialized");
|
||||
return ComplitedWorkOperationResponse.NotFound(_localizer["NullListExceptionCaption"]);
|
||||
}
|
||||
catch (StorageException ex)
|
||||
{
|
||||
_logger.LogError(ex, "StorageException");
|
||||
return ComplitedWorkOperationResponse.InternalServerError($"Error while working with data storage: {ex.InnerException!.Message}");
|
||||
return ComplitedWorkOperationResponse.InternalServerError(_localizer["AdapterMessageStorageException", ex.InnerException!.Message]);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Exception");
|
||||
return ComplitedWorkOperationResponse.InternalServerError(ex.Message);
|
||||
return ComplitedWorkOperationResponse.InternalServerError(_localizer["AdapterMessageUnhandledException", ex.Message]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,67 +67,68 @@ public class ComplitedWorkAdapter : IComplitedWorkAdapter
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = _complitedWorkBusinessLogic.GetComplitedWorksByRoomByPeriod(roomId, fromDate, toDate);
|
||||
var result = _complitedWorkBusinessLogic.GetComplitedWorksByRoomByPeriod(roomId, fromDate.ToUniversalTime(), toDate.ToUniversalTime());
|
||||
return ComplitedWorkOperationResponse.OK(result.Select(x => _mapper.Map<ComplitedWorkViewModel>(x)).ToList());
|
||||
}
|
||||
catch (IncorrectDatesException ex)
|
||||
{
|
||||
_logger.LogError(ex, "IncorrectDatesException");
|
||||
return ComplitedWorkOperationResponse.BadRequest($"Incorrect dates: {ex.Message}");
|
||||
return ComplitedWorkOperationResponse.BadRequest(_localizer["AdapterMessageIncorrectDates", ex.Message]);
|
||||
}
|
||||
catch (ValidationException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ValidationException");
|
||||
return ComplitedWorkOperationResponse.BadRequest($"Incorrect data transmitted: {ex.Message}");
|
||||
return ComplitedWorkOperationResponse.BadRequest(_localizer["AdapterMessageValidationException", ex.Message]);
|
||||
}
|
||||
catch (NullListException)
|
||||
{
|
||||
_logger.LogError("NullListException");
|
||||
return ComplitedWorkOperationResponse.NotFound("The list is not initialized");
|
||||
return ComplitedWorkOperationResponse.NotFound(_localizer["NullListExceptionCaption"]);
|
||||
}
|
||||
catch (StorageException ex)
|
||||
{
|
||||
_logger.LogError(ex, "StorageException");
|
||||
return ComplitedWorkOperationResponse.InternalServerError($"Error while working with data storage: {ex.InnerException!.Message}");
|
||||
return ComplitedWorkOperationResponse.InternalServerError(_localizer["AdapterMessageStorageException", ex.InnerException!.Message]);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Exception");
|
||||
return ComplitedWorkOperationResponse.InternalServerError(ex.Message);
|
||||
return ComplitedWorkOperationResponse.InternalServerError(_localizer["AdapterMessageUnhandledException", ex.Message]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public ComplitedWorkOperationResponse GetListByWorkTypeByPeriod(string workId, DateTime fromDate, DateTime toDate)
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = _complitedWorkBusinessLogic.GetComplitedWorksByWorkTypeByPeriod(workId, fromDate, toDate);
|
||||
var result = _complitedWorkBusinessLogic.GetComplitedWorksByWorkTypeByPeriod(workId, fromDate.ToUniversalTime(), toDate.ToUniversalTime());
|
||||
return ComplitedWorkOperationResponse.OK(result.Select(x => _mapper.Map<ComplitedWorkViewModel>(x)).ToList());
|
||||
}
|
||||
catch (IncorrectDatesException ex)
|
||||
{
|
||||
_logger.LogError(ex, "IncorrectDatesException");
|
||||
return ComplitedWorkOperationResponse.BadRequest($"Incorrect dates: {ex.Message}");
|
||||
return ComplitedWorkOperationResponse.BadRequest(_localizer["AdapterMessageIncorrectDates", ex.Message]);
|
||||
}
|
||||
catch (ValidationException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ValidationException");
|
||||
return ComplitedWorkOperationResponse.BadRequest($"Incorrect data transmitted: {ex.Message}");
|
||||
return ComplitedWorkOperationResponse.BadRequest(_localizer["AdapterMessageValidationException", ex.Message]);
|
||||
}
|
||||
catch (NullListException)
|
||||
{
|
||||
_logger.LogError("NullListException");
|
||||
return ComplitedWorkOperationResponse.NotFound("The list is not initialized");
|
||||
return ComplitedWorkOperationResponse.NotFound(_localizer["NullListExceptionCaption"]);
|
||||
}
|
||||
catch (StorageException ex)
|
||||
{
|
||||
_logger.LogError(ex, "StorageException");
|
||||
return ComplitedWorkOperationResponse.InternalServerError($"Error while working with data storage: {ex.InnerException!.Message}");
|
||||
return ComplitedWorkOperationResponse.InternalServerError(_localizer["AdapterMessageStorageException", ex.InnerException!.Message]);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Exception");
|
||||
return ComplitedWorkOperationResponse.InternalServerError(ex.Message);
|
||||
return ComplitedWorkOperationResponse.InternalServerError(_localizer["AdapterMessageUnhandledException", ex.Message]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -132,33 +136,33 @@ public class ComplitedWorkAdapter : IComplitedWorkAdapter
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = _complitedWorkBusinessLogic.GetComplitedWorksByWorkerByPeriod(workerId, fromDate, toDate);
|
||||
var result = _complitedWorkBusinessLogic.GetComplitedWorksByWorkerByPeriod(workerId, fromDate.ToUniversalTime(), toDate.ToUniversalTime());
|
||||
return ComplitedWorkOperationResponse.OK(result.Select(x => _mapper.Map<ComplitedWorkViewModel>(x)).ToList());
|
||||
}
|
||||
catch (IncorrectDatesException ex)
|
||||
{
|
||||
_logger.LogError(ex, "IncorrectDatesException");
|
||||
return ComplitedWorkOperationResponse.BadRequest($"Incorrect dates: {ex.Message}");
|
||||
return ComplitedWorkOperationResponse.BadRequest(_localizer["AdapterMessageIncorrectDates", ex.Message]);
|
||||
}
|
||||
catch (ValidationException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ValidationException");
|
||||
return ComplitedWorkOperationResponse.BadRequest($"Incorrect data transmitted: {ex.Message}");
|
||||
return ComplitedWorkOperationResponse.BadRequest(_localizer["AdapterMessageValidationException", ex.Message]);
|
||||
}
|
||||
catch (NullListException)
|
||||
{
|
||||
_logger.LogError("NullListException");
|
||||
return ComplitedWorkOperationResponse.NotFound("The list is not initialized");
|
||||
return ComplitedWorkOperationResponse.NotFound(_localizer["NullListExceptionCaption"]);
|
||||
}
|
||||
catch (StorageException ex)
|
||||
{
|
||||
_logger.LogError(ex, "StorageException");
|
||||
return ComplitedWorkOperationResponse.InternalServerError($"Error while working with data storage: {ex.InnerException!.Message}");
|
||||
return ComplitedWorkOperationResponse.InternalServerError(_localizer["AdapterMessageStorageException", ex.InnerException!.Message]);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Exception");
|
||||
return ComplitedWorkOperationResponse.InternalServerError(ex.Message);
|
||||
return ComplitedWorkOperationResponse.InternalServerError(_localizer["AdapterMessageUnhandledException", ex.Message]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -172,22 +176,22 @@ public class ComplitedWorkAdapter : IComplitedWorkAdapter
|
||||
catch (ArgumentNullException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ArgumentNullException");
|
||||
return ComplitedWorkOperationResponse.BadRequest("Data is empty");
|
||||
return ComplitedWorkOperationResponse.BadRequest(_localizer["AdapterMessageArgumentNullException"]);
|
||||
}
|
||||
catch (ElementNotFoundException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ElementNotFoundException");
|
||||
return ComplitedWorkOperationResponse.NotFound($"Not found element by data {data}");
|
||||
return ComplitedWorkOperationResponse.NotFound(_localizer["AdapterMessageElementNotFound", data]);
|
||||
}
|
||||
catch (StorageException ex)
|
||||
{
|
||||
_logger.LogError(ex, "StorageException");
|
||||
return ComplitedWorkOperationResponse.InternalServerError($"Error while working with data storage: {ex.InnerException!.Message}");
|
||||
return ComplitedWorkOperationResponse.InternalServerError(_localizer["AdapterMessageStorageException", ex.InnerException!.Message]);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Exception");
|
||||
return ComplitedWorkOperationResponse.InternalServerError(ex.Message);
|
||||
return ComplitedWorkOperationResponse.InternalServerError(_localizer["AdapterMessageUnhandledException", ex.Message]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -201,27 +205,27 @@ public class ComplitedWorkAdapter : IComplitedWorkAdapter
|
||||
catch (ArgumentNullException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ArgumentNullException");
|
||||
return ComplitedWorkOperationResponse.BadRequest("Data is empty");
|
||||
return ComplitedWorkOperationResponse.BadRequest(_localizer["AdapterMessageArgumentNullException"]);
|
||||
}
|
||||
catch (ValidationException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ValidationException");
|
||||
return ComplitedWorkOperationResponse.BadRequest($"Incorrect data transmitted: {ex.Message}");
|
||||
return ComplitedWorkOperationResponse.BadRequest(_localizer["AdapterMessageValidationException", ex.Message]);
|
||||
}
|
||||
catch (ElementExistsException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ElementExistsException");
|
||||
return ComplitedWorkOperationResponse.BadRequest(ex.Message);
|
||||
return ComplitedWorkOperationResponse.BadRequest(_localizer["AdapterMessageElementExists", ex.ParamName, ex.ParamValue]);
|
||||
}
|
||||
catch (StorageException ex)
|
||||
{
|
||||
_logger.LogError(ex, "StorageException");
|
||||
return ComplitedWorkOperationResponse.InternalServerError($"Error while working with data storage: {ex.InnerException!.Message}");
|
||||
return ComplitedWorkOperationResponse.InternalServerError(_localizer["AdapterMessageStorageException", ex.InnerException!.Message]);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Exception");
|
||||
return ComplitedWorkOperationResponse.InternalServerError(ex.Message);
|
||||
return ComplitedWorkOperationResponse.InternalServerError(_localizer["AdapterMessageUnhandledException", ex.Message]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -235,27 +239,27 @@ public class ComplitedWorkAdapter : IComplitedWorkAdapter
|
||||
catch (ArgumentNullException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ArgumentNullException");
|
||||
return ComplitedWorkOperationResponse.BadRequest("Id is empty");
|
||||
return ComplitedWorkOperationResponse.BadRequest(_localizer["AdapterMessageArgumentNullException"]);
|
||||
}
|
||||
catch (ValidationException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ValidationException");
|
||||
return ComplitedWorkOperationResponse.BadRequest($"Incorrect data transmitted: {ex.Message}");
|
||||
return ComplitedWorkOperationResponse.BadRequest(_localizer["AdapterMessageValidationException", ex.Message]);
|
||||
}
|
||||
catch (ElementNotFoundException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ElementNotFoundException");
|
||||
return ComplitedWorkOperationResponse.NotFound($"Not found element by id: {id}");
|
||||
return ComplitedWorkOperationResponse.NotFound(_localizer["AdapterMessageElementNotFound", id]);
|
||||
}
|
||||
catch (StorageException ex)
|
||||
{
|
||||
_logger.LogError(ex, "StorageException");
|
||||
return ComplitedWorkOperationResponse.InternalServerError($"Error while working with data storage: {ex.InnerException!.Message}");
|
||||
return ComplitedWorkOperationResponse.InternalServerError(_localizer["AdapterMessageStorageException", ex.InnerException!.Message]);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Exception");
|
||||
return ComplitedWorkOperationResponse.InternalServerError(ex.Message);
|
||||
return ComplitedWorkOperationResponse.InternalServerError(_localizer["AdapterMessageUnhandledException", ex.Message]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using AutoMapper;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using TwoFromTheCasketBusinessLogic.Implementation;
|
||||
using TwoFromTheCasketContracts.AdapterContracts;
|
||||
@@ -6,20 +7,23 @@ using TwoFromTheCasketContracts.AdapterContracts.OperationResponses;
|
||||
using TwoFromTheCasketContracts.BusinessLogicsContracts;
|
||||
using TwoFromTheCasketContracts.DataModels;
|
||||
using TwoFromTheCasketContracts.Exceptions;
|
||||
using TwoFromTheCasketContracts.Resources;
|
||||
using TwoFromTheCasketContracts.ViewModels;
|
||||
|
||||
namespace TwoFromTheCasketWebApi.Adapters;
|
||||
|
||||
public class ReportAdapter : IReportAdapter
|
||||
internal class ReportAdapter : IReportAdapter
|
||||
{
|
||||
private readonly IReportContract _reportLogic;
|
||||
private readonly ILogger<ReportAdapter> _logger;
|
||||
private readonly Mapper _mapper;
|
||||
private readonly IStringLocalizer<Messages> _localizer;
|
||||
|
||||
public ReportAdapter(IReportContract reportLogic, ILogger<ReportAdapter> logger)
|
||||
public ReportAdapter(IReportContract reportLogic, ILogger<ReportAdapter> logger, IStringLocalizer<Messages> localizer)
|
||||
{
|
||||
_reportLogic = reportLogic;
|
||||
_logger = logger;
|
||||
_localizer = localizer;
|
||||
|
||||
var config = new MapperConfiguration(cfg =>
|
||||
{
|
||||
@@ -51,26 +55,27 @@ public class ReportAdapter : IReportAdapter
|
||||
{
|
||||
try
|
||||
{
|
||||
var stream = await _reportLogic.CreateDocumentComplitedWorksAsync(from, to, ct);
|
||||
var stream = await _reportLogic.CreateDocumentComplitedWorksAsync(from.ToUniversalTime(), to.ToUniversalTime(), ct);
|
||||
return ReportOperationResponse.OK(stream, "complited_works.xlsx");
|
||||
}
|
||||
catch (IncorrectDatesException ex)
|
||||
{
|
||||
_logger.LogError(ex, "IncorrectDatesException");
|
||||
return ReportOperationResponse.BadRequest($"Некорректный диапазон дат: {ex.Message}");
|
||||
return ReportOperationResponse.BadRequest(_localizer["AdapterMessageIncorrectDates", ex.Message]);
|
||||
}
|
||||
catch (StorageException ex)
|
||||
{
|
||||
_logger.LogError(ex, "StorageException");
|
||||
return ReportOperationResponse.InternalServerError($"Ошибка при обращении к хранилищу: {ex.InnerException?.Message}");
|
||||
return ReportOperationResponse.InternalServerError(_localizer["AdapterMessageStorageException", ex.InnerException?.Message ?? ex.Message]);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Unhandled Exception");
|
||||
return ReportOperationResponse.InternalServerError($"Непредвиденная ошибка: {ex.Message}");
|
||||
return ReportOperationResponse.InternalServerError(_localizer["AdapterMessageUnhandledException", ex.Message]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public async Task<ReportOperationResponse> CreateDocumentRoomHistoryAsync(CancellationToken ct)
|
||||
{
|
||||
try
|
||||
@@ -80,18 +85,17 @@ public class ReportAdapter : IReportAdapter
|
||||
catch (InvalidOperationException ex)
|
||||
{
|
||||
_logger.LogError(ex, "InvalidOperationException");
|
||||
return ReportOperationResponse.InternalServerError($"Error while working with data storage: {ex.InnerException!.Message}");
|
||||
return ReportOperationResponse.InternalServerError(_localizer["AdapterMessageInvalidOperationException", ex.InnerException?.Message ?? ex.Message]);
|
||||
}
|
||||
catch (StorageException ex)
|
||||
{
|
||||
_logger.LogError(ex, "StorageException");
|
||||
return ReportOperationResponse.InternalServerError($"Error while working with data storage: {ex.InnerException!.Message}");
|
||||
return ReportOperationResponse.InternalServerError(_localizer["AdapterMessageStorageException", ex.InnerException?.Message ?? ex.Message]);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Exception");
|
||||
return
|
||||
ReportOperationResponse.InternalServerError(ex.Message);
|
||||
return ReportOperationResponse.InternalServerError(_localizer["AdapterMessageUnhandledException", ex.Message]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,63 +103,62 @@ public class ReportAdapter : IReportAdapter
|
||||
{
|
||||
try
|
||||
{
|
||||
var stream = await _reportLogic.CreateDocumentSalaryByWorkerAsync(workerId, from, to, ct);
|
||||
var stream = await _reportLogic.CreateDocumentSalaryByWorkerAsync(workerId, from.ToUniversalTime(), to.ToUniversalTime(), ct);
|
||||
return ReportOperationResponse.OK(stream, "salary.pdf");
|
||||
}
|
||||
catch (ArgumentNullException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ArgumentNullException");
|
||||
return ReportOperationResponse.BadRequest("Worker ID cannot be null or empty.");
|
||||
return ReportOperationResponse.BadRequest(_localizer["AdapterMessageArgumentNullException"]);
|
||||
}
|
||||
catch (ValidationException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ValidationException");
|
||||
return ReportOperationResponse.BadRequest("Invalid worker ID format.");
|
||||
return ReportOperationResponse.BadRequest(_localizer["AdapterMessageValidationException", ex.Message]);
|
||||
}
|
||||
catch (IncorrectDatesException ex)
|
||||
{
|
||||
_logger.LogError(ex, "IncorrectDatesException");
|
||||
return ReportOperationResponse.BadRequest($"Invalid dates: {ex.Message}");
|
||||
return ReportOperationResponse.BadRequest(_localizer["AdapterMessageIncorrectDates", ex.Message]);
|
||||
}
|
||||
catch (InvalidOperationException ex)
|
||||
{
|
||||
_logger.LogError(ex, "InvalidOperationException");
|
||||
return ReportOperationResponse.BadRequest("Salary data not found.");
|
||||
return ReportOperationResponse.BadRequest(_localizer["AdapterMessageSalaryDataNotFound"]);
|
||||
}
|
||||
catch (StorageException ex)
|
||||
{
|
||||
_logger.LogError(ex, "StorageException");
|
||||
return ReportOperationResponse.InternalServerError($"Storage error: {ex.InnerException?.Message ?? ex.Message}");
|
||||
return ReportOperationResponse.InternalServerError(_localizer["AdapterMessageStorageException", ex.InnerException?.Message ?? ex.Message]);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Unhandled exception");
|
||||
return ReportOperationResponse.InternalServerError(ex.Message);
|
||||
return ReportOperationResponse.InternalServerError(_localizer["AdapterMessageUnhandledException", ex.Message]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public async Task<ReportOperationResponse> GetComplitedWorksByPeriodAsync(DateTime from, DateTime to, CancellationToken ct)
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = await _reportLogic.GetComplitedWorksByPeriodAsync(from, to, ct);
|
||||
var result = await _reportLogic.GetComplitedWorksByPeriodAsync(from.ToUniversalTime(), to.ToUniversalTime(), ct);
|
||||
return ReportOperationResponse.OK(result);
|
||||
}
|
||||
catch (IncorrectDatesException ex)
|
||||
{
|
||||
_logger.LogError(ex, "IncorrectDatesException");
|
||||
return ReportOperationResponse.BadRequest($"Некорректный период: {ex.Message}");
|
||||
return ReportOperationResponse.BadRequest(_localizer["AdapterMessageIncorrectDates", ex.Message]);
|
||||
}
|
||||
catch (StorageException ex)
|
||||
{
|
||||
_logger.LogError(ex, "StorageException");
|
||||
return ReportOperationResponse.InternalServerError($"Ошибка при работе с хранилищем: {ex.InnerException?.Message}");
|
||||
return ReportOperationResponse.InternalServerError(_localizer["AdapterMessageStorageException", ex.InnerException?.Message ?? ex.Message]);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Exception");
|
||||
return ReportOperationResponse.InternalServerError(ex.Message);
|
||||
return ReportOperationResponse.InternalServerError(_localizer["AdapterMessageUnhandledException", ex.Message]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -170,47 +173,46 @@ public class ReportAdapter : IReportAdapter
|
||||
catch (InvalidOperationException ex)
|
||||
{
|
||||
_logger.LogError(ex, "InvalidOperationException");
|
||||
return ReportOperationResponse.BadRequest("Data is not initialized");
|
||||
return ReportOperationResponse.BadRequest(_localizer["AdapterMessageInvalidOperationException", ex.InnerException?.Message ?? ex.Message]);
|
||||
}
|
||||
catch (StorageException ex)
|
||||
{
|
||||
_logger.LogError(ex, "StorageException");
|
||||
return ReportOperationResponse.InternalServerError($"Storage error: {ex.InnerException?.Message ?? ex.Message}");
|
||||
return ReportOperationResponse.InternalServerError(_localizer["AdapterMessageStorageException", ex.InnerException?.Message ?? ex.Message]);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Unhandled exception");
|
||||
return ReportOperationResponse.InternalServerError(ex.Message);
|
||||
return ReportOperationResponse.InternalServerError(_localizer["AdapterMessageUnhandledException", ex.Message]);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<ReportOperationResponse> GetWorkerSalariesByPeriodAsync(string workerId, DateTime from, DateTime to, CancellationToken ct)
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = await _reportLogic.GetWorkerSalariesByPeriodAsync(workerId, from, to, ct);
|
||||
var result = await _reportLogic.GetWorkerSalariesByPeriodAsync(workerId, from.ToUniversalTime(), to.ToUniversalTime(), ct);
|
||||
var mapped = result.Select(x => _mapper.Map<SalaryByWorkerReportViewModel>(x)).ToList();
|
||||
return ReportOperationResponse.OK(mapped);
|
||||
}
|
||||
catch (IncorrectDatesException ex)
|
||||
{
|
||||
_logger.LogError(ex, "IncorrectDatesException");
|
||||
return ReportOperationResponse.BadRequest("The end date must be later than the start date.");
|
||||
return ReportOperationResponse.BadRequest(_localizer["AdapterMessageIncorrectDates", ex.Message]);
|
||||
}
|
||||
catch (ArgumentNullException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ArgumentNullException");
|
||||
return ReportOperationResponse.BadRequest("Worker ID must be provided.");
|
||||
return ReportOperationResponse.BadRequest(_localizer["AdapterMessageArgumentNullException"]);
|
||||
}
|
||||
catch (StorageException ex)
|
||||
{
|
||||
_logger.LogError(ex, "StorageException");
|
||||
return ReportOperationResponse.InternalServerError($"Storage error: {ex.InnerException?.Message ?? ex.Message}");
|
||||
return ReportOperationResponse.InternalServerError(_localizer["AdapterMessageStorageException", ex.InnerException?.Message ?? ex.Message]);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Unhandled exception");
|
||||
return ReportOperationResponse.InternalServerError(ex.Message);
|
||||
return ReportOperationResponse.InternalServerError(_localizer["AdapterMessageUnhandledException", ex.Message]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,20 +1,37 @@
|
||||
using AutoMapper;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using TwoFromTheCasketContracts.AdapterContracts;
|
||||
using TwoFromTheCasketContracts.AdapterContracts.OperationResponses;
|
||||
using TwoFromTheCasketContracts.BindingModels;
|
||||
using TwoFromTheCasketContracts.BusinessLogicsContracts;
|
||||
using TwoFromTheCasketContracts.DataModels;
|
||||
using TwoFromTheCasketContracts.Exceptions;
|
||||
using TwoFromTheCasketContracts.Resources;
|
||||
using TwoFromTheCasketContracts.ViewModels;
|
||||
|
||||
namespace TwoFromTheCasketWebApi.Adapters;
|
||||
|
||||
public class RoomAdapter : IRoomAdapter
|
||||
internal class RoomAdapter : IRoomAdapter
|
||||
{
|
||||
private readonly IRoomBusinessLogicContract _roomBusinessLogic;
|
||||
private readonly ILogger _logger;
|
||||
private readonly Mapper _mapper;
|
||||
private readonly IStringLocalizer<Messages> _localizer;
|
||||
|
||||
public RoomAdapter(IRoomBusinessLogicContract roomBusinessLogic, ILogger<RoomAdapter> logger, IStringLocalizer<Messages> localizer)
|
||||
{
|
||||
_roomBusinessLogic = roomBusinessLogic;
|
||||
_logger = logger;
|
||||
_localizer = localizer;
|
||||
|
||||
var config = new MapperConfiguration(cfg =>
|
||||
{
|
||||
cfg.CreateMap<RoomBindingModel, RoomDataModel>();
|
||||
cfg.CreateMap<RoomDataModel, RoomViewModel>();
|
||||
});
|
||||
|
||||
_mapper = new Mapper(config);
|
||||
}
|
||||
public RoomOperationResponse GetList()
|
||||
{
|
||||
try
|
||||
@@ -25,30 +42,18 @@ public class RoomAdapter : IRoomAdapter
|
||||
}
|
||||
catch (NullListException)
|
||||
{
|
||||
return RoomOperationResponse.NotFound("Room list is null.");
|
||||
return RoomOperationResponse.NotFound(_localizer["NullListExceptionCaption"]);
|
||||
}
|
||||
catch (StorageException ex)
|
||||
{
|
||||
return RoomOperationResponse.InternalServerError($"Storage error: {ex.InnerException?.Message}");
|
||||
return RoomOperationResponse.InternalServerError(_localizer["AdapterMessageStorageException", ex.InnerException?.Message ?? ex.Message]);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return RoomOperationResponse.InternalServerError(ex.Message);
|
||||
return RoomOperationResponse.InternalServerError(_localizer["AdapterMessageUnhandledException", ex.Message]);
|
||||
}
|
||||
}
|
||||
public RoomAdapter(IRoomBusinessLogicContract roomBusinessLogic, ILogger<RoomAdapter> logger)
|
||||
{
|
||||
_roomBusinessLogic = roomBusinessLogic;
|
||||
_logger = logger;
|
||||
|
||||
var config = new MapperConfiguration(cfg =>
|
||||
{
|
||||
cfg.CreateMap<RoomBindingModel, RoomDataModel>();
|
||||
cfg.CreateMap<RoomDataModel, RoomViewModel>();
|
||||
});
|
||||
|
||||
_mapper = new Mapper(config);
|
||||
}
|
||||
|
||||
public RoomOperationResponse GetListByOwner(string ownerFIO)
|
||||
{
|
||||
@@ -56,28 +61,27 @@ public class RoomAdapter : IRoomAdapter
|
||||
{
|
||||
var result = _roomBusinessLogic.GetRoomsByOwner(ownerFIO);
|
||||
if (result == null || result.Count == 0)
|
||||
throw new NullListException();
|
||||
throw new NullListException(_localizer);
|
||||
|
||||
return RoomOperationResponse.OK(result.Select(x => _mapper.Map<RoomViewModel>(x)).ToList());
|
||||
}
|
||||
catch (ArgumentNullException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ArgumentNullException");
|
||||
return RoomOperationResponse.BadRequest("OwnerFIO is empty");
|
||||
return RoomOperationResponse.BadRequest(_localizer["AdapterMessageArgumentNullException"]);
|
||||
}
|
||||
catch (NullListException)
|
||||
{
|
||||
_logger.LogError("NullListException");
|
||||
return RoomOperationResponse.NotFound("No rooms found for the given owner");
|
||||
return RoomOperationResponse.NotFound(_localizer["AdapterMessageNoRoomsForOwner"]);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Unhandled exception");
|
||||
return RoomOperationResponse.InternalServerError(ex.Message);
|
||||
return RoomOperationResponse.InternalServerError(_localizer["AdapterMessageUnhandledException", ex.Message]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public RoomOperationResponse GetListByAddress(string address)
|
||||
{
|
||||
try
|
||||
@@ -85,7 +89,7 @@ public class RoomAdapter : IRoomAdapter
|
||||
var result = _roomBusinessLogic.GetRoomsByAddress(address);
|
||||
if (result == null || result.Count == 0)
|
||||
{
|
||||
return RoomOperationResponse.NotFound("No rooms found with this address.");
|
||||
return RoomOperationResponse.NotFound(_localizer["AdapterMessageNoRoomsForAddress"]);
|
||||
}
|
||||
|
||||
return RoomOperationResponse.OK(result.Select(x => _mapper.Map<RoomViewModel>(x)).ToList());
|
||||
@@ -93,17 +97,17 @@ public class RoomAdapter : IRoomAdapter
|
||||
catch (ArgumentNullException ex)
|
||||
{
|
||||
_logger.LogError(ex, "Address is null");
|
||||
return RoomOperationResponse.BadRequest("Address is required.");
|
||||
return RoomOperationResponse.BadRequest(_localizer["AdapterMessageArgumentNullException"]);
|
||||
}
|
||||
catch (StorageException ex)
|
||||
{
|
||||
_logger.LogError(ex, "Storage error");
|
||||
return RoomOperationResponse.InternalServerError(ex.Message);
|
||||
return RoomOperationResponse.InternalServerError(_localizer["AdapterMessageStorageException", ex.InnerException?.Message ?? ex.Message]);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Unhandled exception");
|
||||
return RoomOperationResponse.InternalServerError(ex.Message);
|
||||
return RoomOperationResponse.InternalServerError(_localizer["AdapterMessageUnhandledException", ex.Message]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -117,27 +121,27 @@ public class RoomAdapter : IRoomAdapter
|
||||
catch (ArgumentNullException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ArgumentNullException");
|
||||
return RoomOperationResponse.BadRequest("Data is empty");
|
||||
return RoomOperationResponse.BadRequest(_localizer["AdapterMessageArgumentNullException"]);
|
||||
}
|
||||
catch (ValidationException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ValidationException");
|
||||
return RoomOperationResponse.BadRequest($"Incorrect data: {ex.Message}");
|
||||
return RoomOperationResponse.BadRequest(_localizer["AdapterMessageValidationException", ex.Message]);
|
||||
}
|
||||
catch (ElementNotFoundException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ElementNotFoundException");
|
||||
return RoomOperationResponse.NotFound($"Not found element by data: {data}");
|
||||
return RoomOperationResponse.NotFound(_localizer["AdapterMessageElementNotFound", data]);
|
||||
}
|
||||
catch (StorageException ex)
|
||||
{
|
||||
_logger.LogError(ex, "StorageException");
|
||||
return RoomOperationResponse.InternalServerError($"Error while working with data storage: {ex.InnerException!.Message}");
|
||||
return RoomOperationResponse.InternalServerError(_localizer["AdapterMessageStorageException", ex.InnerException?.Message ?? ex.Message]);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Exception");
|
||||
return RoomOperationResponse.InternalServerError(ex.Message);
|
||||
return RoomOperationResponse.InternalServerError(_localizer["AdapterMessageUnhandledException", ex.Message]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -151,27 +155,27 @@ public class RoomAdapter : IRoomAdapter
|
||||
catch (ArgumentNullException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ArgumentNullException");
|
||||
return RoomOperationResponse.BadRequest("Data is empty");
|
||||
return RoomOperationResponse.BadRequest(_localizer["AdapterMessageArgumentNullException"]);
|
||||
}
|
||||
catch (ValidationException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ValidationException");
|
||||
return RoomOperationResponse.BadRequest($"Incorrect data transmitted: {ex.Message}");
|
||||
return RoomOperationResponse.BadRequest(_localizer["AdapterMessageValidationException", ex.Message]);
|
||||
}
|
||||
catch (ElementExistsException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ElementExistsException");
|
||||
return RoomOperationResponse.BadRequest(ex.Message);
|
||||
return RoomOperationResponse.BadRequest(_localizer["AdapterMessageElementExists", ex.ParamName, ex.ParamValue]);
|
||||
}
|
||||
catch (StorageException ex)
|
||||
{
|
||||
_logger.LogError(ex, "StorageException");
|
||||
return RoomOperationResponse.InternalServerError($"Error while working with data storage: {ex.InnerException!.Message}");
|
||||
return RoomOperationResponse.InternalServerError(_localizer["AdapterMessageStorageException", ex.InnerException?.Message ?? ex.Message]);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Exception");
|
||||
return RoomOperationResponse.InternalServerError(ex.Message);
|
||||
return RoomOperationResponse.InternalServerError(_localizer["AdapterMessageUnhandledException", ex.Message]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -185,32 +189,32 @@ public class RoomAdapter : IRoomAdapter
|
||||
catch (ArgumentNullException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ArgumentNullException");
|
||||
return RoomOperationResponse.BadRequest("Data is empty");
|
||||
return RoomOperationResponse.BadRequest(_localizer["AdapterMessageArgumentNullException"]);
|
||||
}
|
||||
catch (ValidationException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ValidationException");
|
||||
return RoomOperationResponse.BadRequest($"Incorrect data transmitted: {ex.Message}");
|
||||
return RoomOperationResponse.BadRequest(_localizer["AdapterMessageValidationException", ex.Message]);
|
||||
}
|
||||
catch (ElementNotFoundException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ElementNotFoundException");
|
||||
return RoomOperationResponse.NotFound($"Not found element by Id {model.Id}");
|
||||
return RoomOperationResponse.NotFound(_localizer["AdapterMessageElementNotFound", model.Id]);
|
||||
}
|
||||
catch (ElementExistsException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ElementExistsException");
|
||||
return RoomOperationResponse.BadRequest(ex.Message);
|
||||
return RoomOperationResponse.BadRequest(_localizer["AdapterMessageElementExists", ex.ParamName, ex.ParamValue]);
|
||||
}
|
||||
catch (StorageException ex)
|
||||
{
|
||||
_logger.LogError(ex, "StorageException");
|
||||
return RoomOperationResponse.BadRequest($"Error while working with data storage: {ex.InnerException!.Message}");
|
||||
return RoomOperationResponse.InternalServerError(_localizer["AdapterMessageStorageException", ex.InnerException?.Message ?? ex.Message]);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Exception");
|
||||
return RoomOperationResponse.InternalServerError(ex.Message);
|
||||
return RoomOperationResponse.InternalServerError(_localizer["AdapterMessageUnhandledException", ex.Message]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -224,27 +228,27 @@ public class RoomAdapter : IRoomAdapter
|
||||
catch (ArgumentNullException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ArgumentNullException");
|
||||
return RoomOperationResponse.BadRequest("Id is empty");
|
||||
return RoomOperationResponse.BadRequest(_localizer["AdapterMessageArgumentNullException"]);
|
||||
}
|
||||
catch (ValidationException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ValidationException");
|
||||
return RoomOperationResponse.BadRequest($"Incorrect data transmitted: {ex.Message}");
|
||||
return RoomOperationResponse.BadRequest(_localizer["AdapterMessageValidationException", ex.Message]);
|
||||
}
|
||||
catch (ElementNotFoundException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ElementNotFoundException");
|
||||
return RoomOperationResponse.NotFound($"Not found element by id: {id}");
|
||||
return RoomOperationResponse.NotFound(_localizer["AdapterMessageElementNotFound", id]);
|
||||
}
|
||||
catch (StorageException ex)
|
||||
{
|
||||
_logger.LogError(ex, "StorageException");
|
||||
return RoomOperationResponse.BadRequest($"Error while working with data storage: {ex.InnerException!.Message}");
|
||||
return RoomOperationResponse.InternalServerError(_localizer["AdapterMessageStorageException", ex.InnerException?.Message ?? ex.Message]);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Exception");
|
||||
return RoomOperationResponse.InternalServerError(ex.Message);
|
||||
return RoomOperationResponse.InternalServerError(_localizer["AdapterMessageUnhandledException", ex.Message]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,25 +1,28 @@
|
||||
using AutoMapper;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using TwoFromTheCasketContracts.AdapterContracts;
|
||||
using TwoFromTheCasketContracts.AdapterContracts.OperationResponses;
|
||||
using TwoFromTheCasketContracts.BindingModels;
|
||||
using TwoFromTheCasketContracts.BusinessLogicsContracts;
|
||||
using TwoFromTheCasketContracts.DataModels;
|
||||
using TwoFromTheCasketContracts.Exceptions;
|
||||
using TwoFromTheCasketContracts.Resources;
|
||||
using TwoFromTheCasketContracts.ViewModels;
|
||||
|
||||
namespace TwoFromTheCasketWebApi.Adapters;
|
||||
|
||||
public class SalaryAdapter : ISalaryAdapter
|
||||
internal class SalaryAdapter : ISalaryAdapter
|
||||
{
|
||||
private readonly ISalaryBusinessLogicContract _salaryBusinessLogic;
|
||||
private readonly ILogger _logger;
|
||||
private readonly Mapper _mapper;
|
||||
private readonly IStringLocalizer<Messages> _localizer;
|
||||
|
||||
public SalaryAdapter(ISalaryBusinessLogicContract salaryBusinessLogic, ILogger<SalaryAdapter> logger)
|
||||
public SalaryAdapter(ISalaryBusinessLogicContract salaryBusinessLogic, ILogger<SalaryAdapter> logger, IStringLocalizer<Messages> localizer)
|
||||
{
|
||||
_salaryBusinessLogic = salaryBusinessLogic;
|
||||
_logger = logger;
|
||||
|
||||
_localizer = localizer;
|
||||
var config = new MapperConfiguration(cfg =>
|
||||
{
|
||||
cfg.CreateMap<SalaryBindingModel, SalaryDataModel>();
|
||||
@@ -33,28 +36,28 @@ public class SalaryAdapter : ISalaryAdapter
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = _salaryBusinessLogic.GetSalariesByPeriod(fromDate, toDate);
|
||||
var result = _salaryBusinessLogic.GetSalariesByPeriod(fromDate.ToUniversalTime(), toDate.ToUniversalTime());
|
||||
return SalaryOperationResponse.OK(result.Select(x => _mapper.Map<SalaryViewModel>(x)).ToList());
|
||||
}
|
||||
catch (IncorrectDatesException ex)
|
||||
{
|
||||
_logger.LogError(ex, "IncorrectDatesException");
|
||||
return SalaryOperationResponse.BadRequest($"Incorrect dates: {ex.Message}");
|
||||
return SalaryOperationResponse.BadRequest(_localizer["AdapterMessageIncorrectDates", ex.Message]);
|
||||
}
|
||||
catch (NullListException)
|
||||
{
|
||||
_logger.LogError("NullListException");
|
||||
return SalaryOperationResponse.NotFound("The list is not initialized");
|
||||
return SalaryOperationResponse.NotFound(_localizer["NullListExceptionCaption"]);
|
||||
}
|
||||
catch (StorageException ex)
|
||||
{
|
||||
_logger.LogError(ex, "StorageException");
|
||||
return SalaryOperationResponse.InternalServerError($"Error while working with data storage: {ex.InnerException!.Message}");
|
||||
return SalaryOperationResponse.InternalServerError(_localizer["AdapterMessageStorageException", ex.InnerException?.Message ?? ex.Message]);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Exception");
|
||||
return SalaryOperationResponse.InternalServerError(ex.Message);
|
||||
return SalaryOperationResponse.InternalServerError(_localizer["AdapterMessageUnhandledException", ex.Message]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,58 +65,56 @@ public class SalaryAdapter : ISalaryAdapter
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = _salaryBusinessLogic.GetSalariesByWorkerByPeriod(workerId, fromDate, toDate);
|
||||
var result = _salaryBusinessLogic.GetSalariesByWorkerByPeriod(workerId, fromDate.ToUniversalTime(), toDate.ToUniversalTime());
|
||||
return SalaryOperationResponse.OK(result.Select(x => _mapper.Map<SalaryViewModel>(x)).ToList());
|
||||
}
|
||||
catch (IncorrectDatesException ex)
|
||||
{
|
||||
_logger.LogError(ex, "IncorrectDatesException");
|
||||
return SalaryOperationResponse.BadRequest($"Incorrect dates: {ex.Message}");
|
||||
return SalaryOperationResponse.BadRequest(_localizer["AdapterMessageIncorrectDates", ex.Message]);
|
||||
}
|
||||
catch (ValidationException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ValidationException");
|
||||
return SalaryOperationResponse.BadRequest($"Incorrect data transmitted: {ex.Message}");
|
||||
return SalaryOperationResponse.BadRequest(_localizer["AdapterMessageValidationException", ex.Message]);
|
||||
}
|
||||
catch (NullListException)
|
||||
{
|
||||
_logger.LogError("NullListException");
|
||||
return SalaryOperationResponse.NotFound("The list is not initialized");
|
||||
return SalaryOperationResponse.NotFound(_localizer["NullListExceptionCaption"]);
|
||||
}
|
||||
catch (StorageException ex)
|
||||
{
|
||||
_logger.LogError(ex, "StorageException");
|
||||
return SalaryOperationResponse.InternalServerError($"Error while working with data storage: {ex.InnerException!.Message}");
|
||||
return SalaryOperationResponse.InternalServerError(_localizer["AdapterMessageStorageException", ex.InnerException?.Message ?? ex.Message]);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Exception");
|
||||
return SalaryOperationResponse.InternalServerError(ex.Message);
|
||||
return SalaryOperationResponse.InternalServerError(_localizer["AdapterMessageUnhandledException", ex.Message]);
|
||||
}
|
||||
}
|
||||
|
||||
public SalaryOperationResponse Calculate(DateTime date)
|
||||
{
|
||||
try
|
||||
{
|
||||
_salaryBusinessLogic.CalculateSalaryByMonth(date);
|
||||
_salaryBusinessLogic.CalculateSalaryByMonth(date.ToUniversalTime());
|
||||
return SalaryOperationResponse.NoContent();
|
||||
}
|
||||
catch (NullListException)
|
||||
{
|
||||
_logger.LogError("NullListException");
|
||||
return SalaryOperationResponse.NotFound("The list is not initialized");
|
||||
return SalaryOperationResponse.NotFound(_localizer["NullListExceptionCaption"]);
|
||||
}
|
||||
catch (StorageException ex)
|
||||
{
|
||||
_logger.LogError(ex, "StorageException");
|
||||
return SalaryOperationResponse.InternalServerError($"Error while working with data storage: {ex.InnerException!.Message}");
|
||||
return SalaryOperationResponse.InternalServerError(_localizer["AdapterMessageStorageException", ex.InnerException?.Message ?? ex.Message]);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Exception");
|
||||
return SalaryOperationResponse.InternalServerError(ex.Message);
|
||||
return SalaryOperationResponse.InternalServerError(_localizer["AdapterMessageUnhandledException", ex.Message]);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,24 +1,28 @@
|
||||
using AutoMapper;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using TwoFromTheCasketContracts.AdapterContracts;
|
||||
using TwoFromTheCasketContracts.AdapterContracts.OperationResponses;
|
||||
using TwoFromTheCasketContracts.BindingModels;
|
||||
using TwoFromTheCasketContracts.BusinessLogicsContracts;
|
||||
using TwoFromTheCasketContracts.DataModels;
|
||||
using TwoFromTheCasketContracts.Exceptions;
|
||||
using TwoFromTheCasketContracts.Resources;
|
||||
using TwoFromTheCasketContracts.ViewModels;
|
||||
|
||||
namespace TwoFromTheCasketWebApi.Adapters;
|
||||
|
||||
public class SpecializationAdapter : ISpecializationAdapter
|
||||
internal class SpecializationAdapter : ISpecializationAdapter
|
||||
{
|
||||
private readonly ISpecializationBusinessLogicContract _specializationLogic;
|
||||
private readonly ILogger _logger;
|
||||
private readonly Mapper _mapper;
|
||||
private readonly IStringLocalizer<Messages> _localizer;
|
||||
|
||||
public SpecializationAdapter(ISpecializationBusinessLogicContract specializationLogic, ILogger<SpecializationAdapter> logger)
|
||||
public SpecializationAdapter(ISpecializationBusinessLogicContract specializationLogic, ILogger<SpecializationAdapter> logger, IStringLocalizer<Messages> localizer)
|
||||
{
|
||||
_specializationLogic = specializationLogic;
|
||||
_logger = logger;
|
||||
_localizer = localizer;
|
||||
|
||||
var config = new MapperConfiguration(cfg =>
|
||||
{
|
||||
@@ -39,17 +43,17 @@ public class SpecializationAdapter : ISpecializationAdapter
|
||||
catch (NullListException)
|
||||
{
|
||||
_logger.LogError("NullListException");
|
||||
return SpecializationOperationResponse.NotFound("The list is not initialized");
|
||||
return SpecializationOperationResponse.NotFound(_localizer["NullListExceptionCaption"]);
|
||||
}
|
||||
catch (StorageException ex)
|
||||
{
|
||||
_logger.LogError(ex, "StorageException");
|
||||
return SpecializationOperationResponse.InternalServerError($"Error while working with data storage: {ex.InnerException!.Message}");
|
||||
return SpecializationOperationResponse.InternalServerError(_localizer["AdapterMessageStorageException", ex.InnerException?.Message ?? ex.Message]);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Exception");
|
||||
return SpecializationOperationResponse.InternalServerError(ex.Message);
|
||||
return SpecializationOperationResponse.InternalServerError(_localizer["AdapterMessageUnhandledException", ex.Message]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,22 +67,22 @@ public class SpecializationAdapter : ISpecializationAdapter
|
||||
catch (ArgumentNullException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ArgumentNullException");
|
||||
return SpecializationOperationResponse.BadRequest("Id is empty");
|
||||
return SpecializationOperationResponse.BadRequest(_localizer["AdapterMessageArgumentNullException"]);
|
||||
}
|
||||
catch (ElementNotFoundException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ElementNotFoundException");
|
||||
return SpecializationOperationResponse.NotFound($"Not found element by id: {specializationId}");
|
||||
return SpecializationOperationResponse.NotFound(_localizer["AdapterMessageElementNotFound", specializationId]);
|
||||
}
|
||||
catch (StorageException ex)
|
||||
{
|
||||
_logger.LogError(ex, "StorageException");
|
||||
return SpecializationOperationResponse.InternalServerError($"Error while working with data storage: {ex.InnerException!.Message}");
|
||||
return SpecializationOperationResponse.InternalServerError(_localizer["AdapterMessageStorageException", ex.InnerException?.Message ?? ex.Message]);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Exception");
|
||||
return SpecializationOperationResponse.InternalServerError(ex.Message);
|
||||
return SpecializationOperationResponse.InternalServerError(_localizer["AdapterMessageUnhandledException", ex.Message]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -92,22 +96,22 @@ public class SpecializationAdapter : ISpecializationAdapter
|
||||
catch (ArgumentNullException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ArgumentNullException");
|
||||
return SpecializationOperationResponse.BadRequest("Name is empty");
|
||||
return SpecializationOperationResponse.BadRequest(_localizer["AdapterMessageArgumentNullException"]);
|
||||
}
|
||||
catch (ElementNotFoundException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ElementNotFoundException");
|
||||
return SpecializationOperationResponse.NotFound($"Not found element by name: {specializationName}");
|
||||
return SpecializationOperationResponse.NotFound(_localizer["AdapterMessageElementNotFound", specializationName]);
|
||||
}
|
||||
catch (StorageException ex)
|
||||
{
|
||||
_logger.LogError(ex, "StorageException");
|
||||
return SpecializationOperationResponse.InternalServerError($"Error while working with data storage: {ex.InnerException!.Message}");
|
||||
return SpecializationOperationResponse.InternalServerError(_localizer["AdapterMessageStorageException", ex.InnerException?.Message ?? ex.Message]);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Exception");
|
||||
return SpecializationOperationResponse.InternalServerError(ex.Message);
|
||||
return SpecializationOperationResponse.InternalServerError(_localizer["AdapterMessageUnhandledException", ex.Message]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -121,27 +125,27 @@ public class SpecializationAdapter : ISpecializationAdapter
|
||||
catch (ArgumentNullException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ArgumentNullException");
|
||||
return SpecializationOperationResponse.BadRequest("Data is empty");
|
||||
return SpecializationOperationResponse.BadRequest(_localizer["AdapterMessageArgumentNullException"]);
|
||||
}
|
||||
catch (ValidationException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ValidationException");
|
||||
return SpecializationOperationResponse.BadRequest($"Incorrect data transmitted: {ex.Message}");
|
||||
return SpecializationOperationResponse.BadRequest(_localizer["AdapterMessageValidationException", ex.Message]);
|
||||
}
|
||||
catch (ElementExistsException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ElementExistsException");
|
||||
return SpecializationOperationResponse.BadRequest(ex.Message);
|
||||
return SpecializationOperationResponse.BadRequest(_localizer["AdapterMessageElementExists", ex.ParamName, ex.ParamValue]);
|
||||
}
|
||||
catch (StorageException ex)
|
||||
{
|
||||
_logger.LogError(ex, "StorageException");
|
||||
return SpecializationOperationResponse.InternalServerError($"Error while working with data storage: {ex.InnerException!.Message}");
|
||||
return SpecializationOperationResponse.InternalServerError(_localizer["AdapterMessageStorageException", ex.InnerException?.Message ?? ex.Message]);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Exception");
|
||||
return SpecializationOperationResponse.InternalServerError(ex.Message);
|
||||
return SpecializationOperationResponse.InternalServerError(_localizer["AdapterMessageUnhandledException", ex.Message]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -155,27 +159,27 @@ public class SpecializationAdapter : ISpecializationAdapter
|
||||
catch (ArgumentNullException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ArgumentNullException");
|
||||
return SpecializationOperationResponse.BadRequest("Id is empty");
|
||||
return SpecializationOperationResponse.BadRequest(_localizer["AdapterMessageArgumentNullException"]);
|
||||
}
|
||||
catch (ValidationException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ValidationException");
|
||||
return SpecializationOperationResponse.BadRequest($"Incorrect data transmitted: {ex.Message}");
|
||||
return SpecializationOperationResponse.BadRequest(_localizer["AdapterMessageValidationException", ex.Message]);
|
||||
}
|
||||
catch (ElementNotFoundException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ElementNotFoundException");
|
||||
return SpecializationOperationResponse.NotFound($"Not found element by id: {specializationId}");
|
||||
return SpecializationOperationResponse.NotFound(_localizer["AdapterMessageElementNotFound", specializationId]);
|
||||
}
|
||||
catch (StorageException ex)
|
||||
{
|
||||
_logger.LogError(ex, "StorageException");
|
||||
return SpecializationOperationResponse.InternalServerError($"Error while working with data storage: {ex.InnerException!.Message}");
|
||||
return SpecializationOperationResponse.InternalServerError(_localizer["AdapterMessageStorageException", ex.InnerException?.Message ?? ex.Message]);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Exception");
|
||||
return SpecializationOperationResponse.InternalServerError(ex.Message);
|
||||
return SpecializationOperationResponse.InternalServerError(_localizer["AdapterMessageUnhandledException", ex.Message]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -189,27 +193,27 @@ public class SpecializationAdapter : ISpecializationAdapter
|
||||
catch (ArgumentNullException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ArgumentNullException");
|
||||
return SpecializationOperationResponse.BadRequest("Id is empty");
|
||||
return SpecializationOperationResponse.BadRequest(_localizer["AdapterMessageArgumentNullException"]);
|
||||
}
|
||||
catch (ValidationException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ValidationException");
|
||||
return SpecializationOperationResponse.BadRequest($"Incorrect data transmitted: {ex.Message}");
|
||||
return SpecializationOperationResponse.BadRequest(_localizer["AdapterMessageValidationException", ex.Message]);
|
||||
}
|
||||
catch (ElementNotFoundException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ElementNotFoundException");
|
||||
return SpecializationOperationResponse.NotFound($"Not found element by id: {specializationId}");
|
||||
return SpecializationOperationResponse.NotFound(_localizer["AdapterMessageElementNotFound", specializationId]);
|
||||
}
|
||||
catch (StorageException ex)
|
||||
{
|
||||
_logger.LogError(ex, "StorageException");
|
||||
return SpecializationOperationResponse.InternalServerError($"Error while working with data storage: {ex.InnerException!.Message}");
|
||||
return SpecializationOperationResponse.InternalServerError(_localizer["AdapterMessageStorageException", ex.InnerException?.Message ?? ex.Message]);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Exception");
|
||||
return SpecializationOperationResponse.InternalServerError(ex.Message);
|
||||
return SpecializationOperationResponse.InternalServerError(_localizer["AdapterMessageUnhandledException", ex.Message]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,25 +1,29 @@
|
||||
using AutoMapper;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using TwoFromTheCasketContracts.AdapterContracts;
|
||||
using TwoFromTheCasketContracts.AdapterContracts.OperationResponses;
|
||||
using TwoFromTheCasketContracts.BindingModels;
|
||||
using TwoFromTheCasketContracts.BusinessLogicsContracts;
|
||||
using TwoFromTheCasketContracts.DataModels;
|
||||
using TwoFromTheCasketContracts.Exceptions;
|
||||
using TwoFromTheCasketContracts.Resources;
|
||||
using TwoFromTheCasketContracts.ViewModels;
|
||||
using static System.Runtime.InteropServices.JavaScript.JSType;
|
||||
|
||||
namespace TwoFromTheCasketWebApi.Adapters;
|
||||
|
||||
public class WorkAdapter : IWorkAdapter
|
||||
internal class WorkAdapter : IWorkAdapter
|
||||
{
|
||||
private readonly IWorkBusinessLogicContract _workLogic;
|
||||
private readonly ILogger _logger;
|
||||
private readonly Mapper _mapper;
|
||||
private readonly IStringLocalizer<Messages> _localizer;
|
||||
|
||||
public WorkAdapter(IWorkBusinessLogicContract workLogic, ILogger<WorkAdapter> logger)
|
||||
public WorkAdapter(IWorkBusinessLogicContract workLogic, ILogger<WorkAdapter> logger, IStringLocalizer<Messages> localizer)
|
||||
{
|
||||
_workLogic = workLogic;
|
||||
_logger = logger;
|
||||
_localizer = localizer;
|
||||
|
||||
var config = new MapperConfiguration(cfg =>
|
||||
{
|
||||
@@ -40,17 +44,17 @@ public class WorkAdapter : IWorkAdapter
|
||||
catch (NullListException)
|
||||
{
|
||||
_logger.LogError("NullListException");
|
||||
return WorkOperationResponse.NotFound("The list is not initialized");
|
||||
return WorkOperationResponse.NotFound(_localizer["NullListExceptionCaption"]);
|
||||
}
|
||||
catch (StorageException ex)
|
||||
{
|
||||
_logger.LogError(ex, "StorageException");
|
||||
return WorkOperationResponse.InternalServerError($"Error while working with data storage: {ex.InnerException!.Message}");
|
||||
return WorkOperationResponse.InternalServerError(_localizer["AdapterMessageStorageException", ex.InnerException?.Message ?? ex.Message]);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Exception");
|
||||
return WorkOperationResponse.InternalServerError(ex.Message);
|
||||
return WorkOperationResponse.InternalServerError(_localizer["AdapterMessageUnhandledException", ex.Message]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,33 +62,32 @@ public class WorkAdapter : IWorkAdapter
|
||||
{
|
||||
try
|
||||
{
|
||||
var works = _workLogic.GetWorkByData(dataFrom, dataTo);
|
||||
var works = _workLogic.GetWorkByData(dataFrom.ToUniversalTime(), dataTo.ToUniversalTime());
|
||||
var mapped = _mapper.Map<List<WorkViewModel>>(works);
|
||||
return WorkOperationResponse.OK(mapped);
|
||||
}
|
||||
catch (IncorrectDatesException ex)
|
||||
{
|
||||
_logger.LogError(ex, "IncorrectDatesException");
|
||||
return WorkOperationResponse.BadRequest($"Incorrect dates: {ex.Message}");
|
||||
return WorkOperationResponse.BadRequest(_localizer["AdapterMessageIncorrectDates", ex.Message]);
|
||||
}
|
||||
catch (NullListException)
|
||||
{
|
||||
_logger.LogError("NullListException");
|
||||
return WorkOperationResponse.NotFound("The list is not initialized");
|
||||
return WorkOperationResponse.NotFound(_localizer["NullListExceptionCaption"]);
|
||||
}
|
||||
catch (StorageException ex)
|
||||
{
|
||||
_logger.LogError(ex, "StorageException");
|
||||
return WorkOperationResponse.InternalServerError($"Error while working with data storage: {ex.InnerException!.Message}");
|
||||
return WorkOperationResponse.InternalServerError(_localizer["AdapterMessageStorageException", ex.InnerException?.Message ?? ex.Message]);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Exception");
|
||||
return WorkOperationResponse.InternalServerError(ex.Message);
|
||||
return WorkOperationResponse.InternalServerError(_localizer["AdapterMessageUnhandledException", ex.Message]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public WorkOperationResponse Register(WorkBindingModel model)
|
||||
{
|
||||
try
|
||||
@@ -95,27 +98,27 @@ public class WorkAdapter : IWorkAdapter
|
||||
catch (ArgumentNullException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ArgumentNullException");
|
||||
return WorkOperationResponse.BadRequest("Data is empty");
|
||||
return WorkOperationResponse.BadRequest(_localizer["AdapterMessageArgumentNullException"]);
|
||||
}
|
||||
catch (ValidationException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ValidationException");
|
||||
return WorkOperationResponse.BadRequest($"Incorrect data transmitted: {ex.Message}");
|
||||
return WorkOperationResponse.BadRequest(_localizer["AdapterMessageValidationException", ex.Message]);
|
||||
}
|
||||
catch (ElementExistsException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ElementExistsException");
|
||||
return WorkOperationResponse.BadRequest(ex.Message);
|
||||
return WorkOperationResponse.BadRequest(_localizer["AdapterMessageElementExists", ex.ParamName, ex.ParamValue]);
|
||||
}
|
||||
catch (StorageException ex)
|
||||
{
|
||||
_logger.LogError(ex, "StorageException");
|
||||
return WorkOperationResponse.InternalServerError($"Error while working with data storage: {ex.InnerException!.Message}");
|
||||
return WorkOperationResponse.InternalServerError(_localizer["AdapterMessageStorageException", ex.InnerException?.Message ?? ex.Message]);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Exception");
|
||||
return WorkOperationResponse.InternalServerError(ex.Message);
|
||||
return WorkOperationResponse.InternalServerError(_localizer["AdapterMessageUnhandledException", ex.Message]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -129,32 +132,32 @@ public class WorkAdapter : IWorkAdapter
|
||||
catch (ArgumentNullException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ArgumentNullException");
|
||||
return WorkOperationResponse.BadRequest("Data is empty");
|
||||
return WorkOperationResponse.BadRequest(_localizer["AdapterMessageArgumentNullException"]);
|
||||
}
|
||||
catch (ValidationException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ValidationException");
|
||||
return WorkOperationResponse.BadRequest($"Incorrect data transmitted: {ex.Message}");
|
||||
return WorkOperationResponse.BadRequest(_localizer["AdapterMessageValidationException", ex.Message]);
|
||||
}
|
||||
catch (ElementNotFoundException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ElementNotFoundException");
|
||||
return WorkOperationResponse.NotFound($"Not found element by Id {model.Id}");
|
||||
return WorkOperationResponse.NotFound(_localizer["AdapterMessageElementNotFound", model.Id]);
|
||||
}
|
||||
catch (ElementExistsException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ElementExistsException");
|
||||
return WorkOperationResponse.BadRequest(ex.Message);
|
||||
return WorkOperationResponse.BadRequest(_localizer["AdapterMessageElementExists", ex.ParamName, ex.ParamValue]);
|
||||
}
|
||||
catch (StorageException ex)
|
||||
{
|
||||
_logger.LogError(ex, "StorageException");
|
||||
return WorkOperationResponse.BadRequest($"Error while working with data storage: {ex.InnerException!.Message}");
|
||||
return WorkOperationResponse.InternalServerError(_localizer["AdapterMessageStorageException", ex.InnerException?.Message ?? ex.Message]);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Exception");
|
||||
return WorkOperationResponse.InternalServerError(ex.Message);
|
||||
return WorkOperationResponse.InternalServerError(_localizer["AdapterMessageUnhandledException", ex.Message]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -168,27 +171,27 @@ public class WorkAdapter : IWorkAdapter
|
||||
catch (ArgumentNullException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ArgumentNullException");
|
||||
return WorkOperationResponse.BadRequest("Id is empty");
|
||||
return WorkOperationResponse.BadRequest(_localizer["AdapterMessageArgumentNullException"]);
|
||||
}
|
||||
catch (ValidationException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ValidationException");
|
||||
return WorkOperationResponse.BadRequest($"Incorrect data transmitted: {ex.Message}");
|
||||
return WorkOperationResponse.BadRequest(_localizer["AdapterMessageValidationException", ex.Message]);
|
||||
}
|
||||
catch (ElementNotFoundException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ElementNotFoundException");
|
||||
return WorkOperationResponse.NotFound($"Not found element by id: {id}");
|
||||
return WorkOperationResponse.NotFound(_localizer["AdapterMessageElementNotFound", id]);
|
||||
}
|
||||
catch (StorageException ex)
|
||||
{
|
||||
_logger.LogError(ex, "StorageException");
|
||||
return WorkOperationResponse.BadRequest($"Error while working with data storage: {ex.InnerException!.Message}");
|
||||
return WorkOperationResponse.InternalServerError(_localizer["AdapterMessageStorageException", ex.InnerException?.Message ?? ex.Message]);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Exception");
|
||||
return WorkOperationResponse.InternalServerError(ex.Message);
|
||||
return WorkOperationResponse.InternalServerError(_localizer["AdapterMessageUnhandledException", ex.Message]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using AutoMapper;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using Newtonsoft.Json;
|
||||
using System.Text.Json;
|
||||
using TwoFromTheCasketContracts.AdapterContracts;
|
||||
@@ -7,20 +8,22 @@ using TwoFromTheCasketContracts.BindingModels;
|
||||
using TwoFromTheCasketContracts.BusinessLogicsContracts;
|
||||
using TwoFromTheCasketContracts.DataModels;
|
||||
using TwoFromTheCasketContracts.Exceptions;
|
||||
using TwoFromTheCasketContracts.Resources;
|
||||
using TwoFromTheCasketContracts.ViewModels;
|
||||
|
||||
namespace TwoFromTheCasketWebApi.Adapters;
|
||||
|
||||
public class WorkerAdapter : IWorkerAdapter
|
||||
internal class WorkerAdapter : IWorkerAdapter
|
||||
{
|
||||
private readonly IWorkerBusinessLogicContract _workerLogic;
|
||||
private readonly ILogger _logger;
|
||||
private readonly Mapper _mapper;
|
||||
private readonly JsonSerializerOptions JsonSerializerOptions = new() { PropertyNameCaseInsensitive = true };
|
||||
public WorkerAdapter(IWorkerBusinessLogicContract workerLogic, ILogger<WorkerAdapter> logger)
|
||||
private readonly IStringLocalizer<Messages> _localizer;
|
||||
public WorkerAdapter(IWorkerBusinessLogicContract workerLogic, ILogger<WorkerAdapter> logger, IStringLocalizer<Messages> localizer)
|
||||
{
|
||||
_workerLogic = workerLogic;
|
||||
_logger = logger;
|
||||
_localizer = localizer;
|
||||
|
||||
var config = new MapperConfiguration(cfg =>
|
||||
{
|
||||
@@ -44,17 +47,17 @@ public class WorkerAdapter : IWorkerAdapter
|
||||
catch (NullListException)
|
||||
{
|
||||
_logger.LogError("NullListException");
|
||||
return WorkerOperationResponse.NotFound("The list is not initialized");
|
||||
return WorkerOperationResponse.NotFound(_localizer["NullListExceptionCaption"]);
|
||||
}
|
||||
catch (StorageException ex)
|
||||
{
|
||||
_logger.LogError(ex, "StorageException");
|
||||
return WorkerOperationResponse.InternalServerError($"Error while working with data storage: {ex.InnerException!.Message}");
|
||||
return WorkerOperationResponse.InternalServerError(_localizer["AdapterMessageStorageException", ex.InnerException?.Message ?? ex.Message]);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Exception");
|
||||
return WorkerOperationResponse.InternalServerError(ex.Message);
|
||||
return WorkerOperationResponse.InternalServerError(_localizer["AdapterMessageUnhandledException", ex.Message]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,85 +71,80 @@ public class WorkerAdapter : IWorkerAdapter
|
||||
catch (ValidationException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ValidationException");
|
||||
return WorkerOperationResponse.BadRequest($"Incorrect data transmitted: {ex.Message}");
|
||||
return WorkerOperationResponse.BadRequest(_localizer["AdapterMessageValidationException", ex.Message]);
|
||||
}
|
||||
catch (NullListException)
|
||||
{
|
||||
_logger.LogError("NullListException");
|
||||
return WorkerOperationResponse.NotFound("The list is not initialized");
|
||||
return WorkerOperationResponse.NotFound(_localizer["NullListExceptionCaption"]);
|
||||
}
|
||||
catch (StorageException ex)
|
||||
{
|
||||
_logger.LogError(ex, "StorageException");
|
||||
return WorkerOperationResponse.InternalServerError($"Error while working with data storage: {ex.InnerException!.Message}");
|
||||
return WorkerOperationResponse.InternalServerError(_localizer["AdapterMessageStorageException", ex.InnerException?.Message ?? ex.Message]);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Exception");
|
||||
return WorkerOperationResponse.InternalServerError(ex.Message);
|
||||
return WorkerOperationResponse.InternalServerError(_localizer["AdapterMessageUnhandledException", ex.Message]);
|
||||
}
|
||||
}
|
||||
|
||||
public WorkerOperationResponse GetListByBirthDate(DateTime fromDate, DateTime toDate, bool onlyActive = true)
|
||||
{
|
||||
fromDate = DateTime.SpecifyKind(fromDate.ToUniversalTime(), DateTimeKind.Utc);
|
||||
toDate = DateTime.SpecifyKind(toDate.ToUniversalTime(), DateTimeKind.Utc);
|
||||
|
||||
try
|
||||
{
|
||||
var result = _workerLogic.GetWorkersByBirthDate(fromDate, toDate, onlyActive);
|
||||
var result = _workerLogic.GetWorkersByBirthDate(fromDate.ToUniversalTime(), toDate.ToUniversalTime(), onlyActive);
|
||||
return WorkerOperationResponse.OK(result.Select(x => _mapper.Map<WorkerViewModel>(x)).ToList());
|
||||
}
|
||||
catch (IncorrectDatesException ex)
|
||||
{
|
||||
_logger.LogError(ex, "IncorrectDatesException");
|
||||
return WorkerOperationResponse.BadRequest($"Incorrect dates: {ex.Message}");
|
||||
return WorkerOperationResponse.BadRequest(_localizer["AdapterMessageIncorrectDates", ex.Message]);
|
||||
}
|
||||
catch (NullListException)
|
||||
{
|
||||
_logger.LogError("NullListException");
|
||||
return WorkerOperationResponse.NotFound("The list is not initialized");
|
||||
return WorkerOperationResponse.NotFound(_localizer["NullListExceptionCaption"]);
|
||||
}
|
||||
catch (StorageException ex)
|
||||
{
|
||||
_logger.LogError(ex, "StorageException");
|
||||
return WorkerOperationResponse.InternalServerError($"Error while working with data storage: {ex.InnerException!.Message}");
|
||||
return WorkerOperationResponse.InternalServerError(_localizer["AdapterMessageStorageException", ex.InnerException?.Message ?? ex.Message]);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Exception");
|
||||
return WorkerOperationResponse.InternalServerError(ex.Message);
|
||||
return WorkerOperationResponse.InternalServerError(_localizer["AdapterMessageUnhandledException", ex.Message]);
|
||||
}
|
||||
}
|
||||
|
||||
public WorkerOperationResponse GetListByEmploymentDate(DateTime fromDate, DateTime toDate, bool onlyActive = true)
|
||||
{
|
||||
fromDate = DateTime.SpecifyKind(fromDate.ToUniversalTime(), DateTimeKind.Utc);
|
||||
toDate = DateTime.SpecifyKind(toDate.ToUniversalTime(), DateTimeKind.Utc);
|
||||
try
|
||||
{
|
||||
var result = _workerLogic.GetWorkersByEmploymentDate(fromDate, toDate, onlyActive);
|
||||
var result = _workerLogic.GetWorkersByEmploymentDate(fromDate.ToUniversalTime(), toDate.ToUniversalTime(), onlyActive);
|
||||
return WorkerOperationResponse.OK(result.Select(x => _mapper.Map<WorkerViewModel>(x)).ToList());
|
||||
}
|
||||
catch (IncorrectDatesException ex)
|
||||
{
|
||||
_logger.LogError(ex, "IncorrectDatesException");
|
||||
return WorkerOperationResponse.BadRequest($"Incorrect dates: {ex.Message}");
|
||||
return WorkerOperationResponse.BadRequest(_localizer["AdapterMessageIncorrectDates", ex.Message]);
|
||||
}
|
||||
catch (NullListException)
|
||||
{
|
||||
_logger.LogError("NullListException");
|
||||
return WorkerOperationResponse.NotFound("The list is not initialized");
|
||||
return WorkerOperationResponse.NotFound(_localizer["NullListExceptionCaption"]);
|
||||
}
|
||||
catch (StorageException ex)
|
||||
{
|
||||
_logger.LogError(ex, "StorageException");
|
||||
return WorkerOperationResponse.InternalServerError($"Error while working with data storage: {ex.InnerException!.Message}");
|
||||
return WorkerOperationResponse.InternalServerError(_localizer["AdapterMessageStorageException", ex.InnerException?.Message ?? ex.Message]);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Exception");
|
||||
return WorkerOperationResponse.InternalServerError(ex.Message);
|
||||
return WorkerOperationResponse.InternalServerError(_localizer["AdapterMessageUnhandledException", ex.Message]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -160,22 +158,22 @@ public class WorkerAdapter : IWorkerAdapter
|
||||
catch (ArgumentNullException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ArgumentNullException");
|
||||
return WorkerOperationResponse.BadRequest("Data is empty");
|
||||
return WorkerOperationResponse.BadRequest(_localizer["AdapterMessageArgumentNullException"]);
|
||||
}
|
||||
catch (ElementNotFoundException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ElementNotFoundException");
|
||||
return WorkerOperationResponse.NotFound($"Not found element by data: {data}");
|
||||
return WorkerOperationResponse.NotFound(_localizer["AdapterMessageElementNotFound", data]);
|
||||
}
|
||||
catch (StorageException ex)
|
||||
{
|
||||
_logger.LogError(ex, "StorageException");
|
||||
return WorkerOperationResponse.InternalServerError($"Error while working with data storage: {ex.InnerException!.Message}");
|
||||
return WorkerOperationResponse.InternalServerError(_localizer["AdapterMessageStorageException", ex.InnerException?.Message ?? ex.Message]);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Exception");
|
||||
return WorkerOperationResponse.InternalServerError(ex.Message);
|
||||
return WorkerOperationResponse.InternalServerError(_localizer["AdapterMessageUnhandledException", ex.Message]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -189,27 +187,27 @@ public class WorkerAdapter : IWorkerAdapter
|
||||
catch (ArgumentNullException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ArgumentNullException");
|
||||
return WorkerOperationResponse.BadRequest("Data is empty");
|
||||
return WorkerOperationResponse.BadRequest(_localizer["AdapterMessageArgumentNullException"]);
|
||||
}
|
||||
catch (ValidationException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ValidationException");
|
||||
return WorkerOperationResponse.BadRequest($"Incorrect data transmitted: {ex.Message}");
|
||||
return WorkerOperationResponse.BadRequest(_localizer["AdapterMessageValidationException", ex.Message]);
|
||||
}
|
||||
catch (ElementExistsException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ElementExistsException");
|
||||
return WorkerOperationResponse.BadRequest(ex.Message);
|
||||
return WorkerOperationResponse.BadRequest(_localizer["AdapterMessageElementExists", ex.ParamName, ex.ParamValue]);
|
||||
}
|
||||
catch (StorageException ex)
|
||||
{
|
||||
_logger.LogError(ex, "StorageException");
|
||||
return WorkerOperationResponse.InternalServerError($"Error while working with data storage: {ex.InnerException!.Message}");
|
||||
return WorkerOperationResponse.InternalServerError(_localizer["AdapterMessageStorageException", ex.InnerException?.Message ?? ex.Message]);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Exception");
|
||||
return WorkerOperationResponse.InternalServerError(ex.Message);
|
||||
return WorkerOperationResponse.InternalServerError(_localizer["AdapterMessageUnhandledException", ex.Message]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -223,32 +221,32 @@ public class WorkerAdapter : IWorkerAdapter
|
||||
catch (ArgumentNullException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ArgumentNullException");
|
||||
return WorkerOperationResponse.BadRequest("Data is empty");
|
||||
return WorkerOperationResponse.BadRequest(_localizer["AdapterMessageArgumentNullException"]);
|
||||
}
|
||||
catch (ValidationException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ValidationException");
|
||||
return WorkerOperationResponse.BadRequest($"Incorrect data transmitted: {ex.Message}");
|
||||
return WorkerOperationResponse.BadRequest(_localizer["AdapterMessageValidationException", ex.Message]);
|
||||
}
|
||||
catch (ElementNotFoundException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ElementNotFoundException");
|
||||
return WorkerOperationResponse.NotFound($"Not found element by Id {model.Id}");
|
||||
return WorkerOperationResponse.NotFound(_localizer["AdapterMessageElementNotFound", model.Id]);
|
||||
}
|
||||
catch (ElementExistsException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ElementExistsException");
|
||||
return WorkerOperationResponse.BadRequest(ex.Message);
|
||||
return WorkerOperationResponse.BadRequest(_localizer["AdapterMessageElementExists", ex.ParamName, ex.ParamValue]);
|
||||
}
|
||||
catch (StorageException ex)
|
||||
{
|
||||
_logger.LogError(ex, "StorageException");
|
||||
return WorkerOperationResponse.BadRequest($"Error while working with data storage: {ex.InnerException!.Message}");
|
||||
return WorkerOperationResponse.InternalServerError(_localizer["AdapterMessageStorageException", ex.InnerException?.Message ?? ex.Message]);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Exception");
|
||||
return WorkerOperationResponse.InternalServerError(ex.Message);
|
||||
return WorkerOperationResponse.InternalServerError(_localizer["AdapterMessageUnhandledException", ex.Message]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -262,27 +260,27 @@ public class WorkerAdapter : IWorkerAdapter
|
||||
catch (ArgumentNullException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ArgumentNullException");
|
||||
return WorkerOperationResponse.BadRequest("Id is empty");
|
||||
return WorkerOperationResponse.BadRequest(_localizer["AdapterMessageArgumentNullException"]);
|
||||
}
|
||||
catch (ValidationException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ValidationException");
|
||||
return WorkerOperationResponse.BadRequest($"Incorrect data transmitted: {ex.Message}");
|
||||
return WorkerOperationResponse.BadRequest(_localizer["AdapterMessageValidationException", ex.Message]);
|
||||
}
|
||||
catch (ElementNotFoundException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ElementNotFoundException");
|
||||
return WorkerOperationResponse.NotFound($"Not found element by id: {id}");
|
||||
return WorkerOperationResponse.NotFound(_localizer["AdapterMessageElementNotFound", id]);
|
||||
}
|
||||
catch (StorageException ex)
|
||||
{
|
||||
_logger.LogError(ex, "StorageException");
|
||||
return WorkerOperationResponse.BadRequest($"Error while working with data storage: {ex.InnerException!.Message}");
|
||||
return WorkerOperationResponse.InternalServerError(_localizer["AdapterMessageStorageException", ex.InnerException?.Message ?? ex.Message]);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Exception");
|
||||
return WorkerOperationResponse.InternalServerError(ex.Message);
|
||||
return WorkerOperationResponse.InternalServerError(_localizer["AdapterMessageUnhandledException", ex.Message]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
||||
using Microsoft.AspNetCore.Localization;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
using Serilog;
|
||||
using System.Globalization;
|
||||
using System.IdentityModel.Tokens.Jwt;
|
||||
using TwoFromTheCasketBusinessLogic.Implementation;
|
||||
using TwoFromTheCasketBusinessLogic.OfficePackage;
|
||||
@@ -52,6 +55,21 @@ public class Program
|
||||
};
|
||||
});
|
||||
|
||||
builder.Services.AddLocalization();
|
||||
builder.Services.Configure<RequestLocalizationOptions>(
|
||||
options =>
|
||||
{
|
||||
var supportedCultures = new List<CultureInfo>
|
||||
{
|
||||
new("en-US"),
|
||||
new("ru-RU"),
|
||||
new("fr-FR")
|
||||
};
|
||||
options.DefaultRequestCulture = new RequestCulture(culture: "ru-RU", uiCulture: "ru-RU");
|
||||
options.SupportedCultures = supportedCultures;
|
||||
options.SupportedUICultures = supportedCultures;
|
||||
});
|
||||
|
||||
builder.Services.AddControllers();
|
||||
builder.Services.AddOpenApi();
|
||||
|
||||
@@ -124,6 +142,14 @@ public class Program
|
||||
|
||||
app.MapControllers();
|
||||
app.UseHttpsRedirection();
|
||||
|
||||
var localizeOptions =
|
||||
app.Services.GetService<IOptions<RequestLocalizationOptions>>();
|
||||
if (localizeOptions is not null)
|
||||
{
|
||||
app.UseRequestLocalization(localizeOptions.Value);
|
||||
}
|
||||
|
||||
app.Run();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user