Compare commits

..

5 Commits

25 changed files with 615 additions and 11 deletions

View File

@ -7,6 +7,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FlowerShop", "FlowerShop\Fl
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FlowerShopDataModels", "FlowerShopDataModels\FlowerShopDataModels.csproj", "{FDC31847-CB24-4EBD-8CE5-852ED404CEAE}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FlowerShopContracts", "FlowerShopContracts\FlowerShopContracts.csproj", "{404B251B-7B48-4648-99B4-7E99EDB05A6C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FlowerShopBusinessLogic", "FlowerShopBusinessLogic\FlowerShopBusinessLogic.csproj", "{D8084C04-7B2B-4C8D-A63A-71A3EE1BC065}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -21,6 +25,14 @@ Global
{FDC31847-CB24-4EBD-8CE5-852ED404CEAE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FDC31847-CB24-4EBD-8CE5-852ED404CEAE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FDC31847-CB24-4EBD-8CE5-852ED404CEAE}.Release|Any CPU.Build.0 = Release|Any CPU
{404B251B-7B48-4648-99B4-7E99EDB05A6C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{404B251B-7B48-4648-99B4-7E99EDB05A6C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{404B251B-7B48-4648-99B4-7E99EDB05A6C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{404B251B-7B48-4648-99B4-7E99EDB05A6C}.Release|Any CPU.Build.0 = Release|Any CPU
{D8084C04-7B2B-4C8D-A63A-71A3EE1BC065}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D8084C04-7B2B-4C8D-A63A-71A3EE1BC065}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D8084C04-7B2B-4C8D-A63A-71A3EE1BC065}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D8084C04-7B2B-4C8D-A63A-71A3EE1BC065}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View File

@ -0,0 +1,127 @@
using FlowerShopContracts.BindingModels;
using FlowerShopContracts.BusinessLogicsContracts;
using FlowerShopContracts.SearchModels;
using FlowerShopContracts.StoragesContracts;
using FlowerShopContracts.ViewModels;
using Microsoft.Extensions.Logging;
namespace FlowerShopBusinessLogic.BusinessLogics
{
public class BouquetLogic : IBouquetLogic
{
private readonly ILogger _logger;
private readonly IBouquetStorage _bouquetStorage;
public BouquetLogic(ILogger<BouquetLogic> logger, IBouquetStorage bouquetStorage)
{
_logger = logger;
_bouquetStorage = bouquetStorage;
}
public List<BouquetViewModel>? ReadList(BouquetSearchModel? model)
{
_logger.LogInformation("ReadList. BouquetName: {BouquetName}. Id: {Id}", model?.BouquetName, model?.Id);
var list = model == null ? _bouquetStorage.GetFullList() : _bouquetStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
return list;
}
public BouquetViewModel? ReadElement(BouquetSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadElement. BouquetName: {BouquetName}. Id: {Id}", model.BouquetName, model.Id);
var element = _bouquetStorage.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(BouquetBindingModel model)
{
CheckModel(model);
if (_bouquetStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Update(BouquetBindingModel model)
{
CheckModel(model);
if (_bouquetStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
public bool Delete(BouquetBindingModel model)
{
CheckModel(model, false);
_logger.LogInformation("Delete. Id: {Id}", model.Id);
if (_bouquetStorage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
private void CheckModel(BouquetBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (string.IsNullOrEmpty(model.BouquetName))
{
throw new ArgumentNullException("Нет названия букета", nameof(model.BouquetName));
}
if (model.Price <= 0)
{
throw new ArgumentNullException("Цена букета должна быть больше 0", nameof(model.Price));
}
_logger.LogInformation("Bouquet. BouquetName: {BouquetName}. Price: {Price}. Id: {Id}", model.BouquetName, model.Price, model.Id);
var element = _bouquetStorage.GetElement(new BouquetSearchModel { BouquetName = model.BouquetName });
if (element != null && element.Id != model.Id)
{
throw new InvalidOperationException("Компонент с таким названием уже есть");
}
}
}
}

View File

@ -0,0 +1,127 @@
using FlowerShopContracts.BindingModels;
using FlowerShopContracts.BusinessLogicsContracts;
using FlowerShopContracts.SearchModels;
using FlowerShopContracts.StoragesContracts;
using FlowerShopContracts.ViewModels;
using Microsoft.Extensions.Logging;
namespace FlowerShopBusinessLogic.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("Компонент с таким названием уже есть");
}
}
}
}

View File

@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging" Version="7.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\FlowerShopContracts\FlowerShopContracts.csproj" />
<ProjectReference Include="..\FlowerShopDataModels\FlowerShopDataModels.csproj" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,98 @@
using FlowerShopContracts.BindingModels;
using FlowerShopContracts.BusinessLogicsContracts;
using FlowerShopContracts.SearchModels;
using FlowerShopContracts.StoragesContracts;
using FlowerShopContracts.ViewModels;
using FlowerShopDataModels.Enums;
using Microsoft.Extensions.Logging;
namespace FlowerShopBusinessLogic.BusinessLogics
{
public class OrderLogic : IOrderLogic
{
private readonly ILogger _logger;
private readonly IOrderStorage _orderStorage;
public OrderLogic(ILogger<OrderLogic> 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.Unknown)
{
_logger.LogWarning("Invalid order status");
return false;
}
model.Status = OrderStatus.Accepted;
if (_orderStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool TakeOrderInWork(OrderBindingModel model)
{
throw new NotImplementedException();
}
public bool FinishOrder(OrderBindingModel model)
{
throw new NotImplementedException();
}
public bool DeliveryOrder(OrderBindingModel model)
{
throw new NotImplementedException();
}
private void CheckModel(OrderBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (model.Sum <= 0)
{
throw new ArgumentNullException("Стоимость должна быть больше 0", nameof(model.Sum));
}
_logger.LogInformation("Order. Id: {Id}. Sum: {Sum}. BouquetId: {BouquetId}", model.Id, model.Sum, model.BouquetId);
var element = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id });
if (element != null && element.Id == model.Id)
{
throw new InvalidOperationException("Заказ с таким идентификатором уже есть");
}
}
}
}

View File

@ -0,0 +1,12 @@
using FlowerShopDataModels.Models;
namespace FlowerShopContracts.BindingModels
{
public class BouquetBindingModel : IBouquetModel
{
public int Id { get; set; }
public string BouquetName { get; set; } = string.Empty;
public double Price { get; set; }
public Dictionary<int, (IComponentModel, int)> BouquetComponents { get; set; } = new();
}
}

View File

@ -0,0 +1,11 @@
using FlowerShopDataModels.Models;
namespace FlowerShopContracts.BindingModels
{
public class ComponentBindingModel : IComponentModel
{
public int Id { get; set; }
public string ComponentName { get; set; } = string.Empty;
public double Cost { get; set; }
}
}

View File

@ -0,0 +1,16 @@
using FlowerShopDataModels.Enums;
using FlowerShopDataModels.Models;
namespace FlowerShopContracts.BindingModels
{
public class OrderBindingModel : IOrderModel
{
public int Id { get; set; }
public int BouquetId { get; set; }
public int Count { get; set; }
public double Sum { get; set; }
public OrderStatus Status { get; set; } = OrderStatus.Unknown;
public DateTime DateCreate { get; set; } = DateTime.Now;
public DateTime? DateImplement { get; set; }
}
}

View File

@ -0,0 +1,15 @@
using FlowerShopContracts.BindingModels;
using FlowerShopContracts.SearchModels;
using FlowerShopContracts.ViewModels;
namespace FlowerShopContracts.BusinessLogicsContracts
{
public interface IBouquetLogic
{
List<BouquetViewModel>? ReadList(BouquetSearchModel? model);
BouquetViewModel? ReadElement(BouquetSearchModel model);
bool Create(BouquetBindingModel model);
bool Update(BouquetBindingModel model);
bool Delete(BouquetBindingModel model);
}
}

View File

@ -0,0 +1,15 @@
using FlowerShopContracts.ViewModels;
using FlowerShopContracts.BindingModels;
using FlowerShopContracts.SearchModels;
namespace FlowerShopContracts.BusinessLogicsContracts
{
public interface IComponentLogic
{
List<ComponentViewModel>? ReadList(ComponentSearchModel? model);
ComponentViewModel? ReadElement(ComponentSearchModel model);
bool Create(ComponentBindingModel model);
bool Update(ComponentBindingModel model);
bool Delete(ComponentBindingModel model);
}
}

View File

@ -0,0 +1,15 @@
using FlowerShopContracts.BindingModels;
using FlowerShopContracts.SearchModels;
using FlowerShopContracts.ViewModels;
namespace FlowerShopContracts.BusinessLogicsContracts
{
public interface IOrderLogic
{
List<OrderViewModel>? ReadList(OrderSearchModel? model);
bool CreateOrder(OrderBindingModel model);
bool TakeOrderInWork(OrderBindingModel model);
bool FinishOrder(OrderBindingModel model);
bool DeliveryOrder(OrderBindingModel model);
}
}

View File

@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\FlowerShopDataModels\FlowerShopDataModels.csproj" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,8 @@
namespace FlowerShopContracts.SearchModels
{
public class ComponentSearchModel
{
public int? Id { get; set; }
public string? ComponentName { get; set; }
}
}

View File

@ -0,0 +1,7 @@
namespace FlowerShopContracts.SearchModels
{
public class OrderSearchModel
{
public int? Id { get; set; }
}
}

View File

@ -0,0 +1,8 @@
namespace FlowerShopContracts.SearchModels
{
public class BouquetSearchModel
{
public int? Id { get; set; }
public string? BouquetName { get; set; }
}
}

View File

@ -0,0 +1,16 @@
using FlowerShopContracts.BindingModels;
using FlowerShopContracts.SearchModels;
using FlowerShopContracts.ViewModels;
namespace FlowerShopContracts.StoragesContracts
{
public interface IBouquetStorage
{
List<BouquetViewModel> GetFullList();
List<BouquetViewModel> GetFilteredList(BouquetSearchModel model);
BouquetViewModel? GetElement(BouquetSearchModel model);
BouquetViewModel? Insert(BouquetBindingModel model);
BouquetViewModel? Update(BouquetBindingModel model);
BouquetViewModel? Delete(BouquetBindingModel model);
}
}

View File

@ -0,0 +1,16 @@
using FlowerShopContracts.BindingModels;
using FlowerShopContracts.SearchModels;
using FlowerShopContracts.ViewModels;
namespace FlowerShopContracts.StoragesContracts
{
public interface IComponentStorage
{
List<ComponentViewModel> GetFullList();
List<ComponentViewModel> GetFilteredList(ComponentSearchModel model);
ComponentViewModel? GetElement(ComponentSearchModel model);
ComponentViewModel? Insert(ComponentBindingModel model);
ComponentViewModel? Update(ComponentBindingModel model);
ComponentViewModel? Delete(ComponentBindingModel model);
}
}

View File

@ -0,0 +1,16 @@
using FlowerShopContracts.BindingModels;
using FlowerShopContracts.SearchModels;
using FlowerShopContracts.ViewModels;
namespace FlowerShopContracts.StoragesContracts
{
public interface IOrderStorage
{
List<OrderViewModel> GetFullList();
List<OrderViewModel> GetFilteredList(OrderSearchModel model);
OrderViewModel? GetElement(OrderSearchModel model);
OrderViewModel? Insert(OrderBindingModel model);
OrderViewModel? Update(OrderBindingModel model);
OrderViewModel? Delete(OrderBindingModel model);
}
}

View File

@ -0,0 +1,15 @@
using FlowerShopDataModels.Models;
using System.ComponentModel;
namespace FlowerShopContracts.ViewModels
{
public class BouquetViewModel : IBouquetModel
{
public int Id { get; set; }
[DisplayName("Название букета")]
public string BouquetName { get; set; } = string.Empty;
[DisplayName("Цена")]
public double Price { get; set; }
public Dictionary<int, (IComponentModel, int)> BouquetComponents { get; set; } = new();
}
}

View File

@ -0,0 +1,14 @@
using FlowerShopDataModels.Models;
using System.ComponentModel;
namespace FlowerShopContracts.ViewModels
{
public class ComponentViewModel : IComponentModel
{
public int Id { get; set; }
[DisplayName("Название компонента")]
public string ComponentName { get; set; } = string.Empty;
[DisplayName("Цена")]
public double Cost { get; set; }
}
}

View File

@ -0,0 +1,25 @@
using FlowerShopDataModels.Enums;
using FlowerShopDataModels.Models;
using System.ComponentModel;
namespace FlowerShopContracts.ViewModels
{
public class OrderViewModel : IOrderModel
{
[DisplayName("Номер")]
public int Id { get; set; }
public int BouquetId { get; set; }
[DisplayName("Букет")]
public string BouquetName { get; set; } = string.Empty;
[DisplayName("Количество")]
public int Count { get; set; }
[DisplayName("Сумма")]
public double Sum { get; set; }
[DisplayName("Статус")]
public OrderStatus Status { get; set; } = OrderStatus.Unknown;
[DisplayName("Дата создания")]
public DateTime DateCreate { get; set; } = DateTime.Now;
[DisplayName("Дата выполнения")]
public DateTime? DateImplement { get; set; }
}
}

View File

@ -0,0 +1,9 @@
namespace FlowerShopDataModels.Models
{
public interface IBouquetModel : IId
{
string BouquetName { get; }
double Price { get; }
Dictionary<int, (IComponentModel, int)> BouquetComponents { get; }
}
}

View File

@ -4,7 +4,7 @@ namespace FlowerShopDataModels.Models
{
public interface IOrderModel : IId
{
int ProductId { get; }
int BouquetId { get; }
int Count { get; }
double Sum { get; }
OrderStatus Status { get; }

View File

@ -1,9 +0,0 @@
namespace FlowerShopDataModels.Models
{
public interface IProductModel : IId
{
string ProductName { get; }
double Price { get; }
Dictionary<int, (IComponentModel, int)> ProductComponents { get; }
}
}

View File

@ -6,6 +6,6 @@
Accepted = 0,
Processing = 1,
Ready = 2,
Issued = 3
Delivered = 3
}
}