diff --git a/CaseAccounting/CaseAccountingContracts/BindingModels/DealBindingModel.cs b/CaseAccounting/CaseAccountingContracts/BindingModels/DealBindingModel.cs index 3ba33fe..e321d1d 100644 --- a/CaseAccounting/CaseAccountingContracts/BindingModels/DealBindingModel.cs +++ b/CaseAccounting/CaseAccountingContracts/BindingModels/DealBindingModel.cs @@ -1,4 +1,6 @@ -using CaseAccountingDataModels.Models; +using CaseAccountingContracts.ViewModels; +using CaseAccountingDataModels.Models; +using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Linq; @@ -20,5 +22,15 @@ namespace CaseAccountingContracts.BindingModels public int Id { get; set; } public Dictionary Cases { get; set; } = new(); + + public List CaseViewModels { get; set; } = new(); + + public DealBindingModel() { } + + [JsonConstructor] + public DealBindingModel(Dictionary Cases) + { + this.Cases = Cases.ToDictionary(x => x.Key, x => (ICaseModel)x.Value); + } } } diff --git a/CaseAccounting/CaseAccountingContracts/CaseAccountingContracts.csproj b/CaseAccounting/CaseAccountingContracts/CaseAccountingContracts.csproj index 92f1102..fc338d1 100644 --- a/CaseAccounting/CaseAccountingContracts/CaseAccountingContracts.csproj +++ b/CaseAccounting/CaseAccountingContracts/CaseAccountingContracts.csproj @@ -6,6 +6,10 @@ enable + + + + diff --git a/CaseAccounting/CaseAccountingDataBaseImplement/Models/Deal.cs b/CaseAccounting/CaseAccountingDataBaseImplement/Models/Deal.cs index 1b9ea3f..7bc42a9 100644 --- a/CaseAccounting/CaseAccountingDataBaseImplement/Models/Deal.cs +++ b/CaseAccounting/CaseAccountingDataBaseImplement/Models/Deal.cs @@ -64,7 +64,11 @@ namespace CaseAccountingDataBaseImplement.Models Responsibilities = model.Responsibilities, Date = model.Date, UserId = model.UserId, - User = context.Users.FirstOrDefault(x => x.Id == model.UserId) ?? throw new Exception("User не существует") + User = context.Users.FirstOrDefault(x => x.Id == model.UserId) ?? throw new Exception("User не существует"), + CaseDeals = model.Cases.Select(x => new CaseDeal + { + Case = context.Cases.First(y => y.Id == x.Key) + }).ToList() }; } diff --git a/CaseAccounting/CaseAccountingProviderView/CaseAccountingProviderView.csproj b/CaseAccounting/CaseAccountingProviderView/CaseAccountingProviderView.csproj index bf4d8ce..1a0fd54 100644 --- a/CaseAccounting/CaseAccountingProviderView/CaseAccountingProviderView.csproj +++ b/CaseAccounting/CaseAccountingProviderView/CaseAccountingProviderView.csproj @@ -1,4 +1,4 @@ - + net6.0 @@ -12,6 +12,7 @@ + diff --git a/CaseAccounting/CaseAccountingProviderView/Controllers/DealController.cs b/CaseAccounting/CaseAccountingProviderView/Controllers/DealController.cs index b8a5296..f8b1c51 100644 --- a/CaseAccounting/CaseAccountingProviderView/Controllers/DealController.cs +++ b/CaseAccounting/CaseAccountingProviderView/Controllers/DealController.cs @@ -1,5 +1,6 @@ using CaseAccountingContracts.BindingModels; using CaseAccountingContracts.ViewModels; +using CaseAccountingDataModels.Models; using Microsoft.AspNetCore.Mvc; namespace CaseAccountingProviderView.Controllers @@ -23,7 +24,14 @@ namespace CaseAccountingProviderView.Controllers throw new Exception("403"); } dealModel.UserId = APIUser.User.Id; - APIUser.PostRequest("api/deal/create", dealModel); + var dict = new Dictionary(); + foreach (var element in dealModel.CaseViewModels) + { + var caseModel = APIUser.GetRequest($"api/case/get?id={element.Id}"); + dict.Add(element.Id, caseModel); + } + dealModel.Cases = dict; + APIUser.PostRequest("api/deal/create", dealModel); Response.Redirect("/Home/Deals"); } diff --git a/CaseAccounting/CaseAccountingProviderView/Views/Deal/Create.cshtml b/CaseAccounting/CaseAccountingProviderView/Views/Deal/Create.cshtml index 82a36e5..78666c5 100644 --- a/CaseAccounting/CaseAccountingProviderView/Views/Deal/Create.cshtml +++ b/CaseAccounting/CaseAccountingProviderView/Views/Deal/Create.cshtml @@ -17,6 +17,25 @@

Дата составления:

+
+
+ + + + + + + + + + + + + +
Номер дела:Истец:Ответчик:Дата составления:Примечание:Специализация:
+
+
+ diff --git a/CaseAccounting/CaseAccountingProviderView/wwwroot/css/site.css b/CaseAccounting/CaseAccountingProviderView/wwwroot/css/site.css index f27e5ad..70b730a 100644 --- a/CaseAccounting/CaseAccountingProviderView/wwwroot/css/site.css +++ b/CaseAccounting/CaseAccountingProviderView/wwwroot/css/site.css @@ -15,4 +15,13 @@ html { body { margin-bottom: 60px; +} + +.scrollable-table { + max-height: 400px; + overflow-y: auto; +} + +.scrollable-table tr { + transition: background-color 0.3s ease; } \ No newline at end of file diff --git a/CaseAccounting/CaseAccountingProviderView/wwwroot/js/deal/deal-create.js b/CaseAccounting/CaseAccountingProviderView/wwwroot/js/deal/deal-create.js index e2db6f9..fefc4f5 100644 --- a/CaseAccounting/CaseAccountingProviderView/wwwroot/js/deal/deal-create.js +++ b/CaseAccounting/CaseAccountingProviderView/wwwroot/js/deal/deal-create.js @@ -2,6 +2,37 @@ const subjectInput = document.getElementById("subject-input"); const responsibilitiesInput = document.getElementById("responsibilities-input"); const dateInput = document.getElementById("date-input"); +const tbody = document.getElementById("scrollable-table__tbody") + +var cases = []; +var dataArray = []; + +window.addEventListener("load", async () => { + try { + await $.ajax({ + url: `/case/getallbyuser`, + type: "GET", + contentType: "json" + }).done((result) => { + cases = result; + cases.forEach((caseModel) => { + const { id, name, applicant, defendant, annotation, date, specialization } = caseModel; + const row = tbody.insertRow(); + row.setAttribute("data-id", id); + + const cells = [name, applicant, defendant, annotation, date, specialization]; + cells.forEach((value) => { + const cell = row.insertCell(); + cell.textContent = value; + }); + + row.addEventListener('click', () => addAndRemoveFromList(row)); + }); + }); + } catch (error) { + console.error(error); + } +}); createBtn.addEventListener("click", () => { if (!correctData()) { @@ -26,7 +57,8 @@ createBtn.addEventListener("click", () => { let dealModel = { "Subject": subjectInput.value, "Responsibilities": responsibilitiesInput.value, - "Date": new Date(dateInput.value) + "Date": new Date(dateInput.value), + "CaseViewModels": dataArray }; console.log(dealModel) $.ajax({ @@ -37,4 +69,18 @@ createBtn.addEventListener("click", () => { }).done(() => { window.location.href = "/Home/Deals"; }); -}); \ No newline at end of file +}); + +const addAndRemoveFromList = (row) => { + var id = parseInt(row.dataset.id); + console.log(cases.find(x => x.id === id)) + var index = dataArray.indexOf(cases.find(x => x.id === id)); + if (index === -1) { + dataArray.push(cases.find(x => x.id === id)); + row.classList.add("bg-primary"); + } else { + dataArray.splice(index, 1); + row.classList.remove("bg-primary"); + } + console.log(dataArray); +} \ No newline at end of file diff --git a/CaseAccounting/CaseAccountingRestApi/CaseAccountingRestApi.csproj b/CaseAccounting/CaseAccountingRestApi/CaseAccountingRestApi.csproj index a925a15..188ff97 100644 --- a/CaseAccounting/CaseAccountingRestApi/CaseAccountingRestApi.csproj +++ b/CaseAccounting/CaseAccountingRestApi/CaseAccountingRestApi.csproj @@ -1,4 +1,4 @@ - + net6.0 @@ -7,6 +7,7 @@ + all runtime; build; native; contentfiles; analyzers; buildtransitive @@ -19,6 +20,7 @@ + diff --git a/CaseAccounting/CaseAccountingRestApi/Program.cs b/CaseAccounting/CaseAccountingRestApi/Program.cs index e0098d2..f0ee39e 100644 --- a/CaseAccounting/CaseAccountingRestApi/Program.cs +++ b/CaseAccounting/CaseAccountingRestApi/Program.cs @@ -26,6 +26,8 @@ builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); +builder.Services.AddControllers().AddNewtonsoftJson(); + builder.Services.AddControllers(); // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle builder.Services.AddEndpointsApiExplorer();