Слой бизнес логики
This commit is contained in:
parent
28a3569fed
commit
0a8fd1126d
@ -9,6 +9,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SushiBarDataModels", "Sushi
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SushiBarContracts", "SushiBarContracts\SushiBarContracts.csproj", "{1FD289B3-1422-4535-8969-2F320754517B}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SushiBarBusinessLogic", "SushiBarBusinessLogic\SushiBarBusinessLogic.csproj", "{9CB0FFA6-FA25-440C-8B6A-B6DF2F0639F5}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@ -27,6 +29,10 @@ Global
|
||||
{1FD289B3-1422-4535-8969-2F320754517B}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{1FD289B3-1422-4535-8969-2F320754517B}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{1FD289B3-1422-4535-8969-2F320754517B}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{9CB0FFA6-FA25-440C-8B6A-B6DF2F0639F5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{9CB0FFA6-FA25-440C-8B6A-B6DF2F0639F5}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{9CB0FFA6-FA25-440C-8B6A-B6DF2F0639F5}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{9CB0FFA6-FA25-440C-8B6A-B6DF2F0639F5}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
94
SushiBar/SushiBarBusinessLogic/BusinessLogics/BuyerLogic.cs
Normal file
94
SushiBar/SushiBarBusinessLogic/BusinessLogics/BuyerLogic.cs
Normal file
@ -0,0 +1,94 @@
|
||||
using SushiBarContracts.BindingModels;
|
||||
using SushiBarContracts.BusinessLogicContracts;
|
||||
using SushiBarContracts.SearchModels;
|
||||
using SushiBarContracts.StoragesContracts;
|
||||
using SushiBarContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SushiBarBusinessLogic.BusinessLogics
|
||||
{
|
||||
public class BuyerLogic : IBuyerLogic
|
||||
{
|
||||
|
||||
private readonly IBuyerStorage _buyerStorage;
|
||||
|
||||
public BuyerLogic(IBuyerStorage buyerStorage)
|
||||
{
|
||||
_buyerStorage = buyerStorage;
|
||||
}
|
||||
public BuyerViewModel? ReadElement(BuyerSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
|
||||
var element = _buyerStorage.GetElement(model);
|
||||
if(element == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return element;
|
||||
}
|
||||
|
||||
public List<BuyerViewModel>? ReadList(BuyerSearchModel? model)
|
||||
{
|
||||
var list = model == null ? _buyerStorage.GetFullList() : _buyerStorage.GetFilteredList(model);
|
||||
if(list == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public bool Create(BuyerBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_buyerStorage.Insert(model) == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Delete(BuyerBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
if(_buyerStorage.Delete(model) == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Update(BuyerBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if(_buyerStorage.Update(model) == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void CheckModel(BuyerBindingModel model, bool withParams = true)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
if (!withParams)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.BuyerName))
|
||||
{
|
||||
throw new ArgumentNullException("Нет названия", nameof(model.BuyerName));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
93
SushiBar/SushiBarBusinessLogic/BusinessLogics/CookLogic.cs
Normal file
93
SushiBar/SushiBarBusinessLogic/BusinessLogics/CookLogic.cs
Normal file
@ -0,0 +1,93 @@
|
||||
using SushiBarContracts.BindingModels;
|
||||
using SushiBarContracts.BusinessLogicContracts;
|
||||
using SushiBarContracts.SearchModels;
|
||||
using SushiBarContracts.StoragesContracts;
|
||||
using SushiBarContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SushiBarBusinessLogic.BusinessLogics
|
||||
{
|
||||
public class CookLogic : ICookLogic
|
||||
{
|
||||
private readonly ICookStorage _cookStorage;
|
||||
|
||||
public CookLogic(ICookStorage cookStorage)
|
||||
{
|
||||
_cookStorage = cookStorage;
|
||||
}
|
||||
public CookViewModel? ReadElement(CookSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
|
||||
var element = _cookStorage.GetElement(model);
|
||||
if (element == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return element;
|
||||
}
|
||||
|
||||
public List<CookViewModel>? ReadList(CookSearchModel? model)
|
||||
{
|
||||
var list = model == null ? _cookStorage.GetFullList() : _cookStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public bool Create(CookBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_cookStorage.Insert(model) == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Delete(CookBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
if (_cookStorage.Delete(model) == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Update(CookBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_cookStorage.Update(model) == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void CheckModel(CookBindingModel model, bool withParams = true)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
if (!withParams)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.CookName))
|
||||
{
|
||||
throw new ArgumentNullException("Нет названия", nameof(model.CookName));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
93
SushiBar/SushiBarBusinessLogic/BusinessLogics/MenuLogic.cs
Normal file
93
SushiBar/SushiBarBusinessLogic/BusinessLogics/MenuLogic.cs
Normal file
@ -0,0 +1,93 @@
|
||||
using SushiBarContracts.BindingModels;
|
||||
using SushiBarContracts.BusinessLogicContracts;
|
||||
using SushiBarContracts.SearchModels;
|
||||
using SushiBarContracts.StoragesContracts;
|
||||
using SushiBarContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SushiBarBusinessLogic.BusinessLogics
|
||||
{
|
||||
public class MenuLogic : IMenuLogic
|
||||
{
|
||||
private readonly IMenuStorage _menuStorage;
|
||||
|
||||
public MenuLogic(IMenuStorage menuStorage)
|
||||
{
|
||||
_menuStorage = menuStorage;
|
||||
}
|
||||
public MenuViewModel? ReadElement(MenuSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
|
||||
var element = _menuStorage.GetElement(model);
|
||||
if (element == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return element;
|
||||
}
|
||||
|
||||
public List<MenuViewModel>? ReadList(MenuSearchModel? model)
|
||||
{
|
||||
var list = model == null ? _menuStorage.GetFullList() : _menuStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public bool Create(MenuBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_menuStorage.Insert(model) == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Delete(MenuBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
if (_menuStorage.Delete(model) == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Update(MenuBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_menuStorage.Update(model) == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void CheckModel(MenuBindingModel model, bool withParams = true)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
if (!withParams)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.FoodName))
|
||||
{
|
||||
throw new ArgumentNullException("Нет названия", nameof(model.FoodName));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
93
SushiBar/SushiBarBusinessLogic/BusinessLogics/PlaceLogic.cs
Normal file
93
SushiBar/SushiBarBusinessLogic/BusinessLogics/PlaceLogic.cs
Normal file
@ -0,0 +1,93 @@
|
||||
using SushiBarContracts.BindingModels;
|
||||
using SushiBarContracts.BusinessLogicContracts;
|
||||
using SushiBarContracts.SearchModels;
|
||||
using SushiBarContracts.StoragesContracts;
|
||||
using SushiBarContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SushiBarBusinessLogic.BusinessLogics
|
||||
{
|
||||
public class PlaceLogic : IPlaceLogic
|
||||
{
|
||||
private readonly IPlaceStorage _placeStorage;
|
||||
|
||||
public PlaceLogic(IPlaceStorage placeStorage)
|
||||
{
|
||||
_placeStorage = placeStorage;
|
||||
}
|
||||
public PlaceViewModel? ReadElement(PlaceSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
|
||||
var element = _placeStorage.GetElement(model);
|
||||
if (element == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return element;
|
||||
}
|
||||
|
||||
public List<PlaceViewModel>? ReadList(PlaceSearchModel? model)
|
||||
{
|
||||
var list = model == null ? _placeStorage.GetFullList() : _placeStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public bool Create(PlaceBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_placeStorage.Insert(model) == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Delete(PlaceBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
if (_placeStorage.Delete(model) == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Update(PlaceBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_placeStorage.Update(model) == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void CheckModel(PlaceBindingModel model, bool withParams = true)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
if (!withParams)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.PlaceNumber.ToString()))
|
||||
{
|
||||
throw new ArgumentNullException("Нет названия", nameof(model.PlaceNumber));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
89
SushiBar/SushiBarBusinessLogic/BusinessLogics/TaskLogic.cs
Normal file
89
SushiBar/SushiBarBusinessLogic/BusinessLogics/TaskLogic.cs
Normal file
@ -0,0 +1,89 @@
|
||||
using SushiBarContracts.BindingModels;
|
||||
using SushiBarContracts.BusinessLogicContracts;
|
||||
using SushiBarContracts.SearchModels;
|
||||
using SushiBarContracts.StoragesContracts;
|
||||
using SushiBarContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SushiBarBusinessLogic.BusinessLogics
|
||||
{
|
||||
public class TaskLogic : ITaskLogic
|
||||
{
|
||||
private readonly ITaskStorage _taskStorage;
|
||||
|
||||
public TaskLogic(ITaskStorage taskStorage)
|
||||
{
|
||||
_taskStorage = taskStorage;
|
||||
}
|
||||
public TaskViewModel? ReadElement(TaskSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
|
||||
var element = _taskStorage.GetElement(model);
|
||||
if (element == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return element;
|
||||
}
|
||||
|
||||
public List<TaskViewModel>? ReadList(TaskSearchModel? model)
|
||||
{
|
||||
var list = model == null ? _taskStorage.GetFullList() : _taskStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public bool Create(TaskBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_taskStorage.Insert(model) == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Delete(TaskBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
if (_taskStorage.Delete(model) == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Update(TaskBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_taskStorage.Update(model) == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void CheckModel(TaskBindingModel model, bool withParams = true)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
if (!withParams)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
14
SushiBar/SushiBarBusinessLogic/SushiBarBusinessLogic.csproj
Normal file
14
SushiBar/SushiBarBusinessLogic/SushiBarBusinessLogic.csproj
Normal file
@ -0,0 +1,14 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\SushiBarContracts\SushiBarContracts.csproj" />
|
||||
<ProjectReference Include="..\SushiBarDataModels\SushiBarDataModels.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
@ -1,4 +1,5 @@
|
||||
using SushiBarContracts.SearchModels;
|
||||
using SushiBarContracts.BindingModels;
|
||||
using SushiBarContracts.SearchModels;
|
||||
using SushiBarContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@ -14,8 +15,8 @@ namespace SushiBarContracts.StoragesContracts
|
||||
List<BuyerViewModel> GetFilteredList(BuyerSearchModel model);
|
||||
|
||||
BuyerViewModel? GetElement(BuyerSearchModel model);
|
||||
BuyerViewModel? Insert(BuyerSearchModel model);
|
||||
BuyerViewModel? Update(BuyerSearchModel model);
|
||||
BuyerViewModel? Delete(BuyerSearchModel model);
|
||||
BuyerViewModel? Insert(BuyerBindingModel model);
|
||||
BuyerViewModel? Update(BuyerBindingModel model);
|
||||
BuyerViewModel? Delete(BuyerBindingModel model);
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
using SushiBarContracts.SearchModels;
|
||||
using SushiBarContracts.BindingModels;
|
||||
using SushiBarContracts.SearchModels;
|
||||
using SushiBarContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@ -14,8 +15,8 @@ namespace SushiBarContracts.StoragesContracts
|
||||
List<CookViewModel> GetFilteredList(CookSearchModel model);
|
||||
|
||||
CookViewModel? GetElement(CookSearchModel model);
|
||||
CookViewModel? Insert(CookSearchModel model);
|
||||
CookViewModel? Update(CookSearchModel model);
|
||||
CookViewModel? Delete(CookSearchModel model);
|
||||
CookViewModel? Insert(CookBindingModel model);
|
||||
CookViewModel? Update(CookBindingModel model);
|
||||
CookViewModel? Delete(CookBindingModel model);
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
using SushiBarContracts.SearchModels;
|
||||
using SushiBarContracts.BindingModels;
|
||||
using SushiBarContracts.SearchModels;
|
||||
using SushiBarContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@ -14,8 +15,8 @@ namespace SushiBarContracts.StoragesContracts
|
||||
List<MenuViewModel> GetFilteredList(MenuSearchModel model);
|
||||
|
||||
MenuViewModel? GetElement(MenuSearchModel model);
|
||||
MenuViewModel? Insert(MenuSearchModel model);
|
||||
MenuViewModel? Update(MenuSearchModel model);
|
||||
MenuViewModel? Delete(MenuSearchModel model);
|
||||
MenuViewModel? Insert(MenuBindingModel model);
|
||||
MenuViewModel? Update(MenuBindingModel model);
|
||||
MenuViewModel? Delete(MenuBindingModel model);
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
using SushiBarContracts.SearchModels;
|
||||
using SushiBarContracts.BindingModels;
|
||||
using SushiBarContracts.SearchModels;
|
||||
using SushiBarContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@ -14,8 +15,8 @@ namespace SushiBarContracts.StoragesContracts
|
||||
List<PlaceViewModel> GetFilteredList(PlaceSearchModel model);
|
||||
|
||||
PlaceViewModel? GetElement(PlaceSearchModel model);
|
||||
PlaceViewModel? Insert(PlaceSearchModel model);
|
||||
PlaceViewModel? Update(PlaceSearchModel model);
|
||||
PlaceViewModel? Delete(PlaceSearchModel model);
|
||||
PlaceViewModel? Insert(PlaceBindingModel model);
|
||||
PlaceViewModel? Update(PlaceBindingModel model);
|
||||
PlaceViewModel? Delete(PlaceBindingModel model);
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
using SushiBarContracts.SearchModels;
|
||||
using SushiBarContracts.BindingModels;
|
||||
using SushiBarContracts.SearchModels;
|
||||
using SushiBarContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@ -14,8 +15,8 @@ namespace SushiBarContracts.StoragesContracts
|
||||
List<TaskViewModel> GetFilteredList(TaskSearchModel model);
|
||||
|
||||
TaskViewModel? GetElement(TaskSearchModel model);
|
||||
TaskViewModel? Insert(TaskSearchModel model);
|
||||
TaskViewModel? Update(TaskSearchModel model);
|
||||
TaskViewModel? Delete(TaskSearchModel model);
|
||||
TaskViewModel? Insert(TaskBindingModel model);
|
||||
TaskViewModel? Update(TaskBindingModel model);
|
||||
TaskViewModel? Delete(TaskBindingModel model);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user