Обновил схему БД, разрешил null на комментариях

This commit is contained in:
Никита Потапов 2024-05-26 13:03:03 +04:00
parent 5546ab58e7
commit 9f44ad75be
14 changed files with 101 additions and 23 deletions

View File

@ -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; }
}
}

View File

@ -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; }

View File

@ -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; }

View File

@ -19,7 +19,7 @@ namespace PolyclinicDatabaseImplement.Migrations
.Annotation("SqlServer:Identity", "1, 1"),
DaysCount = table.Column<int>(type: "int", nullable: false),
PillsPerDay = table.Column<int>(type: "int", nullable: false),
Comment = table.Column<string>(type: "nvarchar(max)", nullable: false)
Comment = table.Column<string>(type: "nvarchar(max)", nullable: true)
},
constraints: table =>
{
@ -33,7 +33,7 @@ namespace PolyclinicDatabaseImplement.Migrations
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
Name = table.Column<string>(type: "nvarchar(max)", nullable: false),
Comment = table.Column<string>(type: "nvarchar(max)", nullable: false)
Comment = table.Column<string>(type: "nvarchar(max)", nullable: true)
},
constraints: table =>
{
@ -63,7 +63,7 @@ namespace PolyclinicDatabaseImplement.Migrations
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
ProceduresCount = table.Column<int>(type: "int", nullable: false),
Comment = table.Column<string>(type: "nvarchar(max)", nullable: false),
Comment = table.Column<string>(type: "nvarchar(max)", nullable: true),
CourseId = table.Column<int>(type: "int", nullable: true)
},
constraints: table =>
@ -83,7 +83,7 @@ namespace PolyclinicDatabaseImplement.Migrations
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
Name = table.Column<string>(type: "nvarchar(max)", nullable: false),
Comment = table.Column<string>(type: "nvarchar(max)", nullable: false),
Comment = table.Column<string>(type: "nvarchar(max)", nullable: true),
UserId = table.Column<int>(type: "int", nullable: false),
DateStartDiagnose = table.Column<DateTime>(type: "datetime2", nullable: false),
DateStopDiagnose = table.Column<DateTime>(type: "datetime2", nullable: true)
@ -109,7 +109,7 @@ namespace PolyclinicDatabaseImplement.Migrations
Name = table.Column<string>(type: "nvarchar(max)", nullable: false),
DateStartProcedure = table.Column<DateTime>(type: "datetime2", nullable: false),
DateStopProcedure = table.Column<DateTime>(type: "datetime2", nullable: true),
Comment = table.Column<string>(type: "nvarchar(max)", nullable: false)
Comment = table.Column<string>(type: "nvarchar(max)", nullable: true)
},
constraints: table =>
{
@ -207,7 +207,7 @@ namespace PolyclinicDatabaseImplement.Migrations
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
Name = table.Column<string>(type: "nvarchar(max)", nullable: false),
Comment = table.Column<string>(type: "nvarchar(max)", nullable: false),
Comment = table.Column<string>(type: "nvarchar(max)", nullable: true),
ProcedureId = table.Column<int>(type: "int", nullable: false),
SymptomId = table.Column<int>(type: "int", nullable: false)
},

View File

@ -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; }

View File

@ -13,7 +13,6 @@ namespace PolyclinicDatabaseImplement.Models
[Required]
public string Name { get; set; } = string.Empty;
[Required]
public string Comment { get; set; } = string.Empty;
[Required]

View File

@ -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)

View File

@ -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();

View File

@ -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<SymptomDiagnose> Diagnoses { get; set; } = new();

View File

@ -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<DiagnosesController> _logger;
private readonly IDiagnoseLogic _diagnoseLogic;
public DiagnosesController(ILogger<DiagnosesController> logger, IDiagnoseLogic diagnoseLogic)
{
_logger = logger;
@ -19,20 +21,59 @@ namespace PolyclinicWebAppImplementer.Controllers
[HttpGet]
public IActionResult Index()
{
// TODO выводить только пользовательские диагнозы
List<DiagnoseViewModel> 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");
}
}
}
}

View File

@ -0,0 +1,30 @@
@using PolyclinicContracts.ViewModels
@model DiagnoseViewModel
<h4>@ViewData["Title"]</h4>
<form class="d-flex flex-column" method="post">
<input type="hidden" name="id" readonly value="@Model?.Id" />
<div class="row mb-5">
<div class="col-3">Название:</div>
<div class="col-8"><input type="text" id="name" name="name" value="@Model?.Name" /></div>
</div>
<div class="row mb-5">
<div class="col-3">Коментарий:</div>
<div class="col-8"><textarea id="comment" name="comment">@Model?.Comment</textarea></div>
</div>
<div class="row mb-5">
<div class="col-3">Начало:</div>
<div class="col-8"><input type="date" id="dateStartInput" name="dateStart" value="@Model?.DateStartDiagnose" /></div>
</div>
<div class="row mb-5">
<div class="col-3">Конец:</div>
<div class="col-8"><input type="date" id="dateStopInput" name="dateStop" value="@Model?.DateStopDiagnose" /></div>
</div>
<div class="row mb-5">
<div class="col-4">
<button class="btn btn-success" type="submit">
Сохранить
</button>
@Html.ActionLink("Отмена", "", "Diagnoses", null, new { @class = "btn btn-danger" })
</div>
</div>
</form>

View File

@ -0,0 +1,12 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
namespace PolyclinicWebAppImplementer.Views.Diagnoses
{
public class DiagnoseFormModel : PageModel
{
public void OnGet()
{
}
}
}