Логика есть

This commit is contained in:
maxnes3 2023-05-01 22:55:10 +04:00
parent a40f08d577
commit 5f7f40f1a4
16 changed files with 577 additions and 26 deletions

View File

@ -0,0 +1,117 @@
using PersonnelDepartmentContracts.BindingModels;
using PersonnelDepartmentContracts.BusinessLogicContracts;
using PersonnelDepartmentContracts.SearchModels;
using PersonnelDepartmentContracts.StoragesContracts;
using PersonnelDepartmentContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PersonnelDepartmentBusinessLogic.BusinessLogics
{
public class DealLogic : IDealLogic
{
private readonly IDealStorage _dealStorage;
public DealLogic(IDealStorage dealStorage)
{
_dealStorage = dealStorage ?? throw new ArgumentNullException(nameof(dealStorage));
}
public bool Create(DealBindingModel model)
{
CheckModel(model);
if (_dealStorage.Insert(model) == null)
{
return false;
}
return true;
}
public bool Delete(DealBindingModel model)
{
CheckModel(model);
if (_dealStorage.Delete(model) == null)
{
return false;
}
return true;
}
public DealViewModel? ReadElement(DealSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
var element = _dealStorage.GetElement(model);
if (element == null)
{
return null;
}
return element;
}
public List<DealViewModel>? ReadList(DealSearchModel? model)
{
var list = model == null ? _dealStorage.GetFullList() : _dealStorage.GetFilteredList(model);
if (list == null)
{
return null;
}
return list;
}
public bool Update(DealBindingModel model)
{
CheckModel(model);
if (_dealStorage.Update(model) == null)
{
return false;
}
return true;
}
private void CheckModel(DealBindingModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (model.DepartmentId < 0)
{
throw new ArgumentNullException("Некорректный идентификатор отдела",
nameof(model.DepartmentId));
}
if (model.EmployeeId < 0)
{
throw new ArgumentNullException("Некорректный идентификатор сотрудника",
nameof(model.EmployeeId));
}
if (model.PositionId < 0)
{
throw new ArgumentNullException("Некорректный идентификатор должности",
nameof(model.PositionId));
}
if (model.TypeId < 0)
{
throw new ArgumentNullException("Некорректный идентификатор типа договора",
nameof(model.TypeId));
}
if (_dealStorage.GetElement(new DealSearchModel
{
DateFrom = model.DateFrom,
DateTo = model.DateTo,
DepartmentId = model.DepartmentId,
EmployeeId = model.EmployeeId,
PositionId = model.PositionId,
TypeId = model.TypeId
}) != null)
{
throw new InvalidOperationException("Договор с такими атрибутами уже есть");
}
}
}
}

View File

@ -0,0 +1,103 @@
using PersonnelDepartmentContracts.BindingModels;
using PersonnelDepartmentContracts.BusinessLogicContracts;
using PersonnelDepartmentContracts.SearchModels;
using PersonnelDepartmentContracts.StoragesContracts;
using PersonnelDepartmentContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PersonnelDepartmentBusinessLogic.BusinessLogics
{
public class DepartmentLogic : IDepartmentLogic
{
private readonly IDepartmentStorage _departmentStorage;
public DepartmentLogic(IDepartmentStorage departmentStorage)
{
_departmentStorage = departmentStorage ?? throw new ArgumentNullException(nameof(departmentStorage));
}
public bool Create(DepartmentBindingModel model)
{
CheckModel(model);
if (_departmentStorage.Insert(model) == null)
{
return false;
}
return true;
}
public bool Delete(DepartmentBindingModel model)
{
CheckModel(model);
if (_departmentStorage.Delete(model) == null)
{
return false;
}
return true;
}
public DepartmentViewModel? ReadElement(DepartmentSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
var element = _departmentStorage.GetElement(model);
if (element == null)
{
return null;
}
return element;
}
public List<DepartmentViewModel>? ReadList(DepartmentSearchModel? model)
{
var list = model == null ? _departmentStorage.GetFullList() : _departmentStorage.GetFilteredList(model);
if (list == null)
{
return null;
}
return list;
}
public bool Update(DepartmentBindingModel model)
{
CheckModel(model);
if (_departmentStorage.Update(model) == null)
{
return false;
}
return true;
}
private void CheckModel(DepartmentBindingModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (string.IsNullOrEmpty(model.Name))
{
throw new ArgumentException("Отсутвует название",
nameof(model.Name));
}
if (model.Telephone < 0)
{
throw new ArgumentException("Некоректный контактный телефон",
nameof(model.Telephone));
}
if (_departmentStorage.GetElement(new DepartmentSearchModel
{
Name = model.Name,
Telephone = model.Telephone
}) != null)
{
throw new InvalidOperationException("Отдел с такими атрибутами уже есть");
}
}
}
}

View File

@ -0,0 +1,109 @@
using PersonnelDepartmentContracts.BindingModels;
using PersonnelDepartmentContracts.BusinessLogicContracts;
using PersonnelDepartmentContracts.SearchModels;
using PersonnelDepartmentContracts.StoragesContracts;
using PersonnelDepartmentContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PersonnelDepartmentBusinessLogic.BusinessLogics
{
public class EmployeeLogic : IEmployeeLogic
{
private readonly IEmployeeStorage _employeeStorage;
public EmployeeLogic(IEmployeeStorage employeeStorage)
{
_employeeStorage = employeeStorage ?? throw new ArgumentNullException(nameof(employeeStorage));
}
public bool Create(EmployeeBindingModel model)
{
CheckModel(model);
if (_employeeStorage.Insert(model) == null)
{
return false;
}
return true;
}
public bool Delete(EmployeeBindingModel model)
{
CheckModel(model);
if (_employeeStorage.Delete(model) == null)
{
return false;
}
return true;
}
public EmployeeViewModel? ReadElement(EmployeeSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
var element = _employeeStorage.GetElement(model);
if (element == null)
{
return null;
}
return element;
}
public List<EmployeeViewModel>? ReadList(EmployeeSearchModel? model)
{
var list = model == null ? _employeeStorage.GetFullList() : _employeeStorage.GetFilteredList(model);
if (list == null)
{
return null;
}
return list;
}
public bool Update(EmployeeBindingModel model)
{
CheckModel(model);
if (_employeeStorage.Update(model) == null)
{
return false;
}
return true;
}
private void CheckModel(EmployeeBindingModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (string.IsNullOrEmpty(model.FirstName))
{
throw new ArgumentException("Отсутвует имя сотрудника",
nameof(model.FirstName));
}
if (string.IsNullOrEmpty(model.LastName))
{
throw new ArgumentException("Отсутвует фамилия сотрудника",
nameof(model.LastName));
}
if (string.IsNullOrEmpty(model.Patronymic))
{
throw new ArgumentException("Отсутвует отчество сотрудника",
nameof(model.Patronymic));
}
if (_employeeStorage.GetElement(new EmployeeSearchModel
{
FirstName = model.FirstName,
LastName = model.LastName,
Patronymic = model.Patronymic
}) != null)
{
throw new InvalidOperationException("Сотрудник с такими атрибутами уже есть");
}
}
}
}

View File

@ -0,0 +1,97 @@
using PersonnelDepartmentContracts.BindingModels;
using PersonnelDepartmentContracts.BusinessLogicContracts;
using PersonnelDepartmentContracts.SearchModels;
using PersonnelDepartmentContracts.StoragesContracts;
using PersonnelDepartmentContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PersonnelDepartmentBusinessLogic.BusinessLogics
{
public class PositionLogic : IPositionLogic
{
private readonly IPositionStorage _positionStorage;
public PositionLogic(IPositionStorage positionStorage)
{
_positionStorage = positionStorage ?? throw new ArgumentNullException(nameof(positionStorage));
}
public bool Create(PositionBindingModel model)
{
CheckModel(model);
if (_positionStorage.Insert(model) == null)
{
return false;
}
return true;
}
public bool Delete(PositionBindingModel model)
{
CheckModel(model);
if (_positionStorage.Delete(model) == null)
{
return false;
}
return true;
}
public PositionViewModel? ReadElement(PositionSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
var element = _positionStorage.GetElement(model);
if (element == null)
{
return null;
}
return element;
}
public List<PositionViewModel>? ReadList(PositionSearchModel? model)
{
var list = model == null ? _positionStorage.GetFullList() : _positionStorage.GetFilteredList(model);
if (list == null)
{
return null;
}
return list;
}
public bool Update(PositionBindingModel model)
{
CheckModel(model);
if (_positionStorage.Update(model) == null)
{
return false;
}
return true;
}
private void CheckModel(PositionBindingModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (string.IsNullOrEmpty(model.Name))
{
throw new ArgumentException("Отсутвует имя сотрудника",
nameof(model.Name));
}
if (_positionStorage.GetElement(new PositionSearchModel
{
Name = model.Name
}) != null)
{
throw new InvalidOperationException("Сотрудник с такими атрибутами уже есть");
}
}
}
}

View File

@ -0,0 +1,98 @@
using PersonnelDepartmentContracts.BindingModels;
using PersonnelDepartmentContracts.BusinessLogicContracts;
using PersonnelDepartmentContracts.SearchModels;
using PersonnelDepartmentContracts.StoragesContracts;
using PersonnelDepartmentContracts.ViewModels;
using PersonnelTypeContracts.StoragesContracts;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PersonnelDepartmentBusinessLogic.BusinessLogics
{
public class TypeLogic : ITypeLogic
{
private readonly ITypeStorage _typeStorage;
public TypeLogic(ITypeStorage typeStorage)
{
_typeStorage = typeStorage ?? throw new ArgumentNullException(nameof(typeStorage));
}
public bool Create(TypeBindingModel model)
{
CheckModel(model);
if (_typeStorage.Insert(model) == null)
{
return false;
}
return true;
}
public bool Delete(TypeBindingModel model)
{
CheckModel(model);
if (_typeStorage.Delete(model) == null)
{
return false;
}
return true;
}
public TypeViewModel? ReadElement(TypeSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
var element = _typeStorage.GetElement(model);
if (element == null)
{
return null;
}
return element;
}
public List<TypeViewModel>? ReadList(TypeSearchModel? model)
{
var list = model == null ? _typeStorage.GetFullList() : _typeStorage.GetFilteredList(model);
if (list == null)
{
return null;
}
return list;
}
public bool Update(TypeBindingModel model)
{
CheckModel(model);
if (_typeStorage.Update(model) == null)
{
return false;
}
return true;
}
private void CheckModel(TypeBindingModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (string.IsNullOrEmpty(model.Name))
{
throw new ArgumentException("Отсутвует имя сотрудника",
nameof(model.Name));
}
if (_typeStorage.GetElement(new TypeSearchModel
{
Name = model.Name
}) != null)
{
throw new InvalidOperationException("Сотрудник с такими атрибутами уже есть");
}
}
}
}

View File

@ -6,4 +6,9 @@
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\PersonnelDepartmentContracts\PersonnelDepartmentContracts.csproj" />
<ProjectReference Include="..\PersonnelDepartmentDataModels\PersonnelDepartmentDataModels.csproj" />
</ItemGroup>
</Project>

View File

@ -10,8 +10,4 @@
<ProjectReference Include="..\PersonnelDepartmentDataModels\PersonnelDepartmentDataModels.csproj" />
</ItemGroup>
<ItemGroup>
<Folder Include="StoragesContracts\" />
</ItemGroup>
</Project>

View File

@ -9,9 +9,11 @@ namespace PersonnelDepartmentContracts.SearchModels
public class DealSearchModel
{
public int? Id { get; set; }
public DateTime? DateFrom { get; set; }
public DateTime? DateTo { get; set; }
public int? PositionId { get; set; }
public int? EmployeeId { get; set; }
public int? DepartmentId { get; set; }
public int? TypeId { get; set; }
}
}

View File

@ -11,5 +11,7 @@ namespace PersonnelDepartmentContracts.SearchModels
public int? Id { get; set; }
public string? Name { get; set; }
public int? Telephone { get; set; }
}
}

View File

@ -1,4 +1,5 @@
using PersonnelDepartmentContracts.SearchModels;
using PersonnelDepartmentContracts.BindingModels;
using PersonnelDepartmentContracts.SearchModels;
using PersonnelDepartmentContracts.ViewModels;
using System;
using System.Collections.Generic;
@ -13,8 +14,8 @@ namespace PersonnelDepartmentContracts.StoragesContracts
List<DealViewModel> GetFullList();
List<DealViewModel> GetFilteredList(DealSearchModel model);
DealViewModel? GetElement(DealSearchModel model);
DealViewModel? Insert(DealSearchModel model);
DealViewModel? Update(DealSearchModel model);
DealViewModel? Delete(DealSearchModel model);
DealViewModel? Insert(DealBindingModel model);
DealViewModel? Update(DealBindingModel model);
DealViewModel? Delete(DealBindingModel model);
}
}

View File

@ -1,4 +1,5 @@
using PersonnelDepartmentContracts.SearchModels;
using PersonnelDepartmentContracts.BindingModels;
using PersonnelDepartmentContracts.SearchModels;
using PersonnelDepartmentContracts.ViewModels;
using System;
using System.Collections.Generic;
@ -13,8 +14,8 @@ namespace PersonnelDepartmentContracts.StoragesContracts
List<DepartmentViewModel> GetFullList();
List<DepartmentViewModel> GetFilteredList(DepartmentSearchModel model);
DepartmentViewModel? GetElement(DepartmentSearchModel model);
DepartmentViewModel? Insert(DepartmentSearchModel model);
DepartmentViewModel? Update(DepartmentSearchModel model);
DepartmentViewModel? Delete(DepartmentSearchModel model);
DepartmentViewModel? Insert(DepartmentBindingModel model);
DepartmentViewModel? Update(DepartmentBindingModel model);
DepartmentViewModel? Delete(DepartmentBindingModel model);
}
}

View File

@ -1,4 +1,5 @@
using PersonnelDepartmentContracts.SearchModels;
using PersonnelDepartmentContracts.BindingModels;
using PersonnelDepartmentContracts.SearchModels;
using PersonnelDepartmentContracts.ViewModels;
using System;
using System.Collections.Generic;
@ -13,8 +14,8 @@ namespace PersonnelDepartmentContracts.StoragesContracts
List<EmployeeViewModel> GetFullList();
List<EmployeeViewModel> GetFilteredList(EmployeeSearchModel model);
EmployeeViewModel? GetElement(EmployeeSearchModel model);
EmployeeViewModel? Insert(EmployeeSearchModel model);
EmployeeViewModel? Update(EmployeeSearchModel model);
EmployeeViewModel? Delete(EmployeeSearchModel model);
EmployeeViewModel? Insert(EmployeeBindingModel model);
EmployeeViewModel? Update(EmployeeBindingModel model);
EmployeeViewModel? Delete(EmployeeBindingModel model);
}
}

View File

@ -1,4 +1,5 @@
using PersonnelDepartmentContracts.SearchModels;
using PersonnelDepartmentContracts.BindingModels;
using PersonnelDepartmentContracts.SearchModels;
using PersonnelDepartmentContracts.ViewModels;
using System;
using System.Collections.Generic;
@ -13,8 +14,8 @@ namespace PersonnelDepartmentContracts.StoragesContracts
List<PositionViewModel> GetFullList();
List<PositionViewModel> GetFilteredList(PositionSearchModel model);
PositionViewModel? GetElement(PositionSearchModel model);
PositionViewModel? Insert(PositionSearchModel model);
PositionViewModel? Update(PositionSearchModel model);
PositionViewModel? Delete(PositionSearchModel model);
PositionViewModel? Insert(PositionBindingModel model);
PositionViewModel? Update(PositionBindingModel model);
PositionViewModel? Delete(PositionBindingModel model);
}
}

View File

@ -1,4 +1,5 @@
using PersonnelDepartmentContracts.SearchModels;
using PersonnelDepartmentContracts.BindingModels;
using PersonnelDepartmentContracts.SearchModels;
using PersonnelDepartmentContracts.ViewModels;
using System;
using System.Collections.Generic;
@ -13,8 +14,8 @@ namespace PersonnelTypeContracts.StoragesContracts
List<TypeViewModel> GetFullList();
List<TypeViewModel> GetFilteredList(TypeSearchModel model);
TypeViewModel? GetElement(TypeSearchModel model);
TypeViewModel? Insert(TypeSearchModel model);
TypeViewModel? Update(TypeSearchModel model);
TypeViewModel? Delete(TypeSearchModel model);
TypeViewModel? Insert(TypeBindingModel model);
TypeViewModel? Update(TypeBindingModel model);
TypeViewModel? Delete(TypeBindingModel model);
}
}

View File

@ -6,4 +6,9 @@
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<Folder Include="Models\" />
<Folder Include="Implements\" />
</ItemGroup>
</Project>

View File

@ -9,6 +9,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PersonnelDepartmentDataMode
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PersonnelDepartmentContracts", "PersonnelDepartmentContracts\PersonnelDepartmentContracts.csproj", "{9A959A51-26F5-4B67-B54E-CD271E12C944}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PersonnelDepartmentBusinessLogic", "PersonnelDepartmentBusinessLogic\PersonnelDepartmentBusinessLogic.csproj", "{2FF36159-F497-49BD-B18E-7E33504ED44E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PersonnelDepartmentDatabaseImplement", "PersonnelDepartmentDatabaseImplement\PersonnelDepartmentDatabaseImplement.csproj", "{347F10C9-CD2A-473D-AA4F-F1BAD304B396}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -27,6 +31,14 @@ Global
{9A959A51-26F5-4B67-B54E-CD271E12C944}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9A959A51-26F5-4B67-B54E-CD271E12C944}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9A959A51-26F5-4B67-B54E-CD271E12C944}.Release|Any CPU.Build.0 = Release|Any CPU
{2FF36159-F497-49BD-B18E-7E33504ED44E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2FF36159-F497-49BD-B18E-7E33504ED44E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2FF36159-F497-49BD-B18E-7E33504ED44E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2FF36159-F497-49BD-B18E-7E33504ED44E}.Release|Any CPU.Build.0 = Release|Any CPU
{347F10C9-CD2A-473D-AA4F-F1BAD304B396}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{347F10C9-CD2A-473D-AA4F-F1BAD304B396}.Debug|Any CPU.Build.0 = Debug|Any CPU
{347F10C9-CD2A-473D-AA4F-F1BAD304B396}.Release|Any CPU.ActiveCfg = Release|Any CPU
{347F10C9-CD2A-473D-AA4F-F1BAD304B396}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE