diff --git a/CarCenter/CarCenterContracts/BindingModels/PresaleBindingModel.cs b/CarCenter/CarCenterContracts/BindingModels/PresaleBindingModel.cs index 4b7084c..e53d64b 100644 --- a/CarCenter/CarCenterContracts/BindingModels/PresaleBindingModel.cs +++ b/CarCenter/CarCenterContracts/BindingModels/PresaleBindingModel.cs @@ -20,5 +20,7 @@ namespace CarCenterContracts.BindingModels public double Price { get; set; } public Dictionary PresaleBundlings { get; set; } = new(); - } + + public List RequestIds { get; set; } = new(); + } } diff --git a/CarCenter/CarCenterContracts/ViewModels/RequestViewModel.cs b/CarCenter/CarCenterContracts/ViewModels/RequestViewModel.cs index 5d29204..7ef4068 100644 --- a/CarCenter/CarCenterContracts/ViewModels/RequestViewModel.cs +++ b/CarCenter/CarCenterContracts/ViewModels/RequestViewModel.cs @@ -12,7 +12,7 @@ namespace CarCenterContracts.ViewModels public class RequestViewModel : IRequestModel { public int Id { get; set; } - public int PresaleId { get; set; } + public int? PresaleId { get; set; } [DisplayName("Описание пожелания")] public string Description { get; set; } = string.Empty; [DisplayName("Тип пожелания")] diff --git a/CarCenter/CarCenterDatabaseImplement/Implements/PresaleStorage.cs b/CarCenter/CarCenterDatabaseImplement/Implements/PresaleStorage.cs index eb7abe1..f2f055d 100644 --- a/CarCenter/CarCenterDatabaseImplement/Implements/PresaleStorage.cs +++ b/CarCenter/CarCenterDatabaseImplement/Implements/PresaleStorage.cs @@ -85,7 +85,8 @@ namespace CarCenterDatabaseImplement.Implements return context.Presales .Include(x => x.Bundlings) .ThenInclude(x => x.Bundling) - .FirstOrDefault(x => x.Id == newPresale.Id) + .Include(x => x.Requests) + .FirstOrDefault(x => x.Id == newPresale.Id) ?.GetViewModel; } diff --git a/CarCenter/CarCenterDatabaseImplement/Implements/WorkerStorage.cs b/CarCenter/CarCenterDatabaseImplement/Implements/WorkerStorage.cs index 442e698..2eb5dae 100644 --- a/CarCenter/CarCenterDatabaseImplement/Implements/WorkerStorage.cs +++ b/CarCenter/CarCenterDatabaseImplement/Implements/WorkerStorage.cs @@ -42,12 +42,9 @@ namespace CarCenterDatabaseImplement.Implements public WorkerViewModel? GetElement(WorkerSearchModel model) { using var context = new CarCenterDatabase(); - - if (model.Id.HasValue) - return context.Workers - .FirstOrDefault(x => x.Id == model.Id) - ?.GetViewModel; - return null; + if (!model.Id.HasValue && string.IsNullOrEmpty(model.Email)) { return null; } + return context.Workers.FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id) + || (!string.IsNullOrEmpty(model.Email) && !string.IsNullOrEmpty(model.Password) && x.Email.Equals(model.Email) && x.Password.Equals(model.Password)))?.GetViewModel; } diff --git a/CarCenter/CarCenterDatabaseImplement/Migrations/20240529111244_Test.Designer.cs b/CarCenter/CarCenterDatabaseImplement/Migrations/20240529111244_Test.Designer.cs new file mode 100644 index 0000000..97bc8b7 --- /dev/null +++ b/CarCenter/CarCenterDatabaseImplement/Migrations/20240529111244_Test.Designer.cs @@ -0,0 +1,509 @@ +// +using System; +using CarCenterDatabaseImplement; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace CarCenterDatabaseImplement.Migrations +{ + [DbContext(typeof(CarCenterDatabase))] + [Migration("20240529111244_Test")] + partial class Test + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "6.0.29") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("CarCenterDatabaseImplement.Models.Bundling", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("EquipmentPackage") + .HasColumnType("integer"); + + b.Property("Price") + .HasColumnType("double precision"); + + b.Property("StorekeeperId") + .HasColumnType("integer"); + + b.Property("TirePackage") + .HasColumnType("integer"); + + b.Property("ToolKit") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.ToTable("Bundlings"); + }); + + modelBuilder.Entity("CarCenterDatabaseImplement.Models.Car", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CarBrand") + .HasColumnType("integer"); + + b.Property("CarClass") + .HasColumnType("integer"); + + b.Property("FeatureID") + .HasColumnType("integer"); + + b.Property("FeatureId") + .HasColumnType("integer"); + + b.Property("Model") + .IsRequired() + .HasColumnType("text"); + + b.Property("OrderId") + .HasColumnType("integer"); + + b.Property("Price") + .HasColumnType("double precision"); + + b.Property("StorekeeperId") + .HasColumnType("integer"); + + b.Property("VINnumber") + .HasColumnType("bigint"); + + b.Property("Year") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("FeatureId"); + + b.HasIndex("OrderId"); + + b.HasIndex("StorekeeperId"); + + b.ToTable("Cars"); + }); + + modelBuilder.Entity("CarCenterDatabaseImplement.Models.CarBundling", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("BundlingId") + .HasColumnType("integer"); + + b.Property("CarId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("BundlingId"); + + b.HasIndex("CarId"); + + b.ToTable("CarBundlings"); + }); + + modelBuilder.Entity("CarCenterDatabaseImplement.Models.Feature", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CabinColor") + .IsRequired() + .HasColumnType("text"); + + b.Property("DriveType") + .HasColumnType("integer"); + + b.Property("HelpDevice") + .HasColumnType("integer"); + + b.Property("Price") + .HasColumnType("double precision"); + + b.Property("StorekeeperId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.ToTable("Features"); + }); + + modelBuilder.Entity("CarCenterDatabaseImplement.Models.Order", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("BuyerFCS") + .IsRequired() + .HasColumnType("text"); + + b.Property("PaymentDate") + .HasColumnType("timestamp without time zone"); + + b.Property("PaymentStatus") + .HasColumnType("integer"); + + b.Property("PaymentType") + .HasColumnType("integer"); + + b.Property("Sum") + .HasColumnType("double precision"); + + b.Property("WorkerId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("WorkerId"); + + b.ToTable("Orders"); + }); + + modelBuilder.Entity("CarCenterDatabaseImplement.Models.OrderPresale", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("OrderId") + .HasColumnType("integer"); + + b.Property("PresaleId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("OrderId"); + + b.HasIndex("PresaleId"); + + b.ToTable("OrderPresales"); + }); + + modelBuilder.Entity("CarCenterDatabaseImplement.Models.Presale", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Description") + .IsRequired() + .HasColumnType("text"); + + b.Property("DueTill") + .HasColumnType("timestamp without time zone"); + + b.Property("PresaleStatus") + .HasColumnType("integer"); + + b.Property("Price") + .HasColumnType("double precision"); + + b.Property("WorkerId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.ToTable("Presales"); + }); + + modelBuilder.Entity("CarCenterDatabaseImplement.Models.PresaleBundling", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("BundlingId") + .HasColumnType("integer"); + + b.Property("PresaleId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("BundlingId"); + + b.HasIndex("PresaleId"); + + b.ToTable("PresaleBundlings"); + }); + + modelBuilder.Entity("CarCenterDatabaseImplement.Models.Request", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Description") + .IsRequired() + .HasColumnType("text"); + + b.Property("PresaleId") + .HasColumnType("integer"); + + b.Property("RequestType") + .HasColumnType("integer"); + + b.Property("WorkerId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("PresaleId"); + + b.ToTable("Requests"); + }); + + modelBuilder.Entity("CarCenterDatabaseImplement.Models.Storekeeper", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Email") + .IsRequired() + .HasColumnType("text"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("Password") + .IsRequired() + .HasColumnType("text"); + + b.Property("Patronymic") + .HasColumnType("text"); + + b.Property("PhoneNumber") + .HasColumnType("bigint"); + + b.Property("Surname") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Storekeepers"); + }); + + modelBuilder.Entity("CarCenterDatabaseImplement.Models.Worker", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Email") + .IsRequired() + .HasColumnType("text"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("Password") + .IsRequired() + .HasColumnType("text"); + + b.Property("Patronymic") + .HasColumnType("text"); + + b.Property("PhoneNumber") + .HasColumnType("bigint"); + + b.Property("Surname") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Workers"); + }); + + modelBuilder.Entity("CarCenterDatabaseImplement.Models.Car", b => + { + b.HasOne("CarCenterDatabaseImplement.Models.Feature", "Feature") + .WithMany("Cars") + .HasForeignKey("FeatureId"); + + b.HasOne("CarCenterDatabaseImplement.Models.Order", "Order") + .WithMany("Cars") + .HasForeignKey("OrderId"); + + b.HasOne("CarCenterDatabaseImplement.Models.Storekeeper", "Storekeeper") + .WithMany("Cars") + .HasForeignKey("StorekeeperId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Feature"); + + b.Navigation("Order"); + + b.Navigation("Storekeeper"); + }); + + modelBuilder.Entity("CarCenterDatabaseImplement.Models.CarBundling", b => + { + b.HasOne("CarCenterDatabaseImplement.Models.Bundling", "Bundling") + .WithMany("CarBundling") + .HasForeignKey("BundlingId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("CarCenterDatabaseImplement.Models.Car", "Car") + .WithMany("Bundlings") + .HasForeignKey("CarId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Bundling"); + + b.Navigation("Car"); + }); + + modelBuilder.Entity("CarCenterDatabaseImplement.Models.Order", b => + { + b.HasOne("CarCenterDatabaseImplement.Models.Worker", "Worker") + .WithMany("Orders") + .HasForeignKey("WorkerId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Worker"); + }); + + modelBuilder.Entity("CarCenterDatabaseImplement.Models.OrderPresale", b => + { + b.HasOne("CarCenterDatabaseImplement.Models.Order", "Order") + .WithMany("Presales") + .HasForeignKey("OrderId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("CarCenterDatabaseImplement.Models.Presale", "Presale") + .WithMany("OrderPresales") + .HasForeignKey("PresaleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Order"); + + b.Navigation("Presale"); + }); + + modelBuilder.Entity("CarCenterDatabaseImplement.Models.PresaleBundling", b => + { + b.HasOne("CarCenterDatabaseImplement.Models.Bundling", "Bundling") + .WithMany("PresaleBundling") + .HasForeignKey("BundlingId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("CarCenterDatabaseImplement.Models.Presale", "Presale") + .WithMany("Bundlings") + .HasForeignKey("PresaleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Bundling"); + + b.Navigation("Presale"); + }); + + modelBuilder.Entity("CarCenterDatabaseImplement.Models.Request", b => + { + b.HasOne("CarCenterDatabaseImplement.Models.Presale", "Presale") + .WithMany("Requests") + .HasForeignKey("PresaleId"); + + b.Navigation("Presale"); + }); + + modelBuilder.Entity("CarCenterDatabaseImplement.Models.Bundling", b => + { + b.Navigation("CarBundling"); + + b.Navigation("PresaleBundling"); + }); + + modelBuilder.Entity("CarCenterDatabaseImplement.Models.Car", b => + { + b.Navigation("Bundlings"); + }); + + modelBuilder.Entity("CarCenterDatabaseImplement.Models.Feature", b => + { + b.Navigation("Cars"); + }); + + modelBuilder.Entity("CarCenterDatabaseImplement.Models.Order", b => + { + b.Navigation("Cars"); + + b.Navigation("Presales"); + }); + + modelBuilder.Entity("CarCenterDatabaseImplement.Models.Presale", b => + { + b.Navigation("Bundlings"); + + b.Navigation("OrderPresales"); + + b.Navigation("Requests"); + }); + + modelBuilder.Entity("CarCenterDatabaseImplement.Models.Storekeeper", b => + { + b.Navigation("Cars"); + }); + + modelBuilder.Entity("CarCenterDatabaseImplement.Models.Worker", b => + { + b.Navigation("Orders"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/CarCenter/CarCenterDatabaseImplement/Migrations/20240529111244_Test.cs b/CarCenter/CarCenterDatabaseImplement/Migrations/20240529111244_Test.cs new file mode 100644 index 0000000..959a2b3 --- /dev/null +++ b/CarCenter/CarCenterDatabaseImplement/Migrations/20240529111244_Test.cs @@ -0,0 +1,78 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace CarCenterDatabaseImplement.Migrations +{ + public partial class Test : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_Requests_Presales_PresaleId", + table: "Requests"); + + migrationBuilder.AlterColumn( + name: "PresaleId", + table: "Requests", + type: "integer", + nullable: true, + oldClrType: typeof(int), + oldType: "integer"); + + migrationBuilder.AddColumn( + name: "WorkerId", + table: "Requests", + type: "integer", + nullable: false, + defaultValue: 0); + + migrationBuilder.AddColumn( + name: "WorkerId", + table: "Presales", + type: "integer", + nullable: false, + defaultValue: 0); + + migrationBuilder.AddForeignKey( + name: "FK_Requests_Presales_PresaleId", + table: "Requests", + column: "PresaleId", + principalTable: "Presales", + principalColumn: "Id"); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_Requests_Presales_PresaleId", + table: "Requests"); + + migrationBuilder.DropColumn( + name: "WorkerId", + table: "Requests"); + + migrationBuilder.DropColumn( + name: "WorkerId", + table: "Presales"); + + migrationBuilder.AlterColumn( + name: "PresaleId", + table: "Requests", + type: "integer", + nullable: false, + defaultValue: 0, + oldClrType: typeof(int), + oldType: "integer", + oldNullable: true); + + migrationBuilder.AddForeignKey( + name: "FK_Requests_Presales_PresaleId", + table: "Requests", + column: "PresaleId", + principalTable: "Presales", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + } + } +} diff --git a/CarCenter/CarCenterDatabaseImplement/Migrations/CarCenterDatabaseModelSnapshot.cs b/CarCenter/CarCenterDatabaseImplement/Migrations/CarCenterDatabaseModelSnapshot.cs index 6b18836..ca1ccaf 100644 --- a/CarCenter/CarCenterDatabaseImplement/Migrations/CarCenterDatabaseModelSnapshot.cs +++ b/CarCenter/CarCenterDatabaseImplement/Migrations/CarCenterDatabaseModelSnapshot.cs @@ -230,6 +230,9 @@ namespace CarCenterDatabaseImplement.Migrations b.Property("Price") .HasColumnType("double precision"); + b.Property("WorkerId") + .HasColumnType("integer"); + b.HasKey("Id"); b.ToTable("Presales"); @@ -270,12 +273,15 @@ namespace CarCenterDatabaseImplement.Migrations .IsRequired() .HasColumnType("text"); - b.Property("PresaleId") + b.Property("PresaleId") .HasColumnType("integer"); b.Property("RequestType") .HasColumnType("integer"); + b.Property("WorkerId") + .HasColumnType("integer"); + b.HasKey("Id"); b.HasIndex("PresaleId"); @@ -448,9 +454,7 @@ namespace CarCenterDatabaseImplement.Migrations { b.HasOne("CarCenterDatabaseImplement.Models.Presale", "Presale") .WithMany("Requests") - .HasForeignKey("PresaleId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); + .HasForeignKey("PresaleId"); b.Navigation("Presale"); }); diff --git a/CarCenter/CarCenterDatabaseImplement/Models/Presale.cs b/CarCenter/CarCenterDatabaseImplement/Models/Presale.cs index f2bbd9d..3bd83bf 100644 --- a/CarCenter/CarCenterDatabaseImplement/Models/Presale.cs +++ b/CarCenter/CarCenterDatabaseImplement/Models/Presale.cs @@ -49,7 +49,7 @@ namespace CarCenterDatabaseImplement.Models { return null; } - return new Presale() + var presale = new Presale() { Id = model.Id, PresaleStatus = model.PresaleStatus, @@ -62,6 +62,17 @@ namespace CarCenterDatabaseImplement.Models Bundling = context.Bundlings.First(y => y.Id == x.Key) }).ToList() }; + + foreach (var requestId in model.RequestIds) + { + var request = context.Requests.FirstOrDefault(x => x.Id == requestId); + if (request != null) + { + presale.Requests.Add(request); + } + } + + return presale; } public void UpdateBundlings(CarCenterDatabase context, PresaleBindingModel model) @@ -78,8 +89,16 @@ namespace CarCenterDatabaseImplement.Models } _presaleBundlings = null; } - - public void Update(PresaleBindingModel? model) + public void AddRequests(CarCenterDatabase context, List requestIds) + { + var presale = context.Presales.First(x => x.Id == Id); + foreach (var requestId in requestIds) + { + var request = context.Requests.First(x => x.Id == requestId); + presale.Requests.Add(request); + } + } + public void Update(PresaleBindingModel? model) { if (model == null) { diff --git a/CarCenter/CarCenterDatabaseImplement/Models/Request.cs b/CarCenter/CarCenterDatabaseImplement/Models/Request.cs index 21fceb2..085f392 100644 --- a/CarCenter/CarCenterDatabaseImplement/Models/Request.cs +++ b/CarCenter/CarCenterDatabaseImplement/Models/Request.cs @@ -15,12 +15,12 @@ namespace CarCenterDatabaseImplement.Models { public int Id { get; set; } public int WorkerId { get; set; } - public int PresaleId { get; set; } + public int? PresaleId { get; set; } [Required] public string Description { get; set; } = string.Empty; [Required] public RequestTypes RequestType { get; set; } = RequestTypes.Неизвестно; - public virtual Presale Presale { get; set; } + public virtual Presale? Presale { get; set; } public static Request? Create(RequestBindingModel? model) { diff --git a/CarCenter/CarCenterWorkerApp/Controllers/HomeController.cs b/CarCenter/CarCenterWorkerApp/Controllers/HomeController.cs index a4906c6..659c888 100644 --- a/CarCenter/CarCenterWorkerApp/Controllers/HomeController.cs +++ b/CarCenter/CarCenterWorkerApp/Controllers/HomeController.cs @@ -1,6 +1,7 @@ using CarCenterContracts.BindingModels; using CarCenterContracts.ViewModels; using CarCenterDatabaseImplement.Models; +using CarCenterDataModels.Enums; using CarCenterWorkerApp.Models; using Microsoft.AspNetCore.Mvc; using System.Diagnostics; @@ -109,15 +110,8 @@ namespace CarCenterWorkerApp.Controllers return View(new RequestViewModel()); } [HttpPost] - public IActionResult CreateRequest(RequestBindingModel model, int[] presalesIds) + public IActionResult CreateRequest(RequestBindingModel model) { - var presales = _data.GetPresales(UserWorker.user!.Id); - for (int i = 0; i < presalesIds.Length; i++) - { - var presale = presales!.FirstOrDefault(x => x.Id == presalesIds[i])!; - model.RequestPresales[presalesIds[i]] = presale; - sum += presale.Price; - } if (model.Id == 0) { model.WorkerId = UserWorker.user!.Id; @@ -133,5 +127,69 @@ namespace CarCenterWorkerApp.Controllers return View(); } - } + [HttpGet] + public IActionResult IndexPresale() + { + if (UserWorker.user != null) + { + var productions = _data.GetPresales(UserWorker.user.Id); + return View(productions); + } + return RedirectToAction("IndexNonReg"); + } + [HttpPost] + public IActionResult IndexPresale(int id) + { + _data.DeletePresale(id); + return RedirectToAction("IndexPresale"); + } + [HttpGet] + public IActionResult CreatePresale(int id) + { + var bundlings = _data.GetBundlings(); + var requests = _data.GetRequests(UserWorker.user!.Id); + ViewBag.AllBundlings = bundlings; + ViewBag.Requests = requests; + if (id != 0) + { + var value = _data.GetPresale(id); + if (value != null) + return View(value); + } + return View(new PresaleViewModel()); + } + [HttpPost] + public IActionResult CreatePresale(PresaleBindingModel model,int[] bundlingIds) + { + var bundlings = _data.GetBundlings(); + for (int i = 0; i < bundlingIds.Length; i++) + { + var bundling = bundlings!.FirstOrDefault(x => x.Id == bundlingIds[i])!; + model.PresaleBundlings.Add(i, bundling); + } + var requests = _data.GetRequests(UserWorker.user!.Id); + model.RequestIds = model.RequestIds.Where(id => requests.Any(r => r.Id == id)).ToList(); + + bool changed = false; + if (model.PresaleBundlings.Count > 0) + { + if (model.Id != 0) + { + changed = _data.UpdatePresale(model); + } + else + { + changed = _data.CreatePresale(model); + } + } + if (changed) + return RedirectToAction("IndexPresale"); + else + { + ViewBag.AllBundlings = bundlings; + return View(model); + } + } + + } } \ No newline at end of file diff --git a/CarCenter/CarCenterWorkerApp/Views/Home/Enter.cshtml b/CarCenter/CarCenterWorkerApp/Views/Home/Enter.cshtml index c4f3e69..2d351bc 100644 --- a/CarCenter/CarCenterWorkerApp/Views/Home/Enter.cshtml +++ b/CarCenter/CarCenterWorkerApp/Views/Home/Enter.cshtml @@ -1,23 +1,21 @@ -@{ - ViewData["Title"] = "Enter"; +@{ + ViewData["Title"] = "Enter"; } +
-

Вход в приложение

+

Вход в приложение

-
-
Логин(почта):
-
-
-
-
Пароль:
-
-
-
-
-
- -
-
-
\ No newline at end of file +
+
Логин:
+
+
+
+
Пароль:
+
+
+
+
+
+
+ \ No newline at end of file diff --git a/CarCenter/CarCenterWorkerApp/Views/Home/Index.cshtml b/CarCenter/CarCenterWorkerApp/Views/Home/Index.cshtml index aa92909..7163445 100644 --- a/CarCenter/CarCenterWorkerApp/Views/Home/Index.cshtml +++ b/CarCenter/CarCenterWorkerApp/Views/Home/Index.cshtml @@ -3,5 +3,14 @@ } diff --git a/CarCenter/CarCenterWorkerApp/WorkerData.cs b/CarCenter/CarCenterWorkerApp/WorkerData.cs index d87db63..a4c3dbd 100644 --- a/CarCenter/CarCenterWorkerApp/WorkerData.cs +++ b/CarCenter/CarCenterWorkerApp/WorkerData.cs @@ -3,6 +3,7 @@ using CarCenterContracts.ViewModels; using CarCenterContracts.BindingModels; using CarCenterContracts.StoragesContracts; using CarCenterContracts.SearchModels; +using CarCenterBusinessLogic.BusinessLogics; namespace WorkerApp { @@ -13,17 +14,19 @@ namespace WorkerApp private readonly IPresaleLogic _presaleLogic; private readonly IRequestLogic _requestLogic; private readonly IOrderLogic _orderLogic; + private readonly IBundlingLogic _bundlingLogic; - public WorkerData(ILogger logger, IWorkerLogic storekeeperLogic, IPresaleLogic presaleLogic, IRequestLogic requestLogic, IOrderLogic orderLogic) - { - _logger = logger; - _storekeeperLogic = storekeeperLogic; - _presaleLogic = presaleLogic; - _requestLogic = requestLogic; - _orderLogic = orderLogic; - } + public WorkerData(ILogger logger, IWorkerLogic storekeeperLogic, IPresaleLogic presaleLogic, IRequestLogic requestLogic, IOrderLogic orderLogic, IBundlingLogic bundlingLogic) + { + _logger = logger; + _storekeeperLogic = storekeeperLogic; + _presaleLogic = presaleLogic; + _requestLogic = requestLogic; + _orderLogic = orderLogic; + _bundlingLogic = bundlingLogic; + } - public WorkerViewModel? Login(string email, string password) + public WorkerViewModel? Login(string email, string password) { return _storekeeperLogic.ReadElement(new() { @@ -100,6 +103,9 @@ namespace WorkerApp { return _orderLogic.Delete(new() { Id = orderId }); } - - } + public List? GetBundlings() + { + return _bundlingLogic.ReadList(null); + } + } }