93 lines
3.4 KiB
C#
93 lines
3.4 KiB
C#
|
using ConstructionCompanyContracts.BindingModels;
|
|||
|
using ConstructionCompanyContracts.BusinessLogicContracts;
|
|||
|
using ConstructionCompanyContracts.SearchModels;
|
|||
|
using ConstructionCompanyContracts.StorageContracts;
|
|||
|
using ConstructionCompanyContracts.ViewModels;
|
|||
|
using Microsoft.Extensions.Logging;
|
|||
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Linq;
|
|||
|
using System.Text;
|
|||
|
using System.Threading.Tasks;
|
|||
|
|
|||
|
namespace ConstructionCompanyBusinessLogic.BusinessLogics
|
|||
|
{
|
|||
|
public class EmployeeOrderLogic : IEmployeeOrderLogic
|
|||
|
{
|
|||
|
private readonly ILogger _logger;
|
|||
|
private readonly IEmployeeOrderStorage _employeeOrderStorage;
|
|||
|
|
|||
|
public EmployeeOrderLogic(ILogger<EmployeeOrderLogic> logger, IEmployeeOrderStorage employeeOrderStorage)
|
|||
|
{
|
|||
|
_logger = logger;
|
|||
|
_employeeOrderStorage = employeeOrderStorage;
|
|||
|
}
|
|||
|
|
|||
|
public List<EmployeeOrderViewModel>? ReadList(EmployeeOrderSearchModel? model)
|
|||
|
{
|
|||
|
_logger.LogInformation("ReadList. EmployeeId:{EmployeeId}. OrderId:{OrderId}", model?.EmployeeId, model?.OrderId);
|
|||
|
var list = model == null ? _employeeOrderStorage.GetFullList() : _employeeOrderStorage.GetFilteredList(model);
|
|||
|
if (list == null)
|
|||
|
{
|
|||
|
_logger.LogWarning("ReadList return null list");
|
|||
|
return null;
|
|||
|
}
|
|||
|
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
|||
|
return list;
|
|||
|
}
|
|||
|
|
|||
|
public EmployeeOrderViewModel? ReadElement(EmployeeOrderSearchModel model)
|
|||
|
{
|
|||
|
if (model == null)
|
|||
|
{
|
|||
|
throw new ArgumentNullException(nameof(model));
|
|||
|
}
|
|||
|
_logger.LogInformation("ReadList. EmployeeId:{EmployeeId}. OrderId:{OrderId}", model?.EmployeeId, model?.OrderId);
|
|||
|
var element = _employeeOrderStorage.GetElement(model);
|
|||
|
if (element == null)
|
|||
|
{
|
|||
|
_logger.LogWarning("ReadElement element not found");
|
|||
|
return null;
|
|||
|
}
|
|||
|
_logger.LogInformation("ReadElement find. EmployeeId:{EmployeeId}. OrderId:{OrderId}", model?.EmployeeId, model?.OrderId);
|
|||
|
return element;
|
|||
|
}
|
|||
|
|
|||
|
public bool Create(EmployeeOrderBindingModel model)
|
|||
|
{
|
|||
|
CheckModel(model);
|
|||
|
if (_employeeOrderStorage.Insert(model) == null)
|
|||
|
{
|
|||
|
_logger.LogWarning("Insert operation failed");
|
|||
|
return false;
|
|||
|
}
|
|||
|
return true;
|
|||
|
}
|
|||
|
|
|||
|
public bool Delete(EmployeeOrderBindingModel model)
|
|||
|
{
|
|||
|
CheckModel(model, false);
|
|||
|
_logger.LogInformation("Delete. EmployeeId:{EmployeeId}. OrderId:{OrderId}", model?.EmployeeId, model?.OrderId);
|
|||
|
if (_employeeOrderStorage.Delete(model) == null)
|
|||
|
{
|
|||
|
_logger.LogWarning("Delete operation failed");
|
|||
|
return false;
|
|||
|
}
|
|||
|
return true;
|
|||
|
}
|
|||
|
|
|||
|
private void CheckModel(EmployeeOrderBindingModel model, bool withParams = true)
|
|||
|
{
|
|||
|
if (model == null)
|
|||
|
{
|
|||
|
throw new ArgumentNullException(nameof(model));
|
|||
|
}
|
|||
|
if (!withParams)
|
|||
|
{
|
|||
|
return;
|
|||
|
}
|
|||
|
_logger.LogInformation("EmployeeOrder. EmployeeId:{EmployeeId}. OrderId:{OrderId}", model?.EmployeeId, model?.OrderId);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|