Дошёл до ConfectioneryListImplement и добавил ссылки.

This commit is contained in:
Артём Алейкин 2023-02-14 00:08:23 +04:00
parent b8bc72fe37
commit ec225c1df6
20 changed files with 591 additions and 23 deletions

View File

@ -3,11 +3,15 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17 # Visual Studio Version 17
VisualStudioVersion = 17.0.32112.339 VisualStudioVersion = 17.0.32112.339
MinimumVisualStudioVersion = 10.0.40219.1 MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConfectioneryDataModels", "ConfectioneryDataModels\ConfectioneryDataModels.csproj", "{D7A8174D-1B45-4463-A4D7-C82CA529EE4D}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ConfectioneryDataModels", "ConfectioneryDataModels\ConfectioneryDataModels.csproj", "{D7A8174D-1B45-4463-A4D7-C82CA529EE4D}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConfectioneryContracts", "ConfectioneryContracts\ConfectioneryContracts.csproj", "{C151D91F-BDB0-46AD-8573-3F6174E9E76A}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ConfectioneryContracts", "ConfectioneryContracts\ConfectioneryContracts.csproj", "{C151D91F-BDB0-46AD-8573-3F6174E9E76A}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConfectioneryView", "ConfectioneryView\ConfectioneryView.csproj", "{B222E04E-D0E7-49F4-8747-426125645B93}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ConfectioneryView", "ConfectioneryView\ConfectioneryView.csproj", "{B222E04E-D0E7-49F4-8747-426125645B93}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConfectioneryBusinessLogic", "ConfectioneryBusinessLogic\ConfectioneryBusinessLogic.csproj", "{40859695-0BD6-49A8-8997-AD76F6984144}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConfectioneryListImplement", "ConfectioneryListImplement\ConfectioneryListImplement.csproj", "{8B6BFE3A-CA63-4FCB-B7AC-DB3F28E0F7A7}"
EndProject EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -27,6 +31,14 @@ Global
{B222E04E-D0E7-49F4-8747-426125645B93}.Debug|Any CPU.Build.0 = Debug|Any CPU {B222E04E-D0E7-49F4-8747-426125645B93}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B222E04E-D0E7-49F4-8747-426125645B93}.Release|Any CPU.ActiveCfg = Release|Any CPU {B222E04E-D0E7-49F4-8747-426125645B93}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B222E04E-D0E7-49F4-8747-426125645B93}.Release|Any CPU.Build.0 = Release|Any CPU {B222E04E-D0E7-49F4-8747-426125645B93}.Release|Any CPU.Build.0 = Release|Any CPU
{40859695-0BD6-49A8-8997-AD76F6984144}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{40859695-0BD6-49A8-8997-AD76F6984144}.Debug|Any CPU.Build.0 = Debug|Any CPU
{40859695-0BD6-49A8-8997-AD76F6984144}.Release|Any CPU.ActiveCfg = Release|Any CPU
{40859695-0BD6-49A8-8997-AD76F6984144}.Release|Any CPU.Build.0 = Release|Any CPU
{8B6BFE3A-CA63-4FCB-B7AC-DB3F28E0F7A7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8B6BFE3A-CA63-4FCB-B7AC-DB3F28E0F7A7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8B6BFE3A-CA63-4FCB-B7AC-DB3F28E0F7A7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8B6BFE3A-CA63-4FCB-B7AC-DB3F28E0F7A7}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE

View File

@ -0,0 +1,127 @@
using ConfectioneryContracts.BindingModels;
using ConfectioneryContracts.BusinessLogicsContracts;
using ConfectioneryContracts.SearchModels;
using ConfectioneryContracts.StoragesContracts;
using ConfectioneryContracts.ViewModels;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection.Metadata.Ecma335;
using System.Text;
using System.Threading.Tasks;
namespace ConfectioneryBusinessLogic.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,132 @@
using ConfectioneryContracts.BindingModels;
using ConfectioneryContracts.BusinessLogicsContracts;
using ConfectioneryContracts.SearchModels;
using ConfectioneryContracts.StoragesContracts;
using ConfectioneryContracts.ViewModels;
using ConfectioneryDataModels.Enums;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConfectioneryBusinessLogic.BusinessLogics
{
internal class OrderLogic : IOrderLogic
{
private readonly ILogger _logger;
private readonly IOrderStorage _orderStorage;
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage)
{
_logger = logger;
_orderStorage = orderStorage;
}
public bool CreateOrder(OrderBindingModel model)
{
CheckModel(model);
if (model.Status != OrderStatus.Неизвестен)
{
_logger.LogWarning("Insert operation failed. Order status incorrect.");
return false;
}
model.Status = OrderStatus.Принят;
if (_orderStorage.Insert(model) == null)
{
model.Status = OrderStatus.Неизвестен;
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool StatusUpdate(OrderBindingModel model, OrderStatus newStatus)
{
var viewModel = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id });
if (viewModel == null)
{
throw new ArgumentNullException(nameof(model));
}
if (viewModel.Status + 1 != newStatus)
{
_logger.LogWarning("Update operation failed. Order status incorrect.");
return false;
}
model.Status = newStatus;
if (model.Status == OrderStatus.Готов) model.DateImplement = DateTime.Now;
else
{
model.DateImplement = viewModel.DateImplement;
}
CheckModel(model);
if (_orderStorage.Update(model) == null)
{
model.Status--;
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
public bool DeliveryOrder(OrderBindingModel model)
{
return StatusUpdate(model, OrderStatus.Выдан);
}
public bool FinishOrder(OrderBindingModel model)
{
return StatusUpdate(model, OrderStatus.Готов);
}
public bool TakeOrderInWork(OrderBindingModel model)
{
return StatusUpdate(model, OrderStatus.Выполняется);
}
public List<OrderViewModel>? ReadList(OrderSearchModel? model)
{
_logger.LogInformation("ReadList. OrderId:{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;
}
private void CheckModel(OrderBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if(model.PastryId < 0)
{
throw new ArgumentNullException("Некорректный идентификатор документа",
nameof(model.PastryId));
}
if (model.Count <= 0)
{
throw new ArgumentNullException("Количество кондитерских изделий в заказе должно быть больше 0",
nameof(model.Count));
}
if (model.Sum <= 0)
{
throw new ArgumentNullException("Сумма заказа должна быть больше 0",
nameof(model.Sum));
}
_logger.LogInformation("Pastry. OrderId:{Id}. Sum:{Sum}. PastryId:{PastryId}.",
model.Id, model.Sum, model.PastryId);
}
}
}

View File

@ -0,0 +1,121 @@
using ConfectioneryContracts.BindingModels;
using ConfectioneryContracts.BusinessLogicsContracts;
using ConfectioneryContracts.SearchModels;
using ConfectioneryContracts.StoragesContracts;
using ConfectioneryContracts.ViewModels;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConfectioneryBusinessLogic.BusinessLogics
{
public class PastryLogic : IPastryLogic
{
private readonly ILogger _logger;
private readonly IPastryStorage _pastryStorage;
public PastryLogic(ILogger<PastryLogic> logger, IPastryStorage pastryStorage)
{
_logger = logger;
_pastryStorage = pastryStorage;
}
public List<PastryViewModel>? ReadList(PastrySearchModel? model)
{
_logger.LogInformation("ReadList. PastryName:{PastryName}. Id:{Id}", model?.PastryName, model?.Id);
var list = model == null ? _pastryStorage.GetFullList() : _pastryStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
return list;
}
public PastryViewModel? ReadElement(PastrySearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadElement. PastryName:{PastryName}. Id:{Id}", model.PastryName, model.Id);
var element = _pastryStorage.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(PastryBindingModel model)
{
CheckModel(model);
if (_pastryStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Update(PastryBindingModel model)
{
CheckModel(model);
if (_pastryStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
public bool Delete(PastryBindingModel model)
{
CheckModel(model, false);
_logger.LogInformation("Delete. Id:{Id}", model.Id);
if (_pastryStorage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
private void CheckModel(PastryBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (string.IsNullOrEmpty(model.PastryName))
{
throw new ArgumentNullException("Нет названия кондитерского изделия", nameof(model.PastryName));
}
if (model.Price <= 0)
{
throw new ArgumentNullException("Цена кондитерского изделия должна быть больше 0", nameof(model.Price));
}
_logger.LogInformation("Pastry. PastryName:{PastryName}. Cost:{Cost}. Id:{Id}",
model.PastryName, model.Price, model.Id);
var element = _pastryStorage.GetElement(new PastrySearchModel
{
PastryName = model.PastryName
});
if (element != null && element.Id != model.Id)
{
throw new InvalidOperationException("Кондитерское изделие с таким названием уже есть");
}
}
}
}

View File

@ -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" Version="7.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ConfectioneryContracts\ConfectioneryContracts.csproj" />
</ItemGroup>
</Project>

View File

@ -12,7 +12,7 @@ namespace ConfectioneryContracts.BindingModels
{ {
public int Id { get; set; } public int Id { get; set; }
public int ProductId { get; set; } public int PastryId { get; set; }
public int Count { get; set; } public int Count { get; set; }

View File

@ -7,14 +7,14 @@ using System.Threading.Tasks;
namespace ConfectioneryContracts.BindingModels namespace ConfectioneryContracts.BindingModels
{ {
public class ProductBindingModel : IProductModel public class PastryBindingModel : IPastryModel
{ {
public int Id { get; set; } public int Id { get; set; }
public string ProductName { get; set; } = string.Empty; public string PastryName { get; set; } = string.Empty;
public double Price { get; set; } public double Price { get; set; }
public Dictionary<int, (IComponentModel, int)> ProductComponents { get; set; } = new(); public Dictionary<int, (IComponentModel, int)> PastryComponents { get; set; } = new();
} }
} }

View File

@ -0,0 +1,24 @@
using ConfectioneryContracts.BindingModels;
using ConfectioneryContracts.SearchModels;
using ConfectioneryContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConfectioneryContracts.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,24 @@
using ConfectioneryContracts.BindingModels;
using ConfectioneryContracts.SearchModels;
using ConfectioneryContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConfectioneryContracts.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,24 @@
using ConfectioneryContracts.BindingModels;
using ConfectioneryContracts.SearchModels;
using ConfectioneryContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConfectioneryContracts.BusinessLogicsContracts
{
public interface IPastryLogic
{
List<PastryViewModel>? ReadList(PastrySearchModel? model);
PastryViewModel? ReadElement(PastrySearchModel model);
bool Create(PastryBindingModel model);
bool Update(PastryBindingModel model);
bool Delete(PastryBindingModel model);
}
}

View File

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

View File

@ -6,10 +6,10 @@ using System.Threading.Tasks;
namespace ConfectioneryContracts.SearchModels namespace ConfectioneryContracts.SearchModels
{ {
public class ProductSearchModel public class PastrySearchModel
{ {
public int? Id { get; set; } public int? Id { get; set; }
public string? ProductName { get; set; } public string? PastryName { get; set; }
} }
} }

View File

@ -0,0 +1,26 @@
using ConfectioneryContracts.BindingModels;
using ConfectioneryContracts.SearchModels;
using ConfectioneryContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConfectioneryContracts.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,26 @@
using ConfectioneryContracts.BindingModels;
using ConfectioneryContracts.SearchModels;
using ConfectioneryContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConfectioneryContracts.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,26 @@
using ConfectioneryContracts.BindingModels;
using ConfectioneryContracts.SearchModels;
using ConfectioneryContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConfectioneryContracts.StoragesContracts
{
public interface IPastryStorage
{
List<PastryViewModel> GetFullList();
List<PastryViewModel> GetFilteredList(PastrySearchModel model);
PastryViewModel? GetElement(PastrySearchModel model);
PastryViewModel? Insert(PastryBindingModel model);
PastryViewModel? Update(PastryBindingModel model);
PastryViewModel? Delete(PastryBindingModel model);
}
}

View File

@ -14,10 +14,10 @@ namespace ConfectioneryContracts.ViewModels
[DisplayName("Номер")] [DisplayName("Номер")]
public int Id { get; set; } public int Id { get; set; }
public int ProductId { get; set; } public int PastryId { get; set; }
[DisplayName("Изделие")] [DisplayName("Изделие")]
public string ProductName { get; set; } = string.Empty; public string PastryName { get; set; } = string.Empty;
[DisplayName("Количество")] [DisplayName("Количество")]
public int Count { get; set; } public int Count { get; set; }

View File

@ -8,16 +8,16 @@ using System.Threading.Tasks;
namespace ConfectioneryContracts.ViewModels namespace ConfectioneryContracts.ViewModels
{ {
public class ProductViewModel : IProductModel public class PastryViewModel : IPastryModel
{ {
public int Id { get; set; } public int Id { get; set; }
[DisplayName("Название изделия")] [DisplayName("Название изделия")]
public string ProductName { get; set; } = string.Empty; public string PastryName { get; set; } = string.Empty;
[DisplayName("Цена")] [DisplayName("Цена")]
public double Price { get; set; } public double Price { get; set; }
public Dictionary<int, (IComponentModel, int)> ProductComponents { get; set; } = new(); public Dictionary<int, (IComponentModel, int)> PastryComponents { get; set; } = new();
} }
} }

View File

@ -9,7 +9,7 @@ namespace ConfectioneryDataModels.Models
{ {
public interface IOrderModel : IId public interface IOrderModel : IId
{ {
int ProductId { get; } int PastryId { get; }
int Count { get; } int Count { get; }

View File

@ -6,12 +6,12 @@ using System.Threading.Tasks;
namespace ConfectioneryDataModels.Models namespace ConfectioneryDataModels.Models
{ {
public interface IProductModel : IId public interface IPastryModel : IId
{ {
string ProductName { get; } string PastryName { get; }
double Price { get; } double Price { get; }
Dictionary<int, (IComponentModel, int)> ProductComponents { get; } Dictionary<int, (IComponentModel, int)> PastryComponents { get; }
} }
} }

View File

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