diff --git a/Pizzeria/Pizzeria.sln b/Pizzeria/Pizzeria.sln index 62334c7..5968640 100644 --- a/Pizzeria/Pizzeria.sln +++ b/Pizzeria/Pizzeria.sln @@ -5,6 +5,14 @@ VisualStudioVersion = 17.9.34616.47 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Pizzeria", "Pizzeria\Pizzeria.csproj", "{FBB3868C-DAC0-4481-9E44-16F7AAE00141}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PizzeriaDataModels", "PizzeriaDataModels\PizzeriaDataModels.csproj", "{CD0B496B-7660-4744-9F6E-2ACF483F0299}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PizzeriaContracts", "PizzeriaContracts\PizzeriaContracts.csproj", "{F039417A-21F0-4947-9623-C89A755AB8DD}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PizzeriaListImplement", "PizzeriaListImplement\PizzeriaListImplement.csproj", "{6640B0DE-53D5-4DE7-909A-C8111D5347EA}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PizzeriaBusinessLogic", "PizzeriaBusinessLogic\PizzeriaBusinessLogic.csproj", "{16EC5652-8348-4520-9736-1889B2749416}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -15,6 +23,22 @@ Global {FBB3868C-DAC0-4481-9E44-16F7AAE00141}.Debug|Any CPU.Build.0 = Debug|Any CPU {FBB3868C-DAC0-4481-9E44-16F7AAE00141}.Release|Any CPU.ActiveCfg = Release|Any CPU {FBB3868C-DAC0-4481-9E44-16F7AAE00141}.Release|Any CPU.Build.0 = Release|Any CPU + {CD0B496B-7660-4744-9F6E-2ACF483F0299}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {CD0B496B-7660-4744-9F6E-2ACF483F0299}.Debug|Any CPU.Build.0 = Debug|Any CPU + {CD0B496B-7660-4744-9F6E-2ACF483F0299}.Release|Any CPU.ActiveCfg = Release|Any CPU + {CD0B496B-7660-4744-9F6E-2ACF483F0299}.Release|Any CPU.Build.0 = Release|Any CPU + {F039417A-21F0-4947-9623-C89A755AB8DD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F039417A-21F0-4947-9623-C89A755AB8DD}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F039417A-21F0-4947-9623-C89A755AB8DD}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F039417A-21F0-4947-9623-C89A755AB8DD}.Release|Any CPU.Build.0 = Release|Any CPU + {6640B0DE-53D5-4DE7-909A-C8111D5347EA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6640B0DE-53D5-4DE7-909A-C8111D5347EA}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6640B0DE-53D5-4DE7-909A-C8111D5347EA}.Release|Any CPU.ActiveCfg = Release|Any CPU + {6640B0DE-53D5-4DE7-909A-C8111D5347EA}.Release|Any CPU.Build.0 = Release|Any CPU + {16EC5652-8348-4520-9736-1889B2749416}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {16EC5652-8348-4520-9736-1889B2749416}.Debug|Any CPU.Build.0 = Debug|Any CPU + {16EC5652-8348-4520-9736-1889B2749416}.Release|Any CPU.ActiveCfg = Release|Any CPU + {16EC5652-8348-4520-9736-1889B2749416}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Pizzeria/Pizzeria/Form1.Designer.cs b/Pizzeria/Pizzeria/Form1.Designer.cs deleted file mode 100644 index fa58a96..0000000 --- a/Pizzeria/Pizzeria/Form1.Designer.cs +++ /dev/null @@ -1,39 +0,0 @@ -namespace Pizzeria -{ - partial class Form1 - { - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; - - /// - /// Clean up any resources being used. - /// - /// true if managed resources should be disposed; otherwise, false. - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } - - #region Windows Form Designer generated code - - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - this.components = new System.ComponentModel.Container(); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 450); - this.Text = "Form1"; - } - - #endregion - } -} diff --git a/Pizzeria/Pizzeria/Form1.cs b/Pizzeria/Pizzeria/Form1.cs deleted file mode 100644 index 626b4fd..0000000 --- a/Pizzeria/Pizzeria/Form1.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace Pizzeria -{ - public partial class Form1 : Form - { - public Form1() - { - InitializeComponent(); - } - } -} diff --git a/Pizzeria/Pizzeria/Form1.resx b/Pizzeria/Pizzeria/Form1.resx deleted file mode 100644 index 1af7de1..0000000 --- a/Pizzeria/Pizzeria/Form1.resx +++ /dev/null @@ -1,120 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - \ No newline at end of file diff --git a/Pizzeria/PizzeriaBusinessLogic/BusinessLogic/ComponentLogic.cs b/Pizzeria/PizzeriaBusinessLogic/BusinessLogic/ComponentLogic.cs new file mode 100644 index 0000000..c00ad57 --- /dev/null +++ b/Pizzeria/PizzeriaBusinessLogic/BusinessLogic/ComponentLogic.cs @@ -0,0 +1,105 @@ +using Microsoft.Extensions.Logging; +using PizzeriaContracts.BindingModels; +using PizzeriaContracts.BusinessLogicsContracts; +using PizzeriaContracts.SearchModels; +using PizzeriaContracts.StorageContracts; +using PizzeriaContracts.ViewModels; + +namespace PizzeriaBusinessLogic.BusinessLogic +{ + public class ComponentLogic : IComponentLogic + { + private readonly ILogger _logger; + private readonly IComponentStorage _componentStorage; + public ComponentLogic(ILogger logger, IComponentStorage componentStorage) + { + //_logger = logger; + _componentStorage = componentStorage; + } + public List? 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("Компонент с таким названием уже есть"); + } + } + } +} diff --git a/Pizzeria/PizzeriaBusinessLogic/BusinessLogic/OrderLogic.cs b/Pizzeria/PizzeriaBusinessLogic/BusinessLogic/OrderLogic.cs new file mode 100644 index 0000000..87dd32e --- /dev/null +++ b/Pizzeria/PizzeriaBusinessLogic/BusinessLogic/OrderLogic.cs @@ -0,0 +1,164 @@ +using Microsoft.Extensions.Logging; +using PizzeriaContracts.BindingModels; +using PizzeriaContracts.BusinessLogicsContracts; +using PizzeriaContracts.SearchModels; +using PizzeriaContracts.StorageContracts; +using PizzeriaContracts.ViewModels; +using PizzeriaDataModels.Enums; +using System.Xml.Linq; + +namespace PizzeriaBusinessLogic.BusinessLogic +{ + public class OrderLogic : IOrderLogic + { + private readonly ILogger _logger; + + private readonly IOrderStorage _orderStorage; + + public OrderLogic(ILogger logger, IOrderStorage orderStorage) + { + _logger = logger; + _orderStorage = orderStorage; + } + + public bool CreateOrder(OrderBindingModel model) + { + + CheckModel(model); + + if (model.Status == OrderStatus.Неизвестен) + { + _logger.LogWarning("Order status unknown"); + return false; + } + model.Status = OrderStatus.Принят; + if (_orderStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + public List? 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; + } + + public bool TakeOrderInWork(OrderBindingModel model) + { + return ChangeStatus(model, OrderStatus.Выполняется); + } + + public bool FinishOrder(OrderBindingModel model) + { + return ChangeStatus(model, OrderStatus.Готов); + } + + public bool DeliveryOrder(OrderBindingModel model) + { + return ChangeStatus(model, OrderStatus.Выдан); + } + public bool ChangeStatus(OrderBindingModel model, OrderStatus status) + { + /*Неизвестен = -1, + Принят = 0, + Выполняется = 1, + Готов = 2, + Выдан = 3*/ + + CheckModel(model, false); + + var order = _orderStorage.GetElement(new OrderSearchModel { + Id = model.Id + }); + + if (order == null) + { + throw new ArgumentNullException(nameof(order)); + } + + model.ProductId = order.ProductId; + model.DateCreate = order.DateCreate; + model.DateImplement = order.DateImplement; + model.Status = order.Status; + model.Count = order.Count; + model.Sum = order.Sum; + return true; + /* + + if (model.Status != status - 1) + { + _logger.LogWarning("Status update to " + status + " operation failed"); + return false; + } + + model.Status = status; + + if (model.Status == OrderStatus.Выдан) + { + model.DateImplement = DateTime.Now; + } + + if (_orderStorage.Update(model) == null) + { + model.Status--; + _logger.LogWarning("Changing status operation faled"); + return false; + } + */ + + /* + + if (model.Status == OrderStatus.Готов) + { + model.DateImplement = DateTime.Now; + } + else + { + model.DateImplement = order.DateImplement; + } + if (_orderStorage.Update(model) == null) + { + _logger.LogWarning("Change status 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.ProductId <= 0) + { + throw new ArgumentNullException("Некорректный идентификатор изделия", nameof(model.ProductId)); + } + if (model.Count <= 0) + { + throw new ArgumentNullException("В заказе должно быть хотя бы одно изделие", nameof(model.Count)); + } + if (model.Sum <= 0) + { + throw new ArgumentNullException("Стоимость заказа должна быть больше 0", nameof(model.Sum)); + } + _logger.LogInformation("Order. Id: {Id}. Sum: {Sum}. ProductId: {ProductId}. ReinforcedCount: {Count}", model.Id, model.Sum, model.ProductId, model.Count); + } + + + + } +} diff --git a/Pizzeria/PizzeriaBusinessLogic/BusinessLogic/ProductLogic.cs b/Pizzeria/PizzeriaBusinessLogic/BusinessLogic/ProductLogic.cs new file mode 100644 index 0000000..2873f11 --- /dev/null +++ b/Pizzeria/PizzeriaBusinessLogic/BusinessLogic/ProductLogic.cs @@ -0,0 +1,106 @@ +using Microsoft.Extensions.Logging; +using PizzeriaContracts.BindingModels; +using PizzeriaContracts.BusinessLogicsContracts; +using PizzeriaContracts.SearchModels; +using PizzeriaContracts.StorageContracts; +using PizzeriaContracts.ViewModels; + + +namespace PizzeriaBusinessLogic.BusinessLogic +{ + public class ProductLogic : IProductLogic + { + private readonly ILogger _logger; + private readonly IProductStorage _productStorage; + public ProductLogic(ILogger logger, IProductStorage ProductStorage) + { + //_logger = logger; + _productStorage = ProductStorage; + } + public List? 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; + } + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + 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 ArgumentNullException("Нет названия продукта", nameof(model.ProductName)); + } + if (model.Price <= 0) + { + throw new ArgumentNullException("Цена продукта должна быть больше 0", nameof(model.Price)); + } + _logger.LogInformation("Product. ProductName:{ProductName}.Price:{ Price}. Id: { Id}", model.ProductName, model.Price, model.Id); + var element = _productStorage.GetElement(new ProductSearchModel { ProductName = model.ProductName }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Продукт с таким названием уже есть"); + } + } + } +} diff --git a/Pizzeria/PizzeriaBusinessLogic/PizzeriaBusinessLogic.csproj b/Pizzeria/PizzeriaBusinessLogic/PizzeriaBusinessLogic.csproj new file mode 100644 index 0000000..d899681 --- /dev/null +++ b/Pizzeria/PizzeriaBusinessLogic/PizzeriaBusinessLogic.csproj @@ -0,0 +1,17 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + diff --git a/Pizzeria/PizzeriaContracts/BindingModels/ComponentBindingModel.cs b/Pizzeria/PizzeriaContracts/BindingModels/ComponentBindingModel.cs new file mode 100644 index 0000000..bdc7840 --- /dev/null +++ b/Pizzeria/PizzeriaContracts/BindingModels/ComponentBindingModel.cs @@ -0,0 +1,12 @@ +using PizzeriaDataModels.Models; + +namespace PizzeriaContracts.BindingModels +{ + public class ComponentBindingModel : IComponentModel + { + public int Id { get; set; } + public string ComponentName { get; set; } = string.Empty; + public double Cost { get; set; } + + } +} diff --git a/Pizzeria/PizzeriaContracts/BindingModels/OrderBindingModel.cs b/Pizzeria/PizzeriaContracts/BindingModels/OrderBindingModel.cs new file mode 100644 index 0000000..755f4bb --- /dev/null +++ b/Pizzeria/PizzeriaContracts/BindingModels/OrderBindingModel.cs @@ -0,0 +1,17 @@ +using PizzeriaDataModels.Enums; +using PizzeriaDataModels.Models; + +namespace PizzeriaContracts.BindingModels +{ + public class OrderBindingModel : IOrderModel + { + public int Id { get; set; } + public int ProductId { get; set; } + public int Count { get; set; } + public double Sum { get; set; } + public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; + public DateTime DateCreate { get; set; } = DateTime.Now; + public DateTime? DateImplement { get; set; } + + } +} diff --git a/Pizzeria/PizzeriaContracts/BindingModels/ProductBindingModel.cs b/Pizzeria/PizzeriaContracts/BindingModels/ProductBindingModel.cs new file mode 100644 index 0000000..9ff2ff5 --- /dev/null +++ b/Pizzeria/PizzeriaContracts/BindingModels/ProductBindingModel.cs @@ -0,0 +1,12 @@ +using PizzeriaDataModels.Models; +namespace PizzeriaContracts.BindingModels +{ + public class ProductBindingModel : IProductModel + { + public int Id { get; set; } + public string ProductName { get; set; } = string.Empty; + public double Price { get; set; } + public Dictionary ProductComponents {get;set;} = new(); + + } +} diff --git a/Pizzeria/PizzeriaContracts/BusinessLogicsContracts/IComponentLogic.cs b/Pizzeria/PizzeriaContracts/BusinessLogicsContracts/IComponentLogic.cs new file mode 100644 index 0000000..4f4412d --- /dev/null +++ b/Pizzeria/PizzeriaContracts/BusinessLogicsContracts/IComponentLogic.cs @@ -0,0 +1,15 @@ +using PizzeriaContracts.BindingModels; +using PizzeriaContracts.SearchModels; +using PizzeriaContracts.ViewModels; + +namespace PizzeriaContracts.BusinessLogicsContracts +{ + public interface IComponentLogic + { + List? ReadList(ComponentSearchModel? model); + ComponentViewModel? ReadElement(ComponentSearchModel model); + bool Create(ComponentBindingModel model); + bool Update(ComponentBindingModel model); + bool Delete(ComponentBindingModel model); + } +} diff --git a/Pizzeria/PizzeriaContracts/BusinessLogicsContracts/IOrderLogic.cs b/Pizzeria/PizzeriaContracts/BusinessLogicsContracts/IOrderLogic.cs new file mode 100644 index 0000000..fda864a --- /dev/null +++ b/Pizzeria/PizzeriaContracts/BusinessLogicsContracts/IOrderLogic.cs @@ -0,0 +1,15 @@ +using PizzeriaContracts.BindingModels; +using PizzeriaContracts.SearchModels; +using PizzeriaContracts.ViewModels; + +namespace PizzeriaContracts.BusinessLogicsContracts +{ + public interface IOrderLogic + { + List? ReadList(OrderSearchModel? model); + bool CreateOrder(OrderBindingModel model); + bool TakeOrderInWork(OrderBindingModel model); + bool FinishOrder(OrderBindingModel model); + bool DeliveryOrder(OrderBindingModel model); + } +} diff --git a/Pizzeria/PizzeriaContracts/BusinessLogicsContracts/IProductLogic.cs b/Pizzeria/PizzeriaContracts/BusinessLogicsContracts/IProductLogic.cs new file mode 100644 index 0000000..a21bcfd --- /dev/null +++ b/Pizzeria/PizzeriaContracts/BusinessLogicsContracts/IProductLogic.cs @@ -0,0 +1,15 @@ +using PizzeriaContracts.BindingModels; +using PizzeriaContracts.SearchModels; +using PizzeriaContracts.ViewModels; + +namespace PizzeriaContracts.BusinessLogicsContracts +{ + public interface IProductLogic + { + List? ReadList(ProductSearchModel? model); + ProductViewModel? ReadElement(ProductSearchModel model); + bool Create(ProductBindingModel model); + bool Update(ProductBindingModel model); + bool Delete(ProductBindingModel model); + } +} diff --git a/Pizzeria/PizzeriaContracts/PizzeriaContracts.csproj b/Pizzeria/PizzeriaContracts/PizzeriaContracts.csproj new file mode 100644 index 0000000..f8743a9 --- /dev/null +++ b/Pizzeria/PizzeriaContracts/PizzeriaContracts.csproj @@ -0,0 +1,13 @@ + + + + net6.0 + enable + enable + + + + + + + diff --git a/Pizzeria/PizzeriaContracts/SearchModels/ComponentSearchModel.cs b/Pizzeria/PizzeriaContracts/SearchModels/ComponentSearchModel.cs new file mode 100644 index 0000000..f5684bb --- /dev/null +++ b/Pizzeria/PizzeriaContracts/SearchModels/ComponentSearchModel.cs @@ -0,0 +1,9 @@ +namespace PizzeriaContracts.SearchModels +{ + public class ComponentSearchModel + { + public int? Id { get; set; } + public string? ComponentName { get; set; } + + } +} diff --git a/Pizzeria/PizzeriaContracts/SearchModels/OrderSearchModel.cs b/Pizzeria/PizzeriaContracts/SearchModels/OrderSearchModel.cs new file mode 100644 index 0000000..000683a --- /dev/null +++ b/Pizzeria/PizzeriaContracts/SearchModels/OrderSearchModel.cs @@ -0,0 +1,7 @@ +namespace PizzeriaContracts.SearchModels +{ + public class OrderSearchModel + { + public int? Id { get; set; } + } +} diff --git a/Pizzeria/PizzeriaContracts/SearchModels/ProductSearchModel.cs b/Pizzeria/PizzeriaContracts/SearchModels/ProductSearchModel.cs new file mode 100644 index 0000000..7c2d61a --- /dev/null +++ b/Pizzeria/PizzeriaContracts/SearchModels/ProductSearchModel.cs @@ -0,0 +1,8 @@ +namespace PizzeriaContracts.SearchModels +{ + public class ProductSearchModel + { + public int? Id { get; set; } + public string? ProductName { get; set; } + } +} diff --git a/Pizzeria/PizzeriaContracts/StorageContracts/IComponentStorage.cs b/Pizzeria/PizzeriaContracts/StorageContracts/IComponentStorage.cs new file mode 100644 index 0000000..04baea2 --- /dev/null +++ b/Pizzeria/PizzeriaContracts/StorageContracts/IComponentStorage.cs @@ -0,0 +1,17 @@ +using PizzeriaContracts.BindingModels; +using PizzeriaContracts.SearchModels; +using PizzeriaContracts.ViewModels; + +namespace PizzeriaContracts.StorageContracts +{ + public interface IComponentStorage + { + List GetFullList(); + List GetFilteredList(ComponentSearchModel model); + ComponentViewModel? GetElement(ComponentSearchModel model); + ComponentViewModel? Insert(ComponentBindingModel model); + ComponentViewModel? Update(ComponentBindingModel model); + ComponentViewModel? Delete(ComponentBindingModel model); + + } +} diff --git a/Pizzeria/PizzeriaContracts/StorageContracts/IOrderStorage.cs b/Pizzeria/PizzeriaContracts/StorageContracts/IOrderStorage.cs new file mode 100644 index 0000000..e60b5dd --- /dev/null +++ b/Pizzeria/PizzeriaContracts/StorageContracts/IOrderStorage.cs @@ -0,0 +1,17 @@ +using PizzeriaContracts.BindingModels; +using PizzeriaContracts.SearchModels; +using PizzeriaContracts.ViewModels; + +namespace PizzeriaContracts.StorageContracts +{ + public interface IOrderStorage + { + List GetFullList(); + List GetFilteredList(OrderSearchModel model); + OrderViewModel? GetElement(OrderSearchModel model); + OrderViewModel? Insert(OrderBindingModel model); + OrderViewModel? Update(OrderBindingModel model); + OrderViewModel? Delete(OrderBindingModel model); + + } +} diff --git a/Pizzeria/PizzeriaContracts/StorageContracts/IProductStorage.cs b/Pizzeria/PizzeriaContracts/StorageContracts/IProductStorage.cs new file mode 100644 index 0000000..9b0bfb1 --- /dev/null +++ b/Pizzeria/PizzeriaContracts/StorageContracts/IProductStorage.cs @@ -0,0 +1,17 @@ +using PizzeriaContracts.BindingModels; +using PizzeriaContracts.SearchModels; +using PizzeriaContracts.ViewModels; + +namespace PizzeriaContracts.StorageContracts +{ + public interface IProductStorage + { + List GetFullList(); + List GetFilteredList(ProductSearchModel model); + ProductViewModel? GetElement(ProductSearchModel model); + ProductViewModel? Insert(ProductBindingModel model); + ProductViewModel? Update(ProductBindingModel model); + ProductViewModel? Delete(ProductBindingModel model); + + } +} diff --git a/Pizzeria/PizzeriaContracts/ViewModels/ComponentViewModel.cs b/Pizzeria/PizzeriaContracts/ViewModels/ComponentViewModel.cs new file mode 100644 index 0000000..614f252 --- /dev/null +++ b/Pizzeria/PizzeriaContracts/ViewModels/ComponentViewModel.cs @@ -0,0 +1,14 @@ +using PizzeriaDataModels.Models; +using System.ComponentModel; + +namespace PizzeriaContracts.ViewModels +{ + public class ComponentViewModel : IComponentModel + { + public int Id { get; set; } + [DisplayName("Название компонента")] + public string ComponentName { get; set; } = string.Empty; + [DisplayName("Цена")] + public double Cost { get; set; } + } +} diff --git a/Pizzeria/PizzeriaContracts/ViewModels/OrderViewModel.cs b/Pizzeria/PizzeriaContracts/ViewModels/OrderViewModel.cs new file mode 100644 index 0000000..f5042cf --- /dev/null +++ b/Pizzeria/PizzeriaContracts/ViewModels/OrderViewModel.cs @@ -0,0 +1,31 @@ +using PizzeriaDataModels.Enums; +using PizzeriaDataModels.Models; +using System.ComponentModel; + +namespace PizzeriaContracts.ViewModels +{ + public class OrderViewModel : IOrderModel + { + [DisplayName("Номер")] + public int Id { get; set; } + public int ProductId { get; set; } + + [DisplayName("Изделие")] + public string ProductName { get; set; } = string.Empty; + + [DisplayName("Количество")] + public int Count { get; set; } + + [DisplayName("Сумма")] + public double Sum { get; set; } + + [DisplayName("Статус")] + public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; + + [DisplayName("Дата создания")] + public DateTime DateCreate { get; set; } = DateTime.Now; + + [DisplayName("Дата выполнения")] + public DateTime? DateImplement { get; set; } + } +} diff --git a/Pizzeria/PizzeriaContracts/ViewModels/ProductViewModel.cs b/Pizzeria/PizzeriaContracts/ViewModels/ProductViewModel.cs new file mode 100644 index 0000000..c15904f --- /dev/null +++ b/Pizzeria/PizzeriaContracts/ViewModels/ProductViewModel.cs @@ -0,0 +1,15 @@ +using PizzeriaDataModels.Models; +using System.ComponentModel; + +namespace PizzeriaContracts.ViewModels +{ + public class ProductViewModel : IProductModel + { + public int Id { get; set; } + [DisplayName("Название изделия")] + public string ProductName { get; set; } = string.Empty; + [DisplayName("Цена")] + public double Price { get; set; } + public Dictionary ProductComponents {get;set;} = new(); + } +} diff --git a/Pizzeria/PizzeriaDataModels/Enums/OrderStatus.cs b/Pizzeria/PizzeriaDataModels/Enums/OrderStatus.cs new file mode 100644 index 0000000..bc1856e --- /dev/null +++ b/Pizzeria/PizzeriaDataModels/Enums/OrderStatus.cs @@ -0,0 +1,12 @@ +namespace PizzeriaDataModels.Enums +{ + public enum OrderStatus + { + Неизвестен = -1, + Принят = 0, + Выполняется = 1, + Готов = 2, + Выдан = 3 + + } +} diff --git a/Pizzeria/PizzeriaDataModels/IId.cs b/Pizzeria/PizzeriaDataModels/IId.cs new file mode 100644 index 0000000..7ce0d2f --- /dev/null +++ b/Pizzeria/PizzeriaDataModels/IId.cs @@ -0,0 +1,7 @@ +namespace PizzeriaDataModels +{ + public interface IId + { + int Id { get; } + } +} diff --git a/Pizzeria/PizzeriaDataModels/Models/IComponentModel.cs b/Pizzeria/PizzeriaDataModels/Models/IComponentModel.cs new file mode 100644 index 0000000..001166c --- /dev/null +++ b/Pizzeria/PizzeriaDataModels/Models/IComponentModel.cs @@ -0,0 +1,8 @@ +namespace PizzeriaDataModels.Models +{ + public interface IComponentModel : IId + { + string ComponentName { get; } + double Cost { get; } + } +} diff --git a/Pizzeria/PizzeriaDataModels/Models/IOrderModel.cs b/Pizzeria/PizzeriaDataModels/Models/IOrderModel.cs new file mode 100644 index 0000000..11c9662 --- /dev/null +++ b/Pizzeria/PizzeriaDataModels/Models/IOrderModel.cs @@ -0,0 +1,15 @@ +using PizzeriaDataModels.Enums; + +namespace PizzeriaDataModels.Models +{ + public interface IOrderModel : IId + { + int ProductId { get; } + int Count { get; } + double Sum { get; } + OrderStatus Status { get; } + DateTime DateCreate { get; } + DateTime? DateImplement { get; } + + } +} diff --git a/Pizzeria/PizzeriaDataModels/Models/IProductModel.cs b/Pizzeria/PizzeriaDataModels/Models/IProductModel.cs new file mode 100644 index 0000000..54548eb --- /dev/null +++ b/Pizzeria/PizzeriaDataModels/Models/IProductModel.cs @@ -0,0 +1,9 @@ +namespace PizzeriaDataModels.Models +{ + public interface IProductModel : IId + { + string ProductName { get; } + double Price { get; } + Dictionary ProductComponents { get; } + } +} diff --git a/Pizzeria/PizzeriaDataModels/PizzeriaDataModels.csproj b/Pizzeria/PizzeriaDataModels/PizzeriaDataModels.csproj new file mode 100644 index 0000000..132c02c --- /dev/null +++ b/Pizzeria/PizzeriaDataModels/PizzeriaDataModels.csproj @@ -0,0 +1,9 @@ + + + + net6.0 + enable + enable + + + diff --git a/Pizzeria/PizzeriaListImplement/DataListSingleton.cs b/Pizzeria/PizzeriaListImplement/DataListSingleton.cs new file mode 100644 index 0000000..c8ac9b2 --- /dev/null +++ b/Pizzeria/PizzeriaListImplement/DataListSingleton.cs @@ -0,0 +1,26 @@ +using PizzeriaListImplement.Models; + +namespace PizzeriaListImplement +{ + public class DataListSingleton + { + private static DataListSingleton? _instance; + public List Components { get; set; } + public List Orders { get; set; } + public List Products { get; set; } + private DataListSingleton() + { + Components = new List(); + Orders = new List(); + Products = new List(); + } + public static DataListSingleton GetInstance() + { + if (_instance == null) + { + _instance = new DataListSingleton(); + } + return _instance; + } + } +} diff --git a/Pizzeria/PizzeriaListImplement/Implements/ComponentStorage.cs b/Pizzeria/PizzeriaListImplement/Implements/ComponentStorage.cs new file mode 100644 index 0000000..8591ad0 --- /dev/null +++ b/Pizzeria/PizzeriaListImplement/Implements/ComponentStorage.cs @@ -0,0 +1,102 @@ +using PizzeriaContracts.BindingModels; +using PizzeriaContracts.SearchModels; +using PizzeriaContracts.StorageContracts; +using PizzeriaContracts.ViewModels; +using PizzeriaListImplement.Models; + + +namespace PizzeriaListImplement.Implements +{ + public class ComponentStorage : IComponentStorage + { + private readonly DataListSingleton _source; + public ComponentStorage() + { + _source = DataListSingleton.GetInstance(); + } + public List GetFullList() + { + var result = new List(); + foreach (var component in _source.Components) + { + result.Add(component.GetViewModel); + } + return result; + } + public List GetFilteredList(ComponentSearchModel model) + { + var result = new List(); + if (string.IsNullOrEmpty(model.ComponentName)) + { + return result; + } + foreach (var component in _source.Components) + { + if (component.ComponentName.Contains(model.ComponentName)) + { + result.Add(component.GetViewModel); + } + } + return result; + } + public ComponentViewModel? GetElement(ComponentSearchModel model) + { + if (string.IsNullOrEmpty(model.ComponentName) && !model.Id.HasValue) + { + return null; + } + foreach (var component in _source.Components) + { + if ((!string.IsNullOrEmpty(model.ComponentName) && component.ComponentName == model.ComponentName) || (model.Id.HasValue && component.Id == model.Id)) + { + return component.GetViewModel; + } + } + return null; + } + public ComponentViewModel? Insert(ComponentBindingModel model) + { + model.Id = 1; + foreach (var component in _source.Components) + { + if (model.Id <= component.Id) + { + model.Id = component.Id + 1; + } + } + var newComponent = Component.Create(model); + if (newComponent == null) + { + return null; + } + _source.Components.Add(newComponent); + return newComponent.GetViewModel; + } + public ComponentViewModel? Update(ComponentBindingModel model) + { + foreach (var component in _source.Components) + { + if (component.Id == model.Id) + { + component.Update(model); + return component.GetViewModel; + } + } + return null; + } + public ComponentViewModel? Delete(ComponentBindingModel model) + { + for (int i = 0; i < _source.Components.Count; ++i) + { + if (_source.Components[i].Id == model.Id) + { + var element = _source.Components[i]; + _source.Components.RemoveAt(i); + return element.GetViewModel; + } + } + return null; + } + + } +} diff --git a/Pizzeria/PizzeriaListImplement/Implements/OrderStorage.cs b/Pizzeria/PizzeriaListImplement/Implements/OrderStorage.cs new file mode 100644 index 0000000..0eff7eb --- /dev/null +++ b/Pizzeria/PizzeriaListImplement/Implements/OrderStorage.cs @@ -0,0 +1,104 @@ +using PizzeriaContracts.BindingModels; +using PizzeriaContracts.SearchModels; +using PizzeriaContracts.StorageContracts; +using PizzeriaContracts.ViewModels; +using PizzeriaListImplement.Models; + +namespace PizzeriaListImplement.Implements +{ + public class OrderStorage : IOrderStorage + { + private readonly DataListSingleton _source; + public OrderStorage() + { + _source = DataListSingleton.GetInstance(); + } + + public OrderViewModel? Delete(OrderBindingModel model) + { + for (int i = 0; i < _source.Orders.Count; ++i) + { + if (_source.Orders[i].Id == model.Id) + { + var element = _source.Orders[i]; + _source.Orders.RemoveAt(i); + return element.GetViewModel; + } + } + return null; + } + public OrderViewModel? GetElement(OrderSearchModel model) + { + if (!model.Id.HasValue) + { + return null; + } + foreach (var order in _source.Orders) + { + if ((model.Id.HasValue && order.Id == model.Id)) + { + return order.GetViewModel; + } + } + return null; + } + + public List GetFilteredList(OrderSearchModel model) + { + var result = new List(); + if (!model.Id.HasValue) + { + return result; + } + foreach (var order in _source.Orders) + { + if (order.Id == model.Id) + { + result.Add(order.GetViewModel); + } + } + return result; + } + + public List GetFullList() + { + var result = new List(); + foreach (var order in _source.Orders) + { + result.Add(order.GetViewModel); + } + return result; + } + public OrderViewModel? Insert(OrderBindingModel model) + { + model.Id = 1; + foreach (var order in _source.Orders) + { + if (model.Id <= order.Id) + { + model.Id = order.Id + 1; + } + } + var newOrder = Order.Create(model); + if (newOrder == null) + { + return null; + } + _source.Orders.Add(newOrder); + return newOrder.GetViewModel; + } + public OrderViewModel? Update(OrderBindingModel model) + { + foreach (var order in _source.Orders) + { + if (order.Id == model.Id) + { + order.Update(model); + return order.GetViewModel; + } + } + return null; + } + + } +} diff --git a/Pizzeria/PizzeriaListImplement/Implements/ProductStorage.cs b/Pizzeria/PizzeriaListImplement/Implements/ProductStorage.cs new file mode 100644 index 0000000..56441b9 --- /dev/null +++ b/Pizzeria/PizzeriaListImplement/Implements/ProductStorage.cs @@ -0,0 +1,100 @@ +using PizzeriaContracts.BindingModels; +using PizzeriaContracts.SearchModels; +using PizzeriaContracts.StorageContracts; +using PizzeriaContracts.ViewModels; +using PizzeriaListImplement.Models; + +namespace PizzeriaListImplement.Implements +{ + public class ProductStorage : IProductStorage + { + private readonly DataListSingleton _source; + public ProductStorage() + { + _source = DataListSingleton.GetInstance(); + } + public List GetFullList() + { + var result = new List(); + foreach (var product in _source.Products) + { + result.Add(product.GetViewModel); + } + return result; + } + public List GetFilteredList(ProductSearchModel model) + { + var result = new List(); + if (string.IsNullOrEmpty(model.ProductName)) + { + return result; + } + foreach (var product in _source.Products) + { + if (product.ProductName.Contains(model.ProductName)) + { + result.Add(product.GetViewModel); + } + } + return result; + } + public ProductViewModel? GetElement(ProductSearchModel model) + { + if (string.IsNullOrEmpty(model.ProductName) && !model.Id.HasValue) + { + return null; + } + foreach (var product in _source.Products) + { + if ((!string.IsNullOrEmpty(model.ProductName) && product.ProductName == model.ProductName) || (model.Id.HasValue && product.Id == model.Id)) + { + return product.GetViewModel; + } + } + return null; + } + public ProductViewModel? Insert(ProductBindingModel model) + { + model.Id = 1; + foreach (var product in _source.Products) + { + if (model.Id <= product.Id) + { + model.Id = product.Id + 1; + } + } + var newProduct = Product.Create(model); + if (newProduct == null) + { + return null; + } + _source.Products.Add(newProduct); + return newProduct.GetViewModel; + } + public ProductViewModel? Update(ProductBindingModel model) + { + foreach (var product in _source.Products) + { + if (product.Id == model.Id) + { + product.Update(model); + return product.GetViewModel; + } + } + return null; + } + public ProductViewModel? Delete(ProductBindingModel model) + { + for (int i = 0; i < _source.Products.Count; ++i) + { + if (_source.Products[i].Id == model.Id) + { + var element = _source.Products[i]; + _source.Products.RemoveAt(i); + return element.GetViewModel; + } + } + return null; + } + } +} diff --git a/Pizzeria/PizzeriaListImplement/Models/Component.cs b/Pizzeria/PizzeriaListImplement/Models/Component.cs new file mode 100644 index 0000000..cbf80c4 --- /dev/null +++ b/Pizzeria/PizzeriaListImplement/Models/Component.cs @@ -0,0 +1,42 @@ +using PizzeriaContracts.BindingModels; +using PizzeriaContracts.ViewModels; +using PizzeriaDataModels.Models; + +namespace PizzeriaListImplement.Models +{ + public class Component : IComponentModel + { + public int Id { get; private set; } + public string ComponentName { get; private set; } = string.Empty; + public double Cost { get; set; } + + public static Component? Create(ComponentBindingModel? model) + { + if (model == null) + { + return null; + } + return new Component() + { + Id = model.Id, + ComponentName = model.ComponentName, + Cost = model.Cost + }; + } + public void Update(ComponentBindingModel? model) + { + if (model == null) + { + return; + } + ComponentName = model.ComponentName; + Cost = model.Cost; + } + public ComponentViewModel GetViewModel => new() + { + Id = Id, + ComponentName = ComponentName, + Cost = Cost + }; + } +} diff --git a/Pizzeria/PizzeriaListImplement/Models/Order.cs b/Pizzeria/PizzeriaListImplement/Models/Order.cs new file mode 100644 index 0000000..93de7f0 --- /dev/null +++ b/Pizzeria/PizzeriaListImplement/Models/Order.cs @@ -0,0 +1,70 @@ +using PizzeriaContracts.BindingModels; +using PizzeriaContracts.ViewModels; +using PizzeriaDataModels.Enums; +using PizzeriaDataModels.Models; +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; + +namespace PizzeriaListImplement.Models +{ + public class Order : IOrderModel + { + public int Id { get; private set; } + + public int ProductId { get; private set; } + + public int Count { get; private set; } + + public double Sum { get; private set; } + + public OrderStatus Status { get; private set; } + + public DateTime DateCreate { get; private set; } + + public DateTime? DateImplement { get; private set; } + + public static Order? Create(OrderBindingModel? model) + { + if (model == null) + { + return null; + } + return new Order() + { + Id = model.Id, + ProductId = model.ProductId, + Count = model.Count, + Sum = model.Sum, + Status = model.Status, + DateCreate = model.DateCreate, + DateImplement = model.DateImplement + }; + } + public void Update(OrderBindingModel? model) + { + if (model == null) + { + return; + } + + Status = model.Status; + DateImplement = model.DateImplement; + } + public OrderViewModel GetViewModel => new() + { + Id = Id, + ProductId = ProductId, + Count = Count, + Sum = Sum, + Status = Status, + DateCreate = DateCreate, + DateImplement = DateImplement + }; + + } +} diff --git a/Pizzeria/PizzeriaListImplement/Models/Product.cs b/Pizzeria/PizzeriaListImplement/Models/Product.cs new file mode 100644 index 0000000..b17aeb7 --- /dev/null +++ b/Pizzeria/PizzeriaListImplement/Models/Product.cs @@ -0,0 +1,49 @@ +using PizzeriaContracts.BindingModels; +using PizzeriaContracts.ViewModels; +using PizzeriaDataModels.Models; + +namespace PizzeriaListImplement.Models +{ + public class Product : IProductModel + { + public int Id { get; private set; } + public string ProductName { get; private set; } = string.Empty; + public double Price { get; private set; } + public Dictionary ProductComponents + { + get; + private set; + } = new Dictionary(); + public static Product? Create(ProductBindingModel? model) + { + if (model == null) + { + return null; + } + return new Product() + { + Id = model.Id, + ProductName = model.ProductName, + Price = model.Price, + ProductComponents = model.ProductComponents + }; + } + public void Update(ProductBindingModel? model) + { + if (model == null) + { + return; + } + ProductName = model.ProductName; + Price = model.Price; + ProductComponents = model.ProductComponents; + } + public ProductViewModel GetViewModel => new() + { + Id = Id, + ProductName = ProductName, + Price = Price, + ProductComponents = ProductComponents + }; + } +} diff --git a/Pizzeria/PizzeriaListImplement/PizzeriaListImplement.csproj b/Pizzeria/PizzeriaListImplement/PizzeriaListImplement.csproj new file mode 100644 index 0000000..b612a23 --- /dev/null +++ b/Pizzeria/PizzeriaListImplement/PizzeriaListImplement.csproj @@ -0,0 +1,14 @@ + + + + net6.0 + enable + enable + + + + + + + +