diff --git a/Hospital/HospitalContracts/ViewModels/TreatmentViewModel.cs b/Hospital/HospitalContracts/ViewModels/TreatmentViewModel.cs index 053f991..b610ab1 100644 --- a/Hospital/HospitalContracts/ViewModels/TreatmentViewModel.cs +++ b/Hospital/HospitalContracts/ViewModels/TreatmentViewModel.cs @@ -1,4 +1,5 @@ using HospitalDataModels.Models; +using Newtonsoft.Json; using System.ComponentModel; namespace HospitalContracts.ViewModels @@ -10,5 +11,13 @@ namespace HospitalContracts.ViewModels public string Name { get; set; } = string.Empty; public Dictionary TreatmentProcedures { get; set; } = new(); + + public TreatmentViewModel() { } + + [JsonConstructor] + public TreatmentViewModel(Dictionary TreatmentProcedures) + { + this.TreatmentProcedures = TreatmentProcedures.ToDictionary(x => x.Key, x => x.Value as IProcedureModel); + } } } diff --git a/Hospital/HospitalRestApi/Controllers/TreatmentController.cs b/Hospital/HospitalRestApi/Controllers/TreatmentController.cs new file mode 100644 index 0000000..ae08b64 --- /dev/null +++ b/Hospital/HospitalRestApi/Controllers/TreatmentController.cs @@ -0,0 +1,34 @@ +using HospitalContracts.BusinessLogicContracts; +using HospitalContracts.SearchModels; +using HospitalContracts.ViewModels; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; + +namespace HospitalRestApi.Controllers +{ + [Route("api/[controller]/[action]")] + [ApiController] + public class TreatmentController : ControllerBase + { + private readonly ITreatmentLogic _logic; + + public TreatmentController(ITreatmentLogic logic) + { + _logic = logic; + } + + [HttpGet] + public List? GetTreatments() + { + try + { + return _logic.ReadList(null); + } + catch (Exception ex) + { + throw; + } + } + + } +} diff --git a/Hospital/HospitalWeb/Controllers/RecipeController.cs b/Hospital/HospitalWeb/Controllers/RecipeController.cs index 30bd07c..7d5eedd 100644 --- a/Hospital/HospitalWeb/Controllers/RecipeController.cs +++ b/Hospital/HospitalWeb/Controllers/RecipeController.cs @@ -32,6 +32,7 @@ namespace HospitalWeb.Controllers return Redirect("~/Home/Enter"); } ViewBag.Medicines = APIClient.GetRequest>($"api/medicine/getmedicines"); + ViewBag.Treatments = APIClient.GetRequest>($"api/treatment/gettreatments"); if (!id.HasValue) { return View(new RecipeViewModel()); diff --git a/Hospital/HospitalWeb/Views/Recipe/Create.cshtml b/Hospital/HospitalWeb/Views/Recipe/Create.cshtml index ada2f18..92daef9 100644 --- a/Hospital/HospitalWeb/Views/Recipe/Create.cshtml +++ b/Hospital/HospitalWeb/Views/Recipe/Create.cshtml @@ -31,7 +31,14 @@
- +
Добавление лекарств
+
+ + +
+ +
+
@@ -47,6 +54,27 @@ + } + +
Название
+
+
+ + + + + + + + + @foreach (var treatment in Model.RecipeTreatments) + { + + + + }
Название
@treatment.Value.Name + +
@@ -58,9 +86,13 @@
@foreach (var medicine in Model.RecipeMedicines.Keys) - { + { - } + } + @foreach (var treatment in Model.RecipeTreatments.Keys) + { + + } } @section scripts { @@ -91,6 +123,32 @@ $('#medicinesTable button[data-id="' + medicineId + '"]').closest('tr').remove(); $('#recipe-form input[name="RecipeMedicines[' + medicineId + ']"]').remove(); } + var recipeTreatments = @Json.Serialize(Model.RecipeTreatments); + function addTreatment() { + var treatmentId = $('#treatments').val(); + var treatmentName = $('#treatments option:selected').text(); + if (recipeTreatments.hasOwnProperty(treatmentId)) { + alert('This treatment is already added.'); + return; + } + recipeTreatments[treatmentId] = { Id: treatmentId, Name: treatmentName }; + var row = $('').append($('').text(treatmentName)); + var removeButton = $('