diff --git a/CarCenter/CarCenterContracts/BindingModels/BundlingBindingModel.cs b/CarCenter/CarCenterContracts/BindingModels/BundlingBindingModel.cs index 5eb7625..7859172 100644 --- a/CarCenter/CarCenterContracts/BindingModels/BundlingBindingModel.cs +++ b/CarCenter/CarCenterContracts/BindingModels/BundlingBindingModel.cs @@ -17,5 +17,6 @@ namespace CarCenterContracts.BindingModels public double Price { get; set; } public int StorekeeperId { get; set; } public DateTime DateCreate { get; set; } + public Dictionary BundlingsPresale { get; set; } = new(); } } diff --git a/CarCenter/CarCenterContracts/ViewModels/BundlingViewModel.cs b/CarCenter/CarCenterContracts/ViewModels/BundlingViewModel.cs index 6291291..b8d3f86 100644 --- a/CarCenter/CarCenterContracts/ViewModels/BundlingViewModel.cs +++ b/CarCenter/CarCenterContracts/ViewModels/BundlingViewModel.cs @@ -23,5 +23,6 @@ namespace CarCenterContracts.ViewModels public double Price { get; set; } [DisplayName("Дата создания")] public DateTime DateCreate { get; set; } + public Dictionary BundlingsPresale { get; set; } = new(); } } diff --git a/CarCenter/CarCenterDatabaseImplement/Migrations/20240529143434_preFin.Designer.cs b/CarCenter/CarCenterDatabaseImplement/Migrations/20240529170508_predFin2.Designer.cs similarity index 99% rename from CarCenter/CarCenterDatabaseImplement/Migrations/20240529143434_preFin.Designer.cs rename to CarCenter/CarCenterDatabaseImplement/Migrations/20240529170508_predFin2.Designer.cs index c90b032..22fc028 100644 --- a/CarCenter/CarCenterDatabaseImplement/Migrations/20240529143434_preFin.Designer.cs +++ b/CarCenter/CarCenterDatabaseImplement/Migrations/20240529170508_predFin2.Designer.cs @@ -12,8 +12,8 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; namespace CarCenterDatabaseImplement.Migrations { [DbContext(typeof(CarCenterDatabase))] - [Migration("20240529143434_preFin")] - partial class preFin + [Migration("20240529170508_predFin2")] + partial class predFin2 { protected override void BuildTargetModel(ModelBuilder modelBuilder) { diff --git a/CarCenter/CarCenterDatabaseImplement/Migrations/20240529143434_preFin.cs b/CarCenter/CarCenterDatabaseImplement/Migrations/20240529170508_predFin2.cs similarity index 99% rename from CarCenter/CarCenterDatabaseImplement/Migrations/20240529143434_preFin.cs rename to CarCenter/CarCenterDatabaseImplement/Migrations/20240529170508_predFin2.cs index 42baa92..9554e73 100644 --- a/CarCenter/CarCenterDatabaseImplement/Migrations/20240529143434_preFin.cs +++ b/CarCenter/CarCenterDatabaseImplement/Migrations/20240529170508_predFin2.cs @@ -6,7 +6,7 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; namespace CarCenterDatabaseImplement.Migrations { - public partial class preFin : Migration + public partial class predFin2 : Migration { protected override void Up(MigrationBuilder migrationBuilder) { diff --git a/CarCenter/CarCenterStorekeeperApp/Controllers/HomeController.cs b/CarCenter/CarCenterStorekeeperApp/Controllers/HomeController.cs index 18a2b74..8a111db 100644 --- a/CarCenter/CarCenterStorekeeperApp/Controllers/HomeController.cs +++ b/CarCenter/CarCenterStorekeeperApp/Controllers/HomeController.cs @@ -7,6 +7,7 @@ using System.Diagnostics; using System.IO; using System.Numerics; using CarCenterDataModels.Enums; +using CarCenterDatabaseImplement.Models; namespace CarCenterStorekeeperApp.Controllers { @@ -93,6 +94,8 @@ namespace CarCenterStorekeeperApp.Controllers [HttpGet] public IActionResult CreateBundling(int id) { + var presales = _data.GetPresales(); + ViewBag.AllPresales = presales; if (id != 0) { var value = _data.GetBundling(id); @@ -102,18 +105,28 @@ namespace CarCenterStorekeeperApp.Controllers return View(new BundlingViewModel()); } [HttpPost] - public IActionResult CreateBundling(BundlingBindingModel model) + public IActionResult CreateBundling(BundlingBindingModel model, int[] presaleIds) { - - if (model.Id == 0) + var presales = _data.GetPresales(); + if (model.Id == 0) { model.DateCreate = DateTime.Now; model.StorekeeperId = UserStorekeeper.user!.Id; - if (_data.CreateBundling(model)) + for (int i = 0; i < presaleIds.Length; i++) + { + var presale = presales!.FirstOrDefault(x => x.Id == presaleIds[i])!; + model.BundlingsPresale.Add(i, presale); + } + if (_data.CreateBundling(model)) return RedirectToAction("IndexBundling"); } else { + for (int i = 0; i < presaleIds.Length; i++) + { + var presale = presales!.FirstOrDefault(x => x.Id == presaleIds[i])!; + model.BundlingsPresale.Add(i, presale); + } model.StorekeeperId = UserStorekeeper.user!.Id; if (_data.UpdateBundling(model)) return RedirectToAction("IndexBundling"); diff --git a/CarCenter/CarCenterStorekeeperApp/Views/Home/CreateBundling.cshtml b/CarCenter/CarCenterStorekeeperApp/Views/Home/CreateBundling.cshtml index b0484b2..dceaf88 100644 --- a/CarCenter/CarCenterStorekeeperApp/Views/Home/CreateBundling.cshtml +++ b/CarCenter/CarCenterStorekeeperApp/Views/Home/CreateBundling.cshtml @@ -2,6 +2,7 @@ @using CarCenterDataModels.Enums; @{ ViewData["Title"] = "CreateBundling"; + ViewBag.Presales = Model.BundlingsPresale; } @model BundlingViewModel;
@@ -45,6 +46,43 @@
+ @if (ViewBag.AllPresales != null && ViewBag.AllPresales.Count != 0) + { +
+
Комлектации
+
+ + + + + + + + + + @foreach (var presale in ViewBag.Presales) + { + + + + + + } + +
ID комплектации Удалить
+ @presale.Value.Id +
+
+ + +
+ }
Цена:
@@ -61,6 +99,49 @@