add buisness logics
This commit is contained in:
parent
0f149203e7
commit
0a98b99f16
@ -9,6 +9,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FurnitureAssembly_Storekeep
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FurnitureAssembly_Storekeeper_Contracts", "FurnitureAssembly_Storekeeper_Contracts\FurnitureAssembly_Storekeeper_Contracts.csproj", "{487F90DA-C4AC-4407-A382-953DA3689C2A}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FurnitureAssembly_Storekeeper_Contracts", "FurnitureAssembly_Storekeeper_Contracts\FurnitureAssembly_Storekeeper_Contracts.csproj", "{487F90DA-C4AC-4407-A382-953DA3689C2A}"
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FurnitureAssembly_Storekeeper_BusinessLogic", "FurnitureAssembly_Storekeeper_BusinessLogic\FurnitureAssembly_Storekeeper_BusinessLogic.csproj", "{EC0BAC5C-D13B-4BB1-9E88-68FC69995BC6}"
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
Debug|Any CPU = Debug|Any CPU
|
||||||
@ -27,6 +29,10 @@ Global
|
|||||||
{487F90DA-C4AC-4407-A382-953DA3689C2A}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{487F90DA-C4AC-4407-A382-953DA3689C2A}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{487F90DA-C4AC-4407-A382-953DA3689C2A}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{487F90DA-C4AC-4407-A382-953DA3689C2A}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{487F90DA-C4AC-4407-A382-953DA3689C2A}.Release|Any CPU.Build.0 = Release|Any CPU
|
{487F90DA-C4AC-4407-A382-953DA3689C2A}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{EC0BAC5C-D13B-4BB1-9E88-68FC69995BC6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{EC0BAC5C-D13B-4BB1-9E88-68FC69995BC6}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{EC0BAC5C-D13B-4BB1-9E88-68FC69995BC6}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{EC0BAC5C-D13B-4BB1-9E88-68FC69995BC6}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
@ -0,0 +1,114 @@
|
|||||||
|
using FurnitureAssembly_Storekeeper_Contracts.BindingModels;
|
||||||
|
using FurnitureAssembly_Storekeeper_Contracts.BusinessLogicsContracts;
|
||||||
|
using FurnitureAssembly_Storekeeper_Contracts.SearchModels;
|
||||||
|
using FurnitureAssembly_Storekeeper_Contracts.StoragesContracts;
|
||||||
|
using FurnitureAssembly_Storekeeper_Contracts.ViewModels;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace FurnitureAssembly_Storekeeper_BusinessLogic.BusinessLogics
|
||||||
|
{
|
||||||
|
public class FurnitureLogic: IFurnitureLogic
|
||||||
|
{
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
private readonly IFurnitureStorage _FurnitureStorage;
|
||||||
|
public FurnitureLogic(ILogger<FurnitureLogic> logger, IFurnitureStorage furnitureStorage)
|
||||||
|
{
|
||||||
|
_logger = logger;
|
||||||
|
_FurnitureStorage = furnitureStorage;
|
||||||
|
}
|
||||||
|
public List<FurnitureViewModel>? ReadList(FurnitureSearchModel? model)
|
||||||
|
{
|
||||||
|
_logger.LogInformation("ReadList. FurnitureName:{FurnitureName}.Id:{Id}", model?.FurnitureName, model?.Id);
|
||||||
|
var list = model == null ? _FurnitureStorage.GetFullList() : _FurnitureStorage.GetFilteredList(model);
|
||||||
|
if (list == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("ReadList return null list");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
public FurnitureViewModel? ReadElement(FurnitureSearchModel model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(model));
|
||||||
|
}
|
||||||
|
_logger.LogInformation("ReadElement. FurnitureName:{FurnitureName}.Id:{Id}", model.FurnitureName, model.Id);
|
||||||
|
|
||||||
|
var element = _FurnitureStorage.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(FurnitureBindingModel model)
|
||||||
|
{
|
||||||
|
CheckModel(model);
|
||||||
|
if (_FurnitureStorage.Insert(model) == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Insert operation failed");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
public bool Update(FurnitureBindingModel model)
|
||||||
|
{
|
||||||
|
CheckModel(model);
|
||||||
|
if (_FurnitureStorage.Update(model) == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Update operation failed");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
public bool Delete(FurnitureBindingModel model)
|
||||||
|
{
|
||||||
|
CheckModel(model, false);
|
||||||
|
_logger.LogInformation("Delete. Id:{Id}", model.Id);
|
||||||
|
if (_FurnitureStorage.Delete(model) == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Delete operation failed");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
private void CheckModel(FurnitureBindingModel model, bool withParams = true)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(model));
|
||||||
|
}
|
||||||
|
if (!withParams)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (string.IsNullOrEmpty(model.FurnitureName))
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException("Нет названия продукта",nameof(model.FurnitureName));
|
||||||
|
}
|
||||||
|
if (model.FurnitureCost <= 0)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException("Цена компонента должна быть больше 0", nameof(model.FurnitureCost));
|
||||||
|
}
|
||||||
|
_logger.LogInformation("Furniture. FurnitureName:{FurnitureName}. Cost:{Cost}. Id: {Id}", model.FurnitureName, model.FurnitureCost, model.Id);
|
||||||
|
var element = _FurnitureStorage.GetElement(new FurnitureSearchModel
|
||||||
|
{
|
||||||
|
FurnitureName = model.FurnitureName
|
||||||
|
});
|
||||||
|
if (element != null && element.Id != model.Id)
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException("Изделие с таким названием уже есть");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,113 @@
|
|||||||
|
using FurnitureAssembly_Storekeeper_Contracts.BindingModels;
|
||||||
|
using FurnitureAssembly_Storekeeper_Contracts.BusinessLogicsContracts;
|
||||||
|
using FurnitureAssembly_Storekeeper_Contracts.SearchModels;
|
||||||
|
using FurnitureAssembly_Storekeeper_Contracts.StoragesContracts;
|
||||||
|
using FurnitureAssembly_Storekeeper_Contracts.ViewModels;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
|
namespace FurnitureAssembly_Storekeeper_BusinessLogic.BusinessLogics
|
||||||
|
{
|
||||||
|
public class MaterialLogic : IMaterialLogic
|
||||||
|
{
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
private readonly IMaterialStorage _MaterialStorage;
|
||||||
|
public MaterialLogic(ILogger<MaterialLogic> logger, IMaterialStorage
|
||||||
|
MaterialStorage)
|
||||||
|
{
|
||||||
|
_logger = logger;
|
||||||
|
_MaterialStorage = MaterialStorage;
|
||||||
|
}
|
||||||
|
public List<MaterialViewModel>? ReadList(MaterialSearchModel? model)
|
||||||
|
{
|
||||||
|
_logger.LogInformation("ReadList. MaterialName:{MaterialName}.Id:{Id}", model?.MaterialName, model?.Id);
|
||||||
|
var list = model == null ? _MaterialStorage.GetFullList() :
|
||||||
|
_MaterialStorage.GetFilteredList(model);
|
||||||
|
if (list == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("ReadList return null list");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
public MaterialViewModel? ReadElement(MaterialSearchModel model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(model));
|
||||||
|
}
|
||||||
|
_logger.LogInformation("ReadElement. MaterialName:{MaterialName}.Id:{Id}", model.MaterialName, model.Id);
|
||||||
|
|
||||||
|
var element = _MaterialStorage.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(MaterialBindingModel model)
|
||||||
|
{
|
||||||
|
CheckModel(model);
|
||||||
|
if (_MaterialStorage.Insert(model) == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Insert operation failed");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
public bool Update(MaterialBindingModel model)
|
||||||
|
{
|
||||||
|
CheckModel(model);
|
||||||
|
if (_MaterialStorage.Update(model) == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Update operation failed");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
public bool Delete(MaterialBindingModel model)
|
||||||
|
{
|
||||||
|
CheckModel(model, false);
|
||||||
|
_logger.LogInformation("Delete. Id:{Id}", model.Id);
|
||||||
|
if (_MaterialStorage.Delete(model) == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Delete operation failed");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
private void CheckModel(MaterialBindingModel model, bool withParams =
|
||||||
|
true)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(model));
|
||||||
|
}
|
||||||
|
if (!withParams)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (string.IsNullOrEmpty(model.MaterialName))
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException("Нет названия компонента",
|
||||||
|
nameof(model.MaterialName));
|
||||||
|
}
|
||||||
|
if (model.Cost <= 0)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException("Цена компонента должна быть больше 0", nameof(model.Cost));
|
||||||
|
}
|
||||||
|
_logger.LogInformation("Material. MaterialName:{MaterialName}. Cost:{ Cost}. Id: {Id}", model.MaterialName, model.Cost, model.Id);
|
||||||
|
var element = _MaterialStorage.GetElement(new MaterialSearchModel
|
||||||
|
{
|
||||||
|
MaterialName = model.MaterialName
|
||||||
|
});
|
||||||
|
if (element != null && element.Id != model.Id)
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException("Компонент с таким названием уже есть");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,110 @@
|
|||||||
|
using FurnitureAssembly_Storekeeper_Contracts.BindingModels;
|
||||||
|
using FurnitureAssembly_Storekeeper_Contracts.BusinessLogicsContracts;
|
||||||
|
using FurnitureAssembly_Storekeeper_Contracts.SearchModels;
|
||||||
|
using FurnitureAssembly_Storekeeper_Contracts.StoragesContracts;
|
||||||
|
using FurnitureAssembly_Storekeeper_Contracts.ViewModels;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
|
namespace FurnitureAssembly_Storekeeper_BusinessLogic.BusinessLogics
|
||||||
|
{
|
||||||
|
public class RoleLogic : IRoleLogic
|
||||||
|
{
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
private readonly IRoleStorage _RoleStorage;
|
||||||
|
public RoleLogic(ILogger<RoleLogic> logger, IRoleStorage
|
||||||
|
RoleStorage)
|
||||||
|
{
|
||||||
|
_logger = logger;
|
||||||
|
_RoleStorage = RoleStorage;
|
||||||
|
}
|
||||||
|
public List<RoleViewModel>? ReadList(RoleSearchModel? model)
|
||||||
|
{
|
||||||
|
_logger.LogInformation("ReadList. RoleName:{RoleName}.Id:{Id}", model?.RoleName, model?.Id);
|
||||||
|
var list = model == null ? _RoleStorage.GetFullList() :
|
||||||
|
_RoleStorage.GetFilteredList(model);
|
||||||
|
if (list == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("ReadList return null list");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
public RoleViewModel? ReadElement(RoleSearchModel model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(model));
|
||||||
|
}
|
||||||
|
_logger.LogInformation("ReadElement. RoleName:{RoleName}.Id:{Id}", model.RoleName, model.Id);
|
||||||
|
|
||||||
|
var element = _RoleStorage.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(RoleBindingModel model)
|
||||||
|
{
|
||||||
|
CheckModel(model);
|
||||||
|
if (_RoleStorage.Insert(model) == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Insert operation failed");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
public bool Update(RoleBindingModel model)
|
||||||
|
{
|
||||||
|
CheckModel(model);
|
||||||
|
if (_RoleStorage.Update(model) == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Update operation failed");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
public bool Delete(RoleBindingModel model)
|
||||||
|
{
|
||||||
|
CheckModel(model, false);
|
||||||
|
_logger.LogInformation("Delete. Id:{Id}", model.Id);
|
||||||
|
if (_RoleStorage.Delete(model) == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Delete operation failed");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
private void CheckModel(RoleBindingModel model, bool withParams =
|
||||||
|
true)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(model));
|
||||||
|
}
|
||||||
|
if (!withParams)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (string.IsNullOrEmpty(model.RoleName))
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException("Нет названия роли",
|
||||||
|
nameof(model.RoleName));
|
||||||
|
}
|
||||||
|
|
||||||
|
_logger.LogInformation("Role. RoleName:{RoleName}. Id: {Id}", model.RoleName, model.Id);
|
||||||
|
var element = _RoleStorage.GetElement(new RoleSearchModel
|
||||||
|
{
|
||||||
|
RoleName = model.RoleName
|
||||||
|
});
|
||||||
|
if (element != null && element.Id != model.Id)
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException("Роль с таким названием уже есть");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,109 @@
|
|||||||
|
using FurnitureAssembly_Storekeeper_Contracts.BindingModels;
|
||||||
|
using FurnitureAssembly_Storekeeper_Contracts.BusinessLogicsContracts;
|
||||||
|
using FurnitureAssembly_Storekeeper_Contracts.SearchModels;
|
||||||
|
using FurnitureAssembly_Storekeeper_Contracts.StoragesContracts;
|
||||||
|
using FurnitureAssembly_Storekeeper_Contracts.ViewModels;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
|
namespace FurnitureAssembly_Storekeeper_BusinessLogic.BusinessLogics
|
||||||
|
{
|
||||||
|
public class ScopeLogic : IScopeLogic
|
||||||
|
{
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
private readonly IScopeStorage _ScopeStorage;
|
||||||
|
public ScopeLogic(ILogger<ScopeLogic> logger, IScopeStorage
|
||||||
|
ScopeStorage)
|
||||||
|
{
|
||||||
|
_logger = logger;
|
||||||
|
_ScopeStorage = ScopeStorage;
|
||||||
|
}
|
||||||
|
public List<ScopeViewModel>? ReadList(ScopeSearchModel? model)
|
||||||
|
{
|
||||||
|
_logger.LogInformation("ReadList. ScopeName:{ScopeName}.Id:{Id}", model?.ScopeName, model?.Id);
|
||||||
|
var list = model == null ? _ScopeStorage.GetFullList() :
|
||||||
|
_ScopeStorage.GetFilteredList(model);
|
||||||
|
if (list == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("ReadList return null list");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
public ScopeViewModel? ReadElement(ScopeSearchModel model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(model));
|
||||||
|
}
|
||||||
|
_logger.LogInformation("ReadElement. ScopeName:{ScopeName}.Id:{Id}", model.ScopeName, model.Id);
|
||||||
|
|
||||||
|
var element = _ScopeStorage.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(ScopeBindingModel model)
|
||||||
|
{
|
||||||
|
CheckModel(model);
|
||||||
|
if (_ScopeStorage.Insert(model) == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Insert operation failed");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
public bool Update(ScopeBindingModel model)
|
||||||
|
{
|
||||||
|
CheckModel(model);
|
||||||
|
if (_ScopeStorage.Update(model) == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Update operation failed");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
public bool Delete(ScopeBindingModel model)
|
||||||
|
{
|
||||||
|
CheckModel(model, false);
|
||||||
|
_logger.LogInformation("Delete. Id:{Id}", model.Id);
|
||||||
|
if (_ScopeStorage.Delete(model) == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Delete operation failed");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
private void CheckModel(ScopeBindingModel model, bool withParams =
|
||||||
|
true)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(model));
|
||||||
|
}
|
||||||
|
if (!withParams)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (string.IsNullOrEmpty(model.ScopeName))
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException("Нет названия области использования",
|
||||||
|
nameof(model.ScopeName));
|
||||||
|
}
|
||||||
|
_logger.LogInformation("Scope. ScopeName:{ScopeName}. Id: {Id}", model.ScopeName,model.Id);
|
||||||
|
var element = _ScopeStorage.GetElement(new ScopeSearchModel
|
||||||
|
{
|
||||||
|
ScopeName = model.ScopeName
|
||||||
|
});
|
||||||
|
if (element != null && element.Id != model.Id)
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException("Область использования с таким названием уже есть");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,123 @@
|
|||||||
|
using FurnitureAssembly_Storekeeper_Contracts.BindingModels;
|
||||||
|
using FurnitureAssembly_Storekeeper_Contracts.BusinessLogicsContracts;
|
||||||
|
using FurnitureAssembly_Storekeeper_Contracts.SearchModels;
|
||||||
|
using FurnitureAssembly_Storekeeper_Contracts.StoragesContracts;
|
||||||
|
using FurnitureAssembly_Storekeeper_Contracts.ViewModels;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace FurnitureAssembly_Storekeeper_BusinessLogic.BusinessLogics
|
||||||
|
{
|
||||||
|
public class UserLogic : IUserLogic
|
||||||
|
{
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
private readonly IUserStorage _UserStorage;
|
||||||
|
|
||||||
|
public UserLogic(ILogger<UserLogic> logger, IUserStorage UserStorage)
|
||||||
|
{
|
||||||
|
_logger = logger;
|
||||||
|
_UserStorage = UserStorage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Create(UserBindingModel model)
|
||||||
|
{
|
||||||
|
CheckModel(model);
|
||||||
|
if (_UserStorage.Insert(model) == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Insert operation failed");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Delete(UserBindingModel model)
|
||||||
|
{
|
||||||
|
CheckModel(model, false);
|
||||||
|
_logger.LogInformation("Delete. Id:{Id}", model.Id);
|
||||||
|
if (_UserStorage.Delete(model) == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Delete operation failed");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public UserViewModel? ReadElement(UserSearchModel model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(model));
|
||||||
|
}
|
||||||
|
_logger.LogInformation("ReadElement. Login: {Email} Id:{ Id}", model.Login, model.Id);
|
||||||
|
var element = _UserStorage.GetElement(model);
|
||||||
|
if (element == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("ReadElement element not found");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
|
||||||
|
return element;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<UserViewModel>? ReadList(UserSearchModel? model)
|
||||||
|
{
|
||||||
|
_logger.LogInformation("ReadList. Login: {Email}. Id:{ Id}", model?.Login, model?.Id);
|
||||||
|
var list = model == null ? _UserStorage.GetFullList() : _UserStorage.GetFilteredList(model);
|
||||||
|
if (list == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("ReadList return null list");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Update(UserBindingModel model)
|
||||||
|
{
|
||||||
|
CheckModel(model);
|
||||||
|
if (_UserStorage.Update(model) == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Update operation failed");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void CheckModel(UserBindingModel model, bool withParams = true)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(model));
|
||||||
|
}
|
||||||
|
if (!withParams)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (string.IsNullOrEmpty(model.UserName))
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException("Нет ФИО пользователя",
|
||||||
|
nameof(model.UserName));
|
||||||
|
}
|
||||||
|
if (string.IsNullOrEmpty(model.Login))
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException("Нет логина пользователя",
|
||||||
|
nameof(model.Login));
|
||||||
|
}
|
||||||
|
if (string.IsNullOrEmpty(model.Password))
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException("Нет пароля пользователя",
|
||||||
|
nameof(model.Password));
|
||||||
|
}
|
||||||
|
_logger.LogInformation("Component. UserName:{UserName}. Login:{ Login}. Id: { Id}", model.UserName, model.Login, model.Id);
|
||||||
|
var element = _UserStorage.GetElement(new UserSearchModel { Login = model.Login });
|
||||||
|
if (element != null && element.Id != model.Id)
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException("Пользователь с таким логином уже есть");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -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="..\FurnitureAssembly_Storekeeper_Contracts\FurnitureAssembly_Storekeeper_Contracts.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
@ -9,7 +9,7 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace FurnitureAssembly_Storekeeper_Contracts.BusinessLogicsContracts
|
namespace FurnitureAssembly_Storekeeper_Contracts.BusinessLogicsContracts
|
||||||
{
|
{
|
||||||
public interface IfurnitureLogic
|
public interface IFurnitureLogic
|
||||||
{
|
{
|
||||||
List<FurnitureViewModel>? ReadList(FurnitureSearchModel? model);
|
List<FurnitureViewModel>? ReadList(FurnitureSearchModel? model);
|
||||||
FurnitureViewModel? ReadElement(FurnitureSearchModel model);
|
FurnitureViewModel? ReadElement(FurnitureSearchModel model);
|
||||||
|
@ -7,7 +7,7 @@ using System.Linq;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace FurnitureAssemblyContracts.BusinessLogicsContracts
|
namespace FurnitureAssembly_Storekeeper_Contracts.BusinessLogicsContracts
|
||||||
{
|
{
|
||||||
public interface IRoleLogic
|
public interface IRoleLogic
|
||||||
{
|
{
|
||||||
|
@ -9,6 +9,6 @@ namespace FurnitureAssembly_Storekeeper_Contracts.SearchModels
|
|||||||
public class RoleSearchModel
|
public class RoleSearchModel
|
||||||
{
|
{
|
||||||
public int? Id { get; set; }
|
public int? Id { get; set; }
|
||||||
public string? RolelName { get; set; }
|
public string? RoleName { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user