Сделана бизнесс логика для сотрудника
This commit is contained in:
parent
ff9c3c267f
commit
f9a38dd140
@ -11,6 +11,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ZooDataModels", "ZooDataMod
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ZooDataBaseImplement", "ZooDataBaseImplement\ZooDataBaseImplement.csproj", "{599C34A0-51C7-4782-9F9C-F2EFCC02FFA2}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ZooBusinessLogic", "ZooBusinessLogic\ZooBusinessLogic.csproj", "{CE5F683C-D19D-43FD-A0DA-0E66BD228996}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@ -33,6 +35,10 @@ Global
|
||||
{599C34A0-51C7-4782-9F9C-F2EFCC02FFA2}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{599C34A0-51C7-4782-9F9C-F2EFCC02FFA2}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{599C34A0-51C7-4782-9F9C-F2EFCC02FFA2}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{CE5F683C-D19D-43FD-A0DA-0E66BD228996}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{CE5F683C-D19D-43FD-A0DA-0E66BD228996}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{CE5F683C-D19D-43FD-A0DA-0E66BD228996}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{CE5F683C-D19D-43FD-A0DA-0E66BD228996}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
112
git/JurasicZoo/ZooBusinessLogic/BusinessLogic/EmployeeLogic.cs
Normal file
112
git/JurasicZoo/ZooBusinessLogic/BusinessLogic/EmployeeLogic.cs
Normal file
@ -0,0 +1,112 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using ZooContracts.BindingModels;
|
||||
using ZooContracts.BuisnessLogicsContracts;
|
||||
using ZooContracts.SearchModels;
|
||||
using ZooContracts.StorageContracts;
|
||||
using ZooContracts.ViewModels;
|
||||
|
||||
namespace ZooBusinessLogic.BusinessLogic
|
||||
{
|
||||
public class EmployeeLogic :IEmployeeLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IEmployeeStorage _employeeStorage;
|
||||
|
||||
public EmployeeLogic(ILogger<EmployeeLogic> logger, IEmployeeStorage employeeStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_employeeStorage = employeeStorage;
|
||||
}
|
||||
public List<EmployeeViewModel>? ReadList(EmployeeSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. EmployeeFIO:{EmployeeFIO}. Id:{ Id}", model?.EmployeeFIO, model?.Id);
|
||||
var list = model == null ? _employeeStorage.GetFullList() : _employeeStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList return null list");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||
return list;
|
||||
}
|
||||
|
||||
public EmployeeViewModel? ReadElement(EmployeeSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
_logger.LogInformation("ReadElement. EmployeeFIO:{EmployeeFIO}.Id:{ Id}", model.EmployeeFIO, model.Id);
|
||||
var element = _employeeStorage.GetElement(model);
|
||||
if (element == null)
|
||||
{
|
||||
_logger.LogWarning("ReadElement element not found");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
|
||||
return element;
|
||||
}
|
||||
|
||||
public bool Create(EmployeeBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_employeeStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public bool Update(EmployeeBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_employeeStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public bool Delete(EmployeeBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
_logger.LogInformation("Delete. Id:{Id}", model.Id);
|
||||
if (_employeeStorage.Delete(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Delete operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
private void CheckModel(EmployeeBindingModel model, bool withParams =
|
||||
true)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
if (!withParams)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.Login))
|
||||
{
|
||||
throw new ArgumentNullException("Нет логина сотрудника",
|
||||
nameof(model.Login));
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.Password))
|
||||
{
|
||||
throw new ArgumentNullException("Нет пароля клиента", nameof(model.Password));
|
||||
}
|
||||
_logger.LogInformation("Employee. EmployeeFIO:{EmployeeFIO}.Login:{ Login}.Password:{Password} Id: { Id}", model.EmployeeFIO, model.Login, model.Password, model.Id);
|
||||
var element = _employeeStorage.GetElement(new EmployeeSearchModel
|
||||
{
|
||||
EmployeeFIO = model.EmployeeFIO
|
||||
});
|
||||
if (element != null && element.Id != model.Id)
|
||||
{
|
||||
throw new InvalidOperationException("Сотрудник с таким логином уже есть");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
113
git/JurasicZoo/ZooBusinessLogic/BusinessLogic/PreserveLogic.cs
Normal file
113
git/JurasicZoo/ZooBusinessLogic/BusinessLogic/PreserveLogic.cs
Normal file
@ -0,0 +1,113 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using ZooContracts.BindingModels;
|
||||
using ZooContracts.BuisnessLogicsContracts;
|
||||
using ZooContracts.SearchModels;
|
||||
using ZooContracts.StorageContracts;
|
||||
using ZooContracts.ViewModels;
|
||||
|
||||
namespace ZooBusinessLogic.BusinessLogic
|
||||
{
|
||||
public class PreserveLogic : IPreserveLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IPreserveStorage _preserveStorage;
|
||||
|
||||
public PreserveLogic(ILogger<PreserveLogic> logger, IPreserveStorage preserveStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_preserveStorage = preserveStorage;
|
||||
}
|
||||
public List<PreserveViewModel>? ReadList(PreserveSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. PreserveName:{PreserveName}. Id:{ Id}", model?.PreserveName, model?.Id);
|
||||
var list = model == null ? _preserveStorage.GetFullList() : _preserveStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList return null list");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||
return list;
|
||||
}
|
||||
|
||||
public PreserveViewModel? ReadElement(PreserveSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
_logger.LogInformation("ReadElement. PreserveName:{PreserveName}.Id:{ Id}", model.PreserveName, model.Id);
|
||||
var element = _preserveStorage.GetElement(model);
|
||||
if (element == null)
|
||||
{
|
||||
_logger.LogWarning("ReadElement element not found");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
|
||||
return element;
|
||||
}
|
||||
|
||||
public bool Create(PreserveBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_preserveStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public bool Update(PreserveBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_preserveStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public bool Delete(PreserveBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
_logger.LogInformation("Delete. Id:{Id}", model.Id);
|
||||
if (_preserveStorage.Delete(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Delete operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
private void CheckModel(PreserveBindingModel model, bool withParams =
|
||||
true)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
if (!withParams)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (model.PreservePrice<=0)
|
||||
{
|
||||
throw new ArgumentNullException("Cтоимости посещения заповедника должна быть больше 0",
|
||||
nameof(model.PreservePrice));
|
||||
}
|
||||
_logger.LogInformation("Preserve. PreserveName:{PreserveName}.PreservePrice:{PreservePrice} Id: { Id}", model.PreserveName, model.PreservePrice, model.Id);
|
||||
var element = _preserveStorage.GetElement(new PreserveSearchModel
|
||||
{
|
||||
PreserveName = model.PreserveName
|
||||
});
|
||||
if (element != null && element.Id != model.Id)
|
||||
{
|
||||
throw new InvalidOperationException("Заповедник с таким названием уже есть");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
17
git/JurasicZoo/ZooBusinessLogic/ZooBusinessLogic.csproj
Normal file
17
git/JurasicZoo/ZooBusinessLogic/ZooBusinessLogic.csproj
Normal file
@ -0,0 +1,17 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\ZooContracts\ZooContracts.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
Loading…
Reference in New Issue
Block a user