ПИбд-22 Боровков М В 1 лабораторная работа #1
@ -9,6 +9,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SushiBarDataModels", "Sushi
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SushiBarContracts", "SushiBarContracts\SushiBarContracts.csproj", "{D3DDD3BE-863D-42E3-8CE7-FE527C5ADA13}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SushiBarContracts", "SushiBarContracts\SushiBarContracts.csproj", "{D3DDD3BE-863D-42E3-8CE7-FE527C5ADA13}"
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SushiBarBusinessLogic", "SushiBarBusinessLogic\SushiBarBusinessLogic.csproj", "{CD8F84A5-5665-49EC-9630-F27A3176BA47}"
|
||||||
|
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
|
|||||||
{D3DDD3BE-863D-42E3-8CE7-FE527C5ADA13}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{D3DDD3BE-863D-42E3-8CE7-FE527C5ADA13}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{D3DDD3BE-863D-42E3-8CE7-FE527C5ADA13}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{D3DDD3BE-863D-42E3-8CE7-FE527C5ADA13}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{D3DDD3BE-863D-42E3-8CE7-FE527C5ADA13}.Release|Any CPU.Build.0 = Release|Any CPU
|
{D3DDD3BE-863D-42E3-8CE7-FE527C5ADA13}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{CD8F84A5-5665-49EC-9630-F27A3176BA47}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{CD8F84A5-5665-49EC-9630-F27A3176BA47}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{CD8F84A5-5665-49EC-9630-F27A3176BA47}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{CD8F84A5-5665-49EC-9630-F27A3176BA47}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
109
SushiBar/SushiBarBusinessLogic/BusinessLogics/ComponentLogic.cs
Normal file
109
SushiBar/SushiBarBusinessLogic/BusinessLogics/ComponentLogic.cs
Normal file
@ -0,0 +1,109 @@
|
|||||||
|
using SushiBarContracts.BusinessLogicsContracts;
|
||||||
|
using SushiBarContracts.BindingModels;
|
||||||
|
using SushiBarContracts.SearchModels;
|
||||||
|
using SushiBarContracts.StoragesContracts;
|
||||||
|
using SushiBarContracts.ViewModels;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
|
namespace SushiBarBusinessLogic.BusinessLogics
|
||||||
|
{
|
||||||
|
public class ComponentLogic : IComponentLogic
|
||||||
|
{
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
private readonly IComponentStorage _componentStorage;
|
||||||
|
public ComponentLogic(ILogger<ComponentLogic> logger, IComponentStorage componentStorage)
|
||||||
|
{
|
||||||
|
_logger = logger;
|
||||||
|
_componentStorage = componentStorage;
|
||||||
|
}
|
||||||
|
public List<ComponentViewModel>? ReadList(ComponentSearchModel? model)
|
||||||
|
{
|
||||||
|
_logger.LogInformation("ReadList. ComponentName:{ComponentName}. Id:{ Id}", model?.ComponentName, model?.Id);
|
||||||
|
var list = model == null ? _componentStorage.GetFullList() :
|
||||||
|
_componentStorage.GetFilteredList(model);
|
||||||
|
if (list == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("ReadList return null list");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
public ComponentViewModel? ReadElement(ComponentSearchModel model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(model));
|
||||||
|
}
|
||||||
|
_logger.LogInformation("ReadElement. ComponentName:{ComponentName}. Id:{ Id}", model.ComponentName, model.Id);
|
||||||
|
var element = _componentStorage.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(ComponentBindingModel model)
|
||||||
|
{
|
||||||
|
CheckModel(model);
|
||||||
|
if (_componentStorage.Insert(model) == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Insert operation failed");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
public bool Update(ComponentBindingModel model)
|
||||||
|
{
|
||||||
|
CheckModel(model);
|
||||||
|
if (_componentStorage.Update(model) == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Update operation failed");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
public bool Delete(ComponentBindingModel model)
|
||||||
|
{
|
||||||
|
CheckModel(model, false);
|
||||||
|
_logger.LogInformation("Delete. Id:{Id}", model.Id);
|
||||||
|
if (_componentStorage.Delete(model) == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Delete operation failed");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
private void CheckModel(ComponentBindingModel model, bool withParams = true)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(model));
|
||||||
|
}
|
||||||
|
if (!withParams)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (string.IsNullOrEmpty(model.ComponentName))
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException("Нет названия компонента", nameof(model.ComponentName));
|
||||||
|
}
|
||||||
|
if (model.Cost <= 0)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException("Цена компонента должна быть больше 0", nameof(model.Cost));
|
||||||
|
}
|
||||||
|
_logger.LogInformation("Component. ComponentName:{ComponentName}. Cost:{ Cost}. Id: { Id}", model.ComponentName, model.Cost, model.Id);
|
||||||
|
var element = _componentStorage.GetElement(new ComponentSearchModel
|
||||||
|
{
|
||||||
|
ComponentName = model.ComponentName
|
||||||
|
});
|
||||||
|
if (element != null && element.Id != model.Id)
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException("Компонент с таким названием уже есть");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
132
SushiBar/SushiBarBusinessLogic/BusinessLogics/OrderLogic.cs
Normal file
132
SushiBar/SushiBarBusinessLogic/BusinessLogics/OrderLogic.cs
Normal file
@ -0,0 +1,132 @@
|
|||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using SushiBarContracts.BindingModels;
|
||||||
|
using SushiBarContracts.BusinessLogicsContracts;
|
||||||
|
using SushiBarContracts.SearchModels;
|
||||||
|
using SushiBarContracts.StoragesContracts;
|
||||||
|
using SushiBarContracts.ViewModels;
|
||||||
|
using SushiBarDataModels.Enums;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace SushiBarBusinessLogic.BusinessLogics
|
||||||
|
{
|
||||||
|
public class OrderLogic : IOrderLogic
|
||||||
|
{
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
private readonly IOrderStorage _orderStorage;
|
||||||
|
public OrderLogic(ILogger logger, IOrderStorage orderStorage)
|
||||||
|
{
|
||||||
|
_logger = logger;
|
||||||
|
_orderStorage = orderStorage;
|
||||||
|
}
|
||||||
|
public List<OrderViewModel>? ReadList(OrderSearchModel? model)
|
||||||
|
{
|
||||||
|
_logger.LogInformation("ReadList. Id:{ Id}", model?.Id);
|
||||||
|
var list = model == null ? _orderStorage.GetFullList() :
|
||||||
|
_orderStorage.GetFilteredList(model);
|
||||||
|
if (list == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("ReadList return null list");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
public bool CreateOrder(OrderBindingModel model)
|
||||||
|
{
|
||||||
|
CheckModel(model);
|
||||||
|
if (model.Status != OrderStatus.Неизвестен)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Wrong Order Status");
|
||||||
|
_logger.LogWarning("Insert operation failed");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
model.Status = OrderStatus.Принят;
|
||||||
|
if (_orderStorage.Insert(model) == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Insert operation failed");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
public bool TakeOrderInWork(OrderBindingModel model)
|
||||||
|
{
|
||||||
|
CheckModel(model);
|
||||||
|
if (model.Status != OrderStatus.Принят)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Wrong Order Status");
|
||||||
|
_logger.LogWarning("Insert operation failed");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
model.Status = OrderStatus.Выполняется;
|
||||||
|
if (_orderStorage.Update(model) == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Insert operation failed");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
public bool DeliveryOrder(OrderBindingModel model)
|
||||||
|
{
|
||||||
|
CheckModel(model);
|
||||||
|
if (model.Status != OrderStatus.Выполняется)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Wrong Order Status");
|
||||||
|
_logger.LogWarning("Insert operation failed");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
model.Status = OrderStatus.Готов;
|
||||||
|
if (_orderStorage.Update(model) == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Insert operation failed");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool FinishOrder(OrderBindingModel model)
|
||||||
|
{
|
||||||
|
CheckModel(model);
|
||||||
|
if (model.Status != OrderStatus.Готов)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Wrong Order Status");
|
||||||
|
_logger.LogWarning("Insert operation failed");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
model.Status = OrderStatus.Выдан;
|
||||||
|
if (_orderStorage.Update(model) == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Insert operation failed");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void CheckModel(OrderBindingModel model, bool withParams = true)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(model));
|
||||||
|
}
|
||||||
|
if (!withParams)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (model.DateImplement != null && model.DateCreate > model.DateImplement)
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException("Заказ не может быть начат после его завершения");
|
||||||
|
}
|
||||||
|
if (model.Count <= 0)
|
||||||
|
{
|
||||||
|
throw new ArgumentException("Количество продукта должно быть бльше 0");
|
||||||
|
}
|
||||||
|
if (model.Sum <= 0)
|
||||||
|
{
|
||||||
|
throw new ArgumentException("Сумма заказа должна быть больше 0", nameof(model.Sum));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
106
SushiBar/SushiBarBusinessLogic/BusinessLogics/ProductLogic.cs
Normal file
106
SushiBar/SushiBarBusinessLogic/BusinessLogics/ProductLogic.cs
Normal file
@ -0,0 +1,106 @@
|
|||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using SushiBarContracts.BindingModels;
|
||||||
|
using SushiBarContracts.BusinessLogicsContracts;
|
||||||
|
using SushiBarContracts.SearchModels;
|
||||||
|
using SushiBarContracts.StoragesContracts;
|
||||||
|
using SushiBarContracts.ViewModels;
|
||||||
|
|
||||||
|
namespace SushiBarBusinessLogic.BusinessLogics
|
||||||
|
{
|
||||||
|
public class ProductLogic : IProductLogic
|
||||||
|
{
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
private readonly IProductStorage _productStorage;
|
||||||
|
public ProductLogic(ILogger logger, IProductStorage productStorage)
|
||||||
|
{
|
||||||
|
_logger = logger;
|
||||||
|
_productStorage = productStorage;
|
||||||
|
}
|
||||||
|
public List<ProductViewModel>? ReadList(ProductSearchModel? model)
|
||||||
|
{
|
||||||
|
_logger.LogInformation("ReadList. ProductName:{ProductName}. Id:{ Id}", model?.ProductName, model?.Id);
|
||||||
|
var list = model == null ? _productStorage.GetFullList() :
|
||||||
|
_productStorage.GetFilteredList(model);
|
||||||
|
if (list == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("ReadList return null list");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
public ProductViewModel? ReadElement(ProductSearchModel model)
|
||||||
|
{
|
||||||
|
if(model == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(model));
|
||||||
|
}
|
||||||
|
_logger.LogInformation("ReadElement. ProductName:{ProductName}. Id:{ Id}", model.ProductName, model.Id);
|
||||||
|
var element = _productStorage.GetElement(model);
|
||||||
|
if (element == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("ReadElement element not found");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return element;
|
||||||
|
}
|
||||||
|
public bool Create(ProductBindingModel model)
|
||||||
|
{
|
||||||
|
CheckModel(model);
|
||||||
|
if (_productStorage.Insert(model) == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Insert operation failed");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
public bool Update(ProductBindingModel model)
|
||||||
|
{
|
||||||
|
CheckModel(model);
|
||||||
|
if (_productStorage.Update(model) == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Update operation failed");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
public bool Delete(ProductBindingModel model)
|
||||||
|
{
|
||||||
|
CheckModel(model, false);
|
||||||
|
_logger.LogInformation("Delete. Id:{Id}", model.Id);
|
||||||
|
if (_productStorage.Delete(model) == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Delete operation failed");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
private void CheckModel(ProductBindingModel model, bool withParams = true)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(model));
|
||||||
|
}
|
||||||
|
if (!withParams)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (string.IsNullOrEmpty(model.ProductName))
|
||||||
|
{
|
||||||
|
throw new ArgumentException("Нет названия продукта", nameof(model.ProductName));
|
||||||
|
}
|
||||||
|
if (model.Price <= 0)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException("Цена продукта должна быть больше 0", nameof(model.Price));
|
||||||
|
}
|
||||||
|
var element = _productStorage.GetElement(new ProductSearchModel
|
||||||
|
{
|
||||||
|
ProductName = model.ProductName
|
||||||
|
});
|
||||||
|
if (element != null && element.Id != model.Id)
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException("Продукт с таким названием уже есть");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user