From 9f44ad75bebbe9a36ef911673fb15d29ba58864c Mon Sep 17 00:00:00 2001 From: "ns.potapov" Date: Sun, 26 May 2024 13:03:03 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9E=D0=B1=D0=BD=D0=BE=D0=B2=D0=B8=D0=BB=20?= =?UTF-8?q?=D1=81=D1=85=D0=B5=D0=BC=D1=83=20=D0=91=D0=94,=20=D1=80=D0=B0?= =?UTF-8?q?=D0=B7=D1=80=D0=B5=D1=88=D0=B8=D0=BB=20null=20=D0=BD=D0=B0=20?= =?UTF-8?q?=D0=BA=D0=BE=D0=BC=D0=BC=D0=B5=D0=BD=D1=82=D0=B0=D1=80=D0=B8?= =?UTF-8?q?=D1=8F=D1=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BindingModels/DiagnoseBindingModel.cs | 6 +-- .../ViewModels/DiagnoseViewModel.cs | 2 +- .../Models/IDiagnoseModel.cs | 2 +- .../Migrations/20240501145526_Init-Create.cs | 12 ++--- .../Models/Diagnose.cs | 3 +- .../Models/Medicament.cs | 1 - .../Models/Procedure.cs | 1 - .../Models/Recipe.cs | 1 - .../Models/Symptom.cs | 1 - .../Controllers/DiagnosesController.cs | 53 ++++++++++++++++--- .../Views/Diagnoses/DiagnoseForm.cshtml | 30 +++++++++++ .../Views/Diagnoses/DiagnoseForm.cshtml.cs | 12 +++++ .../{Index.cshtml => DiagnosesList.cshtml} | 0 ...ndex.cshtml.cs => DiagnosesList.cshtml.cs} | 0 14 files changed, 101 insertions(+), 23 deletions(-) create mode 100644 Polyclinic/PolyclinicWebAppImplementer/Views/Diagnoses/DiagnoseForm.cshtml create mode 100644 Polyclinic/PolyclinicWebAppImplementer/Views/Diagnoses/DiagnoseForm.cshtml.cs rename Polyclinic/PolyclinicWebAppImplementer/Views/Diagnoses/{Index.cshtml => DiagnosesList.cshtml} (100%) rename Polyclinic/PolyclinicWebAppImplementer/Views/Diagnoses/{Index.cshtml.cs => DiagnosesList.cshtml.cs} (100%) diff --git a/Polyclinic/PolyclinicContracts/BindingModels/DiagnoseBindingModel.cs b/Polyclinic/PolyclinicContracts/BindingModels/DiagnoseBindingModel.cs index 01877ac..90f9d3e 100644 --- a/Polyclinic/PolyclinicContracts/BindingModels/DiagnoseBindingModel.cs +++ b/Polyclinic/PolyclinicContracts/BindingModels/DiagnoseBindingModel.cs @@ -5,10 +5,10 @@ namespace PolyclinicContracts.BindingModels public class DiagnoseBindingModel : IDiagnoseModel { public string Name { get; set; } = string.Empty; - public string Comment { get; set; } = string.Empty; + public string? Comment { get; set; } public int UserId { get; set; } public int Id { get; set; } - public DateTime DateStartDiagnose { get; } - public DateTime? DateStopDiagnose { get; } + public DateTime DateStartDiagnose { get; set; } + public DateTime? DateStopDiagnose { get; set; } } } diff --git a/Polyclinic/PolyclinicContracts/ViewModels/DiagnoseViewModel.cs b/Polyclinic/PolyclinicContracts/ViewModels/DiagnoseViewModel.cs index 96093b0..d832dbe 100644 --- a/Polyclinic/PolyclinicContracts/ViewModels/DiagnoseViewModel.cs +++ b/Polyclinic/PolyclinicContracts/ViewModels/DiagnoseViewModel.cs @@ -9,7 +9,7 @@ namespace PolyclinicContracts.ViewModels public string Name { get; set; } = string.Empty; [DisplayName("Комментарий")] - public string Comment { get; set; } = string.Empty; + public string? Comment { get; set; } = string.Empty; [DisplayName("Дата 'от'")] public DateTime DateStartDiagnose { get; set; } diff --git a/Polyclinic/PolyclinicDataModels/Models/IDiagnoseModel.cs b/Polyclinic/PolyclinicDataModels/Models/IDiagnoseModel.cs index bdb1165..32c7ed1 100644 --- a/Polyclinic/PolyclinicDataModels/Models/IDiagnoseModel.cs +++ b/Polyclinic/PolyclinicDataModels/Models/IDiagnoseModel.cs @@ -3,7 +3,7 @@ public interface IDiagnoseModel : IId { string Name { get; } - string Comment { get; } + string? Comment { get; } int UserId { get; } DateTime DateStartDiagnose { get; } DateTime? DateStopDiagnose { get; } diff --git a/Polyclinic/PolyclinicDatabaseImplement/Migrations/20240501145526_Init-Create.cs b/Polyclinic/PolyclinicDatabaseImplement/Migrations/20240501145526_Init-Create.cs index 64ec6dd..9c2af76 100644 --- a/Polyclinic/PolyclinicDatabaseImplement/Migrations/20240501145526_Init-Create.cs +++ b/Polyclinic/PolyclinicDatabaseImplement/Migrations/20240501145526_Init-Create.cs @@ -19,7 +19,7 @@ namespace PolyclinicDatabaseImplement.Migrations .Annotation("SqlServer:Identity", "1, 1"), DaysCount = table.Column(type: "int", nullable: false), PillsPerDay = table.Column(type: "int", nullable: false), - Comment = table.Column(type: "nvarchar(max)", nullable: false) + Comment = table.Column(type: "nvarchar(max)", nullable: true) }, constraints: table => { @@ -33,7 +33,7 @@ namespace PolyclinicDatabaseImplement.Migrations Id = table.Column(type: "int", nullable: false) .Annotation("SqlServer:Identity", "1, 1"), Name = table.Column(type: "nvarchar(max)", nullable: false), - Comment = table.Column(type: "nvarchar(max)", nullable: false) + Comment = table.Column(type: "nvarchar(max)", nullable: true) }, constraints: table => { @@ -63,7 +63,7 @@ namespace PolyclinicDatabaseImplement.Migrations Id = table.Column(type: "int", nullable: false) .Annotation("SqlServer:Identity", "1, 1"), ProceduresCount = table.Column(type: "int", nullable: false), - Comment = table.Column(type: "nvarchar(max)", nullable: false), + Comment = table.Column(type: "nvarchar(max)", nullable: true), CourseId = table.Column(type: "int", nullable: true) }, constraints: table => @@ -83,7 +83,7 @@ namespace PolyclinicDatabaseImplement.Migrations Id = table.Column(type: "int", nullable: false) .Annotation("SqlServer:Identity", "1, 1"), Name = table.Column(type: "nvarchar(max)", nullable: false), - Comment = table.Column(type: "nvarchar(max)", nullable: false), + Comment = table.Column(type: "nvarchar(max)", nullable: true), UserId = table.Column(type: "int", nullable: false), DateStartDiagnose = table.Column(type: "datetime2", nullable: false), DateStopDiagnose = table.Column(type: "datetime2", nullable: true) @@ -109,7 +109,7 @@ namespace PolyclinicDatabaseImplement.Migrations Name = table.Column(type: "nvarchar(max)", nullable: false), DateStartProcedure = table.Column(type: "datetime2", nullable: false), DateStopProcedure = table.Column(type: "datetime2", nullable: true), - Comment = table.Column(type: "nvarchar(max)", nullable: false) + Comment = table.Column(type: "nvarchar(max)", nullable: true) }, constraints: table => { @@ -207,7 +207,7 @@ namespace PolyclinicDatabaseImplement.Migrations Id = table.Column(type: "int", nullable: false) .Annotation("SqlServer:Identity", "1, 1"), Name = table.Column(type: "nvarchar(max)", nullable: false), - Comment = table.Column(type: "nvarchar(max)", nullable: false), + Comment = table.Column(type: "nvarchar(max)", nullable: true), ProcedureId = table.Column(type: "int", nullable: false), SymptomId = table.Column(type: "int", nullable: false) }, diff --git a/Polyclinic/PolyclinicDatabaseImplement/Models/Diagnose.cs b/Polyclinic/PolyclinicDatabaseImplement/Models/Diagnose.cs index 526d6e1..e0d8172 100644 --- a/Polyclinic/PolyclinicDatabaseImplement/Models/Diagnose.cs +++ b/Polyclinic/PolyclinicDatabaseImplement/Models/Diagnose.cs @@ -9,8 +9,7 @@ namespace PolyclinicDatabaseImplement.Models { [Required] public string Name { get; set; } = string.Empty; - [Required] - public string Comment { get; set; } = string.Empty; + public string? Comment { get; set; } [Required] public int UserId { get; set; } diff --git a/Polyclinic/PolyclinicDatabaseImplement/Models/Medicament.cs b/Polyclinic/PolyclinicDatabaseImplement/Models/Medicament.cs index 1e01374..a221a43 100644 --- a/Polyclinic/PolyclinicDatabaseImplement/Models/Medicament.cs +++ b/Polyclinic/PolyclinicDatabaseImplement/Models/Medicament.cs @@ -13,7 +13,6 @@ namespace PolyclinicDatabaseImplement.Models [Required] public string Name { get; set; } = string.Empty; - [Required] public string Comment { get; set; } = string.Empty; [Required] diff --git a/Polyclinic/PolyclinicDatabaseImplement/Models/Procedure.cs b/Polyclinic/PolyclinicDatabaseImplement/Models/Procedure.cs index bbf91e7..db2d496 100644 --- a/Polyclinic/PolyclinicDatabaseImplement/Models/Procedure.cs +++ b/Polyclinic/PolyclinicDatabaseImplement/Models/Procedure.cs @@ -21,7 +21,6 @@ namespace PolyclinicDatabaseImplement.Models public DateTime? DateStopProcedure { get; set; } public virtual User User { get; set; } = new(); - [Required] public string Comment { get; set; } = string.Empty; public static Procedure Create(ProcedureBindingModel bindingModel) diff --git a/Polyclinic/PolyclinicDatabaseImplement/Models/Recipe.cs b/Polyclinic/PolyclinicDatabaseImplement/Models/Recipe.cs index bf3a0c4..d8b2ffc 100644 --- a/Polyclinic/PolyclinicDatabaseImplement/Models/Recipe.cs +++ b/Polyclinic/PolyclinicDatabaseImplement/Models/Recipe.cs @@ -14,7 +14,6 @@ namespace PolyclinicDatabaseImplement.Models [Required] public int ProceduresCount { get; set; } - [Required] public string Comment { get; set; } = string.Empty; public int? CourseId { get; set; } public virtual Course Course { get; set; } = new(); diff --git a/Polyclinic/PolyclinicDatabaseImplement/Models/Symptom.cs b/Polyclinic/PolyclinicDatabaseImplement/Models/Symptom.cs index 59f59ba..f0c9b51 100644 --- a/Polyclinic/PolyclinicDatabaseImplement/Models/Symptom.cs +++ b/Polyclinic/PolyclinicDatabaseImplement/Models/Symptom.cs @@ -11,7 +11,6 @@ namespace PolyclinicDatabaseImplement.Models { [Required] public string Name { get; set; } = string.Empty; - [Required] public string Comment { get; set; } = string.Empty; [ForeignKey("SymptomId")] public virtual List Diagnoses { get; set; } = new(); diff --git a/Polyclinic/PolyclinicWebAppImplementer/Controllers/DiagnosesController.cs b/Polyclinic/PolyclinicWebAppImplementer/Controllers/DiagnosesController.cs index 2fa2fb3..67a3682 100644 --- a/Polyclinic/PolyclinicWebAppImplementer/Controllers/DiagnosesController.cs +++ b/Polyclinic/PolyclinicWebAppImplementer/Controllers/DiagnosesController.cs @@ -1,5 +1,7 @@ using Microsoft.AspNetCore.Mvc; +using PolyclinicContracts.BindingModels; using PolyclinicContracts.BusinessLogicsContracts; +using PolyclinicContracts.SearchModels; using PolyclinicContracts.ViewModels; using PolyclinicWebAppImplementer.Models; @@ -9,7 +11,7 @@ namespace PolyclinicWebAppImplementer.Controllers { private readonly ILogger _logger; private readonly IDiagnoseLogic _diagnoseLogic; - + public DiagnosesController(ILogger logger, IDiagnoseLogic diagnoseLogic) { _logger = logger; @@ -19,20 +21,59 @@ namespace PolyclinicWebAppImplementer.Controllers [HttpGet] public IActionResult Index() { + // TODO выводить только пользовательские диагнозы List diagnoses = _diagnoseLogic.ReadList(); - return View(diagnoses); + return View("DiagnosesList", diagnoses); } [HttpGet] - public IActionResult CreateDiagnose() + [HttpPost] + public IActionResult Add(int id, string name, string comment, DateTime dateStart, DateTime dateStop) { - + if (HttpContext.Request.Method == "GET") + { + ViewData["Title"] = "Новый диагноз"; + return View("DiagnoseForm"); + } + else + { + // TODO прописать UserId + DiagnoseBindingModel diagnose = new DiagnoseBindingModel + { + Id = id, + Name = name, + Comment = comment, + DateStartDiagnose = dateStart, + DateStopDiagnose = dateStop, + }; + _diagnoseLogic.Create(diagnose); + return RedirectToAction("Index"); + } } [HttpGet] - public IActionResult EditDiagnose() + [HttpPost] + public IActionResult Edit(int id, string name, string comment, DateTime dateStart, DateTime dateStop) { - + if (HttpContext.Request.Method == "GET") + { + var obj = _diagnoseLogic.ReadElement(new DiagnoseSearchModel { Id = id }); + ViewData["Title"] = "Редактировать диагноз"; + return View("DiagnoseForm", obj); + } + else + { + DiagnoseBindingModel diagnose = new DiagnoseBindingModel + { + Id = id, + Name = name, + Comment = comment, + DateStartDiagnose = dateStart, + DateStopDiagnose = dateStop, + }; + _diagnoseLogic.Update(diagnose); + return RedirectToAction("Index"); + } } } } diff --git a/Polyclinic/PolyclinicWebAppImplementer/Views/Diagnoses/DiagnoseForm.cshtml b/Polyclinic/PolyclinicWebAppImplementer/Views/Diagnoses/DiagnoseForm.cshtml new file mode 100644 index 0000000..8bd83ff --- /dev/null +++ b/Polyclinic/PolyclinicWebAppImplementer/Views/Diagnoses/DiagnoseForm.cshtml @@ -0,0 +1,30 @@ +@using PolyclinicContracts.ViewModels +@model DiagnoseViewModel +

@ViewData["Title"]

+
+ +
+
Название:
+
+
+
+
Коментарий:
+
+
+
+
Начало:
+
+
+
+
Конец:
+
+
+
+
+ + @Html.ActionLink("Отмена", "", "Diagnoses", null, new { @class = "btn btn-danger" }) +
+
+
\ No newline at end of file diff --git a/Polyclinic/PolyclinicWebAppImplementer/Views/Diagnoses/DiagnoseForm.cshtml.cs b/Polyclinic/PolyclinicWebAppImplementer/Views/Diagnoses/DiagnoseForm.cshtml.cs new file mode 100644 index 0000000..2956788 --- /dev/null +++ b/Polyclinic/PolyclinicWebAppImplementer/Views/Diagnoses/DiagnoseForm.cshtml.cs @@ -0,0 +1,12 @@ +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.RazorPages; + +namespace PolyclinicWebAppImplementer.Views.Diagnoses +{ + public class DiagnoseFormModel : PageModel + { + public void OnGet() + { + } + } +} diff --git a/Polyclinic/PolyclinicWebAppImplementer/Views/Diagnoses/Index.cshtml b/Polyclinic/PolyclinicWebAppImplementer/Views/Diagnoses/DiagnosesList.cshtml similarity index 100% rename from Polyclinic/PolyclinicWebAppImplementer/Views/Diagnoses/Index.cshtml rename to Polyclinic/PolyclinicWebAppImplementer/Views/Diagnoses/DiagnosesList.cshtml diff --git a/Polyclinic/PolyclinicWebAppImplementer/Views/Diagnoses/Index.cshtml.cs b/Polyclinic/PolyclinicWebAppImplementer/Views/Diagnoses/DiagnosesList.cshtml.cs similarity index 100% rename from Polyclinic/PolyclinicWebAppImplementer/Views/Diagnoses/Index.cshtml.cs rename to Polyclinic/PolyclinicWebAppImplementer/Views/Diagnoses/DiagnosesList.cshtml.cs