From 9ab410c5afe60269a8b2313565dc0344b9c44393 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B8=D0=BA=D0=BE=D0=BB=D0=B0=D0=B9?= Date: Sun, 2 Apr 2023 13:41:20 +0400 Subject: [PATCH 01/10] =?UTF-8?q?=D0=9C=D0=B0=D0=BA=D0=B5=D1=82=D1=8B=20?= =?UTF-8?q?=D0=B4=D0=BB=D1=8F=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=BD=D0=B8?= =?UTF-8?q?=D0=BA=D0=B0=20=D0=B3=D0=BE=D1=82=D0=BE=D0=B2=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/WorkerController.cs | 30 +++- .../Views/Worker/Build.cshtml | 75 +++++++++ .../Views/Worker/Builds.cshtml | 126 ++++++++------- .../Views/Worker/Comments.cshtml | 150 +++++++++++------- .../Views/Worker/Purchase.cshtml | 10 +- .../Views/Worker/Purchases.cshtml | 2 +- .../Views/Worker/WorkerReport.cshtml | 10 ++ .../Views/Worker/listComponents.cshtml | 147 ++++++++++------- 8 files changed, 376 insertions(+), 174 deletions(-) create mode 100644 HardwareShop/HardwareShopClientApp/Views/Worker/Build.cshtml diff --git a/HardwareShop/HardwareShopClientApp/Controllers/WorkerController.cs b/HardwareShop/HardwareShopClientApp/Controllers/WorkerController.cs index e43cbaf..c50da31 100644 --- a/HardwareShop/HardwareShopClientApp/Controllers/WorkerController.cs +++ b/HardwareShop/HardwareShopClientApp/Controllers/WorkerController.cs @@ -17,10 +17,7 @@ namespace HardwareShopClientApp.Controllers _logger = logger; } - public IActionResult Builds() - { - return View(); - } + public IActionResult Comments() { @@ -69,5 +66,30 @@ namespace HardwareShopClientApp.Controllers { return View(); } + + [HttpGet] + public IActionResult Builds() + { + return View(); + } + + [HttpPost] + public void Builds(int id) + { + //return View(); + //string login = (string)TempData["UserId"]; + + Response.Redirect("Build"); + } + + [HttpGet] + public IActionResult Build() + { + //return View(); + //string login = (string)TempData["UserId"]; + + return View(); + } + } } \ No newline at end of file diff --git a/HardwareShop/HardwareShopClientApp/Views/Worker/Build.cshtml b/HardwareShop/HardwareShopClientApp/Views/Worker/Build.cshtml new file mode 100644 index 0000000..323d46c --- /dev/null +++ b/HardwareShop/HardwareShopClientApp/Views/Worker/Build.cshtml @@ -0,0 +1,75 @@ + + +@using HardwareShopContracts.ViewModels +@{ + ViewData["Title"] = "Build"; +} + +@model List + +@section Header { +
+ +
+} +
+
+
+

Товар

+
+
+ + +
+ +
+ + + + + + + + + + + +
+ Номер + + Комплектующее + + Цена + + Логин пользователя +
+
+ + + diff --git a/HardwareShop/HardwareShopClientApp/Views/Worker/Builds.cshtml b/HardwareShop/HardwareShopClientApp/Views/Worker/Builds.cshtml index 5bfc6f8..cd83230 100644 --- a/HardwareShop/HardwareShopClientApp/Views/Worker/Builds.cshtml +++ b/HardwareShop/HardwareShopClientApp/Views/Worker/Builds.cshtml @@ -1,62 +1,76 @@ -@{ +@using HardwareShopContracts.ViewModels +@{ ViewData["Title"] = "Builds"; } +@model List + @section Header {
- -
+ + } -
-

Регистрация

-
-
-
- - -
-
- - -
-
- - -
-
- - -
- - -
- +
+
+
+

Сборки

+
+
+ + + + + + + + + + + + +
+ Номер + + Дата оплаты + + Сумма + + Статус + + Логин пользователя +
+
+
+
+ + + + +
+
diff --git a/HardwareShop/HardwareShopClientApp/Views/Worker/Comments.cshtml b/HardwareShop/HardwareShopClientApp/Views/Worker/Comments.cshtml index cebb316..f09f392 100644 --- a/HardwareShop/HardwareShopClientApp/Views/Worker/Comments.cshtml +++ b/HardwareShop/HardwareShopClientApp/Views/Worker/Comments.cshtml @@ -1,62 +1,102 @@ -@{ +@using HardwareShopContracts.ViewModels +@{ ViewData["Title"] = "Comments"; } +@model List + @section Header {
- -
+ + } -
-

Регистрация

-
-
-
- - -
-
- - -
-
- - -
-
- - -
- - -
+
+
+
+

Сборки

+
+
+ + + + + + + + + + + +
+ Номер + + Текст + + Название сборки + + Логин пользователя +
+
+
+
+ + + + +
+ + +
diff --git a/HardwareShop/HardwareShopClientApp/Views/Worker/Purchase.cshtml b/HardwareShop/HardwareShopClientApp/Views/Worker/Purchase.cshtml index 1318430..f1750e1 100644 --- a/HardwareShop/HardwareShopClientApp/Views/Worker/Purchase.cshtml +++ b/HardwareShop/HardwareShopClientApp/Views/Worker/Purchase.cshtml @@ -55,7 +55,7 @@ Цена - Пользователь + Логин пользователя Количество @@ -79,25 +79,25 @@ + \ No newline at end of file diff --git a/HardwareShop/HardwareShopClientApp/Views/Worker/Comments.cshtml b/HardwareShop/HardwareShopClientApp/Views/Worker/Comments.cshtml index f09f392..bb67b2a 100644 --- a/HardwareShop/HardwareShopClientApp/Views/Worker/Comments.cshtml +++ b/HardwareShop/HardwareShopClientApp/Views/Worker/Comments.cshtml @@ -30,6 +30,9 @@ +
diff --git a/HardwareShop/HardwareShopClientApp/Views/Worker/MainWorker.cshtml b/HardwareShop/HardwareShopClientApp/Views/Worker/MainWorker.cshtml index e60f995..a2643be 100644 --- a/HardwareShop/HardwareShopClientApp/Views/Worker/MainWorker.cshtml +++ b/HardwareShop/HardwareShopClientApp/Views/Worker/MainWorker.cshtml @@ -27,6 +27,9 @@ + diff --git a/HardwareShop/HardwareShopClientApp/Views/Worker/Purchase.cshtml b/HardwareShop/HardwareShopClientApp/Views/Worker/Purchase.cshtml index f1750e1..cb2f1e0 100644 --- a/HardwareShop/HardwareShopClientApp/Views/Worker/Purchase.cshtml +++ b/HardwareShop/HardwareShopClientApp/Views/Worker/Purchase.cshtml @@ -30,6 +30,9 @@ + diff --git a/HardwareShop/HardwareShopClientApp/Views/Worker/Purchases.cshtml b/HardwareShop/HardwareShopClientApp/Views/Worker/Purchases.cshtml index 9345ff0..00a5581 100644 --- a/HardwareShop/HardwareShopClientApp/Views/Worker/Purchases.cshtml +++ b/HardwareShop/HardwareShopClientApp/Views/Worker/Purchases.cshtml @@ -29,6 +29,9 @@ + @@ -37,7 +40,7 @@ }
-
+

Покупки

diff --git a/HardwareShop/HardwareShopClientApp/Views/Worker/WorkerReport.cshtml b/HardwareShop/HardwareShopClientApp/Views/Worker/WorkerReport.cshtml index cfae243..97889f2 100644 --- a/HardwareShop/HardwareShopClientApp/Views/Worker/WorkerReport.cshtml +++ b/HardwareShop/HardwareShopClientApp/Views/Worker/WorkerReport.cshtml @@ -28,6 +28,9 @@ +
diff --git a/HardwareShop/HardwareShopClientApp/Views/Worker/linkingBuild.cshtml b/HardwareShop/HardwareShopClientApp/Views/Worker/linkingBuild.cshtml new file mode 100644 index 0000000..0ba6767 --- /dev/null +++ b/HardwareShop/HardwareShopClientApp/Views/Worker/linkingBuild.cshtml @@ -0,0 +1,116 @@ + + +@using HardwareShopContracts.ViewModels +@{ + ViewData["Title"] = "linkingBuild"; +} + +@model List + +@section Header { +
+ +
+} + +
+
+

Выбранные покупки

+
+
+ + +
+ +
+ + + + + + + + + + + +
+ Номер + + Комплектующее + + Цена + + Логин пользователя +
+
+
+
+ + + + + +
+ + + + \ No newline at end of file diff --git a/HardwareShop/HardwareShopClientApp/Views/Worker/listComponents.cshtml b/HardwareShop/HardwareShopClientApp/Views/Worker/listComponents.cshtml index c0f58c9..b1d46ff 100644 --- a/HardwareShop/HardwareShopClientApp/Views/Worker/listComponents.cshtml +++ b/HardwareShop/HardwareShopClientApp/Views/Worker/listComponents.cshtml @@ -31,6 +31,9 @@ + diff --git a/HardwareShop/HardwareShopContracts/ViewModels/BuildViewModel.cs b/HardwareShop/HardwareShopContracts/ViewModels/BuildViewModel.cs index 68f0c74..53011b5 100644 --- a/HardwareShop/HardwareShopContracts/ViewModels/BuildViewModel.cs +++ b/HardwareShop/HardwareShopContracts/ViewModels/BuildViewModel.cs @@ -12,7 +12,7 @@ namespace HardwareShopContracts.ViewModels [DisplayName("Название компонента")] public string BuildName { get; set; } = string.Empty; - [DisplayName("Логин работника")] + [DisplayName("Логин пользователя")] public string UserLogin { get; set; } = string.Empty; public int UserId { get; set; } diff --git a/HardwareShop/HardwareShopContracts/ViewModels/CommentViewModel.cs b/HardwareShop/HardwareShopContracts/ViewModels/CommentViewModel.cs index 15343a3..6620922 100644 --- a/HardwareShop/HardwareShopContracts/ViewModels/CommentViewModel.cs +++ b/HardwareShop/HardwareShopContracts/ViewModels/CommentViewModel.cs @@ -17,7 +17,7 @@ namespace HardwareShopContracts.ViewModels public int UserId { get; set; } - [DisplayName("Логин работника")] + [DisplayName("Логин пользователя")] public string UserLogin { get; set; } = string.Empty; } } diff --git a/HardwareShop/HardwareShopContracts/ViewModels/PurchaseViewModel.cs b/HardwareShop/HardwareShopContracts/ViewModels/PurchaseViewModel.cs index 2a6967a..bc96eb6 100644 --- a/HardwareShop/HardwareShopContracts/ViewModels/PurchaseViewModel.cs +++ b/HardwareShop/HardwareShopContracts/ViewModels/PurchaseViewModel.cs @@ -18,7 +18,7 @@ namespace HardwareShopContracts.ViewModels public int UserId { get; set; } - [DisplayName("Логин работника")] + [DisplayName("Логин пользователя")] public string UserLogin { get; set; } = string.Empty; public Dictionary? PurchaseBuilds { get; set; } diff --git a/HardwareShop/HardwareShopDatabaseImplement/Models/Worker/Build.cs b/HardwareShop/HardwareShopDatabaseImplement/Models/Worker/Build.cs index 9132609..9660312 100644 --- a/HardwareShop/HardwareShopDatabaseImplement/Models/Worker/Build.cs +++ b/HardwareShop/HardwareShopDatabaseImplement/Models/Worker/Build.cs @@ -23,14 +23,14 @@ namespace HardwareShopDatabaseImplement.Models.Worker public virtual User User { get; set; } [ForeignKey("BuildId")] - public virtual List? Comments { get; set; } + public virtual List Comments { get; set; } = new(); [ForeignKey("BuildId")] - public virtual List? Components { get; set; } + public virtual List Components { get; set; } = new(); [ForeignKey("BuildId")] - public virtual List? Purchases { get; set; } + public virtual List Purchases { get; set; } = new(); private Dictionary? _buildComponents = null; From 934080cd54e56990dfbc9966790b936a759142b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B8=D0=BA=D0=BE=D0=BB=D0=B0=D0=B9?= Date: Sun, 2 Apr 2023 15:43:05 +0400 Subject: [PATCH 04/10] fix --- .../BusinessLogics/Worker/BuildLogic.cs | 23 +++++++- .../BindingModels/BuildBindingModel.cs | 4 +- .../BindingModels/PurchaseBindingModel.cs | 3 +- .../BusinessLogicsContracts/IBuildLogic.cs | 1 + .../ViewModels/BuildViewModel.cs | 5 +- .../ViewModels/PurchaseViewModel.cs | 4 +- .../Models/IBuildModel.cs | 4 +- .../Models/IPurchaseModel.cs | 5 +- .../Implements/Worker/BuildStorage.cs | 2 +- .../Implements/Worker/PurchaseStorage.cs | 1 - .../20230401181954_init.Designer.cs | 4 +- .../Migrations/20230401181954_init.cs | 4 +- .../HardwareShopDatabaseModelSnapshot.cs | 4 +- .../Models/Worker/Build.cs | 41 +++++++------- .../Models/Worker/Purchase.cs | 56 ++----------------- 15 files changed, 63 insertions(+), 98 deletions(-) diff --git a/HardwareShop/HardwareShopBusinessLogic/BusinessLogics/Worker/BuildLogic.cs b/HardwareShop/HardwareShopBusinessLogic/BusinessLogics/Worker/BuildLogic.cs index eb51e78..f1cde06 100644 --- a/HardwareShop/HardwareShopBusinessLogic/BusinessLogics/Worker/BuildLogic.cs +++ b/HardwareShop/HardwareShopBusinessLogic/BusinessLogics/Worker/BuildLogic.cs @@ -10,10 +10,12 @@ namespace HardwareShopContracts.BusinessLogicsContracts { private readonly ILogger _logger; private readonly IBuildStorage _buildStorage; - public BuildLogic(ILogger logger, IBuildStorage buildStorage) + private readonly IComponentStorage _componentStorage; + public BuildLogic(ILogger logger, IBuildStorage buildStorage, IComponentStorage componentStorage) { _logger = logger; _buildStorage = buildStorage; + _componentStorage = componentStorage; } public List? ReadList(BuildSearchModel? model) @@ -116,5 +118,24 @@ namespace HardwareShopContracts.BusinessLogicsContracts throw new InvalidOperationException("Продукт с таким названием уже есть"); } } + + //нужно переделать + public double Price(ComponentSearchModel model) + { + _logger.LogInformation("ReadList. Id:{Id}", model?.Id); + var list = _componentStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return 0; + } + double sum = 0; + foreach (var component in list) + { + sum += component.Cost; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return sum; + } } } diff --git a/HardwareShop/HardwareShopContracts/BindingModels/BuildBindingModel.cs b/HardwareShop/HardwareShopContracts/BindingModels/BuildBindingModel.cs index 9caaf5f..d373725 100644 --- a/HardwareShop/HardwareShopContracts/BindingModels/BuildBindingModel.cs +++ b/HardwareShop/HardwareShopContracts/BindingModels/BuildBindingModel.cs @@ -6,12 +6,12 @@ namespace HardwareShopContracts.BindingModels { public int Id { get; set; } - public decimal Price { get; set; } + public double Price { get; set; } public string BuildName { get; set; } = string.Empty; public int UserId { get; set; } - public Dictionary? BuildComponents { get; set; } + public Dictionary BuildPurchases { get; set; } = new(); } } diff --git a/HardwareShop/HardwareShopContracts/BindingModels/PurchaseBindingModel.cs b/HardwareShop/HardwareShopContracts/BindingModels/PurchaseBindingModel.cs index 654d33b..20c3b84 100644 --- a/HardwareShop/HardwareShopContracts/BindingModels/PurchaseBindingModel.cs +++ b/HardwareShop/HardwareShopContracts/BindingModels/PurchaseBindingModel.cs @@ -7,7 +7,7 @@ namespace HardwareShopContracts.BindingModels { public int Id { get; set; } - public decimal Sum { get; set; } + public double Sum { get; set; } public PurchaseStatus PurchaseStatus { get; set; } = PurchaseStatus.Неизвестен; @@ -15,7 +15,6 @@ namespace HardwareShopContracts.BindingModels public int UserId { get; set; } - public Dictionary? PurchaseBuilds { get; set; } public Dictionary PurchaseGoods { get; set; } = new(); } diff --git a/HardwareShop/HardwareShopContracts/BusinessLogicsContracts/IBuildLogic.cs b/HardwareShop/HardwareShopContracts/BusinessLogicsContracts/IBuildLogic.cs index 2833e19..0663249 100644 --- a/HardwareShop/HardwareShopContracts/BusinessLogicsContracts/IBuildLogic.cs +++ b/HardwareShop/HardwareShopContracts/BusinessLogicsContracts/IBuildLogic.cs @@ -8,6 +8,7 @@ namespace HardwareShopContracts.BusinessLogicsContracts { List? ReadList(BuildSearchModel? model); BuildViewModel? ReadElement(BuildSearchModel model); + double Price(ComponentSearchModel model); bool Create(BuildBindingModel model); bool Update(BuildBindingModel model); bool Delete(BuildBindingModel model); diff --git a/HardwareShop/HardwareShopContracts/ViewModels/BuildViewModel.cs b/HardwareShop/HardwareShopContracts/ViewModels/BuildViewModel.cs index 53011b5..4d80ce4 100644 --- a/HardwareShop/HardwareShopContracts/ViewModels/BuildViewModel.cs +++ b/HardwareShop/HardwareShopContracts/ViewModels/BuildViewModel.cs @@ -7,7 +7,7 @@ namespace HardwareShopContracts.ViewModels public int Id { get; set; } [DisplayName("Цена")] - public decimal Price { get; set; } + public double Price { get; set; } [DisplayName("Название компонента")] public string BuildName { get; set; } = string.Empty; @@ -17,6 +17,7 @@ namespace HardwareShopContracts.ViewModels public int UserId { get; set; } - public Dictionary? BuildComponents { get; set; } + public Dictionary BuildPurchases { get; set; } = new(); + } } diff --git a/HardwareShop/HardwareShopContracts/ViewModels/PurchaseViewModel.cs b/HardwareShop/HardwareShopContracts/ViewModels/PurchaseViewModel.cs index bc96eb6..ee1be3b 100644 --- a/HardwareShop/HardwareShopContracts/ViewModels/PurchaseViewModel.cs +++ b/HardwareShop/HardwareShopContracts/ViewModels/PurchaseViewModel.cs @@ -8,7 +8,7 @@ namespace HardwareShopContracts.ViewModels public int Id { get; set; } [DisplayName("Цена")] - public decimal Sum { get; set; } + public double Sum { get; set; } [DisplayName("Статус покупки")] public PurchaseStatus PurchaseStatus { get; set; } = PurchaseStatus.Неизвестен; @@ -21,8 +21,6 @@ namespace HardwareShopContracts.ViewModels [DisplayName("Логин пользователя")] public string UserLogin { get; set; } = string.Empty; - public Dictionary? PurchaseBuilds { get; set; } - public Dictionary PurchaseGoods { get; set; } = new(); } } diff --git a/HardwareShop/HardwareShopDataModels/Models/IBuildModel.cs b/HardwareShop/HardwareShopDataModels/Models/IBuildModel.cs index 0540675..3e57d64 100644 --- a/HardwareShop/HardwareShopDataModels/Models/IBuildModel.cs +++ b/HardwareShop/HardwareShopDataModels/Models/IBuildModel.cs @@ -9,12 +9,12 @@ namespace HardwareShopDataModels.Models { public interface IBuildModel : IId { - decimal Price { get; } + double Price { get; } string BuildName { get; } int UserId { get; } - Dictionary? BuildComponents { get; } + Dictionary BuildPurchases { get; } } } diff --git a/HardwareShop/HardwareShopDataModels/Models/IPurchaseModel.cs b/HardwareShop/HardwareShopDataModels/Models/IPurchaseModel.cs index 69d4ef4..91420cf 100644 --- a/HardwareShop/HardwareShopDataModels/Models/IPurchaseModel.cs +++ b/HardwareShop/HardwareShopDataModels/Models/IPurchaseModel.cs @@ -4,17 +4,14 @@ namespace HardwareShopDataModels.Models { public interface IPurchaseModel : IId { - decimal Sum { get; } + double Sum { get; } PurchaseStatus PurchaseStatus { get; } - //через "?" обозначается что поле может быть null DateTime? DatePurchase { get; } int UserId { get; } - Dictionary? PurchaseBuilds { get; } - Dictionary PurchaseGoods { get; } } } diff --git a/HardwareShop/HardwareShopDatabaseImplement/Implements/Worker/BuildStorage.cs b/HardwareShop/HardwareShopDatabaseImplement/Implements/Worker/BuildStorage.cs index 30bd71e..85941df 100644 --- a/HardwareShop/HardwareShopDatabaseImplement/Implements/Worker/BuildStorage.cs +++ b/HardwareShop/HardwareShopDatabaseImplement/Implements/Worker/BuildStorage.cs @@ -97,7 +97,7 @@ namespace HardwareShopDatabaseImplement.Implements.Worker } build.Update(model); context.SaveChanges(); - build.UpdateComponents(context, model); + build.UpdatePurchases(context, model); transaction.Commit(); return build?.GetViewModel; } diff --git a/HardwareShop/HardwareShopDatabaseImplement/Implements/Worker/PurchaseStorage.cs b/HardwareShop/HardwareShopDatabaseImplement/Implements/Worker/PurchaseStorage.cs index 428a796..24cfc9a 100644 --- a/HardwareShop/HardwareShopDatabaseImplement/Implements/Worker/PurchaseStorage.cs +++ b/HardwareShop/HardwareShopDatabaseImplement/Implements/Worker/PurchaseStorage.cs @@ -93,7 +93,6 @@ namespace HardwareShopDatabaseImplement.Implements.Worker purchase.Update(model); context.SaveChanges(); purchase.UpdateGoods(context, model); - purchase.UpdateBuilds(context, model); transaction.Commit(); return purchase.GetViewModel; } diff --git a/HardwareShop/HardwareShopDatabaseImplement/Migrations/20230401181954_init.Designer.cs b/HardwareShop/HardwareShopDatabaseImplement/Migrations/20230401181954_init.Designer.cs index 33a5bbc..85e1b34 100644 --- a/HardwareShop/HardwareShopDatabaseImplement/Migrations/20230401181954_init.Designer.cs +++ b/HardwareShop/HardwareShopDatabaseImplement/Migrations/20230401181954_init.Designer.cs @@ -243,7 +243,7 @@ namespace HardwareShopDatabaseImplement.Migrations b.Property("ClientId") .HasColumnType("integer"); - b.Property("Price") + b.Property("Price") .HasColumnType("numeric"); b.Property("UserId") @@ -303,7 +303,7 @@ namespace HardwareShopDatabaseImplement.Migrations b.Property("PurchaseStatus") .HasColumnType("integer"); - b.Property("Sum") + b.Property("Sum") .HasColumnType("numeric"); b.Property("UserId") diff --git a/HardwareShop/HardwareShopDatabaseImplement/Migrations/20230401181954_init.cs b/HardwareShop/HardwareShopDatabaseImplement/Migrations/20230401181954_init.cs index 019e2c2..342204a 100644 --- a/HardwareShop/HardwareShopDatabaseImplement/Migrations/20230401181954_init.cs +++ b/HardwareShop/HardwareShopDatabaseImplement/Migrations/20230401181954_init.cs @@ -34,7 +34,7 @@ namespace HardwareShopDatabaseImplement.Migrations { Id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), - Price = table.Column(type: "numeric", nullable: false), + Price = table.Column(type: "numeric", nullable: false), BuildName = table.Column(type: "text", nullable: false), UserId = table.Column(type: "integer", nullable: false), ClientId = table.Column(type: "integer", nullable: false) @@ -100,7 +100,7 @@ namespace HardwareShopDatabaseImplement.Migrations { Id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), - Sum = table.Column(type: "numeric", nullable: false), + Sum = table.Column(type: "numeric", nullable: false), PurchaseStatus = table.Column(type: "integer", nullable: false), DatePurchase = table.Column(type: "timestamp with time zone", nullable: true), UserId = table.Column(type: "integer", nullable: false), diff --git a/HardwareShop/HardwareShopDatabaseImplement/Migrations/HardwareShopDatabaseModelSnapshot.cs b/HardwareShop/HardwareShopDatabaseImplement/Migrations/HardwareShopDatabaseModelSnapshot.cs index e765088..b2b8803 100644 --- a/HardwareShop/HardwareShopDatabaseImplement/Migrations/HardwareShopDatabaseModelSnapshot.cs +++ b/HardwareShop/HardwareShopDatabaseImplement/Migrations/HardwareShopDatabaseModelSnapshot.cs @@ -240,7 +240,7 @@ namespace HardwareShopDatabaseImplement.Migrations b.Property("ClientId") .HasColumnType("integer"); - b.Property("Price") + b.Property("Price") .HasColumnType("numeric"); b.Property("UserId") @@ -300,7 +300,7 @@ namespace HardwareShopDatabaseImplement.Migrations b.Property("PurchaseStatus") .HasColumnType("integer"); - b.Property("Sum") + b.Property("Sum") .HasColumnType("numeric"); b.Property("UserId") diff --git a/HardwareShop/HardwareShopDatabaseImplement/Models/Worker/Build.cs b/HardwareShop/HardwareShopDatabaseImplement/Models/Worker/Build.cs index 9660312..0f34f20 100644 --- a/HardwareShop/HardwareShopDatabaseImplement/Models/Worker/Build.cs +++ b/HardwareShop/HardwareShopDatabaseImplement/Models/Worker/Build.cs @@ -12,7 +12,7 @@ namespace HardwareShopDatabaseImplement.Models.Worker public int Id { get; set; } [Required] - public decimal Price { get; set; } + public double Price { get; set; } [Required] public string BuildName { get; set; } = string.Empty; @@ -32,19 +32,18 @@ namespace HardwareShopDatabaseImplement.Models.Worker [ForeignKey("BuildId")] public virtual List Purchases { get; set; } = new(); - - private Dictionary? _buildComponents = null; + public Dictionary? _buildPurchases = null; [NotMapped] - public Dictionary BuildComponents + public Dictionary BuildPurchases { get { - if (_buildComponents == null) + if (_buildPurchases == null) { - _buildComponents = Components.ToDictionary(recBC => recBC.ComponentId, recBC => (recBC.Component as IComponentModel, recBC.Count)); + _buildPurchases = Purchases.ToDictionary(recBP => recBP.PurchaseId, recBP => (recBP.Purchase as IPurchaseModel, recBP.Count)); } - return _buildComponents; + return _buildPurchases; } } @@ -53,12 +52,11 @@ namespace HardwareShopDatabaseImplement.Models.Worker return new Build() { Id = model.Id, - Price = model.Price, BuildName = model.BuildName, UserId = model.UserId, - Components = model.BuildComponents.Select(x => new BuildComponent + Purchases = model.BuildPurchases.Select(x => new PurchaseBuild { - Component = context.Components.First(y => y.Id == x.Key), + Purchase = context.Purchases.First(y => y.Id == x.Key), Count = x.Value.Item2 }).ToList() }; @@ -77,37 +75,36 @@ namespace HardwareShopDatabaseImplement.Models.Worker Price = Price, UserLogin = User.Login, UserId = UserId, - BuildComponents = BuildComponents }; - public void UpdateComponents(HardwareShopDatabase context, BuildBindingModel model) + public void UpdatePurchases(HardwareShopDatabase context, BuildBindingModel model) { - var buildComponents = context.BuildsComponents.Where(rec => rec.BuildId == model.Id).ToList(); - if (buildComponents != null && buildComponents.Count > 0) + var buildPurchases = context.PurchasesBuilds.Where(rec => rec.BuildId == model.Id).ToList(); + if (buildPurchases != null && buildPurchases.Count > 0) { // удалили те в бд, которых нет в модели - context.BuildsComponents.RemoveRange(buildComponents.Where(rec => !model.BuildComponents.ContainsKey(rec.ComponentId))); + context.PurchasesBuilds.RemoveRange(buildPurchases.Where(rec => !model.BuildPurchases.ContainsKey(rec.PurchaseId))); context.SaveChanges(); // обновили количество у существующих записей - foreach (var updateComponent in buildComponents) + foreach (var updateComponent in buildPurchases) { - updateComponent.Count = model.BuildComponents[updateComponent.ComponentId].Item2; - model.BuildComponents.Remove(updateComponent.ComponentId); + updateComponent.Count = model.BuildPurchases[updateComponent.PurchaseId].Item2; + model.BuildPurchases.Remove(updateComponent.PurchaseId); } context.SaveChanges(); } var build = context.Builds.First(x => x.Id == Id); //добавляем в бд блюда которые есть в моделе, но ещё нет в бд - foreach (var dc in model.BuildComponents) + foreach (var dc in model.BuildPurchases) { - context.BuildsComponents.Add(new BuildComponent + context.PurchasesBuilds.Add(new PurchaseBuild { Build = build, - Component = context.Components.First(x => x.Id == dc.Key), + Purchase = context.Purchases.First(x => x.Id == dc.Key), Count = dc.Value.Item2 }); context.SaveChanges(); } - _buildComponents = null; + _buildPurchases = null; } } diff --git a/HardwareShop/HardwareShopDatabaseImplement/Models/Worker/Purchase.cs b/HardwareShop/HardwareShopDatabaseImplement/Models/Worker/Purchase.cs index 4c573fc..efa33cc 100644 --- a/HardwareShop/HardwareShopDatabaseImplement/Models/Worker/Purchase.cs +++ b/HardwareShop/HardwareShopDatabaseImplement/Models/Worker/Purchase.cs @@ -14,7 +14,7 @@ namespace HardwareShopDatabaseImplement.Models.Worker public int Id { get; set; } [Required] - public decimal Sum { get; set; } + public double Sum { get; set; } [Required] public PurchaseStatus PurchaseStatus { get; set; } = PurchaseStatus.Неизвестен; @@ -29,27 +29,13 @@ namespace HardwareShopDatabaseImplement.Models.Worker [ForeignKey("PurchaseId")] public virtual List? Builds { get; set; } - public Dictionary? _purchaseBuilds = null; - - [NotMapped] - public Dictionary? PurchaseBuilds - { - get - { - if (_purchaseBuilds == null) - { - _purchaseBuilds = Builds.ToDictionary(recPB => recPB.BuildId, recPB => (recPB.Build as IBuildModel, recPB.Count)); - } - return _purchaseBuilds; - } - } - [ForeignKey("PurchaseId")] public virtual List Goods { get; set; } = new(); public Dictionary? _purchaseGoods = null; + [NotMapped] - public Dictionary? PurchaseGoods + public Dictionary PurchaseGoods { get { @@ -70,16 +56,11 @@ namespace HardwareShopDatabaseImplement.Models.Worker PurchaseStatus = model.PurchaseStatus, DatePurchase = model.DatePurchase, UserId = model.UserId, - Builds = model.PurchaseBuilds.Select(x => new PurchaseBuild - { - Build = context.Builds.First(y => y.Id == x.Key), - Count = x.Value.Item2 - }).ToList(), Goods = model.PurchaseGoods.Select(x => new PurchaseGood { Good = context.Goods.First(y => y.Id == x.Key), Count = x.Value.Item2 - }).ToList() + }).ToList(), }; } @@ -97,38 +78,9 @@ namespace HardwareShopDatabaseImplement.Models.Worker DatePurchase = DatePurchase, UserId = UserId, UserLogin = User.Login, - PurchaseBuilds = PurchaseBuilds, PurchaseGoods = PurchaseGoods }; - public void UpdateBuilds(HardwareShopDatabase context, PurchaseBindingModel model) - { - var purchaseBuilds = context.PurchasesBuilds.Where(rec => rec.PurchaseId == model.Id).ToList(); - if (purchaseBuilds != null && purchaseBuilds.Count > 0) - { - context.PurchasesBuilds.RemoveRange(purchaseBuilds.Where(rec => !model.PurchaseBuilds.ContainsKey(rec.BuildId))); - context.SaveChanges(); - foreach (var updateBuild in purchaseBuilds) - { - updateBuild.Count = model.PurchaseBuilds[updateBuild.BuildId].Item2; - model.PurchaseBuilds.Remove(updateBuild.BuildId); - } - context.SaveChanges(); - } - var purchase = context.Purchases.First(x => x.Id == Id); - foreach (var dc in model.PurchaseBuilds) - { - context.PurchasesBuilds.Add(new PurchaseBuild - { - Purchase = purchase, - Build = context.Builds.First(x => x.Id == dc.Key), - Count = dc.Value.Item2 - }); - context.SaveChanges(); - } - _purchaseBuilds = null; - } - public void UpdateGoods(HardwareShopDatabase context, PurchaseBindingModel model) { var purchaseGoods = context.PurchasesGoods.Where(rec => rec.PurchaseId == model.Id).ToList(); From 8203d2284974dc556cfb54c69f284005a7200e0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B8=D0=BA=D0=BE=D0=BB=D0=B0=D0=B9?= Date: Sun, 2 Apr 2023 16:10:21 +0400 Subject: [PATCH 05/10] fix --- .../BindingModels/PurchaseBindingModel.cs | 1 - .../SearchModels/BuildSearchModel.cs | 2 ++ .../Implements/Worker/BuildStorage.cs | 2 +- .../Implements/Worker/CommentStorage.cs | 13 ++++++------- .../Models/Worker/Build.cs | 14 +++++--------- .../Models/Worker/Purchase.cs | 1 + 6 files changed, 15 insertions(+), 18 deletions(-) diff --git a/HardwareShop/HardwareShopContracts/BindingModels/PurchaseBindingModel.cs b/HardwareShop/HardwareShopContracts/BindingModels/PurchaseBindingModel.cs index 20c3b84..ccaaf61 100644 --- a/HardwareShop/HardwareShopContracts/BindingModels/PurchaseBindingModel.cs +++ b/HardwareShop/HardwareShopContracts/BindingModels/PurchaseBindingModel.cs @@ -15,7 +15,6 @@ namespace HardwareShopContracts.BindingModels public int UserId { get; set; } - public Dictionary PurchaseGoods { get; set; } = new(); } } diff --git a/HardwareShop/HardwareShopContracts/SearchModels/BuildSearchModel.cs b/HardwareShop/HardwareShopContracts/SearchModels/BuildSearchModel.cs index 3d5caee..19cb465 100644 --- a/HardwareShop/HardwareShopContracts/SearchModels/BuildSearchModel.cs +++ b/HardwareShop/HardwareShopContracts/SearchModels/BuildSearchModel.cs @@ -8,5 +8,7 @@ namespace HardwareShopContracts.SearchModels public string? BuildName { get; set; } = string.Empty; public int? UserId { get; set; } + + public int? PurchaseId { get; set; } } } diff --git a/HardwareShop/HardwareShopDatabaseImplement/Implements/Worker/BuildStorage.cs b/HardwareShop/HardwareShopDatabaseImplement/Implements/Worker/BuildStorage.cs index 85941df..8b8c068 100644 --- a/HardwareShop/HardwareShopDatabaseImplement/Implements/Worker/BuildStorage.cs +++ b/HardwareShop/HardwareShopDatabaseImplement/Implements/Worker/BuildStorage.cs @@ -61,7 +61,7 @@ namespace HardwareShopDatabaseImplement.Implements.Worker public BuildViewModel? Insert(BuildBindingModel model) { using var context = new HardwareShopDatabase(); - var newBuild = Build.Create(context, model); + var newBuild = Build.Create(model); if (newBuild == null) { return null; diff --git a/HardwareShop/HardwareShopDatabaseImplement/Implements/Worker/CommentStorage.cs b/HardwareShop/HardwareShopDatabaseImplement/Implements/Worker/CommentStorage.cs index 63dcaa6..9812184 100644 --- a/HardwareShop/HardwareShopDatabaseImplement/Implements/Worker/CommentStorage.cs +++ b/HardwareShop/HardwareShopDatabaseImplement/Implements/Worker/CommentStorage.cs @@ -21,7 +21,7 @@ namespace HardwareShopDatabaseImplement.Implements.Worker public List GetFilteredList(CommentSearchModel model) { - if (!model.Id.HasValue) + if (!model.BuildId.HasValue && !model.UserId.HasValue) { return new(); } @@ -35,13 +35,12 @@ namespace HardwareShopDatabaseImplement.Implements.Worker .Select(x => x.GetViewModel) .ToList(); } - return context.Comments - .Include(x => x.Build) - .Include(x => x.User) - .Where(x => x.BuildId == model.BuildId) - .Select(x => x.GetViewModel) - .ToList(); + .Include(x => x.Build) + .Include(x => x.User) + .Where(x => x.BuildId == model.BuildId) + .Select(x => x.GetViewModel) + .ToList(); } public CommentViewModel? GetElement(CommentSearchModel model) diff --git a/HardwareShop/HardwareShopDatabaseImplement/Models/Worker/Build.cs b/HardwareShop/HardwareShopDatabaseImplement/Models/Worker/Build.cs index 0f34f20..c3765eb 100644 --- a/HardwareShop/HardwareShopDatabaseImplement/Models/Worker/Build.cs +++ b/HardwareShop/HardwareShopDatabaseImplement/Models/Worker/Build.cs @@ -47,18 +47,13 @@ namespace HardwareShopDatabaseImplement.Models.Worker } } - public static Build Create(HardwareShopDatabase context, BuildBindingModel model) + public static Build Create(BuildBindingModel model) { return new Build() { Id = model.Id, BuildName = model.BuildName, UserId = model.UserId, - Purchases = model.BuildPurchases.Select(x => new PurchaseBuild - { - Purchase = context.Purchases.First(y => y.Id == x.Key), - Count = x.Value.Item2 - }).ToList() }; } @@ -75,6 +70,7 @@ namespace HardwareShopDatabaseImplement.Models.Worker Price = Price, UserLogin = User.Login, UserId = UserId, + BuildPurchases = BuildPurchases, }; public void UpdatePurchases(HardwareShopDatabase context, BuildBindingModel model) @@ -94,13 +90,13 @@ namespace HardwareShopDatabaseImplement.Models.Worker } var build = context.Builds.First(x => x.Id == Id); //добавляем в бд блюда которые есть в моделе, но ещё нет в бд - foreach (var dc in model.BuildPurchases) + foreach (var bp in model.BuildPurchases) { context.PurchasesBuilds.Add(new PurchaseBuild { Build = build, - Purchase = context.Purchases.First(x => x.Id == dc.Key), - Count = dc.Value.Item2 + Purchase = context.Purchases.First(x => x.Id == bp.Key), + Count = bp.Value.Item2 }); context.SaveChanges(); } diff --git a/HardwareShop/HardwareShopDatabaseImplement/Models/Worker/Purchase.cs b/HardwareShop/HardwareShopDatabaseImplement/Models/Worker/Purchase.cs index efa33cc..35a163f 100644 --- a/HardwareShop/HardwareShopDatabaseImplement/Models/Worker/Purchase.cs +++ b/HardwareShop/HardwareShopDatabaseImplement/Models/Worker/Purchase.cs @@ -68,6 +68,7 @@ namespace HardwareShopDatabaseImplement.Models.Worker { PurchaseStatus = model.PurchaseStatus; DatePurchase = model.DatePurchase; + Sum = model.Sum; } public PurchaseViewModel GetViewModel => new() From ff2f0d57db9832a092f87024bff1b0923976ece6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B8=D0=BA=D0=BE=D0=BB=D0=B0=D0=B9?= Date: Sun, 2 Apr 2023 16:32:22 +0400 Subject: [PATCH 06/10] fix --- .../SearchModels/BuildSearchModel.cs | 2 - .../Implements/Worker/BuildStorage.cs | 45 ++++++++++--------- 2 files changed, 24 insertions(+), 23 deletions(-) diff --git a/HardwareShop/HardwareShopContracts/SearchModels/BuildSearchModel.cs b/HardwareShop/HardwareShopContracts/SearchModels/BuildSearchModel.cs index 19cb465..3d5caee 100644 --- a/HardwareShop/HardwareShopContracts/SearchModels/BuildSearchModel.cs +++ b/HardwareShop/HardwareShopContracts/SearchModels/BuildSearchModel.cs @@ -8,7 +8,5 @@ namespace HardwareShopContracts.SearchModels public string? BuildName { get; set; } = string.Empty; public int? UserId { get; set; } - - public int? PurchaseId { get; set; } } } diff --git a/HardwareShop/HardwareShopDatabaseImplement/Implements/Worker/BuildStorage.cs b/HardwareShop/HardwareShopDatabaseImplement/Implements/Worker/BuildStorage.cs index 8b8c068..cd6992f 100644 --- a/HardwareShop/HardwareShopDatabaseImplement/Implements/Worker/BuildStorage.cs +++ b/HardwareShop/HardwareShopDatabaseImplement/Implements/Worker/BuildStorage.cs @@ -13,9 +13,8 @@ namespace HardwareShopDatabaseImplement.Implements.Worker { using var context = new HardwareShopDatabase(); return context.Builds - .Include(x => x.Components) - .ThenInclude(x => x.Component) - .Include(x => x.Comments) + .Include(x => x.Purchases) + .ThenInclude(x => x.Purchase) .Include(x => x.User) .ToList() .Select(x => x.GetViewModel) @@ -24,17 +23,25 @@ namespace HardwareShopDatabaseImplement.Implements.Worker public List GetFilteredList(BuildSearchModel model) { - if (!model.UserId.HasValue) + if (string.IsNullOrEmpty(model.BuildName) && !model.UserId.HasValue) { return new(); } using var context = new HardwareShopDatabase(); + if (!string.IsNullOrEmpty(model.BuildName)) + { + return context.Builds + .Include(x => x.Purchases) + .ThenInclude(x => x.Purchase) + .Include(x => x.BuildName.Contains(model.BuildName)) + .ToList() + .Select(x => x.GetViewModel) + .ToList(); + } return context.Builds - .Include(x => x.Components) - .ThenInclude(x => x.Component) - .Include(x => x.Comments) - .Include(x => x.User) - .Where(x => x.UserId == model.UserId) + .Include(x => x.Purchases) + .ThenInclude(x => x.Purchase) + .Include(x => x.UserId == model.UserId) .ToList() .Select(x => x.GetViewModel) .ToList(); @@ -48,9 +55,8 @@ namespace HardwareShopDatabaseImplement.Implements.Worker } using var context = new HardwareShopDatabase(); return context.Builds - .Include(x => x.Components) - .ThenInclude(x => x.Component) - .Include(x => x.Comments) + .Include(x => x.Purchases) + .ThenInclude(x => x.Purchase) .Include(x => x.User) .Where(x => x.Id == model.Id) .FirstOrDefault(x => (!string.IsNullOrEmpty(model.BuildName) && x.BuildName == model.BuildName) || @@ -69,9 +75,8 @@ namespace HardwareShopDatabaseImplement.Implements.Worker context.Builds.Add(newBuild); context.SaveChanges(); return context.Builds - .Include(x => x.Components) - .ThenInclude(x => x.Component) - .Include(x => x.Comments) + .Include(x => x.Purchases) + .ThenInclude(x => x.Purchase) .Include(x => x.User) .Where(x => x.UserId == model.Id) .FirstOrDefault(x => x.Id == newBuild.Id) @@ -85,9 +90,8 @@ namespace HardwareShopDatabaseImplement.Implements.Worker try { var build = context.Builds - .Include(x => x.Components) - .ThenInclude(x => x.Component) - .Include(x => x.Comments) + .Include(x => x.Purchases) + .ThenInclude(x => x.Purchase) .Include(x => x.User) .Where(x => x.UserId == model.UserId) .FirstOrDefault(x => x.Id == model.Id); @@ -112,9 +116,8 @@ namespace HardwareShopDatabaseImplement.Implements.Worker { using var context = new HardwareShopDatabase(); var element = context.Builds - .Include(x => x.Components) - .ThenInclude(x => x.Component) - .Include(x => x.Comments) + .Include(x => x.Purchases) + .ThenInclude(x => x.Purchase) .Include(x => x.User) .Where(x => x.UserId == model.Id) .FirstOrDefault(rec => rec.Id == model.Id); From cf82bd4fe762326d84fe562a110dcb45b18b5d07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B8=D0=BA=D0=BE=D0=BB=D0=B0=D0=B9?= Date: Sun, 2 Apr 2023 16:37:37 +0400 Subject: [PATCH 07/10] fix --- .../BindingModels/GoodBindingModel.cs | 2 +- .../Models/Storekeeper/Good.cs | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/HardwareShop/HardwareShopContracts/BindingModels/GoodBindingModel.cs b/HardwareShop/HardwareShopContracts/BindingModels/GoodBindingModel.cs index 098d088..49f4107 100644 --- a/HardwareShop/HardwareShopContracts/BindingModels/GoodBindingModel.cs +++ b/HardwareShop/HardwareShopContracts/BindingModels/GoodBindingModel.cs @@ -12,7 +12,7 @@ namespace HardwareShopContracts.BindingModels public int UserId { get; set; } - public Dictionary GoodComponents + public Dictionary GoodsComponents { get; set; diff --git a/HardwareShop/HardwareShopDatabaseImplement/Models/Storekeeper/Good.cs b/HardwareShop/HardwareShopDatabaseImplement/Models/Storekeeper/Good.cs index a870057..6c3d753 100644 --- a/HardwareShop/HardwareShopDatabaseImplement/Models/Storekeeper/Good.cs +++ b/HardwareShop/HardwareShopDatabaseImplement/Models/Storekeeper/Good.cs @@ -55,7 +55,7 @@ namespace HardwareShopDatabaseImplement.Models.Storekeeper GoodName = model.GoodName, Price = model.Price, UserId = model.UserId, - Components = model.GoodComponents.Select(x => new GoodComponent + Components = model.GoodsComponents.Select(x => new GoodComponent { Component = context.Components.First(y => y.Id == x.Key), Count = x.Value.Item2 @@ -80,7 +80,7 @@ namespace HardwareShopDatabaseImplement.Models.Storekeeper Price = Price, UserId = UserId, UserLogin = User.Login, - GoodComponents = GoodsComponents + GoodsComponents = GoodsComponents }; public void UpdateComponents(HardwareShopDatabase context, GoodBindingModel model) @@ -91,18 +91,18 @@ namespace HardwareShopDatabaseImplement.Models.Storekeeper { // удалили те, которых нет в модели context.GoodsComponents .RemoveRange(goodComponents - .Where(rec => !model.GoodComponents.ContainsKey(rec.ComponentId))); + .Where(rec => !model.GoodsComponents.ContainsKey(rec.ComponentId))); context.SaveChanges(); // обновили количество у существующих записей foreach (var updateComponent in goodComponents) { - updateComponent.Count = model.GoodComponents[updateComponent.ComponentId].Item2; - model.GoodComponents.Remove(updateComponent.ComponentId); + updateComponent.Count = model.GoodsComponents[updateComponent.ComponentId].Item2; + model.GoodsComponents.Remove(updateComponent.ComponentId); } context.SaveChanges(); } var good = context.Goods.First(x => x.Id == Id); - foreach (var gc in model.GoodComponents) + foreach (var gc in model.GoodsComponents) { context.GoodsComponents.Add(new GoodComponent { From 2debfe4ba8dbdd4a578a3391b23c1a11178b5f64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B8=D0=BA=D0=BE=D0=BB=D0=B0=D0=B9?= Date: Sun, 2 Apr 2023 17:13:48 +0400 Subject: [PATCH 08/10] =?UTF-8?q?=D0=B1=D1=80=D0=B5=D0=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogics/Worker/BuildLogic.cs | 1 + .../BusinessLogics/Worker/PurchaseLogic.cs | 18 ++++++++ .../BusinessLogicsContracts/IPurchaseLogic.cs | 1 + .../StoragesContracts/IPurchaseStorage.cs | 2 + .../Implements/Worker/PurchaseStorage.cs | 46 +++++++++++++------ 5 files changed, 54 insertions(+), 14 deletions(-) diff --git a/HardwareShop/HardwareShopBusinessLogic/BusinessLogics/Worker/BuildLogic.cs b/HardwareShop/HardwareShopBusinessLogic/BusinessLogics/Worker/BuildLogic.cs index f1cde06..c7c96bc 100644 --- a/HardwareShop/HardwareShopBusinessLogic/BusinessLogics/Worker/BuildLogic.cs +++ b/HardwareShop/HardwareShopBusinessLogic/BusinessLogics/Worker/BuildLogic.cs @@ -137,5 +137,6 @@ namespace HardwareShopContracts.BusinessLogicsContracts _logger.LogInformation("ReadList. Count:{Count}", list.Count); return sum; } + } } diff --git a/HardwareShop/HardwareShopBusinessLogic/BusinessLogics/Worker/PurchaseLogic.cs b/HardwareShop/HardwareShopBusinessLogic/BusinessLogics/Worker/PurchaseLogic.cs index 8563aac..0e7ff6a 100644 --- a/HardwareShop/HardwareShopBusinessLogic/BusinessLogics/Worker/PurchaseLogic.cs +++ b/HardwareShop/HardwareShopBusinessLogic/BusinessLogics/Worker/PurchaseLogic.cs @@ -123,5 +123,23 @@ namespace HardwareShopContracts.BusinessLogicsContracts } _logger.LogInformation("Purchase. UserId:{UserId}. PurchaseID:{Id}. Sum:{ Sum}", model.UserId, model.Id, model.Sum); } + + public double Price(PurchaseSearchModel model) + { + _logger.LogInformation("ReadList. Id:{Id}", model?.Id); + var list = _purchaseStorage.GetFilteredListBuild(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return 0; + } + double sum = 0; + foreach (var build in list) + { + sum += build.Value.Item1* build.Value.Item2.Price; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return sum; + } } } diff --git a/HardwareShop/HardwareShopContracts/BusinessLogicsContracts/IPurchaseLogic.cs b/HardwareShop/HardwareShopContracts/BusinessLogicsContracts/IPurchaseLogic.cs index 0882fad..265fadb 100644 --- a/HardwareShop/HardwareShopContracts/BusinessLogicsContracts/IPurchaseLogic.cs +++ b/HardwareShop/HardwareShopContracts/BusinessLogicsContracts/IPurchaseLogic.cs @@ -8,6 +8,7 @@ namespace HardwareShopContracts.BusinessLogicsContracts { List? ReadList(PurchaseSearchModel? model); CommentViewModel? ReadElement(CommentSearchModel model); + double Price(PurchaseSearchModel model); bool Create(PurchaseBindingModel model); bool Update(PurchaseBindingModel model); bool Delete(PurchaseBindingModel model); diff --git a/HardwareShop/HardwareShopContracts/StoragesContracts/IPurchaseStorage.cs b/HardwareShop/HardwareShopContracts/StoragesContracts/IPurchaseStorage.cs index 7a60b86..f75115b 100644 --- a/HardwareShop/HardwareShopContracts/StoragesContracts/IPurchaseStorage.cs +++ b/HardwareShop/HardwareShopContracts/StoragesContracts/IPurchaseStorage.cs @@ -1,6 +1,7 @@ using HardwareShopContracts.BindingModels; using HardwareShopContracts.SearchModels; using HardwareShopContracts.ViewModels; +using HardwareShopDataModels.Models; namespace HardwareShopContracts.StoragesContracts { @@ -8,6 +9,7 @@ namespace HardwareShopContracts.StoragesContracts { List GetFullList(); List GetFilteredList(PurchaseSearchModel model); + Dictionary GetFilteredListBuild(PurchaseSearchModel model); PurchaseViewModel? GetElement(PurchaseSearchModel model); PurchaseViewModel? Insert(PurchaseBindingModel model); PurchaseViewModel? Update(PurchaseBindingModel model); diff --git a/HardwareShop/HardwareShopDatabaseImplement/Implements/Worker/PurchaseStorage.cs b/HardwareShop/HardwareShopDatabaseImplement/Implements/Worker/PurchaseStorage.cs index 24cfc9a..d241852 100644 --- a/HardwareShop/HardwareShopDatabaseImplement/Implements/Worker/PurchaseStorage.cs +++ b/HardwareShop/HardwareShopDatabaseImplement/Implements/Worker/PurchaseStorage.cs @@ -2,7 +2,9 @@ using HardwareShopContracts.SearchModels; using HardwareShopContracts.StoragesContracts; using HardwareShopContracts.ViewModels; +using HardwareShopDatabaseImplement.Models.ManyToMany; using HardwareShopDatabaseImplement.Models.Worker; +using HardwareShopDataModels.Models; using Microsoft.EntityFrameworkCore; namespace HardwareShopDatabaseImplement.Implements.Worker @@ -15,6 +17,7 @@ namespace HardwareShopDatabaseImplement.Implements.Worker return context.Purchases .Include(x => x.Builds) .Include(x => x.Goods) + .ThenInclude(x => x.Good) .Include(x => x.User) .Select(x => x.GetViewModel) .ToList(); @@ -23,25 +26,36 @@ namespace HardwareShopDatabaseImplement.Implements.Worker public List GetFilteredList(PurchaseSearchModel model) { using var context = new HardwareShopDatabase(); - if (model.UserId.HasValue) + if (!model.UserId.HasValue) { - return context.Purchases - .Include(x => x.Builds) - .Include(x => x.Goods) - .Include(x => x.User) - .Where(x => x.UserId == model.UserId) - .Select(x => x.GetViewModel) - .ToList(); + return new(); } return context.Purchases - .Include(x => x.Builds) - .Include(x => x.Goods) - .Include(x => x.User) - .Where(x => x.Id == model.Id) - .Select(x => x.GetViewModel) - .ToList(); + .Include(x => x.Builds) + .Include(x => x.Goods) + .ThenInclude(x => x.Good) + .Include(x => x.User) + .Where(x => x.UserId == model.UserId) + .Select(x => x.GetViewModel) + .ToList(); } + public Dictionary GetFilteredListBuild(PurchaseSearchModel model) + { + using var context = new HardwareShopDatabase(); + var listBuilds = context.PurchasesBuilds + .Include(x => x.Build) + .Where(x => x.PurchaseId == model.Id) + .ToList(); + Dictionary? _purchaseBuilds = null; + foreach(var build in listBuilds) + { + _purchaseBuilds.Add(build.BuildId, (build.Count, build.Build)); + } + return _purchaseBuilds; + } + + public PurchaseViewModel? GetElement(PurchaseSearchModel model) { if (!model.Id.HasValue) @@ -52,6 +66,7 @@ namespace HardwareShopDatabaseImplement.Implements.Worker return context.Purchases .Include(x => x.Builds) .Include(x => x.Goods) + .ThenInclude(x => x.Good) .Include(x => x.User) .FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id) ?.GetViewModel; @@ -70,6 +85,7 @@ namespace HardwareShopDatabaseImplement.Implements.Worker return context.Purchases .Include(x => x.Builds) .Include(x => x.Goods) + .ThenInclude(x => x.Good) .Include(x => x.User) .FirstOrDefault(x => x.Id == newPurchase.Id) ?.GetViewModel; @@ -84,6 +100,7 @@ namespace HardwareShopDatabaseImplement.Implements.Worker var purchase = context.Purchases .Include(x => x.Builds) .Include(x => x.Goods) + .ThenInclude(x => x.Good) .Include(x => x.User) .FirstOrDefault(x => x.Id == model.Id); if (purchase == null) @@ -109,6 +126,7 @@ namespace HardwareShopDatabaseImplement.Implements.Worker var element = context.Purchases .Include(x => x.Builds) .Include(x => x.Goods) + .ThenInclude(x => x.Good) .Include(x => x.User) .FirstOrDefault(rec => rec.Id == model.Id); if (element != null) From 3dd37697c8da654341d049388576db76b393f850 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B8=D0=BA=D0=BE=D0=BB=D0=B0=D0=B9?= Date: Sun, 2 Apr 2023 17:15:03 +0400 Subject: [PATCH 09/10] =?UTF-8?q?=D0=B2=D1=80=D0=BE=D0=B4=D0=B5=20=D0=B2?= =?UTF-8?q?=D1=81=D1=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogics/Worker/BuildLogic.cs | 20 ----------------- .../BusinessLogics/Worker/PurchaseLogic.cs | 18 --------------- .../BusinessLogicsContracts/IBuildLogic.cs | 1 - .../BusinessLogicsContracts/IPurchaseLogic.cs | 1 - .../StoragesContracts/IPurchaseStorage.cs | 1 - .../Implements/Worker/PurchaseStorage.cs | 22 ------------------- 6 files changed, 63 deletions(-) diff --git a/HardwareShop/HardwareShopBusinessLogic/BusinessLogics/Worker/BuildLogic.cs b/HardwareShop/HardwareShopBusinessLogic/BusinessLogics/Worker/BuildLogic.cs index c7c96bc..60ad2c5 100644 --- a/HardwareShop/HardwareShopBusinessLogic/BusinessLogics/Worker/BuildLogic.cs +++ b/HardwareShop/HardwareShopBusinessLogic/BusinessLogics/Worker/BuildLogic.cs @@ -118,25 +118,5 @@ namespace HardwareShopContracts.BusinessLogicsContracts throw new InvalidOperationException("Продукт с таким названием уже есть"); } } - - //нужно переделать - public double Price(ComponentSearchModel model) - { - _logger.LogInformation("ReadList. Id:{Id}", model?.Id); - var list = _componentStorage.GetFilteredList(model); - if (list == null) - { - _logger.LogWarning("ReadList return null list"); - return 0; - } - double sum = 0; - foreach (var component in list) - { - sum += component.Cost; - } - _logger.LogInformation("ReadList. Count:{Count}", list.Count); - return sum; - } - } } diff --git a/HardwareShop/HardwareShopBusinessLogic/BusinessLogics/Worker/PurchaseLogic.cs b/HardwareShop/HardwareShopBusinessLogic/BusinessLogics/Worker/PurchaseLogic.cs index 0e7ff6a..8563aac 100644 --- a/HardwareShop/HardwareShopBusinessLogic/BusinessLogics/Worker/PurchaseLogic.cs +++ b/HardwareShop/HardwareShopBusinessLogic/BusinessLogics/Worker/PurchaseLogic.cs @@ -123,23 +123,5 @@ namespace HardwareShopContracts.BusinessLogicsContracts } _logger.LogInformation("Purchase. UserId:{UserId}. PurchaseID:{Id}. Sum:{ Sum}", model.UserId, model.Id, model.Sum); } - - public double Price(PurchaseSearchModel model) - { - _logger.LogInformation("ReadList. Id:{Id}", model?.Id); - var list = _purchaseStorage.GetFilteredListBuild(model); - if (list == null) - { - _logger.LogWarning("ReadList return null list"); - return 0; - } - double sum = 0; - foreach (var build in list) - { - sum += build.Value.Item1* build.Value.Item2.Price; - } - _logger.LogInformation("ReadList. Count:{Count}", list.Count); - return sum; - } } } diff --git a/HardwareShop/HardwareShopContracts/BusinessLogicsContracts/IBuildLogic.cs b/HardwareShop/HardwareShopContracts/BusinessLogicsContracts/IBuildLogic.cs index 0663249..2833e19 100644 --- a/HardwareShop/HardwareShopContracts/BusinessLogicsContracts/IBuildLogic.cs +++ b/HardwareShop/HardwareShopContracts/BusinessLogicsContracts/IBuildLogic.cs @@ -8,7 +8,6 @@ namespace HardwareShopContracts.BusinessLogicsContracts { List? ReadList(BuildSearchModel? model); BuildViewModel? ReadElement(BuildSearchModel model); - double Price(ComponentSearchModel model); bool Create(BuildBindingModel model); bool Update(BuildBindingModel model); bool Delete(BuildBindingModel model); diff --git a/HardwareShop/HardwareShopContracts/BusinessLogicsContracts/IPurchaseLogic.cs b/HardwareShop/HardwareShopContracts/BusinessLogicsContracts/IPurchaseLogic.cs index 265fadb..0882fad 100644 --- a/HardwareShop/HardwareShopContracts/BusinessLogicsContracts/IPurchaseLogic.cs +++ b/HardwareShop/HardwareShopContracts/BusinessLogicsContracts/IPurchaseLogic.cs @@ -8,7 +8,6 @@ namespace HardwareShopContracts.BusinessLogicsContracts { List? ReadList(PurchaseSearchModel? model); CommentViewModel? ReadElement(CommentSearchModel model); - double Price(PurchaseSearchModel model); bool Create(PurchaseBindingModel model); bool Update(PurchaseBindingModel model); bool Delete(PurchaseBindingModel model); diff --git a/HardwareShop/HardwareShopContracts/StoragesContracts/IPurchaseStorage.cs b/HardwareShop/HardwareShopContracts/StoragesContracts/IPurchaseStorage.cs index f75115b..50a1ad4 100644 --- a/HardwareShop/HardwareShopContracts/StoragesContracts/IPurchaseStorage.cs +++ b/HardwareShop/HardwareShopContracts/StoragesContracts/IPurchaseStorage.cs @@ -9,7 +9,6 @@ namespace HardwareShopContracts.StoragesContracts { List GetFullList(); List GetFilteredList(PurchaseSearchModel model); - Dictionary GetFilteredListBuild(PurchaseSearchModel model); PurchaseViewModel? GetElement(PurchaseSearchModel model); PurchaseViewModel? Insert(PurchaseBindingModel model); PurchaseViewModel? Update(PurchaseBindingModel model); diff --git a/HardwareShop/HardwareShopDatabaseImplement/Implements/Worker/PurchaseStorage.cs b/HardwareShop/HardwareShopDatabaseImplement/Implements/Worker/PurchaseStorage.cs index d241852..8013365 100644 --- a/HardwareShop/HardwareShopDatabaseImplement/Implements/Worker/PurchaseStorage.cs +++ b/HardwareShop/HardwareShopDatabaseImplement/Implements/Worker/PurchaseStorage.cs @@ -15,7 +15,6 @@ namespace HardwareShopDatabaseImplement.Implements.Worker { using var context = new HardwareShopDatabase(); return context.Purchases - .Include(x => x.Builds) .Include(x => x.Goods) .ThenInclude(x => x.Good) .Include(x => x.User) @@ -31,7 +30,6 @@ namespace HardwareShopDatabaseImplement.Implements.Worker return new(); } return context.Purchases - .Include(x => x.Builds) .Include(x => x.Goods) .ThenInclude(x => x.Good) .Include(x => x.User) @@ -40,22 +38,6 @@ namespace HardwareShopDatabaseImplement.Implements.Worker .ToList(); } - public Dictionary GetFilteredListBuild(PurchaseSearchModel model) - { - using var context = new HardwareShopDatabase(); - var listBuilds = context.PurchasesBuilds - .Include(x => x.Build) - .Where(x => x.PurchaseId == model.Id) - .ToList(); - Dictionary? _purchaseBuilds = null; - foreach(var build in listBuilds) - { - _purchaseBuilds.Add(build.BuildId, (build.Count, build.Build)); - } - return _purchaseBuilds; - } - - public PurchaseViewModel? GetElement(PurchaseSearchModel model) { if (!model.Id.HasValue) @@ -64,7 +46,6 @@ namespace HardwareShopDatabaseImplement.Implements.Worker } using var context = new HardwareShopDatabase(); return context.Purchases - .Include(x => x.Builds) .Include(x => x.Goods) .ThenInclude(x => x.Good) .Include(x => x.User) @@ -83,7 +64,6 @@ namespace HardwareShopDatabaseImplement.Implements.Worker context.Purchases.Add(newPurchase); context.SaveChanges(); return context.Purchases - .Include(x => x.Builds) .Include(x => x.Goods) .ThenInclude(x => x.Good) .Include(x => x.User) @@ -98,7 +78,6 @@ namespace HardwareShopDatabaseImplement.Implements.Worker try { var purchase = context.Purchases - .Include(x => x.Builds) .Include(x => x.Goods) .ThenInclude(x => x.Good) .Include(x => x.User) @@ -124,7 +103,6 @@ namespace HardwareShopDatabaseImplement.Implements.Worker { using var context = new HardwareShopDatabase(); var element = context.Purchases - .Include(x => x.Builds) .Include(x => x.Goods) .ThenInclude(x => x.Good) .Include(x => x.User) From e7fff05911dc5db202c152db215d151358d86e05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B8=D0=BA=D0=BE=D0=BB=D0=B0=D0=B9?= Date: Sun, 2 Apr 2023 17:41:03 +0400 Subject: [PATCH 10/10] =?UTF-8?q?=D0=BE=D0=B1=D0=BD=D0=BE=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D1=81=D1=83=D0=BC=D0=BC=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Models/Worker/Build.cs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/HardwareShop/HardwareShopDatabaseImplement/Models/Worker/Build.cs b/HardwareShop/HardwareShopDatabaseImplement/Models/Worker/Build.cs index 82c4680..ea70d0b 100644 --- a/HardwareShop/HardwareShopDatabaseImplement/Models/Worker/Build.cs +++ b/HardwareShop/HardwareShopDatabaseImplement/Models/Worker/Build.cs @@ -4,6 +4,7 @@ using HardwareShopDatabaseImplement.Models.ManyToMany; using HardwareShopDataModels.Models; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; +using System.Diagnostics; namespace HardwareShopDatabaseImplement.Models.Worker { @@ -98,10 +99,24 @@ namespace HardwareShopDatabaseImplement.Models.Worker Purchase = context.Purchases.First(x => x.Id == bp.Key), Count = bp.Value.Item2 }); + var purchase = context.Purchases.First(x => x.Id == bp.Key); + if (purchase != null) + { + purchase.Sum += bp.Value.Item2* build.Price; + } context.SaveChanges(); + } _buildPurchases = null; } + + public void UpdateSumPurchase(HardwareShopDatabase context, BuildBindingModel model) + { + var buildPurchases = context.PurchasesBuilds.Where(rec => rec.BuildId == model.Id).ToList(); + + } + + } }