From ebb55f4300289783fa8e7afec3f7eccba450bbbc Mon Sep 17 00:00:00 2001 From: Yourdax Date: Sat, 25 May 2024 23:32:30 +0400 Subject: [PATCH] =?UTF-8?q?+=D1=80=D0=B0=D0=B1=D0=BE=D1=87=D0=B8=D0=B5=20?= =?UTF-8?q?=D1=84=D0=BE=D1=80=D0=BC=D0=BE=D1=87=D0=BA=D0=B8=20=D0=B4=D0=BB?= =?UTF-8?q?=D1=8F=20=D0=BF=D1=80=D0=BE=D0=B4=D1=83=D0=BA=D1=82=D0=BE=D0=B2?= =?UTF-8?q?=20=D0=B8=20=D0=B1=D0=BB=D1=8E=D0=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DiningRoom/DiningRoom.sln | 20 +- .../CardLogic.cs | 6 +- .../ComponentLogic.cs | 2 +- .../DrinkLogic.cs | 7 +- .../OrderLogic.cs | 4 +- .../ProductLogic.cs | 2 +- .../ReportLogic.cs | 6 +- .../UserLogic.cs | 2 +- .../BindingModels/CardBindingModel.cs | 2 - .../BindingModels/ComponentBindingModel.cs | 7 +- .../BindingModels/DrinkBindingModel.cs | 3 - .../BindingModels/OrderBindingModel.cs | 1 - .../BindingModels/ProductBindingModel.cs | 3 - .../BusinessLogicContracts/IDrinkLogic.cs | 1 - .../BusinessLogicContracts/IReportLogic.cs | 2 +- .../SearchModels/CardSearchModel.cs | 1 - .../SearchModels/ComponentSearchModel.cs | 2 - .../SearchModels/DrinkSearchModel.cs | 1 - .../SearchModels/OrderSearchModel.cs | 1 - .../SearchModels/ProductSearchModel.cs | 3 - .../StorageContracts/IComponentStorage.cs | 2 +- .../StorageContracts/IDrinkStorage.cs | 1 - .../ViewModels/CardViewModel.cs | 2 - .../ViewModels/ComponentViewModel.cs | 7 +- .../ViewModels/DrinkViewModel.cs | 3 - .../ViewModels/OrderViewModel.cs | 1 - .../ViewModels/ProductViewModel.cs | 3 - .../Enums/ComponentUnit.cs | 9 + .../DiningRoomDataModels/Models/ICardModel.cs | 4 - .../Models/IComponentModel.cs | 11 +- .../Models/IDrinkModel.cs | 5 - .../Models/IOrderModel.cs | 2 - .../Models/IProductModel.cs | 4 - .../Implements/CardStorage.cs | 4 +- .../Implements/ComponentStorage.cs | 4 +- .../Implements/DrinkStorage.cs | 13 - .../Implements/OrderStorage.cs | 6 +- .../Implements/ProductStorage.cs | 14 +- ... 20240525184442_InitialCreate.Designer.cs} | 137 +++++----- ...ate.cs => 20240525184442_InitialCreate.cs} | 246 ++++++++++-------- .../DiningRoomDatabaseModelSnapshot.cs | 135 +++++----- .../Models/Card.cs | 3 - .../Models/Component.cs | 9 +- .../Models/Drink.cs | 19 +- .../Models/Order.cs | 5 +- .../Models/Product.cs | 5 - .../Controllers/CardController.cs | 11 +- .../Controllers/ComponentController.cs | 16 -- .../Controllers/DrinkController.cs | 29 --- .../Controllers/OrderController.cs | 19 +- .../Controllers/ProductController.cs | 16 -- DiningRoom/DiningRoomRestApi/Program.cs | 2 +- .../DiningRoomView/DiningRoomView.csproj | 4 + DiningRoom/DiningRoomView/Form1.Designer.cs | 39 --- DiningRoom/DiningRoomView/Form1.cs | 10 - .../DiningRoomView/FormComponent.Designer.cs | 142 ++++++++++ DiningRoom/DiningRoomView/FormComponent.cs | 88 +++++++ .../{Form1.resx => FormComponent.resx} | 50 ++-- .../DiningRoomView/FormComponents.Designer.cs | 114 ++++++++ DiningRoom/DiningRoomView/FormComponents.cs | 107 ++++++++ DiningRoom/DiningRoomView/FormComponents.resx | 120 +++++++++ .../DiningRoomView/FormMain.Designer.cs | 228 ++++++++++++++++ DiningRoom/DiningRoomView/FormMain.cs | 198 ++++++++++++++ DiningRoom/DiningRoomView/FormMain.resx | 126 +++++++++ .../DiningRoomView/FormProduct.Designer.cs | 224 ++++++++++++++++ DiningRoom/DiningRoomView/FormProduct.cs | 201 ++++++++++++++ DiningRoom/DiningRoomView/FormProduct.resx | 120 +++++++++ .../FormProductComponent.Designer.cs | 120 +++++++++ .../DiningRoomView/FormProductComponent.cs | 77 ++++++ .../DiningRoomView/FormProductComponent.resx | 120 +++++++++ DiningRoom/DiningRoomView/Program.cs | 44 +++- 71 files changed, 2393 insertions(+), 562 deletions(-) rename DiningRoom/DiningRoomBusinessLogic/{BusinessLogics => BusinessLogic}/CardLogic.cs (88%) rename DiningRoom/DiningRoomBusinessLogic/{BusinessLogics => BusinessLogic}/ComponentLogic.cs (98%) rename DiningRoom/DiningRoomBusinessLogic/{BusinessLogics => BusinessLogic}/DrinkLogic.cs (93%) rename DiningRoom/DiningRoomBusinessLogic/{BusinessLogics => BusinessLogic}/OrderLogic.cs (96%) rename DiningRoom/DiningRoomBusinessLogic/{BusinessLogics => BusinessLogic}/ProductLogic.cs (98%) rename DiningRoom/DiningRoomBusinessLogic/{BusinessLogics => BusinessLogic}/ReportLogic.cs (85%) rename DiningRoom/DiningRoomBusinessLogic/{BusinessLogics => BusinessLogic}/UserLogic.cs (98%) create mode 100644 DiningRoom/DiningRoomDataModels/Enums/ComponentUnit.cs rename DiningRoom/DiningRoomDatabaseImplement/Migrations/{20240504170055_InitialCreate.Designer.cs => 20240525184442_InitialCreate.Designer.cs} (83%) rename DiningRoom/DiningRoomDatabaseImplement/Migrations/{20240504170055_InitialCreate.cs => 20240525184442_InitialCreate.cs} (77%) delete mode 100644 DiningRoom/DiningRoomView/Form1.Designer.cs delete mode 100644 DiningRoom/DiningRoomView/Form1.cs create mode 100644 DiningRoom/DiningRoomView/FormComponent.Designer.cs create mode 100644 DiningRoom/DiningRoomView/FormComponent.cs rename DiningRoom/DiningRoomView/{Form1.resx => FormComponent.resx} (93%) create mode 100644 DiningRoom/DiningRoomView/FormComponents.Designer.cs create mode 100644 DiningRoom/DiningRoomView/FormComponents.cs create mode 100644 DiningRoom/DiningRoomView/FormComponents.resx create mode 100644 DiningRoom/DiningRoomView/FormMain.Designer.cs create mode 100644 DiningRoom/DiningRoomView/FormMain.cs create mode 100644 DiningRoom/DiningRoomView/FormMain.resx create mode 100644 DiningRoom/DiningRoomView/FormProduct.Designer.cs create mode 100644 DiningRoom/DiningRoomView/FormProduct.cs create mode 100644 DiningRoom/DiningRoomView/FormProduct.resx create mode 100644 DiningRoom/DiningRoomView/FormProductComponent.Designer.cs create mode 100644 DiningRoom/DiningRoomView/FormProductComponent.cs create mode 100644 DiningRoom/DiningRoomView/FormProductComponent.resx diff --git a/DiningRoom/DiningRoom.sln b/DiningRoom/DiningRoom.sln index 0484969..bf8c5d3 100644 --- a/DiningRoom/DiningRoom.sln +++ b/DiningRoom/DiningRoom.sln @@ -13,9 +13,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DiningRoomDatabaseImplement EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DiningRoomBusinessLogic", "DiningRoomBusinessLogic\DiningRoomBusinessLogic.csproj", "{89A8AB71-ADD4-405D-AE0B-03ACB1A1BF24}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DiningRoomRestApi", "DiningRoomRestApi\DiningRoomRestApi.csproj", "{BE787325-AB78-45A0-AE64-62E46E64248E}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DiningRoomClientApp", "DiningRoomClientApp\DiningRoomClientApp.csproj", "{543BA573-04E2-4CF1-8848-19B8EFE56EE1}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DiningRoomClientApp", "DiningRoomClientApp\DiningRoomClientApp.csproj", "{ACC2241A-F9C7-482B-839A-B7D625136145}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DiningRoomRestApi", "DiningRoomRestApi\DiningRoomRestApi.csproj", "{75B8E90E-E98D-4B04-9EF1-BBDAC55F1936}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -43,14 +43,14 @@ Global {89A8AB71-ADD4-405D-AE0B-03ACB1A1BF24}.Debug|Any CPU.Build.0 = Debug|Any CPU {89A8AB71-ADD4-405D-AE0B-03ACB1A1BF24}.Release|Any CPU.ActiveCfg = Release|Any CPU {89A8AB71-ADD4-405D-AE0B-03ACB1A1BF24}.Release|Any CPU.Build.0 = Release|Any CPU - {BE787325-AB78-45A0-AE64-62E46E64248E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {BE787325-AB78-45A0-AE64-62E46E64248E}.Debug|Any CPU.Build.0 = Debug|Any CPU - {BE787325-AB78-45A0-AE64-62E46E64248E}.Release|Any CPU.ActiveCfg = Release|Any CPU - {BE787325-AB78-45A0-AE64-62E46E64248E}.Release|Any CPU.Build.0 = Release|Any CPU - {ACC2241A-F9C7-482B-839A-B7D625136145}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {ACC2241A-F9C7-482B-839A-B7D625136145}.Debug|Any CPU.Build.0 = Debug|Any CPU - {ACC2241A-F9C7-482B-839A-B7D625136145}.Release|Any CPU.ActiveCfg = Release|Any CPU - {ACC2241A-F9C7-482B-839A-B7D625136145}.Release|Any CPU.Build.0 = Release|Any CPU + {543BA573-04E2-4CF1-8848-19B8EFE56EE1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {543BA573-04E2-4CF1-8848-19B8EFE56EE1}.Debug|Any CPU.Build.0 = Debug|Any CPU + {543BA573-04E2-4CF1-8848-19B8EFE56EE1}.Release|Any CPU.ActiveCfg = Release|Any CPU + {543BA573-04E2-4CF1-8848-19B8EFE56EE1}.Release|Any CPU.Build.0 = Release|Any CPU + {75B8E90E-E98D-4B04-9EF1-BBDAC55F1936}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {75B8E90E-E98D-4B04-9EF1-BBDAC55F1936}.Debug|Any CPU.Build.0 = Debug|Any CPU + {75B8E90E-E98D-4B04-9EF1-BBDAC55F1936}.Release|Any CPU.ActiveCfg = Release|Any CPU + {75B8E90E-E98D-4B04-9EF1-BBDAC55F1936}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/DiningRoom/DiningRoomBusinessLogic/BusinessLogics/CardLogic.cs b/DiningRoom/DiningRoomBusinessLogic/BusinessLogic/CardLogic.cs similarity index 88% rename from DiningRoom/DiningRoomBusinessLogic/BusinessLogics/CardLogic.cs rename to DiningRoom/DiningRoomBusinessLogic/BusinessLogic/CardLogic.cs index ec2c87b..ed1e96c 100644 --- a/DiningRoom/DiningRoomBusinessLogic/BusinessLogics/CardLogic.cs +++ b/DiningRoom/DiningRoomBusinessLogic/BusinessLogic/CardLogic.cs @@ -11,7 +11,7 @@ using System.Reflection; using System.Text; using System.Threading.Tasks; -namespace DiningRoomBusinessLogic.BusinessLogics +namespace DiningRoomBusinessLogic.BusinessLogic { public class CardLogic : ICardLogic { @@ -25,8 +25,8 @@ namespace DiningRoomBusinessLogic.BusinessLogics public List? ReadList(CardSearchModel? model) { - //model.UserId = -1 для swagger, чтобы можно было считать все заявки всех пользователей - var list = (model == null || model.UserId == -1) ? _CardStorage.GetFullList() : _CardStorage.GetFilteredList(model); + + var list = (model == null) ? _CardStorage.GetFullList() : _CardStorage.GetFilteredList(model); if (list == null) { _logger.LogWarning("ReadList Cards return null list"); diff --git a/DiningRoom/DiningRoomBusinessLogic/BusinessLogics/ComponentLogic.cs b/DiningRoom/DiningRoomBusinessLogic/BusinessLogic/ComponentLogic.cs similarity index 98% rename from DiningRoom/DiningRoomBusinessLogic/BusinessLogics/ComponentLogic.cs rename to DiningRoom/DiningRoomBusinessLogic/BusinessLogic/ComponentLogic.cs index ebafcc8..c74c8a0 100644 --- a/DiningRoom/DiningRoomBusinessLogic/BusinessLogics/ComponentLogic.cs +++ b/DiningRoom/DiningRoomBusinessLogic/BusinessLogic/ComponentLogic.cs @@ -6,7 +6,7 @@ using DiningRoomContracts.ViewModels; using Microsoft.Extensions.Logging; -namespace DiningRoomBusinessLogic.BusinessLogics +namespace DiningRoomBusinessLogic.BusinessLogic { public class ComponentLogic : IComponentLogic { diff --git a/DiningRoom/DiningRoomBusinessLogic/BusinessLogics/DrinkLogic.cs b/DiningRoom/DiningRoomBusinessLogic/BusinessLogic/DrinkLogic.cs similarity index 93% rename from DiningRoom/DiningRoomBusinessLogic/BusinessLogics/DrinkLogic.cs rename to DiningRoom/DiningRoomBusinessLogic/BusinessLogic/DrinkLogic.cs index b5ecc53..bae378a 100644 --- a/DiningRoom/DiningRoomBusinessLogic/BusinessLogics/DrinkLogic.cs +++ b/DiningRoom/DiningRoomBusinessLogic/BusinessLogic/DrinkLogic.cs @@ -6,7 +6,7 @@ using DiningRoomContracts.ViewModels; using Microsoft.Extensions.Logging; -namespace DiningRoomBusinessLogic.BusinessLogics +namespace DiningRoomBusinessLogic.BusinessLogic { public class DrinkLogic : IDrinkLogic { @@ -104,10 +104,5 @@ namespace DiningRoomBusinessLogic.BusinessLogics throw new InvalidOperationException("Напиток с таким названием уже есть"); } } - public bool ConnectCardDrink(DrinkBindingModel model) - { - _logger.LogInformation("Connect Card {rId} with drink {aId}", model.Id, model.CardId); - return _DrinkStorage.ConnectCardDrink(model); - } } } diff --git a/DiningRoom/DiningRoomBusinessLogic/BusinessLogics/OrderLogic.cs b/DiningRoom/DiningRoomBusinessLogic/BusinessLogic/OrderLogic.cs similarity index 96% rename from DiningRoom/DiningRoomBusinessLogic/BusinessLogics/OrderLogic.cs rename to DiningRoom/DiningRoomBusinessLogic/BusinessLogic/OrderLogic.cs index 4d5660a..d3769fd 100644 --- a/DiningRoom/DiningRoomBusinessLogic/BusinessLogics/OrderLogic.cs +++ b/DiningRoom/DiningRoomBusinessLogic/BusinessLogic/OrderLogic.cs @@ -11,7 +11,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace DiningRoomBusinessLogic.BusinessLogics +namespace DiningRoomBusinessLogic.BusinessLogic { public class OrderLogic : IOrderLogic { @@ -28,7 +28,7 @@ namespace DiningRoomBusinessLogic.BusinessLogics public List? ReadList(OrderSearchModel? model) { - var list = (model == null || model.UserId == -1) ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model); + var list = (model == null) ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model); if (list == null) { _logger.LogWarning("ReadList return null list"); diff --git a/DiningRoom/DiningRoomBusinessLogic/BusinessLogics/ProductLogic.cs b/DiningRoom/DiningRoomBusinessLogic/BusinessLogic/ProductLogic.cs similarity index 98% rename from DiningRoom/DiningRoomBusinessLogic/BusinessLogics/ProductLogic.cs rename to DiningRoom/DiningRoomBusinessLogic/BusinessLogic/ProductLogic.cs index 3fc0375..4c3aa9b 100644 --- a/DiningRoom/DiningRoomBusinessLogic/BusinessLogics/ProductLogic.cs +++ b/DiningRoom/DiningRoomBusinessLogic/BusinessLogic/ProductLogic.cs @@ -6,7 +6,7 @@ using DiningRoomContracts.ViewModels; using Microsoft.Extensions.Logging; -namespace DiningRoomBusinessLogic.BusinessLogics +namespace DiningRoomBusinessLogic.BusinessLogic { public class ProductLogic : IProductLogic { diff --git a/DiningRoom/DiningRoomBusinessLogic/BusinessLogics/ReportLogic.cs b/DiningRoom/DiningRoomBusinessLogic/BusinessLogic/ReportLogic.cs similarity index 85% rename from DiningRoom/DiningRoomBusinessLogic/BusinessLogics/ReportLogic.cs rename to DiningRoom/DiningRoomBusinessLogic/BusinessLogic/ReportLogic.cs index 9c8d34f..3ed5449 100644 --- a/DiningRoom/DiningRoomBusinessLogic/BusinessLogics/ReportLogic.cs +++ b/DiningRoom/DiningRoomBusinessLogic/BusinessLogic/ReportLogic.cs @@ -4,7 +4,7 @@ using DiningRoomContracts.SearchModels; using DiningRoomContracts.StorageContracts; using DiningRoomContracts.ViewModels; -namespace DiningRoomBusinessLogic.BusinessLogics +namespace DiningRoomBusinessLogic.BusinessLogic { public class ReportLogic : IReportLogic { @@ -26,9 +26,9 @@ namespace DiningRoomBusinessLogic.BusinessLogics /// /// Получение отчёта для отправки на почту /// - public List GetReportComponentsByCardDate(UserSearchModel CurrentUser, ReportBindingModel Report) + public List GetReportComponentsByCardDate(ReportBindingModel Report) { - return _componentStorage.GetComponentsByDate(Report, CurrentUser); + return _componentStorage.GetComponentsByDate(Report); } public void SaveReportToWordFile(ReportBindingModel Model) diff --git a/DiningRoom/DiningRoomBusinessLogic/BusinessLogics/UserLogic.cs b/DiningRoom/DiningRoomBusinessLogic/BusinessLogic/UserLogic.cs similarity index 98% rename from DiningRoom/DiningRoomBusinessLogic/BusinessLogics/UserLogic.cs rename to DiningRoom/DiningRoomBusinessLogic/BusinessLogic/UserLogic.cs index a4385d4..c5fbde1 100644 --- a/DiningRoom/DiningRoomBusinessLogic/BusinessLogics/UserLogic.cs +++ b/DiningRoom/DiningRoomBusinessLogic/BusinessLogic/UserLogic.cs @@ -10,7 +10,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace DiningRoomBusinessLogic.BusinessLogics +namespace DiningRoomBusinessLogic.BusinessLogic { public class UserLogic : IUserLogic { diff --git a/DiningRoom/DiningRoomContracts/BindingModels/CardBindingModel.cs b/DiningRoom/DiningRoomContracts/BindingModels/CardBindingModel.cs index f19de81..f8182d5 100644 --- a/DiningRoom/DiningRoomContracts/BindingModels/CardBindingModel.cs +++ b/DiningRoom/DiningRoomContracts/BindingModels/CardBindingModel.cs @@ -11,8 +11,6 @@ namespace DiningRoomContracts.BindingModels public class CardBindingModel : ICardModel { public int Id { get; set; } - - public int UserId { get; set; } public int? DrinkId { get; set; } public string CardName { get; set; } = string.Empty; public DateTime DateCardCreate { get; set; } = DateTime.Now; diff --git a/DiningRoom/DiningRoomContracts/BindingModels/ComponentBindingModel.cs b/DiningRoom/DiningRoomContracts/BindingModels/ComponentBindingModel.cs index b9139c8..086fbca 100644 --- a/DiningRoom/DiningRoomContracts/BindingModels/ComponentBindingModel.cs +++ b/DiningRoom/DiningRoomContracts/BindingModels/ComponentBindingModel.cs @@ -1,4 +1,5 @@ -using DiningRoomDataModels.Models; +using DiningRoomDataModels.Enums; +using DiningRoomDataModels.Models; namespace DiningRoomContracts.BindingModels { @@ -6,10 +7,8 @@ namespace DiningRoomContracts.BindingModels { public int Id { get; set; } - public int UserId { get; set; } - public string ComponentName { get; set; } = string.Empty; - public string Unit { get; set; } = string.Empty; + public ComponentUnit Unit { get; set; } = ComponentUnit.Неизвестна; public double Cost { get; set; } } } diff --git a/DiningRoom/DiningRoomContracts/BindingModels/DrinkBindingModel.cs b/DiningRoom/DiningRoomContracts/BindingModels/DrinkBindingModel.cs index 9c6628a..4e79556 100644 --- a/DiningRoom/DiningRoomContracts/BindingModels/DrinkBindingModel.cs +++ b/DiningRoom/DiningRoomContracts/BindingModels/DrinkBindingModel.cs @@ -6,9 +6,6 @@ namespace DiningRoomContracts.BindingModels { public int Id { get; set; } - public int UserId { get; set; } - public int CardId { get; set; } - public string DrinkName { get; set; } = string.Empty; public double Cost { get; set; } diff --git a/DiningRoom/DiningRoomContracts/BindingModels/OrderBindingModel.cs b/DiningRoom/DiningRoomContracts/BindingModels/OrderBindingModel.cs index 37ef8a8..82e8e9a 100644 --- a/DiningRoom/DiningRoomContracts/BindingModels/OrderBindingModel.cs +++ b/DiningRoom/DiningRoomContracts/BindingModels/OrderBindingModel.cs @@ -11,7 +11,6 @@ namespace DiningRoomContracts.BindingModels public class OrderBindingModel : IOrderModel { public int Id { get; set; } - public int UserId { get; set; } public int ProductId { get; set; } public string ProductName { get; set; } = string.Empty; public DateTime DateCreate { get; set; } = DateTime.Now; diff --git a/DiningRoom/DiningRoomContracts/BindingModels/ProductBindingModel.cs b/DiningRoom/DiningRoomContracts/BindingModels/ProductBindingModel.cs index a4d92d1..3582735 100644 --- a/DiningRoom/DiningRoomContracts/BindingModels/ProductBindingModel.cs +++ b/DiningRoom/DiningRoomContracts/BindingModels/ProductBindingModel.cs @@ -6,9 +6,6 @@ namespace DiningRoomContracts.BindingModels { public int Id { get; set; } - public int UserId { get; set; } - public int? OrderId { get; set; } - public string ProductName { get; set; } = string.Empty; public double Cost { get; set; } diff --git a/DiningRoom/DiningRoomContracts/BusinessLogicContracts/IDrinkLogic.cs b/DiningRoom/DiningRoomContracts/BusinessLogicContracts/IDrinkLogic.cs index 1a051af..db26e34 100644 --- a/DiningRoom/DiningRoomContracts/BusinessLogicContracts/IDrinkLogic.cs +++ b/DiningRoom/DiningRoomContracts/BusinessLogicContracts/IDrinkLogic.cs @@ -15,6 +15,5 @@ namespace DiningRoomContracts.BusinessLogicContracts bool Update(DrinkBindingModel Model); bool Delete(DrinkBindingModel Model); - bool ConnectCardDrink(DrinkBindingModel model); } } diff --git a/DiningRoom/DiningRoomContracts/BusinessLogicContracts/IReportLogic.cs b/DiningRoom/DiningRoomContracts/BusinessLogicContracts/IReportLogic.cs index a169cde..b887d5e 100644 --- a/DiningRoom/DiningRoomContracts/BusinessLogicContracts/IReportLogic.cs +++ b/DiningRoom/DiningRoomContracts/BusinessLogicContracts/IReportLogic.cs @@ -14,7 +14,7 @@ namespace DiningRoomContracts.BusinessLogicContracts /// /// Получение отчёта для отправки на почту /// - List GetReportComponentsByCardDate(UserSearchModel CurrentUser, ReportBindingModel Report); + List GetReportComponentsByCardDate(ReportBindingModel Report); void SaveReportToWordFile(ReportBindingModel Model); diff --git a/DiningRoom/DiningRoomContracts/SearchModels/CardSearchModel.cs b/DiningRoom/DiningRoomContracts/SearchModels/CardSearchModel.cs index 5e8f068..2967f20 100644 --- a/DiningRoom/DiningRoomContracts/SearchModels/CardSearchModel.cs +++ b/DiningRoom/DiningRoomContracts/SearchModels/CardSearchModel.cs @@ -4,7 +4,6 @@ { public int? Id { get; set; } - public int? UserId { get; set; } public DateTime? DateCardCreate { get; set; } public DateTime? DateFrom { get; set; } public DateTime? DateTo { get; set; } diff --git a/DiningRoom/DiningRoomContracts/SearchModels/ComponentSearchModel.cs b/DiningRoom/DiningRoomContracts/SearchModels/ComponentSearchModel.cs index 0701459..54986c3 100644 --- a/DiningRoom/DiningRoomContracts/SearchModels/ComponentSearchModel.cs +++ b/DiningRoom/DiningRoomContracts/SearchModels/ComponentSearchModel.cs @@ -3,8 +3,6 @@ public class ComponentSearchModel { public int? Id { get; set; } - - public int? UserId { get; set; } public string ComponentName { get; set; } } } diff --git a/DiningRoom/DiningRoomContracts/SearchModels/DrinkSearchModel.cs b/DiningRoom/DiningRoomContracts/SearchModels/DrinkSearchModel.cs index 1a8bbeb..61ee3c2 100644 --- a/DiningRoom/DiningRoomContracts/SearchModels/DrinkSearchModel.cs +++ b/DiningRoom/DiningRoomContracts/SearchModels/DrinkSearchModel.cs @@ -4,7 +4,6 @@ { public int? Id { get; set; } - public int? UserId { get; set; } public int? CardId { get; set; } public string? DrinkName { get; set; } diff --git a/DiningRoom/DiningRoomContracts/SearchModels/OrderSearchModel.cs b/DiningRoom/DiningRoomContracts/SearchModels/OrderSearchModel.cs index bcc1ebb..064050a 100644 --- a/DiningRoom/DiningRoomContracts/SearchModels/OrderSearchModel.cs +++ b/DiningRoom/DiningRoomContracts/SearchModels/OrderSearchModel.cs @@ -11,7 +11,6 @@ namespace DiningRoomContracts.SearchModels public class OrderSearchModel { public int? Id { get; set; } - public int? UserId { get; set; } public DateTime? DateFrom { get; set; } public DateTime? DateTo { get; set; } diff --git a/DiningRoom/DiningRoomContracts/SearchModels/ProductSearchModel.cs b/DiningRoom/DiningRoomContracts/SearchModels/ProductSearchModel.cs index b2f9e7c..7b9ade1 100644 --- a/DiningRoom/DiningRoomContracts/SearchModels/ProductSearchModel.cs +++ b/DiningRoom/DiningRoomContracts/SearchModels/ProductSearchModel.cs @@ -4,9 +4,6 @@ { public int? Id { get; set; } - public int? UserId { get; set; } - public int? OrderId { get; set; } - public string? ProductName { get; set; } } } diff --git a/DiningRoom/DiningRoomContracts/StorageContracts/IComponentStorage.cs b/DiningRoom/DiningRoomContracts/StorageContracts/IComponentStorage.cs index 37a1ca2..68e37b2 100644 --- a/DiningRoom/DiningRoomContracts/StorageContracts/IComponentStorage.cs +++ b/DiningRoom/DiningRoomContracts/StorageContracts/IComponentStorage.cs @@ -19,6 +19,6 @@ namespace DiningRoomContracts.StorageContracts ComponentViewModel? Delete(ComponentBindingModel Model); List GetComponentsOrders(List Models); - List GetComponentsByDate(ReportBindingModel ReportModel, UserSearchModel UserModel); + List GetComponentsByDate(ReportBindingModel ReportModel); } } diff --git a/DiningRoom/DiningRoomContracts/StorageContracts/IDrinkStorage.cs b/DiningRoom/DiningRoomContracts/StorageContracts/IDrinkStorage.cs index 2179e7a..7db12da 100644 --- a/DiningRoom/DiningRoomContracts/StorageContracts/IDrinkStorage.cs +++ b/DiningRoom/DiningRoomContracts/StorageContracts/IDrinkStorage.cs @@ -17,6 +17,5 @@ namespace DiningRoomContracts.StorageContracts DrinkViewModel? Update(DrinkBindingModel Model); DrinkViewModel? Delete(DrinkBindingModel Model); - bool ConnectCardDrink(DrinkBindingModel model); } } diff --git a/DiningRoom/DiningRoomContracts/ViewModels/CardViewModel.cs b/DiningRoom/DiningRoomContracts/ViewModels/CardViewModel.cs index fc09b87..64ec1b2 100644 --- a/DiningRoom/DiningRoomContracts/ViewModels/CardViewModel.cs +++ b/DiningRoom/DiningRoomContracts/ViewModels/CardViewModel.cs @@ -7,8 +7,6 @@ namespace DiningRoomContracts.ViewModels { public int Id { get; set; } - public int UserId { get; set; } - [DisplayName("Название карты")] public string CardName { get; set; } = string.Empty; diff --git a/DiningRoom/DiningRoomContracts/ViewModels/ComponentViewModel.cs b/DiningRoom/DiningRoomContracts/ViewModels/ComponentViewModel.cs index acd82d1..7ba0430 100644 --- a/DiningRoom/DiningRoomContracts/ViewModels/ComponentViewModel.cs +++ b/DiningRoom/DiningRoomContracts/ViewModels/ComponentViewModel.cs @@ -1,4 +1,5 @@ -using DiningRoomDataModels.Models; +using DiningRoomDataModels.Enums; +using DiningRoomDataModels.Models; using System.ComponentModel; namespace DiningRoomContracts.ViewModels @@ -7,13 +8,11 @@ namespace DiningRoomContracts.ViewModels { public int Id { get; set; } - public int UserId { get; set; } - [DisplayName("Название продукта")] public string ComponentName { get; set; } = string.Empty; [DisplayName("Единица измерения")] - public string Unit { get; set; } = string.Empty; + public ComponentUnit Unit { get; set; } = ComponentUnit.Неизвестна; [DisplayName("Стоимость")] public double Cost { get; set; } diff --git a/DiningRoom/DiningRoomContracts/ViewModels/DrinkViewModel.cs b/DiningRoom/DiningRoomContracts/ViewModels/DrinkViewModel.cs index 9e9fbc4..16be0e5 100644 --- a/DiningRoom/DiningRoomContracts/ViewModels/DrinkViewModel.cs +++ b/DiningRoom/DiningRoomContracts/ViewModels/DrinkViewModel.cs @@ -6,9 +6,6 @@ namespace DiningRoomContracts.ViewModels public class DrinkViewModel : IDrinkModel { public int Id { get; set; } - - public int UserId { get; set; } - public int CardId { get; set; } public string CardName { get; set; } = string.Empty; [DisplayName("Название товара")] diff --git a/DiningRoom/DiningRoomContracts/ViewModels/OrderViewModel.cs b/DiningRoom/DiningRoomContracts/ViewModels/OrderViewModel.cs index e413a26..4aa3466 100644 --- a/DiningRoom/DiningRoomContracts/ViewModels/OrderViewModel.cs +++ b/DiningRoom/DiningRoomContracts/ViewModels/OrderViewModel.cs @@ -14,7 +14,6 @@ namespace DiningRoomContracts.ViewModels [DisplayName("Номер")] public int Id { get; set; } public int ProductId { get; set; } - public int UserId { get; set; } [DisplayName("Дата Создания")] public DateTime DateCreate { get; set; } = DateTime.Now; [DisplayName("Блюдо")] diff --git a/DiningRoom/DiningRoomContracts/ViewModels/ProductViewModel.cs b/DiningRoom/DiningRoomContracts/ViewModels/ProductViewModel.cs index 127125c..0a1748a 100644 --- a/DiningRoom/DiningRoomContracts/ViewModels/ProductViewModel.cs +++ b/DiningRoom/DiningRoomContracts/ViewModels/ProductViewModel.cs @@ -7,9 +7,6 @@ namespace DiningRoomContracts.ViewModels { public int Id { get; set; } - public int UserId { get; set; } - public int? OrderId { get; set; } - [DisplayName("Название товара")] public string ProductName { get; set; } = string.Empty; diff --git a/DiningRoom/DiningRoomDataModels/Enums/ComponentUnit.cs b/DiningRoom/DiningRoomDataModels/Enums/ComponentUnit.cs new file mode 100644 index 0000000..25d77d3 --- /dev/null +++ b/DiningRoom/DiningRoomDataModels/Enums/ComponentUnit.cs @@ -0,0 +1,9 @@ +namespace DiningRoomDataModels.Enums +{ + public enum ComponentUnit + { + Неизвестна = -1, + Граммы = 0, + Миллилитры = 1, + } +} diff --git a/DiningRoom/DiningRoomDataModels/Models/ICardModel.cs b/DiningRoom/DiningRoomDataModels/Models/ICardModel.cs index 46da448..dcfdeaf 100644 --- a/DiningRoom/DiningRoomDataModels/Models/ICardModel.cs +++ b/DiningRoom/DiningRoomDataModels/Models/ICardModel.cs @@ -5,10 +5,6 @@ /// public interface ICardModel : IId { - /// - /// Пользователь, который добавил карту - /// - int UserId { get; } /// /// Название карты diff --git a/DiningRoom/DiningRoomDataModels/Models/IComponentModel.cs b/DiningRoom/DiningRoomDataModels/Models/IComponentModel.cs index 2ea858c..7f360bb 100644 --- a/DiningRoom/DiningRoomDataModels/Models/IComponentModel.cs +++ b/DiningRoom/DiningRoomDataModels/Models/IComponentModel.cs @@ -1,15 +1,12 @@ -namespace DiningRoomDataModels.Models +using DiningRoomDataModels.Enums; + +namespace DiningRoomDataModels.Models { /// /// Продукт /// public interface IComponentModel : IId { - /// - /// Пользователь, который добавил продукт - /// - int UserId { get; } - /// /// Название продукта /// @@ -17,7 +14,7 @@ /// /// Единица измерения /// - string Unit { get; } + ComponentUnit Unit { get; } /// /// Цена продукта diff --git a/DiningRoom/DiningRoomDataModels/Models/IDrinkModel.cs b/DiningRoom/DiningRoomDataModels/Models/IDrinkModel.cs index e54ceb8..64e8f7a 100644 --- a/DiningRoom/DiningRoomDataModels/Models/IDrinkModel.cs +++ b/DiningRoom/DiningRoomDataModels/Models/IDrinkModel.cs @@ -5,10 +5,6 @@ /// public interface IDrinkModel : IId { - /// - /// Пользователь, который добавил напиток - /// - int UserId { get; } /// /// Название напитка @@ -19,7 +15,6 @@ /// Стоимость товара /// double Cost { get; } - int CardId { get; } /// /// Список продуктов diff --git a/DiningRoom/DiningRoomDataModels/Models/IOrderModel.cs b/DiningRoom/DiningRoomDataModels/Models/IOrderModel.cs index 3af22d0..fe84f8e 100644 --- a/DiningRoom/DiningRoomDataModels/Models/IOrderModel.cs +++ b/DiningRoom/DiningRoomDataModels/Models/IOrderModel.cs @@ -9,8 +9,6 @@ namespace DiningRoomDataModels.Models { public interface IOrderModel : IId { - //ID пользователя, который создал заказ - int UserId { get; } /// /// Дата создания заказа /// diff --git a/DiningRoom/DiningRoomDataModels/Models/IProductModel.cs b/DiningRoom/DiningRoomDataModels/Models/IProductModel.cs index 7d30e25..45087b2 100644 --- a/DiningRoom/DiningRoomDataModels/Models/IProductModel.cs +++ b/DiningRoom/DiningRoomDataModels/Models/IProductModel.cs @@ -5,10 +5,6 @@ /// public interface IProductModel : IId { - /// - /// Пользователь, который добавил блюдо - /// - int UserId { get; } /// /// Название блюда diff --git a/DiningRoom/DiningRoomDatabaseImplement/Implements/CardStorage.cs b/DiningRoom/DiningRoomDatabaseImplement/Implements/CardStorage.cs index b41dde9..a3552a3 100644 --- a/DiningRoom/DiningRoomDatabaseImplement/Implements/CardStorage.cs +++ b/DiningRoom/DiningRoomDatabaseImplement/Implements/CardStorage.cs @@ -32,14 +32,14 @@ namespace DiningRoomDatabaseImplement.Implements if (model.DateFrom.HasValue && model.DateTo.HasValue) { return context.Cards - .Where(x => (x.UserId == model.UserId) && (x.DateCardCreate >= model.DateFrom && x.DateCardCreate <= model.DateTo)) + .Where(x => (x.DateCardCreate >= model.DateFrom && x.DateCardCreate <= model.DateTo)) .Include(x => x.Drinks) .Select(x => x.GetViewModel) .ToList(); } //возвращение просто всех заявок пользователя (замена GetFullList) return context.Cards - .Where(x => x.UserId == model.UserId) + .Where(x => x.Id == model.Id) .Include(x => x.Drinks) .Select(x => x.GetViewModel) .ToList(); diff --git a/DiningRoom/DiningRoomDatabaseImplement/Implements/ComponentStorage.cs b/DiningRoom/DiningRoomDatabaseImplement/Implements/ComponentStorage.cs index 68db08e..c85f1fc 100644 --- a/DiningRoom/DiningRoomDatabaseImplement/Implements/ComponentStorage.cs +++ b/DiningRoom/DiningRoomDatabaseImplement/Implements/ComponentStorage.cs @@ -114,12 +114,12 @@ namespace DiningRoomDatabaseImplement.Implements .ToList(); } - public List GetComponentsByDate(ReportBindingModel ReportModel, UserSearchModel UserModel) + public List GetComponentsByDate(ReportBindingModel ReportModel) { using var Context = new DiningRoomDatabase(); return Context.Cards - .Where(card => card.UserId == UserModel.Id && card.DateCardCreate >= ReportModel.DateFrom && card.DateCardCreate <= ReportModel.DateTo) + .Where(card => card.DateCardCreate >= ReportModel.DateFrom && card.DateCardCreate <= ReportModel.DateTo) .Include(card => card.Drinks) .ThenInclude(d => d.Components) .ThenInclude(dc => dc.Component) diff --git a/DiningRoom/DiningRoomDatabaseImplement/Implements/DrinkStorage.cs b/DiningRoom/DiningRoomDatabaseImplement/Implements/DrinkStorage.cs index 135f44a..9f95133 100644 --- a/DiningRoom/DiningRoomDatabaseImplement/Implements/DrinkStorage.cs +++ b/DiningRoom/DiningRoomDatabaseImplement/Implements/DrinkStorage.cs @@ -102,18 +102,5 @@ namespace DiningRoomDatabaseImplement.Implements } return null; } - public bool ConnectCardDrink(DrinkBindingModel model) - { - using var context = new DiningRoomDatabase(); - var Card = context.Cards.FirstOrDefault(x => x.Id == model.Id); - var Drink = context.Drinks.FirstOrDefault(x => x.Id == model.CardId); - if (Card == null || Drink == null) - { - return false; - } - Drink.ConnectDrink(context, model); - context.SaveChanges(); - return true; - } } } \ No newline at end of file diff --git a/DiningRoom/DiningRoomDatabaseImplement/Implements/OrderStorage.cs b/DiningRoom/DiningRoomDatabaseImplement/Implements/OrderStorage.cs index 763985d..8887d9f 100644 --- a/DiningRoom/DiningRoomDatabaseImplement/Implements/OrderStorage.cs +++ b/DiningRoom/DiningRoomDatabaseImplement/Implements/OrderStorage.cs @@ -55,7 +55,7 @@ namespace DiningRoomDatabaseImplement.Implements if (model.DateFrom.HasValue && model.DateTo.HasValue) { return context.Orders - .Where(x => (x.UserId == model.UserId) && (x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo)) + .Where(x =>(x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo)) .Include(x => x.Product) .ToList() .Select(x => x.GetViewModel) @@ -65,7 +65,7 @@ namespace DiningRoomDatabaseImplement.Implements else if (model.Status.HasValue) { return context.Orders - .Where(x => (x.UserId == model.UserId) && (x.Status == model.Status)) + .Where(x => (x.Status == model.Status)) .Include(x => x.Product) .ToList() .Select(x => x.GetViewModel) @@ -73,7 +73,7 @@ namespace DiningRoomDatabaseImplement.Implements } return context.Orders - .Where(x => x.UserId == model.UserId) + .Where(x => x.Id == model.Id) .Include(x => x.Product) .ToList() .Select(x => x.GetViewModel) diff --git a/DiningRoom/DiningRoomDatabaseImplement/Implements/ProductStorage.cs b/DiningRoom/DiningRoomDatabaseImplement/Implements/ProductStorage.cs index 1f17ed1..4e6d7ad 100644 --- a/DiningRoom/DiningRoomDatabaseImplement/Implements/ProductStorage.cs +++ b/DiningRoom/DiningRoomDatabaseImplement/Implements/ProductStorage.cs @@ -24,24 +24,12 @@ namespace DiningRoomDatabaseImplement.Implements public List GetFilteredList(ProductSearchModel model) { using var context = new DiningRoomDatabase(); - - // Optional search by order - if (model.OrderId.HasValue) - { - return context.Products - .Include(x => x.Order) - .Include(x => x.Components) - .ThenInclude(x => x.Component) - .Where(x => x.UserId == model.UserId) - .Select(x => x.GetViewModel) - .ToList(); - } return context.Products .Include(x => x.Order) .Include(x => x.Components) .ThenInclude(x => x.Component) - .Where(x => x.UserId == model.UserId) + .Where(x => x.Id == model.Id) .Select(x => x.GetViewModel) .ToList(); } diff --git a/DiningRoom/DiningRoomDatabaseImplement/Migrations/20240504170055_InitialCreate.Designer.cs b/DiningRoom/DiningRoomDatabaseImplement/Migrations/20240525184442_InitialCreate.Designer.cs similarity index 83% rename from DiningRoom/DiningRoomDatabaseImplement/Migrations/20240504170055_InitialCreate.Designer.cs rename to DiningRoom/DiningRoomDatabaseImplement/Migrations/20240525184442_InitialCreate.Designer.cs index afbc938..f518d2b 100644 --- a/DiningRoom/DiningRoomDatabaseImplement/Migrations/20240504170055_InitialCreate.Designer.cs +++ b/DiningRoom/DiningRoomDatabaseImplement/Migrations/20240525184442_InitialCreate.Designer.cs @@ -12,7 +12,7 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; namespace DiningRoomDatabaseImplement.Migrations { [DbContext(typeof(DiningRoomDatabase))] - [Migration("20240504170055_InitialCreate")] + [Migration("20240525184442_InitialCreate")] partial class InitialCreate { /// @@ -20,11 +20,26 @@ namespace DiningRoomDatabaseImplement.Migrations { #pragma warning disable 612, 618 modelBuilder - .HasAnnotation("ProductVersion", "7.0.18") + .HasAnnotation("DrinkVersion", "7.0.18") .HasAnnotation("Relational:MaxIdentifierLength", 63); NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + modelBuilder.Entity("CardDrink", b => + { + b.Property("CardId") + .HasColumnType("integer"); + + b.Property("DrinkId") + .HasColumnType("integer"); + + b.HasKey("CardId", "DrinkId"); + + b.HasIndex("DrinkId"); + + b.ToTable("CardDrink"); + }); + modelBuilder.Entity("DiningRoomDatabaseImplement.Models.Card", b => { b.Property("Id") @@ -40,7 +55,7 @@ namespace DiningRoomDatabaseImplement.Migrations b.Property("DateCardCreate") .HasColumnType("timestamp without time zone"); - b.Property("UserId") + b.Property("UserId") .HasColumnType("integer"); b.HasKey("Id"); @@ -65,11 +80,10 @@ namespace DiningRoomDatabaseImplement.Migrations b.Property("Cost") .HasColumnType("double precision"); - b.Property("Unit") - .IsRequired() - .HasColumnType("text"); + b.Property("Unit") + .HasColumnType("integer"); - b.Property("UserId") + b.Property("UserId") .HasColumnType("integer"); b.HasKey("Id"); @@ -87,9 +101,6 @@ namespace DiningRoomDatabaseImplement.Migrations NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - b.Property("CardId") - .HasColumnType("integer"); - b.Property("Cost") .HasColumnType("double precision"); @@ -97,13 +108,11 @@ namespace DiningRoomDatabaseImplement.Migrations .IsRequired() .HasColumnType("text"); - b.Property("UserId") + b.Property("UserId") .HasColumnType("integer"); b.HasKey("Id"); - b.HasIndex("CardId"); - b.HasIndex("UserId"); b.ToTable("Drinks"); @@ -130,6 +139,8 @@ namespace DiningRoomDatabaseImplement.Migrations b.HasIndex("ComponentId"); + b.HasIndex("DrinkId"); + b.ToTable("DrinkComponents"); }); @@ -147,10 +158,10 @@ namespace DiningRoomDatabaseImplement.Migrations b.Property("DateCreate") .HasColumnType("timestamp without time zone"); - b.Property("ProductId") + b.Property("DrinkId") .HasColumnType("integer"); - b.Property("ProductName") + b.Property("DrinkName") .IsRequired() .HasColumnType("text"); @@ -160,19 +171,19 @@ namespace DiningRoomDatabaseImplement.Migrations b.Property("Sum") .HasColumnType("double precision"); - b.Property("UserId") + b.Property("UserId") .HasColumnType("integer"); b.HasKey("Id"); - b.HasIndex("ProductId"); + b.HasIndex("DrinkId"); b.HasIndex("UserId"); b.ToTable("Orders"); }); - modelBuilder.Entity("DiningRoomDatabaseImplement.Models.Product", b => + modelBuilder.Entity("DiningRoomDatabaseImplement.Models.Drink", b => { b.Property("Id") .ValueGeneratedOnAdd() @@ -183,21 +194,21 @@ namespace DiningRoomDatabaseImplement.Migrations b.Property("Cost") .HasColumnType("double precision"); - b.Property("ProductName") + b.Property("DrinkName") .IsRequired() .HasColumnType("text"); - b.Property("UserId") + b.Property("UserId") .HasColumnType("integer"); b.HasKey("Id"); b.HasIndex("UserId"); - b.ToTable("Products"); + b.ToTable("Drinks"); }); - modelBuilder.Entity("DiningRoomDatabaseImplement.Models.ProductComponent", b => + modelBuilder.Entity("DiningRoomDatabaseImplement.Models.DrinkComponent", b => { b.Property("Id") .ValueGeneratedOnAdd() @@ -211,16 +222,16 @@ namespace DiningRoomDatabaseImplement.Migrations b.Property("Count") .HasColumnType("integer"); - b.Property("ProductId") + b.Property("DrinkId") .HasColumnType("integer"); b.HasKey("Id"); b.HasIndex("ComponentId"); - b.HasIndex("ProductId"); + b.HasIndex("DrinkId"); - b.ToTable("ProductComponents"); + b.ToTable("DrinkComponents"); }); modelBuilder.Entity("DiningRoomDatabaseImplement.Models.User", b => @@ -248,39 +259,40 @@ namespace DiningRoomDatabaseImplement.Migrations b.ToTable("Users"); }); + modelBuilder.Entity("CardDrink", b => + { + b.HasOne("DiningRoomDatabaseImplement.Models.Card", null) + .WithMany() + .HasForeignKey("CardId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("DiningRoomDatabaseImplement.Models.Drink", null) + .WithMany() + .HasForeignKey("DrinkId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + modelBuilder.Entity("DiningRoomDatabaseImplement.Models.Card", b => { b.HasOne("DiningRoomDatabaseImplement.Models.User", null) .WithMany("Cards") - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); + .HasForeignKey("UserId"); }); modelBuilder.Entity("DiningRoomDatabaseImplement.Models.Component", b => { b.HasOne("DiningRoomDatabaseImplement.Models.User", null) .WithMany("Components") - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); + .HasForeignKey("UserId"); }); modelBuilder.Entity("DiningRoomDatabaseImplement.Models.Drink", b => { - b.HasOne("DiningRoomDatabaseImplement.Models.Card", "Card") - .WithMany("Drinks") - .HasForeignKey("CardId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - b.HasOne("DiningRoomDatabaseImplement.Models.User", null) .WithMany("Drinks") - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Card"); + .HasForeignKey("UserId"); }); modelBuilder.Entity("DiningRoomDatabaseImplement.Models.DrinkComponent", b => @@ -293,7 +305,7 @@ namespace DiningRoomDatabaseImplement.Migrations b.HasOne("DiningRoomDatabaseImplement.Models.Drink", "Drink") .WithMany("Components") - .HasForeignKey("ComponentId") + .HasForeignKey("DrinkId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); @@ -304,59 +316,50 @@ namespace DiningRoomDatabaseImplement.Migrations modelBuilder.Entity("DiningRoomDatabaseImplement.Models.Order", b => { - b.HasOne("DiningRoomDatabaseImplement.Models.Product", "Product") + b.HasOne("DiningRoomDatabaseImplement.Models.Drink", "Drink") .WithMany("Order") - .HasForeignKey("ProductId") + .HasForeignKey("DrinkId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); b.HasOne("DiningRoomDatabaseImplement.Models.User", null) .WithMany("Orders") - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); + .HasForeignKey("UserId"); - b.Navigation("Product"); + b.Navigation("Drink"); }); - modelBuilder.Entity("DiningRoomDatabaseImplement.Models.Product", b => + modelBuilder.Entity("DiningRoomDatabaseImplement.Models.Drink", b => { b.HasOne("DiningRoomDatabaseImplement.Models.User", null) - .WithMany("Products") - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); + .WithMany("Drinks") + .HasForeignKey("UserId"); }); - modelBuilder.Entity("DiningRoomDatabaseImplement.Models.ProductComponent", b => + modelBuilder.Entity("DiningRoomDatabaseImplement.Models.DrinkComponent", b => { b.HasOne("DiningRoomDatabaseImplement.Models.Component", "Component") - .WithMany("ProductComponents") + .WithMany("DrinkComponents") .HasForeignKey("ComponentId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); - b.HasOne("DiningRoomDatabaseImplement.Models.Product", "Product") + b.HasOne("DiningRoomDatabaseImplement.Models.Drink", "Drink") .WithMany("Components") - .HasForeignKey("ProductId") + .HasForeignKey("DrinkId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); b.Navigation("Component"); - b.Navigation("Product"); - }); - - modelBuilder.Entity("DiningRoomDatabaseImplement.Models.Card", b => - { - b.Navigation("Drinks"); + b.Navigation("Drink"); }); modelBuilder.Entity("DiningRoomDatabaseImplement.Models.Component", b => { b.Navigation("DrinkComponents"); - b.Navigation("ProductComponents"); + b.Navigation("DrinkComponents"); }); modelBuilder.Entity("DiningRoomDatabaseImplement.Models.Drink", b => @@ -364,7 +367,7 @@ namespace DiningRoomDatabaseImplement.Migrations b.Navigation("Components"); }); - modelBuilder.Entity("DiningRoomDatabaseImplement.Models.Product", b => + modelBuilder.Entity("DiningRoomDatabaseImplement.Models.Drink", b => { b.Navigation("Components"); @@ -381,7 +384,7 @@ namespace DiningRoomDatabaseImplement.Migrations b.Navigation("Orders"); - b.Navigation("Products"); + b.Navigation("Drinks"); }); #pragma warning restore 612, 618 } diff --git a/DiningRoom/DiningRoomDatabaseImplement/Migrations/20240504170055_InitialCreate.cs b/DiningRoom/DiningRoomDatabaseImplement/Migrations/20240525184442_InitialCreate.cs similarity index 77% rename from DiningRoom/DiningRoomDatabaseImplement/Migrations/20240504170055_InitialCreate.cs rename to DiningRoom/DiningRoomDatabaseImplement/Migrations/20240525184442_InitialCreate.cs index 2dc1303..8e75624 100644 --- a/DiningRoom/DiningRoomDatabaseImplement/Migrations/20240504170055_InitialCreate.cs +++ b/DiningRoom/DiningRoomDatabaseImplement/Migrations/20240525184442_InitialCreate.cs @@ -33,9 +33,9 @@ namespace DiningRoomDatabaseImplement.Migrations { Id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), - UserId = table.Column(type: "integer", nullable: false), CardName = table.Column(type: "text", nullable: false), - DateCardCreate = table.Column(type: "timestamp without time zone", nullable: false) + DateCardCreate = table.Column(type: "timestamp without time zone", nullable: false), + UserId = table.Column(type: "integer", nullable: true) }, constraints: table => { @@ -44,8 +44,7 @@ namespace DiningRoomDatabaseImplement.Migrations name: "FK_Cards_Users_UserId", column: x => x.UserId, principalTable: "Users", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); + principalColumn: "Id"); }); migrationBuilder.CreateTable( @@ -54,10 +53,10 @@ namespace DiningRoomDatabaseImplement.Migrations { Id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), - UserId = table.Column(type: "integer", nullable: false), ComponentName = table.Column(type: "text", nullable: false), - Unit = table.Column(type: "text", nullable: false), - Cost = table.Column(type: "double precision", nullable: false) + Unit = table.Column(type: "integer", nullable: false), + Cost = table.Column(type: "double precision", nullable: false), + UserId = table.Column(type: "integer", nullable: true) }, constraints: table => { @@ -66,29 +65,7 @@ namespace DiningRoomDatabaseImplement.Migrations name: "FK_Components_Users_UserId", column: x => x.UserId, principalTable: "Users", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "Products", - columns: table => new - { - Id = table.Column(type: "integer", nullable: false) - .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), - UserId = table.Column(type: "integer", nullable: false), - ProductName = table.Column(type: "text", nullable: false), - Cost = table.Column(type: "double precision", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Products", x => x.Id); - table.ForeignKey( - name: "FK_Products_Users_UserId", - column: x => x.UserId, - principalTable: "Users", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); + principalColumn: "Id"); }); migrationBuilder.CreateTable( @@ -97,82 +74,60 @@ namespace DiningRoomDatabaseImplement.Migrations { Id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), - UserId = table.Column(type: "integer", nullable: false), DrinkName = table.Column(type: "text", nullable: false), Cost = table.Column(type: "double precision", nullable: false), - CardId = table.Column(type: "integer", nullable: false) + UserId = table.Column(type: "integer", nullable: true) }, constraints: table => { table.PrimaryKey("PK_Drinks", x => x.Id); table.ForeignKey( - name: "FK_Drinks_Cards_CardId", + name: "FK_Drinks_Users_UserId", + column: x => x.UserId, + principalTable: "Users", + principalColumn: "Id"); + }); + + migrationBuilder.CreateTable( + name: "Drinks", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + DrinkName = table.Column(type: "text", nullable: false), + Cost = table.Column(type: "double precision", nullable: false), + UserId = table.Column(type: "integer", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Drinks", x => x.Id); + table.ForeignKey( + name: "FK_Drinks_Users_UserId", + column: x => x.UserId, + principalTable: "Users", + principalColumn: "Id"); + }); + + migrationBuilder.CreateTable( + name: "CardDrink", + columns: table => new + { + CardId = table.Column(type: "integer", nullable: false), + DrinkId = table.Column(type: "integer", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_CardDrink", x => new { x.CardId, x.DrinkId }); + table.ForeignKey( + name: "FK_CardDrink_Cards_CardId", column: x => x.CardId, principalTable: "Cards", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( - name: "FK_Drinks_Users_UserId", - column: x => x.UserId, - principalTable: "Users", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "Orders", - columns: table => new - { - Id = table.Column(type: "integer", nullable: false) - .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), - ProductId = table.Column(type: "integer", nullable: false), - ProductName = table.Column(type: "text", nullable: false), - Count = table.Column(type: "integer", nullable: false), - Sum = table.Column(type: "double precision", nullable: false), - Status = table.Column(type: "integer", nullable: false), - DateCreate = table.Column(type: "timestamp without time zone", nullable: false), - UserId = table.Column(type: "integer", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Orders", x => x.Id); - table.ForeignKey( - name: "FK_Orders_Products_ProductId", - column: x => x.ProductId, - principalTable: "Products", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - table.ForeignKey( - name: "FK_Orders_Users_UserId", - column: x => x.UserId, - principalTable: "Users", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "ProductComponents", - columns: table => new - { - Id = table.Column(type: "integer", nullable: false) - .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), - ProductId = table.Column(type: "integer", nullable: false), - ComponentId = table.Column(type: "integer", nullable: false), - Count = table.Column(type: "integer", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_ProductComponents", x => x.Id); - table.ForeignKey( - name: "FK_ProductComponents_Components_ComponentId", - column: x => x.ComponentId, - principalTable: "Components", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - table.ForeignKey( - name: "FK_ProductComponents_Products_ProductId", - column: x => x.ProductId, - principalTable: "Products", + name: "FK_CardDrink_Drinks_DrinkId", + column: x => x.DrinkId, + principalTable: "Drinks", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); @@ -197,13 +152,75 @@ namespace DiningRoomDatabaseImplement.Migrations principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( - name: "FK_DrinkComponents_Drinks_ComponentId", - column: x => x.ComponentId, + name: "FK_DrinkComponents_Drinks_DrinkId", + column: x => x.DrinkId, principalTable: "Drinks", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); + migrationBuilder.CreateTable( + name: "Orders", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + DrinkId = table.Column(type: "integer", nullable: false), + DrinkName = table.Column(type: "text", nullable: false), + Count = table.Column(type: "integer", nullable: false), + Sum = table.Column(type: "double precision", nullable: false), + Status = table.Column(type: "integer", nullable: false), + DateCreate = table.Column(type: "timestamp without time zone", nullable: false), + UserId = table.Column(type: "integer", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Orders", x => x.Id); + table.ForeignKey( + name: "FK_Orders_Drinks_DrinkId", + column: x => x.DrinkId, + principalTable: "Drinks", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_Orders_Users_UserId", + column: x => x.UserId, + principalTable: "Users", + principalColumn: "Id"); + }); + + migrationBuilder.CreateTable( + name: "DrinkComponents", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + DrinkId = table.Column(type: "integer", nullable: false), + ComponentId = table.Column(type: "integer", nullable: false), + Count = table.Column(type: "integer", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_DrinkComponents", x => x.Id); + table.ForeignKey( + name: "FK_DrinkComponents_Components_ComponentId", + column: x => x.ComponentId, + principalTable: "Components", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_DrinkComponents_Drinks_DrinkId", + column: x => x.DrinkId, + principalTable: "Drinks", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_CardDrink_DrinkId", + table: "CardDrink", + column: "DrinkId"); + migrationBuilder.CreateIndex( name: "IX_Cards_UserId", table: "Cards", @@ -220,9 +237,9 @@ namespace DiningRoomDatabaseImplement.Migrations column: "ComponentId"); migrationBuilder.CreateIndex( - name: "IX_Drinks_CardId", - table: "Drinks", - column: "CardId"); + name: "IX_DrinkComponents_DrinkId", + table: "DrinkComponents", + column: "DrinkId"); migrationBuilder.CreateIndex( name: "IX_Drinks_UserId", @@ -230,9 +247,9 @@ namespace DiningRoomDatabaseImplement.Migrations column: "UserId"); migrationBuilder.CreateIndex( - name: "IX_Orders_ProductId", + name: "IX_Orders_DrinkId", table: "Orders", - column: "ProductId"); + column: "DrinkId"); migrationBuilder.CreateIndex( name: "IX_Orders_UserId", @@ -240,24 +257,27 @@ namespace DiningRoomDatabaseImplement.Migrations column: "UserId"); migrationBuilder.CreateIndex( - name: "IX_ProductComponents_ComponentId", - table: "ProductComponents", + name: "IX_DrinkComponents_ComponentId", + table: "DrinkComponents", column: "ComponentId"); migrationBuilder.CreateIndex( - name: "IX_ProductComponents_ProductId", - table: "ProductComponents", - column: "ProductId"); + name: "IX_DrinkComponents_DrinkId", + table: "DrinkComponents", + column: "DrinkId"); migrationBuilder.CreateIndex( - name: "IX_Products_UserId", - table: "Products", + name: "IX_Drinks_UserId", + table: "Drinks", column: "UserId"); } /// protected override void Down(MigrationBuilder migrationBuilder) { + migrationBuilder.DropTable( + name: "CardDrink"); + migrationBuilder.DropTable( name: "DrinkComponents"); @@ -265,7 +285,10 @@ namespace DiningRoomDatabaseImplement.Migrations name: "Orders"); migrationBuilder.DropTable( - name: "ProductComponents"); + name: "DrinkComponents"); + + migrationBuilder.DropTable( + name: "Cards"); migrationBuilder.DropTable( name: "Drinks"); @@ -274,10 +297,7 @@ namespace DiningRoomDatabaseImplement.Migrations name: "Components"); migrationBuilder.DropTable( - name: "Products"); - - migrationBuilder.DropTable( - name: "Cards"); + name: "Drinks"); migrationBuilder.DropTable( name: "Users"); diff --git a/DiningRoom/DiningRoomDatabaseImplement/Migrations/DiningRoomDatabaseModelSnapshot.cs b/DiningRoom/DiningRoomDatabaseImplement/Migrations/DiningRoomDatabaseModelSnapshot.cs index bbee309..10d4dd6 100644 --- a/DiningRoom/DiningRoomDatabaseImplement/Migrations/DiningRoomDatabaseModelSnapshot.cs +++ b/DiningRoom/DiningRoomDatabaseImplement/Migrations/DiningRoomDatabaseModelSnapshot.cs @@ -17,11 +17,26 @@ namespace DiningRoomDatabaseImplement.Migrations { #pragma warning disable 612, 618 modelBuilder - .HasAnnotation("ProductVersion", "7.0.18") + .HasAnnotation("DrinkVersion", "7.0.18") .HasAnnotation("Relational:MaxIdentifierLength", 63); NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + modelBuilder.Entity("CardDrink", b => + { + b.Property("CardId") + .HasColumnType("integer"); + + b.Property("DrinkId") + .HasColumnType("integer"); + + b.HasKey("CardId", "DrinkId"); + + b.HasIndex("DrinkId"); + + b.ToTable("CardDrink"); + }); + modelBuilder.Entity("DiningRoomDatabaseImplement.Models.Card", b => { b.Property("Id") @@ -37,7 +52,7 @@ namespace DiningRoomDatabaseImplement.Migrations b.Property("DateCardCreate") .HasColumnType("timestamp without time zone"); - b.Property("UserId") + b.Property("UserId") .HasColumnType("integer"); b.HasKey("Id"); @@ -62,11 +77,10 @@ namespace DiningRoomDatabaseImplement.Migrations b.Property("Cost") .HasColumnType("double precision"); - b.Property("Unit") - .IsRequired() - .HasColumnType("text"); + b.Property("Unit") + .HasColumnType("integer"); - b.Property("UserId") + b.Property("UserId") .HasColumnType("integer"); b.HasKey("Id"); @@ -84,9 +98,6 @@ namespace DiningRoomDatabaseImplement.Migrations NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - b.Property("CardId") - .HasColumnType("integer"); - b.Property("Cost") .HasColumnType("double precision"); @@ -94,13 +105,11 @@ namespace DiningRoomDatabaseImplement.Migrations .IsRequired() .HasColumnType("text"); - b.Property("UserId") + b.Property("UserId") .HasColumnType("integer"); b.HasKey("Id"); - b.HasIndex("CardId"); - b.HasIndex("UserId"); b.ToTable("Drinks"); @@ -127,6 +136,8 @@ namespace DiningRoomDatabaseImplement.Migrations b.HasIndex("ComponentId"); + b.HasIndex("DrinkId"); + b.ToTable("DrinkComponents"); }); @@ -144,10 +155,10 @@ namespace DiningRoomDatabaseImplement.Migrations b.Property("DateCreate") .HasColumnType("timestamp without time zone"); - b.Property("ProductId") + b.Property("DrinkId") .HasColumnType("integer"); - b.Property("ProductName") + b.Property("DrinkName") .IsRequired() .HasColumnType("text"); @@ -157,19 +168,19 @@ namespace DiningRoomDatabaseImplement.Migrations b.Property("Sum") .HasColumnType("double precision"); - b.Property("UserId") + b.Property("UserId") .HasColumnType("integer"); b.HasKey("Id"); - b.HasIndex("ProductId"); + b.HasIndex("DrinkId"); b.HasIndex("UserId"); b.ToTable("Orders"); }); - modelBuilder.Entity("DiningRoomDatabaseImplement.Models.Product", b => + modelBuilder.Entity("DiningRoomDatabaseImplement.Models.Drink", b => { b.Property("Id") .ValueGeneratedOnAdd() @@ -180,21 +191,21 @@ namespace DiningRoomDatabaseImplement.Migrations b.Property("Cost") .HasColumnType("double precision"); - b.Property("ProductName") + b.Property("DrinkName") .IsRequired() .HasColumnType("text"); - b.Property("UserId") + b.Property("UserId") .HasColumnType("integer"); b.HasKey("Id"); b.HasIndex("UserId"); - b.ToTable("Products"); + b.ToTable("Drinks"); }); - modelBuilder.Entity("DiningRoomDatabaseImplement.Models.ProductComponent", b => + modelBuilder.Entity("DiningRoomDatabaseImplement.Models.DrinkComponent", b => { b.Property("Id") .ValueGeneratedOnAdd() @@ -208,16 +219,16 @@ namespace DiningRoomDatabaseImplement.Migrations b.Property("Count") .HasColumnType("integer"); - b.Property("ProductId") + b.Property("DrinkId") .HasColumnType("integer"); b.HasKey("Id"); b.HasIndex("ComponentId"); - b.HasIndex("ProductId"); + b.HasIndex("DrinkId"); - b.ToTable("ProductComponents"); + b.ToTable("DrinkComponents"); }); modelBuilder.Entity("DiningRoomDatabaseImplement.Models.User", b => @@ -245,39 +256,40 @@ namespace DiningRoomDatabaseImplement.Migrations b.ToTable("Users"); }); + modelBuilder.Entity("CardDrink", b => + { + b.HasOne("DiningRoomDatabaseImplement.Models.Card", null) + .WithMany() + .HasForeignKey("CardId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("DiningRoomDatabaseImplement.Models.Drink", null) + .WithMany() + .HasForeignKey("DrinkId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + modelBuilder.Entity("DiningRoomDatabaseImplement.Models.Card", b => { b.HasOne("DiningRoomDatabaseImplement.Models.User", null) .WithMany("Cards") - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); + .HasForeignKey("UserId"); }); modelBuilder.Entity("DiningRoomDatabaseImplement.Models.Component", b => { b.HasOne("DiningRoomDatabaseImplement.Models.User", null) .WithMany("Components") - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); + .HasForeignKey("UserId"); }); modelBuilder.Entity("DiningRoomDatabaseImplement.Models.Drink", b => { - b.HasOne("DiningRoomDatabaseImplement.Models.Card", "Card") - .WithMany("Drinks") - .HasForeignKey("CardId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - b.HasOne("DiningRoomDatabaseImplement.Models.User", null) .WithMany("Drinks") - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Card"); + .HasForeignKey("UserId"); }); modelBuilder.Entity("DiningRoomDatabaseImplement.Models.DrinkComponent", b => @@ -290,7 +302,7 @@ namespace DiningRoomDatabaseImplement.Migrations b.HasOne("DiningRoomDatabaseImplement.Models.Drink", "Drink") .WithMany("Components") - .HasForeignKey("ComponentId") + .HasForeignKey("DrinkId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); @@ -301,59 +313,50 @@ namespace DiningRoomDatabaseImplement.Migrations modelBuilder.Entity("DiningRoomDatabaseImplement.Models.Order", b => { - b.HasOne("DiningRoomDatabaseImplement.Models.Product", "Product") + b.HasOne("DiningRoomDatabaseImplement.Models.Drink", "Drink") .WithMany("Order") - .HasForeignKey("ProductId") + .HasForeignKey("DrinkId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); b.HasOne("DiningRoomDatabaseImplement.Models.User", null) .WithMany("Orders") - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); + .HasForeignKey("UserId"); - b.Navigation("Product"); + b.Navigation("Drink"); }); - modelBuilder.Entity("DiningRoomDatabaseImplement.Models.Product", b => + modelBuilder.Entity("DiningRoomDatabaseImplement.Models.Drink", b => { b.HasOne("DiningRoomDatabaseImplement.Models.User", null) - .WithMany("Products") - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); + .WithMany("Drinks") + .HasForeignKey("UserId"); }); - modelBuilder.Entity("DiningRoomDatabaseImplement.Models.ProductComponent", b => + modelBuilder.Entity("DiningRoomDatabaseImplement.Models.DrinkComponent", b => { b.HasOne("DiningRoomDatabaseImplement.Models.Component", "Component") - .WithMany("ProductComponents") + .WithMany("DrinkComponents") .HasForeignKey("ComponentId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); - b.HasOne("DiningRoomDatabaseImplement.Models.Product", "Product") + b.HasOne("DiningRoomDatabaseImplement.Models.Drink", "Drink") .WithMany("Components") - .HasForeignKey("ProductId") + .HasForeignKey("DrinkId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); b.Navigation("Component"); - b.Navigation("Product"); - }); - - modelBuilder.Entity("DiningRoomDatabaseImplement.Models.Card", b => - { - b.Navigation("Drinks"); + b.Navigation("Drink"); }); modelBuilder.Entity("DiningRoomDatabaseImplement.Models.Component", b => { b.Navigation("DrinkComponents"); - b.Navigation("ProductComponents"); + b.Navigation("DrinkComponents"); }); modelBuilder.Entity("DiningRoomDatabaseImplement.Models.Drink", b => @@ -361,7 +364,7 @@ namespace DiningRoomDatabaseImplement.Migrations b.Navigation("Components"); }); - modelBuilder.Entity("DiningRoomDatabaseImplement.Models.Product", b => + modelBuilder.Entity("DiningRoomDatabaseImplement.Models.Drink", b => { b.Navigation("Components"); @@ -378,7 +381,7 @@ namespace DiningRoomDatabaseImplement.Migrations b.Navigation("Orders"); - b.Navigation("Products"); + b.Navigation("Drinks"); }); #pragma warning restore 612, 618 } diff --git a/DiningRoom/DiningRoomDatabaseImplement/Models/Card.cs b/DiningRoom/DiningRoomDatabaseImplement/Models/Card.cs index 14c5e62..7701a81 100644 --- a/DiningRoom/DiningRoomDatabaseImplement/Models/Card.cs +++ b/DiningRoom/DiningRoomDatabaseImplement/Models/Card.cs @@ -16,7 +16,6 @@ namespace DiningRoomDatabaseImplement.Models public class Card : ICardModel { public int Id { get; set; } - public int UserId { get; set; } [Required] public string CardName { get; set; } = string.Empty; [Required] @@ -29,7 +28,6 @@ namespace DiningRoomDatabaseImplement.Models { Id = model.Id, CardName = model.CardName, - UserId = model.UserId, DateCardCreate = model.DateCardCreate, }; } @@ -41,7 +39,6 @@ namespace DiningRoomDatabaseImplement.Models { Id = Id, CardName = CardName, - UserId = UserId, DateCardCreate = DateCardCreate, }; diff --git a/DiningRoom/DiningRoomDatabaseImplement/Models/Component.cs b/DiningRoom/DiningRoomDatabaseImplement/Models/Component.cs index 1cd2915..1ba3ebf 100644 --- a/DiningRoom/DiningRoomDatabaseImplement/Models/Component.cs +++ b/DiningRoom/DiningRoomDatabaseImplement/Models/Component.cs @@ -1,5 +1,6 @@ using DiningRoomContracts.BindingModels; using DiningRoomContracts.ViewModels; +using DiningRoomDataModels.Enums; using DiningRoomDataModels.Models; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; @@ -10,13 +11,10 @@ namespace DiningRoomDatabaseImplement.Models { public int Id { get; private set; } - [Required] - public int UserId { get; private set; } - [Required] public string ComponentName { get; private set; } = string.Empty; [Required] - public string Unit { get; private set; } = string.Empty; + public ComponentUnit Unit { get; private set; } = ComponentUnit.Неизвестна; [Required] public double Cost { get; private set; } @@ -35,7 +33,6 @@ namespace DiningRoomDatabaseImplement.Models return new Component() { Id = Model.Id, - UserId = Model.UserId, ComponentName = Model.ComponentName, Cost = Model.Cost, Unit = Model.Unit, @@ -46,7 +43,6 @@ namespace DiningRoomDatabaseImplement.Models return new Component { Id = Model.Id, - UserId = Model.UserId, ComponentName = Model.ComponentName, Cost = Model.Cost, Unit = Model.Unit, @@ -66,7 +62,6 @@ namespace DiningRoomDatabaseImplement.Models public ComponentViewModel GetViewModel => new() { Id = Id, - UserId = UserId, ComponentName = ComponentName, Cost = Cost, Unit = Unit, diff --git a/DiningRoom/DiningRoomDatabaseImplement/Models/Drink.cs b/DiningRoom/DiningRoomDatabaseImplement/Models/Drink.cs index 8c98d74..7dd7227 100644 --- a/DiningRoom/DiningRoomDatabaseImplement/Models/Drink.cs +++ b/DiningRoom/DiningRoomDatabaseImplement/Models/Drink.cs @@ -12,20 +12,15 @@ namespace DiningRoomDatabaseImplement.Models { public int Id { get; private set; } - [Required] - public int UserId { get; private set; } - [Required] public string DrinkName { get; private set; } = string.Empty; [Required] public double Cost { get; private set; } + [ForeignKey("DrinkId")] + public virtual List Card { get; set; } = new(); - public int CardId { get; private set; } - public virtual Card? Card { get; set; } = new(); - - - [ForeignKey("ComponentId")] + [ForeignKey("DrinkId")] public virtual List Components { get; set; } = new(); private Dictionary? _drinkComponents; @@ -52,10 +47,8 @@ namespace DiningRoomDatabaseImplement.Models return new() { Id = Model.Id, - UserId = Model.UserId, DrinkName = Model.DrinkName, Cost = Model.Cost, - CardId = Model.CardId, Components = Model.DrinkComponents.Select(x => new DrinkComponent { Component = Context.Components.First(y => y.Id == x.Key), @@ -78,7 +71,6 @@ namespace DiningRoomDatabaseImplement.Models { Id = Id, DrinkName = DrinkName, - CardName = context.Cards.FirstOrDefault(x => x.Id == CardId)?.CardName ?? string.Empty, Cost = Cost, DrinkComponents = DrinkComponents }; @@ -112,10 +104,5 @@ namespace DiningRoomDatabaseImplement.Models } _drinkComponents = null; } - public void ConnectDrink(DiningRoomDatabase context, DrinkBindingModel model) - { - CardId = model.CardId; - Card = context.Cards.First(x => x.Id == model.CardId); - } } } diff --git a/DiningRoom/DiningRoomDatabaseImplement/Models/Order.cs b/DiningRoom/DiningRoomDatabaseImplement/Models/Order.cs index 638a9ef..f4a439b 100644 --- a/DiningRoom/DiningRoomDatabaseImplement/Models/Order.cs +++ b/DiningRoom/DiningRoomDatabaseImplement/Models/Order.cs @@ -28,8 +28,7 @@ namespace DiningRoomDatabaseImplement.Models [Required] public DateTime DateCreate { get; set; } public virtual Product Product { get; set; } - [Required] - public int UserId { get; private set; } + public static Order? Create(OrderBindingModel model) { @@ -42,7 +41,6 @@ namespace DiningRoomDatabaseImplement.Models Id = model.Id, ProductId = model.ProductId, ProductName = model.ProductName, - UserId = model.UserId, DateCreate = model.DateCreate, Status = model.Status, Count = model.Count, @@ -71,7 +69,6 @@ namespace DiningRoomDatabaseImplement.Models Id = Id, ProductId = ProductId, ProductName = context.Products.FirstOrDefault(x => x.Id == ProductId)?.ProductName ?? string.Empty, - UserId = UserId, DateCreate = DateCreate, Status = Status, Count = Count, diff --git a/DiningRoom/DiningRoomDatabaseImplement/Models/Product.cs b/DiningRoom/DiningRoomDatabaseImplement/Models/Product.cs index a69a8b9..758dc20 100644 --- a/DiningRoom/DiningRoomDatabaseImplement/Models/Product.cs +++ b/DiningRoom/DiningRoomDatabaseImplement/Models/Product.cs @@ -11,9 +11,6 @@ namespace DiningRoomDatabaseImplement.Models { public int Id { get; set; } - [Required] - public int UserId { get; set; } - [Required] public string ProductName { get; set; } = string.Empty; @@ -46,7 +43,6 @@ namespace DiningRoomDatabaseImplement.Models return new() { Id = Model.Id, - UserId = Model.UserId, ProductName = Model.ProductName, Cost = Model.Cost, Components = Model.ProductComponents.Select(x => new ProductComponent @@ -64,7 +60,6 @@ namespace DiningRoomDatabaseImplement.Models public ProductViewModel GetViewModel => new() { Id = Id, - UserId = UserId, ProductName = ProductName, Cost = Cost, ProductComponents = ProductComponents diff --git a/DiningRoom/DiningRoomRestApi/Controllers/CardController.cs b/DiningRoom/DiningRoomRestApi/Controllers/CardController.cs index 0532dbb..c8ea5c5 100644 --- a/DiningRoom/DiningRoomRestApi/Controllers/CardController.cs +++ b/DiningRoom/DiningRoomRestApi/Controllers/CardController.cs @@ -39,20 +39,19 @@ namespace DiningRoomRestApi.Controllers } /// - /// Получение карт по id пользователя (полный список, кот. будет выводиться) + /// Получение карт по id(полный список, кот. будет выводиться) /// - /// - /// + [HttpGet] - public List? GetCards(int userId) + public List? GetCards(int Id) { try { - return _logic.ReadList(new CardSearchModel { UserId = userId }); + return _logic.ReadList(new CardSearchModel { Id = Id }); } catch (Exception ex) { - _logger.LogError(ex, "Ошибка получения списка заказов клиента id={Id}", userId); + _logger.LogError(ex, "Ошибка получения списка заказов клиента id={Id}", Id); throw; } } diff --git a/DiningRoom/DiningRoomRestApi/Controllers/ComponentController.cs b/DiningRoom/DiningRoomRestApi/Controllers/ComponentController.cs index 72da5df..e999d33 100644 --- a/DiningRoom/DiningRoomRestApi/Controllers/ComponentController.cs +++ b/DiningRoom/DiningRoomRestApi/Controllers/ComponentController.cs @@ -36,22 +36,6 @@ namespace DiningRoomRestApi.Controllers } } - [HttpGet] - public List? GetComponents(int? UserId) - { - try - { - return _componentLogic.ReadList(new ComponentSearchModel - { - UserId = UserId - }); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка получения списка продуктов пользователя с Id = {Id}", UserId); - throw; - } - } [HttpPost] public void CreateComponent(ComponentBindingModel Model) diff --git a/DiningRoom/DiningRoomRestApi/Controllers/DrinkController.cs b/DiningRoom/DiningRoomRestApi/Controllers/DrinkController.cs index ae8fc75..c5d2f03 100644 --- a/DiningRoom/DiningRoomRestApi/Controllers/DrinkController.cs +++ b/DiningRoom/DiningRoomRestApi/Controllers/DrinkController.cs @@ -36,35 +36,6 @@ namespace DiningRoomRestApi.Controllers } } - [HttpGet] - public List? GetDrinks(int? UserId) - { - try - { - return _DrinkLogic.ReadList(new DrinkSearchModel - { - UserId = UserId - }); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка получения списка напитков пользователя с Id = {Id}", UserId); - throw; - } - } - [HttpPost] - public void ConnectCardDrink(int CardId, int DrinkId) - { - try - { - _DrinkLogic.ConnectCardDrink(new DrinkBindingModel { Id = DrinkId, CardId = CardId }); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка связывания заявки со сборкой"); - throw; - } - } [HttpPost] public void CreateDrink(DrinkBindingModel Model) diff --git a/DiningRoom/DiningRoomRestApi/Controllers/OrderController.cs b/DiningRoom/DiningRoomRestApi/Controllers/OrderController.cs index e94e95f..4a92d1b 100644 --- a/DiningRoom/DiningRoomRestApi/Controllers/OrderController.cs +++ b/DiningRoom/DiningRoomRestApi/Controllers/OrderController.cs @@ -38,24 +38,7 @@ namespace DiningRoomRestApi.Controllers } } - /// - /// Получение заказов по id пользователя (полный список, кот. будет выводиться) - /// - /// - /// - [HttpGet] - public List? GetOrders(int? userId) - { - try - { - return _logic.ReadList(new OrderSearchModel { UserId = userId }); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка получения списка заказов клиента id={Id}", userId); - throw; - } - } + [HttpPost] public void CreateOrder(OrderBindingModel model) diff --git a/DiningRoom/DiningRoomRestApi/Controllers/ProductController.cs b/DiningRoom/DiningRoomRestApi/Controllers/ProductController.cs index 2301599..00ef20e 100644 --- a/DiningRoom/DiningRoomRestApi/Controllers/ProductController.cs +++ b/DiningRoom/DiningRoomRestApi/Controllers/ProductController.cs @@ -36,22 +36,6 @@ namespace DiningRoomRestApi.Controllers } } - [HttpGet] - public List? GetProducts(int? UserId) - { - try - { - return _productLogic.ReadList(new ProductSearchModel - { - UserId = UserId - }); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка получения списка блюд пользователя с Id = {Id}", UserId); - throw; - } - } [HttpPost] public void CreateProduct(ProductBindingModel Model) diff --git a/DiningRoom/DiningRoomRestApi/Program.cs b/DiningRoom/DiningRoomRestApi/Program.cs index 26e4899..5e1c0d3 100644 --- a/DiningRoom/DiningRoomRestApi/Program.cs +++ b/DiningRoom/DiningRoomRestApi/Program.cs @@ -1,4 +1,4 @@ -using DiningRoomBusinessLogic.BusinessLogics; +using DiningRoomBusinessLogic.BusinessLogic; using DiningRoomContracts.BusinessLogicContracts; using DiningRoomContracts.StorageContracts; using DiningRoomDatabaseImplement.Implements; diff --git a/DiningRoom/DiningRoomView/DiningRoomView.csproj b/DiningRoom/DiningRoomView/DiningRoomView.csproj index bfc35ab..7ea523a 100644 --- a/DiningRoom/DiningRoomView/DiningRoomView.csproj +++ b/DiningRoom/DiningRoomView/DiningRoomView.csproj @@ -13,11 +13,15 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive + + + + \ No newline at end of file diff --git a/DiningRoom/DiningRoomView/Form1.Designer.cs b/DiningRoom/DiningRoomView/Form1.Designer.cs deleted file mode 100644 index eeb19c5..0000000 --- a/DiningRoom/DiningRoomView/Form1.Designer.cs +++ /dev/null @@ -1,39 +0,0 @@ -namespace DiningRoomView -{ - 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/DiningRoom/DiningRoomView/Form1.cs b/DiningRoom/DiningRoomView/Form1.cs deleted file mode 100644 index 2790f89..0000000 --- a/DiningRoom/DiningRoomView/Form1.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace DiningRoomView -{ - public partial class Form1 : Form - { - public Form1() - { - InitializeComponent(); - } - } -} diff --git a/DiningRoom/DiningRoomView/FormComponent.Designer.cs b/DiningRoom/DiningRoomView/FormComponent.Designer.cs new file mode 100644 index 0000000..2784a3e --- /dev/null +++ b/DiningRoom/DiningRoomView/FormComponent.Designer.cs @@ -0,0 +1,142 @@ +namespace DiningRoomView +{ + partial class FormComponent + { + /// + /// 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() + { + ButtonSave = new Button(); + ButtonCancel = new Button(); + label1 = new Label(); + textBoxName = new TextBox(); + textBoxCost = new TextBox(); + label2 = new Label(); + comboBoxUnit = new ComboBox(); + label3 = new Label(); + SuspendLayout(); + // + // ButtonSave + // + ButtonSave.Location = new Point(192, 111); + ButtonSave.Name = "ButtonSave"; + ButtonSave.Size = new Size(86, 23); + ButtonSave.TabIndex = 0; + ButtonSave.Text = "Сохранение"; + ButtonSave.UseVisualStyleBackColor = true; + ButtonSave.Click += ButtonSave_Click; + // + // ButtonCancel + // + ButtonCancel.Location = new Point(284, 111); + ButtonCancel.Name = "ButtonCancel"; + ButtonCancel.Size = new Size(75, 23); + ButtonCancel.TabIndex = 1; + ButtonCancel.Text = "Отмена"; + ButtonCancel.UseVisualStyleBackColor = true; + ButtonCancel.Click += ButtonCancel_Click; + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(12, 15); + label1.Name = "label1"; + label1.Size = new Size(62, 15); + label1.TabIndex = 2; + label1.Text = "Название:"; + // + // textBoxName + // + textBoxName.Location = new Point(138, 12); + textBoxName.Name = "textBoxName"; + textBoxName.Size = new Size(222, 23); + textBoxName.TabIndex = 3; + // + // textBoxCost + // + textBoxCost.Location = new Point(138, 38); + textBoxCost.Name = "textBoxCost"; + textBoxCost.Size = new Size(222, 23); + textBoxCost.TabIndex = 4; + // + // label2 + // + label2.AutoSize = true; + label2.Location = new Point(12, 41); + label2.Name = "label2"; + label2.Size = new Size(38, 15); + label2.TabIndex = 5; + label2.Text = "Цена:"; + // + // comboBoxUnit + // + comboBoxUnit.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxUnit.FormattingEnabled = true; + comboBoxUnit.Location = new Point(137, 64); + comboBoxUnit.Name = "comboBoxUnit"; + comboBoxUnit.Size = new Size(222, 23); + comboBoxUnit.TabIndex = 11; + // + // label3 + // + label3.AutoSize = true; + label3.Location = new Point(12, 67); + label3.Name = "label3"; + label3.Size = new Size(119, 15); + label3.TabIndex = 12; + label3.Text = "Единица измерения:"; + // + // FormComponent + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(377, 151); + Controls.Add(label3); + Controls.Add(comboBoxUnit); + Controls.Add(label2); + Controls.Add(textBoxCost); + Controls.Add(textBoxName); + Controls.Add(label1); + Controls.Add(ButtonCancel); + Controls.Add(ButtonSave); + Name = "FormComponent"; + Text = "Компонент"; + Load += FormComponent_Load; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private System.Windows.Forms.Button ButtonSave; + private System.Windows.Forms.Button ButtonCancel; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.TextBox textBoxName; + private TextBox textBoxCost; + private Label label2; + private ComboBox comboBoxUnit; + private Label label3; + } +} \ No newline at end of file diff --git a/DiningRoom/DiningRoomView/FormComponent.cs b/DiningRoom/DiningRoomView/FormComponent.cs new file mode 100644 index 0000000..f69a7bf --- /dev/null +++ b/DiningRoom/DiningRoomView/FormComponent.cs @@ -0,0 +1,88 @@ +using DiningRoomContracts.BindingModels; +using DiningRoomContracts.BusinessLogicContracts; +using DiningRoomContracts.SearchModels; +using DiningRoomDataModels.Enums; +using Microsoft.Extensions.Logging; + +namespace DiningRoomView +{ + public partial class FormComponent : Form + { + private readonly ILogger _logger; + private readonly IComponentLogic _logic; + private int? _id; + public int Id { set { _id = value; } } + public FormComponent(ILogger logger, IComponentLogic logic) + { + InitializeComponent(); _logger = logger; + _logic = logic; + } + private void FormComponent_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + try + { + _logger.LogInformation(" "); + var view = _logic.ReadElement(new ComponentSearchModel { Id = _id.Value }); + if (view != null) + { + textBoxName.Text = view.ComponentName; + textBoxCost.Text = view.Cost.ToString(); + comboBoxUnit.DisplayMember = "Unit"; + comboBoxUnit.ValueMember = "Id"; + comboBoxUnit.DataSource = Enum.GetValues(typeof(ComponentUnit)); ; + comboBoxUnit.SelectedItem = null; + } + } + catch (Exception ex) + { + _logger.LogError(ex, " "); + MessageBox.Show(ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + else + { + comboBoxUnit.DataSource = Enum.GetValues(typeof(ComponentUnit)); ; + comboBoxUnit.SelectedItem = 1; + } + } + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxName.Text)) + { + MessageBox.Show(" ", "", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation(" "); + try + { + var model = new ComponentBindingModel + { + Id = _id ?? 0, + ComponentName = textBoxName.Text, + Unit = (ComponentUnit)comboBoxUnit.SelectedItem, + Cost = Convert.ToDouble(textBoxCost.Text) + }; + var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model); + if (!operationResult) + { + throw new Exception(" . ."); + } + MessageBox.Show(" ", "", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, " "); + MessageBox.Show(ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/DiningRoom/DiningRoomView/Form1.resx b/DiningRoom/DiningRoomView/FormComponent.resx similarity index 93% rename from DiningRoom/DiningRoomView/Form1.resx rename to DiningRoom/DiningRoomView/FormComponent.resx index 1af7de1..af32865 100644 --- a/DiningRoom/DiningRoomView/Form1.resx +++ b/DiningRoom/DiningRoomView/FormComponent.resx @@ -1,17 +1,17 @@  - diff --git a/DiningRoom/DiningRoomView/FormComponents.Designer.cs b/DiningRoom/DiningRoomView/FormComponents.Designer.cs new file mode 100644 index 0000000..859ef79 --- /dev/null +++ b/DiningRoom/DiningRoomView/FormComponents.Designer.cs @@ -0,0 +1,114 @@ +namespace DiningRoomView +{ + partial class FormComponents + { + /// + /// 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() + { + dataGridView = new DataGridView(); + ButtonAdd = new Button(); + ButtonUpd = new Button(); + ButtonDel = new Button(); + ButtonRef = new Button(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // dataGridView + // + dataGridView.BackgroundColor = SystemColors.ControlLightLight; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Location = new Point(0, 0); + dataGridView.Name = "dataGridView"; + dataGridView.RowTemplate.Height = 25; + dataGridView.Size = new Size(414, 426); + dataGridView.TabIndex = 0; + // + // ButtonAdd + // + ButtonAdd.Location = new Point(429, 12); + ButtonAdd.Name = "ButtonAdd"; + ButtonAdd.Size = new Size(101, 23); + ButtonAdd.TabIndex = 1; + ButtonAdd.Text = "Добавить"; + ButtonAdd.UseVisualStyleBackColor = true; + ButtonAdd.Click += ButtonAdd_Click; + // + // ButtonUpd + // + ButtonUpd.Location = new Point(429, 51); + ButtonUpd.Name = "ButtonUpd"; + ButtonUpd.Size = new Size(101, 23); + ButtonUpd.TabIndex = 2; + ButtonUpd.Text = "Изменить"; + ButtonUpd.UseVisualStyleBackColor = true; + ButtonUpd.Click += ButtonUpd_Click; + // + // ButtonDel + // + ButtonDel.Location = new Point(429, 91); + ButtonDel.Name = "ButtonDel"; + ButtonDel.Size = new Size(101, 23); + ButtonDel.TabIndex = 3; + ButtonDel.Text = "Удалить"; + ButtonDel.UseVisualStyleBackColor = true; + ButtonDel.Click += ButtonDel_Click; + // + // ButtonRef + // + ButtonRef.Location = new Point(429, 133); + ButtonRef.Name = "ButtonRef"; + ButtonRef.Size = new Size(101, 23); + ButtonRef.TabIndex = 4; + ButtonRef.Text = "Обновить"; + ButtonRef.UseVisualStyleBackColor = true; + ButtonRef.Click += ButtonRef_Click; + // + // FormComponents + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(542, 428); + Controls.Add(ButtonRef); + Controls.Add(ButtonDel); + Controls.Add(ButtonUpd); + Controls.Add(ButtonAdd); + Controls.Add(dataGridView); + Name = "FormComponents"; + Text = "Компоненты"; + Load += FormComponents_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private System.Windows.Forms.DataGridView dataGridView; + private System.Windows.Forms.Button ButtonAdd; + private System.Windows.Forms.Button ButtonUpd; + private System.Windows.Forms.Button ButtonDel; + private System.Windows.Forms.Button ButtonRef; + } +} \ No newline at end of file diff --git a/DiningRoom/DiningRoomView/FormComponents.cs b/DiningRoom/DiningRoomView/FormComponents.cs new file mode 100644 index 0000000..fd09c1c --- /dev/null +++ b/DiningRoom/DiningRoomView/FormComponents.cs @@ -0,0 +1,107 @@ +using DiningRoomContracts.BindingModels; +using DiningRoomContracts.BusinessLogicContracts; +using DiningRoomContracts.SearchModels; +using DiningRoomDataModels.Models; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace DiningRoomView +{ + public partial class FormComponents : Form + { + private readonly ILogger _logger; + private readonly IComponentLogic _logic; + public FormComponents(ILogger logger, IComponentLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + private void FormComponents_Load(object sender, EventArgs e) + { + LoadData(); + } + private void LoadData() + { + try + { + var list = _logic.ReadList(null); + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["Id"].Visible = false; + dataGridView.Columns["ComponentName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + + } + _logger.LogInformation("Загрузка компонентов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки компонентов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void ButtonAdd_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormComponent)); + if (service is FormComponent form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + private void ButtonUpd_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormComponent)); + if (service is FormComponent form) + { + form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + private void ButtonDel_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Удаление компонента"); + try + { + if (!_logic.Delete(new ComponentBindingModel { Id = id })) + { + throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления компонента"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + private void ButtonRef_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/DiningRoom/DiningRoomView/FormComponents.resx b/DiningRoom/DiningRoomView/FormComponents.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/DiningRoom/DiningRoomView/FormComponents.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/DiningRoom/DiningRoomView/FormMain.Designer.cs b/DiningRoom/DiningRoomView/FormMain.Designer.cs new file mode 100644 index 0000000..7cfdf31 --- /dev/null +++ b/DiningRoom/DiningRoomView/FormMain.Designer.cs @@ -0,0 +1,228 @@ +namespace DiningRoomView +{ + partial class FormMain + { + /// + /// 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() + { + dataGridView1 = new DataGridView(); + dataGridView2 = new DataGridView(); + menuStrip1 = new MenuStrip(); + продуктыToolStripMenuItem = new ToolStripMenuItem(); + клиентыToolStripMenuItem = new ToolStripMenuItem(); + поставщикиToolStripMenuItem = new ToolStripMenuItem(); + button1 = new Button(); + label1 = new Label(); + label2 = new Label(); + button3 = new Button(); + button4 = new Button(); + button2 = new Button(); + button5 = new Button(); + button6 = new Button(); + button7 = new Button(); + ((System.ComponentModel.ISupportInitialize)dataGridView1).BeginInit(); + ((System.ComponentModel.ISupportInitialize)dataGridView2).BeginInit(); + menuStrip1.SuspendLayout(); + SuspendLayout(); + // + // dataGridView1 + // + dataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView1.Location = new Point(12, 53); + dataGridView1.Name = "dataGridView1"; + dataGridView1.RowTemplate.Height = 25; + dataGridView1.Size = new Size(455, 257); + dataGridView1.TabIndex = 0; + // + // dataGridView2 + // + dataGridView2.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView2.Location = new Point(12, 341); + dataGridView2.Name = "dataGridView2"; + dataGridView2.RowTemplate.Height = 25; + dataGridView2.Size = new Size(455, 240); + dataGridView2.TabIndex = 1; + // + // menuStrip1 + // + menuStrip1.Items.AddRange(new ToolStripItem[] { продуктыToolStripMenuItem, клиентыToolStripMenuItem, поставщикиToolStripMenuItem }); + menuStrip1.Location = new Point(0, 0); + menuStrip1.Name = "menuStrip1"; + menuStrip1.Size = new Size(666, 24); + menuStrip1.TabIndex = 2; + menuStrip1.Text = "menuStrip1"; + // + // продуктыToolStripMenuItem + // + продуктыToolStripMenuItem.Name = "продуктыToolStripMenuItem"; + продуктыToolStripMenuItem.Size = new Size(74, 20); + продуктыToolStripMenuItem.Text = "Продукты"; + продуктыToolStripMenuItem.Click += ПродуктыToolStripMenuItem_Click; + // + // клиентыToolStripMenuItem + // + клиентыToolStripMenuItem.Name = "клиентыToolStripMenuItem"; + клиентыToolStripMenuItem.Size = new Size(12, 20); + // + // поставщикиToolStripMenuItem + // + поставщикиToolStripMenuItem.Name = "поставщикиToolStripMenuItem"; + поставщикиToolStripMenuItem.Size = new Size(12, 20); + // + // button1 + // + button1.Location = new Point(491, 139); + button1.Name = "button1"; + button1.Size = new Size(153, 23); + button1.TabIndex = 3; + button1.Text = "Создать блюдо"; + button1.UseVisualStyleBackColor = true; + button1.Click += ButtonAddProduct_Click; + // + // label1 + // + label1.AutoSize = true; + label1.Font = new Font("Segoe UI", 14.25F, FontStyle.Regular, GraphicsUnit.Point); + label1.Location = new Point(179, 24); + label1.Name = "label1"; + label1.Size = new Size(68, 25); + label1.TabIndex = 5; + label1.Text = "Блюда"; + // + // label2 + // + label2.AutoSize = true; + label2.Font = new Font("Segoe UI", 14.25F, FontStyle.Regular, GraphicsUnit.Point); + label2.Location = new Point(179, 313); + label2.Name = "label2"; + label2.Size = new Size(85, 25); + label2.TabIndex = 6; + label2.Text = "Напитки"; + // + // button3 + // + button3.Location = new Point(491, 168); + button3.Name = "button3"; + button3.Size = new Size(153, 23); + button3.TabIndex = 7; + button3.Text = "Редактировать блюдо"; + button3.UseVisualStyleBackColor = true; + button3.Click += ButtonUpdProduct_Click; + // + // button4 + // + button4.Location = new Point(491, 442); + button4.Name = "button4"; + button4.Size = new Size(153, 23); + button4.TabIndex = 8; + button4.Text = "Редактировать напиток"; + button4.UseVisualStyleBackColor = true; + // + // button2 + // + button2.Location = new Point(491, 197); + button2.Name = "button2"; + button2.Size = new Size(153, 23); + button2.TabIndex = 9; + button2.Text = "Удалить блюдо"; + button2.UseVisualStyleBackColor = true; + button2.Click += ButtonDelProduct_Click; + // + // button5 + // + button5.Location = new Point(491, 315); + button5.Name = "button5"; + button5.Size = new Size(153, 23); + button5.TabIndex = 10; + button5.Text = "Обновить списки"; + button5.UseVisualStyleBackColor = true; + // + // button6 + // + button6.Location = new Point(491, 413); + button6.Name = "button6"; + button6.Size = new Size(153, 23); + button6.TabIndex = 11; + button6.Text = "Создать напиток"; + button6.UseVisualStyleBackColor = true; + // + // button7 + // + button7.Location = new Point(491, 471); + button7.Name = "button7"; + button7.Size = new Size(153, 23); + button7.TabIndex = 12; + button7.Text = "Удалить напиток"; + button7.UseVisualStyleBackColor = true; + // + // FormMain + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(666, 593); + Controls.Add(button7); + Controls.Add(button6); + Controls.Add(button5); + Controls.Add(button2); + Controls.Add(button4); + Controls.Add(button3); + Controls.Add(label2); + Controls.Add(label1); + Controls.Add(button1); + Controls.Add(dataGridView2); + Controls.Add(dataGridView1); + Controls.Add(menuStrip1); + MainMenuStrip = menuStrip1; + Name = "FormMain"; + Text = "FormMain"; + Load += FormMain_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView1).EndInit(); + ((System.ComponentModel.ISupportInitialize)dataGridView2).EndInit(); + menuStrip1.ResumeLayout(false); + menuStrip1.PerformLayout(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private DataGridView dataGridView1; + private DataGridView dataGridView2; + private MenuStrip menuStrip1; + private ToolStripMenuItem продуктыToolStripMenuItem; + private ToolStripMenuItem клиентыToolStripMenuItem; + private ToolStripMenuItem поставщикиToolStripMenuItem; + private Button button1; + private Label label1; + private Label label2; + private Button button3; + private Button button4; + private Button button2; + private Button button5; + private Button button6; + private Button button7; + } +} \ No newline at end of file diff --git a/DiningRoom/DiningRoomView/FormMain.cs b/DiningRoom/DiningRoomView/FormMain.cs new file mode 100644 index 0000000..fdbe260 --- /dev/null +++ b/DiningRoom/DiningRoomView/FormMain.cs @@ -0,0 +1,198 @@ +using Microsoft.Extensions.Logging; +using DiningRoomContracts.BusinessLogicContracts; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using DiningRoomContracts.BindingModels; + +namespace DiningRoomView +{ + public partial class FormMain : Form + { + private readonly ILogger _logger; + private readonly IProductLogic _productLogic; + private readonly IDrinkLogic _drinkLogic; + public FormMain(ILogger logger, IProductLogic productLogic, IDrinkLogic drinkLogic) + { + InitializeComponent(); + _logger = logger; + _productLogic = productLogic; + _drinkLogic = drinkLogic; + } + private void FormMain_Load(object sender, EventArgs e) + { + LoadData(); + } + private void LoadData() + { + _logger.LogInformation("Загрузка блюд"); + try + { + var list = _productLogic.ReadList(null); + if (list != null) + { + dataGridView1.DataSource = list; + dataGridView1.Columns["Id"].Visible = false; + dataGridView1.Columns["ProductComponents"].Visible = false; + dataGridView1.Columns["ProductName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + + } + _logger.LogInformation("Загрузка блюд успешна"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки блюд"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + + _logger.LogInformation("Загрузка напитков"); + try + { + var list = _drinkLogic.ReadList(null); + if (list != null) + { + dataGridView2.DataSource = list; + + } + _logger.LogInformation("Загрузка напитков успешна"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки напитков"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void ПродуктыToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormComponents)); + if (service is FormComponents form) + { + form.ShowDialog(); + } + } + private void ButtonAddProduct_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormProduct)); + if (service is FormProduct form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + private void ButtonUpdProduct_Click(object sender, EventArgs e) + { + if (dataGridView1.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormProduct)); + if (service is FormProduct form) + { + form.Id = Convert.ToInt32(dataGridView1.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + private void ButtonDelProduct_Click(object sender, EventArgs e) + { + if (dataGridView1.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + int id = Convert.ToInt32(dataGridView1.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Удаление продукта"); + try + { + if (!_productLogic.Delete(new ProductBindingModel { Id = id })) + { + throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления продукта"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + private void ButtonAddDrink_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormProduct)); + if (service is FormProduct form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + private void ButtonUpdDrink_Click(object sender, EventArgs e) + { + if (dataGridView1.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormProduct)); + if (service is FormProduct form) + { + form.Id = Convert.ToInt32(dataGridView1.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + private void ButtonDelDrink_Click(object sender, EventArgs e) + { + if (dataGridView1.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + int id = Convert.ToInt32(dataGridView1.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Удаление продукта"); + try + { + if (!_productLogic.Delete(new ProductBindingModel { Id = id })) + { + throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления продукта"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + //private void ButtonCreateSale_Click(object sender, EventArgs e) + //{ + // var service = Program.ServiceProvider?.GetService(typeof(FormCreateSale)); + // if (service is FormCreateSale form) + // { + // form.ShowDialog(); + // LoadData(); + // } + //} + //private void ButtonCreateSupply_Click(object sender, EventArgs e) + //{ + // var service = Program.ServiceProvider?.GetService(typeof(FormCreateSupply)); + // if (service is FormCreateSupply form) + // { + // form.ShowDialog(); + // LoadData(); + // } + //} + } +} diff --git a/DiningRoom/DiningRoomView/FormMain.resx b/DiningRoom/DiningRoomView/FormMain.resx new file mode 100644 index 0000000..9e93228 --- /dev/null +++ b/DiningRoom/DiningRoomView/FormMain.resx @@ -0,0 +1,126 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + + 17, 17 + + + 75 + + \ No newline at end of file diff --git a/DiningRoom/DiningRoomView/FormProduct.Designer.cs b/DiningRoom/DiningRoomView/FormProduct.Designer.cs new file mode 100644 index 0000000..fe8cac2 --- /dev/null +++ b/DiningRoom/DiningRoomView/FormProduct.Designer.cs @@ -0,0 +1,224 @@ +namespace DiningRoomView +{ + partial class FormProduct + { + /// + /// 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() + { + labelName = new Label(); + labelPrice = new Label(); + textBoxName = new TextBox(); + textBoxPrice = new TextBox(); + groupBox1 = new GroupBox(); + dataGridView = new DataGridView(); + ID = new DataGridViewTextBoxColumn(); + ComponentName = new DataGridViewTextBoxColumn(); + Count = new DataGridViewTextBoxColumn(); + ButtonRef = new Button(); + ButtonDel = new Button(); + ButtonUpd = new Button(); + ButtonAdd = new Button(); + ButtonSave = new Button(); + ButtonCancel = new Button(); + groupBox1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // labelName + // + labelName.AutoSize = true; + labelName.Location = new Point(12, 9); + labelName.Name = "labelName"; + labelName.Size = new Size(62, 15); + labelName.TabIndex = 0; + labelName.Text = "Название:"; + // + // labelPrice + // + labelPrice.AutoSize = true; + labelPrice.Location = new Point(12, 41); + labelPrice.Name = "labelPrice"; + labelPrice.Size = new Size(38, 15); + labelPrice.TabIndex = 1; + labelPrice.Text = "Цена:"; + // + // textBoxName + // + textBoxName.Location = new Point(94, 6); + textBoxName.Name = "textBoxName"; + textBoxName.Size = new Size(247, 23); + textBoxName.TabIndex = 2; + // + // textBoxPrice + // + textBoxPrice.Location = new Point(94, 38); + textBoxPrice.Name = "textBoxPrice"; + textBoxPrice.Size = new Size(100, 23); + textBoxPrice.TabIndex = 3; + // + // groupBox1 + // + groupBox1.Controls.Add(dataGridView); + groupBox1.Controls.Add(ButtonRef); + groupBox1.Controls.Add(ButtonDel); + groupBox1.Controls.Add(ButtonUpd); + groupBox1.Controls.Add(ButtonAdd); + groupBox1.Location = new Point(12, 67); + groupBox1.Name = "groupBox1"; + groupBox1.Size = new Size(510, 338); + groupBox1.TabIndex = 4; + groupBox1.TabStop = false; + groupBox1.Text = "Компонент"; + // + // dataGridView + // + dataGridView.BackgroundColor = SystemColors.ButtonHighlight; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Columns.AddRange(new DataGridViewColumn[] { ID, ComponentName, Count }); + dataGridView.Location = new Point(0, 21); + dataGridView.Name = "dataGridView"; + dataGridView.RowTemplate.Height = 25; + dataGridView.Size = new Size(394, 311); + dataGridView.TabIndex = 5; + // + // ID + // + ID.HeaderText = "Id"; + ID.Name = "ID"; + ID.Visible = false; + ID.Width = 250; + // + // ComponentName + // + ComponentName.HeaderText = "Компоненте"; + ComponentName.Name = "ComponentName"; + ComponentName.Width = 250; + // + // Count + // + Count.HeaderText = "Количество"; + Count.Name = "Count"; + // + // ButtonRef + // + ButtonRef.Location = new Point(400, 169); + ButtonRef.Name = "ButtonRef"; + ButtonRef.Size = new Size(106, 28); + ButtonRef.TabIndex = 4; + ButtonRef.Text = "Обновить"; + ButtonRef.UseVisualStyleBackColor = true; + ButtonRef.Click += ButtonRef_Click; + // + // ButtonDel + // + ButtonDel.Location = new Point(400, 135); + ButtonDel.Name = "ButtonDel"; + ButtonDel.Size = new Size(106, 28); + ButtonDel.TabIndex = 3; + ButtonDel.Text = "Удалить"; + ButtonDel.UseVisualStyleBackColor = true; + ButtonDel.Click += ButtonDel_Click; + // + // ButtonUpd + // + ButtonUpd.Location = new Point(400, 101); + ButtonUpd.Name = "ButtonUpd"; + ButtonUpd.Size = new Size(106, 28); + ButtonUpd.TabIndex = 2; + ButtonUpd.Text = "Изменить"; + ButtonUpd.UseVisualStyleBackColor = true; + ButtonUpd.Click += ButtonUpd_Click; + // + // ButtonAdd + // + ButtonAdd.Location = new Point(400, 67); + ButtonAdd.Name = "ButtonAdd"; + ButtonAdd.Size = new Size(106, 28); + ButtonAdd.TabIndex = 1; + ButtonAdd.Text = "Добавить"; + ButtonAdd.UseVisualStyleBackColor = true; + ButtonAdd.Click += ButtonAdd_Click; + // + // ButtonSave + // + ButtonSave.Location = new Point(354, 415); + ButtonSave.Name = "ButtonSave"; + ButtonSave.Size = new Size(75, 23); + ButtonSave.TabIndex = 5; + ButtonSave.Text = "Сохранить"; + ButtonSave.UseVisualStyleBackColor = true; + ButtonSave.Click += ButtonSave_Click; + // + // ButtonCancel + // + ButtonCancel.Location = new Point(435, 415); + ButtonCancel.Name = "ButtonCancel"; + ButtonCancel.Size = new Size(75, 23); + ButtonCancel.TabIndex = 6; + ButtonCancel.Text = "Отмена"; + ButtonCancel.UseVisualStyleBackColor = true; + ButtonCancel.Click += ButtonCancel_Click; + // + // FormProduct + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(536, 450); + Controls.Add(ButtonCancel); + Controls.Add(ButtonSave); + Controls.Add(groupBox1); + Controls.Add(textBoxPrice); + Controls.Add(textBoxName); + Controls.Add(labelPrice); + Controls.Add(labelName); + Name = "FormProduct"; + Text = "Создание изделия"; + Load += FormProduct_Load; + groupBox1.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private System.Windows.Forms.Label labelName; + private System.Windows.Forms.Label labelPrice; + private System.Windows.Forms.TextBox textBoxName; + private System.Windows.Forms.TextBox textBoxPrice; + private System.Windows.Forms.GroupBox groupBox1; + private System.Windows.Forms.DataGridView dataGridView; + private System.Windows.Forms.Button ButtonRef; + private System.Windows.Forms.Button ButtonDel; + private System.Windows.Forms.Button ButtonUpd; + private System.Windows.Forms.Button ButtonAdd; + private System.Windows.Forms.Button ButtonSave; + private System.Windows.Forms.Button ButtonCancel; + private System.Windows.Forms.DataGridViewTextBoxColumn ID; + private System.Windows.Forms.DataGridViewTextBoxColumn ComponentName; + private System.Windows.Forms.DataGridViewTextBoxColumn Count; + } +} \ No newline at end of file diff --git a/DiningRoom/DiningRoomView/FormProduct.cs b/DiningRoom/DiningRoomView/FormProduct.cs new file mode 100644 index 0000000..b74d5d7 --- /dev/null +++ b/DiningRoom/DiningRoomView/FormProduct.cs @@ -0,0 +1,201 @@ +using DiningRoomContracts.BindingModels; +using DiningRoomContracts.BusinessLogicContracts; +using DiningRoomContracts.SearchModels; +using DiningRoomDataModels.Models; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace DiningRoomView +{ + public partial class FormProduct : Form + { + private readonly ILogger _logger; + private readonly IProductLogic _logic; + private int? _id; + private Dictionary _productComponents; + public int Id { set { _id = value; } } + public FormProduct(ILogger logger, IProductLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + _productComponents = new Dictionary(); + } + private void FormProduct_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + _logger.LogInformation("Загрузка изделия"); + try + { + var view = _logic.ReadElement(new ProductSearchModel { Id = _id.Value }); + if (view != null) + { + textBoxName.Text = view.ProductName; + textBoxPrice.Text = view.Cost.ToString(); + _productComponents = view.ProductComponents ?? new Dictionary(); + LoadData(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки изделия"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + private void LoadData() + { + _logger.LogInformation("Загрузка компонент изделия"); + try + { + if (_productComponents != null) + { + dataGridView.Rows.Clear(); + foreach (var pc in _productComponents) + { + dataGridView.Rows.Add(new object[] { pc.Key, pc.Value.Item1.ComponentName, pc.Value.Item2 }); + } + textBoxPrice.Text = CalcPrice().ToString(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки компонент изделия"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void ButtonAdd_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormProductComponent)); + if (service is FormProductComponent form) + { + if (form.ShowDialog() == DialogResult.OK) + { + if (form.ComponentModel == null) + { + return; + } + _logger.LogInformation("Добавление нового компонента: {ComponentName} - {Count}", form.ComponentModel.ComponentName, form.Count); + if (_productComponents.ContainsKey(form.Id)) + { + _productComponents[form.Id] = (form.ComponentModel, form.Count); + } + else + { + _productComponents.Add(form.Id, (form.ComponentModel, form.Count)); + } + LoadData(); + } + } + } + private void ButtonUpd_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormProductComponent)); + if (service is FormProductComponent form) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value); + form.Id = id; + form.Count = _productComponents[id].Item2; + if (form.ShowDialog() == DialogResult.OK) + { + if (form.ComponentModel == null) + { + return; + } + _logger.LogInformation("Изменение компонента: {ComponentName} - {Count}", form.ComponentModel.ComponentName, form.Count); + _productComponents[form.Id] = (form.ComponentModel, form.Count); + LoadData(); + } + } + } + } + private void ButtonDel_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + try + { + _logger.LogInformation("Удаление компонента: {ComponentName} - {Count}", dataGridView.SelectedRows[0].Cells[1].Value); _productComponents?.Remove(Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value)); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + LoadData(); + } + } + } + private void ButtonRef_Click(object sender, EventArgs e) + { + LoadData(); + } + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxName.Text)) + { + MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBoxPrice.Text)) + { + MessageBox.Show("Заполните цену", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (_productComponents == null || _productComponents.Count == 0) + { + MessageBox.Show("Заполните компоненты", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение изделия"); + try + { + var model = new ProductBindingModel + { + Id = _id ?? 0, + ProductName = textBoxName.Text, + Cost = Convert.ToDouble(textBoxPrice.Text), + ProductComponents = _productComponents + }; + var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка сохранения изделия"); MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + private double CalcPrice() + { + double price = 0; + foreach (var elem in _productComponents) + { + price += ((elem.Value.Item1?.Cost ?? 0) * elem.Value.Item2); + } + return Math.Round(price * 1.1, 2); + } + } +} diff --git a/DiningRoom/DiningRoomView/FormProduct.resx b/DiningRoom/DiningRoomView/FormProduct.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/DiningRoom/DiningRoomView/FormProduct.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/DiningRoom/DiningRoomView/FormProductComponent.Designer.cs b/DiningRoom/DiningRoomView/FormProductComponent.Designer.cs new file mode 100644 index 0000000..630c91a --- /dev/null +++ b/DiningRoom/DiningRoomView/FormProductComponent.Designer.cs @@ -0,0 +1,120 @@ +namespace DiningRoomView +{ + partial class FormProductComponent + { + /// + /// 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() + { + labelComponent = new Label(); + labelCount = new Label(); + textBoxCount = new TextBox(); + comboBoxComponent = new ComboBox(); + buttonCancel = new Button(); + buttonSave = new Button(); + SuspendLayout(); + // + // labelComponent + // + labelComponent.AutoSize = true; + labelComponent.Location = new Point(12, 9); + labelComponent.Name = "labelComponent"; + labelComponent.Size = new Size(72, 15); + labelComponent.TabIndex = 0; + labelComponent.Text = "Компонент:"; + labelComponent.Click += labelComponent_Click; + // + // labelCount + // + labelCount.AutoSize = true; + labelCount.Location = new Point(12, 37); + labelCount.Name = "labelCount"; + labelCount.Size = new Size(75, 15); + labelCount.TabIndex = 1; + labelCount.Text = "Количество:"; + // + // textBoxCount + // + textBoxCount.Location = new Point(90, 34); + textBoxCount.Name = "textBoxCount"; + textBoxCount.Size = new Size(235, 23); + textBoxCount.TabIndex = 3; + // + // comboBoxComponent + // + comboBoxComponent.BackColor = SystemColors.Window; + comboBoxComponent.FormattingEnabled = true; + comboBoxComponent.Location = new Point(90, 6); + comboBoxComponent.Name = "comboBoxComponent"; + comboBoxComponent.Size = new Size(235, 23); + comboBoxComponent.TabIndex = 4; + // + // buttonCancel + // + buttonCancel.Location = new Point(248, 63); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(75, 23); + buttonCancel.TabIndex = 5; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += buttonCancel_Click; + // + // buttonSave + // + buttonSave.Location = new Point(167, 63); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(75, 23); + buttonSave.TabIndex = 6; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += buttonSave_Click; + // + // FormProductComponent + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(337, 97); + Controls.Add(buttonSave); + Controls.Add(buttonCancel); + Controls.Add(comboBoxComponent); + Controls.Add(textBoxCount); + Controls.Add(labelCount); + Controls.Add(labelComponent); + Name = "FormProductComponent"; + Text = "Компонент"; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private System.Windows.Forms.Label labelComponent; + private System.Windows.Forms.Label labelCount; + private System.Windows.Forms.TextBox textBoxCount; + private System.Windows.Forms.ComboBox comboBoxComponent; + private System.Windows.Forms.Button buttonCancel; + private System.Windows.Forms.Button buttonSave; + } +} \ No newline at end of file diff --git a/DiningRoom/DiningRoomView/FormProductComponent.cs b/DiningRoom/DiningRoomView/FormProductComponent.cs new file mode 100644 index 0000000..eb70040 --- /dev/null +++ b/DiningRoom/DiningRoomView/FormProductComponent.cs @@ -0,0 +1,77 @@ +using DiningRoomContracts.BusinessLogicContracts; +using DiningRoomContracts.ViewModels; +using DiningRoomDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace DiningRoomView +{ + public partial class FormProductComponent : Form + { + private readonly List? _list; + public int Id { get { return Convert.ToInt32(comboBoxComponent.SelectedValue); } set { comboBoxComponent.SelectedValue = value; } } + public IComponentModel? ComponentModel + { + get + { + if (_list == null) + { + return null; + } + foreach (var elem in _list) + { + if (elem.Id == Id) + { + return elem; + } + } + return null; + } + } + public int Count { get { return Convert.ToInt32(textBoxCount.Text); } set { textBoxCount.Text = value.ToString(); } } + public FormProductComponent(IComponentLogic logic) + { + InitializeComponent(); + _list = logic.ReadList(null); + if (_list != null) + { + comboBoxComponent.DisplayMember = "ComponentName"; + comboBoxComponent.ValueMember = "Id"; + comboBoxComponent.DataSource = _list; + comboBoxComponent.SelectedItem = null; + } + } + private void buttonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxCount.Text)) + { + MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (comboBoxComponent.SelectedValue == null) + { + MessageBox.Show("Выберите компонент", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + DialogResult = DialogResult.OK; + Close(); + } + private void buttonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + + private void labelComponent_Click(object sender, EventArgs e) + { + + } + } +} diff --git a/DiningRoom/DiningRoomView/FormProductComponent.resx b/DiningRoom/DiningRoomView/FormProductComponent.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/DiningRoom/DiningRoomView/FormProductComponent.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/DiningRoom/DiningRoomView/Program.cs b/DiningRoom/DiningRoomView/Program.cs index 01760f7..aad4ffd 100644 --- a/DiningRoom/DiningRoomView/Program.cs +++ b/DiningRoom/DiningRoomView/Program.cs @@ -1,7 +1,19 @@ +using DiningRoomView; +using DiningRoomContracts.BusinessLogicContracts; +using DiningRoomContracts.StorageContracts; +using DiningRoomDatabaseImplement.Implements; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using DiningRoomBusinessLogic.BusinessLogic; + + + namespace DiningRoomView { internal static class Program { + private static ServiceProvider? _serviceProvider; + public static ServiceProvider? ServiceProvider => _serviceProvider; /// /// The main entry point for the application. /// @@ -11,7 +23,37 @@ namespace DiningRoomView // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new Form1()); + var services = new ServiceCollection(); + ConfigureServices(services); + _serviceProvider = services.BuildServiceProvider(); + Application.Run(_serviceProvider.GetRequiredService()); + } + + private static void ConfigureServices(ServiceCollection services) + { + services.AddLogging(option => + { + option.SetMinimumLevel(LogLevel.Information); + }); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + + } } } \ No newline at end of file