у Никиты работают круды для симптомов, почему у меня изменения остались?...
This commit is contained in:
commit
abc0bcf254
@ -73,7 +73,7 @@ namespace PolyclinicBusinessLogic.BusinessLogics
|
||||
|
||||
public bool Update(SymptomBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
CheckModel(model, false);
|
||||
if (_symptomStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
|
@ -1,10 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PolyclinicContracts.BindingModels
|
||||
namespace PolyclinicContracts.BindingModels
|
||||
{
|
||||
public class ReportBindingModel
|
||||
{
|
||||
|
@ -3,6 +3,6 @@
|
||||
public class SymptomSearchModel
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
public string?Name { get; set; }
|
||||
public string? Name { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -31,12 +31,9 @@ namespace PolyclinicDatabaseImplement.Implements
|
||||
public List<CourseViewModel> GetFilteredList(CourseSearchModel model)
|
||||
{
|
||||
var elements = GetFullList();
|
||||
foreach (var prop in model.GetType().GetProperties())
|
||||
if (model.Id != null)
|
||||
{
|
||||
if (model.GetType().GetProperty(prop.Name)?.GetValue(model, null) != null)
|
||||
{
|
||||
elements = elements.Where(x => x.GetType().GetProperty(prop.Name)?.GetValue(x, null) == model.GetType().GetProperty(prop.Name)?.GetValue(model, null)).ToList();
|
||||
}
|
||||
elements = elements.Where(x => x.Id == model.Id).ToList();
|
||||
}
|
||||
return elements;
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
using PolyclinicContracts.BindingModels;
|
||||
using PolyclinicContracts.SearchModels;
|
||||
using PolyclinicContracts.StoragesContracts;
|
||||
@ -31,12 +32,13 @@ namespace PolyclinicDatabaseImplement.Implements
|
||||
public List<SymptomViewModel> GetFilteredList(SymptomSearchModel model)
|
||||
{
|
||||
var elements = GetFullList();
|
||||
foreach (var prop in model.GetType().GetProperties())
|
||||
if (model.Id != null)
|
||||
{
|
||||
if (model.GetType().GetProperty(prop.Name)?.GetValue(model, null) != null)
|
||||
{
|
||||
elements = elements.Where(x => x.GetType().GetProperty(prop.Name)?.GetValue(x, null) == model.GetType().GetProperty(prop.Name)?.GetValue(model, null)).ToList();
|
||||
elements = elements.Where(x => x.Id == model.Id).ToList();
|
||||
}
|
||||
if (!model.Name.IsNullOrEmpty())
|
||||
{
|
||||
elements = elements.Where(x => x.Name == model.Name).ToList();
|
||||
}
|
||||
return elements;
|
||||
}
|
||||
@ -67,6 +69,9 @@ namespace PolyclinicDatabaseImplement.Implements
|
||||
public SymptomViewModel? Update(SymptomBindingModel model)
|
||||
{
|
||||
using var context = new PolyclinicDatabase();
|
||||
using var transaction = context.Database.BeginTransaction();
|
||||
try
|
||||
{
|
||||
var element = context.Symptomes.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (element == null)
|
||||
{
|
||||
@ -74,7 +79,16 @@ namespace PolyclinicDatabaseImplement.Implements
|
||||
}
|
||||
element.Update(model);
|
||||
context.SaveChanges();
|
||||
element.UpdateDiagnoses(context, model);
|
||||
transaction.Commit();
|
||||
return element.GetViewModel;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
transaction.Rollback();
|
||||
throw;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -84,6 +84,7 @@ namespace PolyclinicDatabaseImplement.Models
|
||||
Procedure = Procedure,
|
||||
Recipe = database.Recipes.First(x => x.Id == pc.Key)
|
||||
});
|
||||
database.SaveChanges();
|
||||
}
|
||||
_recipeProcedures = null;
|
||||
}
|
||||
|
@ -63,19 +63,18 @@ namespace PolyclinicDatabaseImplement.Models
|
||||
public void UpdateDiagnoses(PolyclinicDatabase context, SymptomBindingModel model)
|
||||
{
|
||||
var symptomDiagnoses = context.SymptomDiagnoses.Where(rec => rec.SymptomId == model.Id).ToList();
|
||||
|
||||
if (symptomDiagnoses != null && symptomDiagnoses.Count > 0)
|
||||
{
|
||||
// удалили те, которых нет в модели
|
||||
context.SymptomDiagnoses.RemoveRange(symptomDiagnoses
|
||||
.Where(rec => !model.SymptomDiagnoses.ContainsKey(rec.DiagnoseId)));
|
||||
context.SymptomDiagnoses.RemoveRange(symptomDiagnoses);
|
||||
context.SaveChanges();
|
||||
}
|
||||
var course = context.Symptomes.First(x => x.Id == Id);
|
||||
var symptom = context.Symptomes.First(x => x.Id == model.Id);
|
||||
foreach (var pc in model.SymptomDiagnoses)
|
||||
{
|
||||
context.SymptomDiagnoses.Add(new SymptomDiagnose
|
||||
{
|
||||
Symptom = course,
|
||||
Symptom = symptom,
|
||||
Diagnose = context.Diagnoses.First(x => x.Id == pc.Key),
|
||||
});
|
||||
context.SaveChanges();
|
||||
|
@ -3,6 +3,7 @@ using PolyclinicContracts.BindingModels;
|
||||
using PolyclinicContracts.BusinessLogicsContracts;
|
||||
using PolyclinicContracts.SearchModels;
|
||||
using PolyclinicContracts.ViewModels;
|
||||
using PolyclinicDataModels.Models;
|
||||
using PolyclinicWebAppImplementer.Models;
|
||||
|
||||
namespace PolyclinicWebAppImplementer.Controllers
|
||||
@ -25,21 +26,29 @@ namespace PolyclinicWebAppImplementer.Controllers
|
||||
}
|
||||
[HttpGet]
|
||||
[HttpPost]
|
||||
public IActionResult Add(SymptomFormModel model)
|
||||
public IActionResult Add(SymptomFormModel model, int[] selectedDiagnoses)
|
||||
{
|
||||
if (HttpContext.Request.Method == "GET")
|
||||
{
|
||||
ViewData["Title"] = "Новый симптом";
|
||||
model = new();
|
||||
model.AvailableDiagnoses = _diagnoseLogic.ReadList();
|
||||
model = new()
|
||||
{
|
||||
Diagnoses = _diagnoseLogic.ReadList().Select(x => (x, false)).ToList()
|
||||
};
|
||||
return View("SymptomForm", model);
|
||||
}
|
||||
else
|
||||
{
|
||||
var allDiagnoses = _diagnoseLogic.ReadList();
|
||||
SymptomBindingModel symptom = new SymptomBindingModel
|
||||
{
|
||||
Name = model.SymptomViewModel.Name,
|
||||
Comment = model.SymptomViewModel.Comment,
|
||||
SymptomDiagnoses = selectedDiagnoses
|
||||
.ToDictionary(
|
||||
x => x,
|
||||
x => allDiagnoses.Where(y => y.Id == x) as IDiagnoseModel
|
||||
)
|
||||
};
|
||||
_symptomLogic.Create(symptom);
|
||||
return RedirectToAction("Index");
|
||||
@ -47,21 +56,32 @@ namespace PolyclinicWebAppImplementer.Controllers
|
||||
}
|
||||
[HttpGet]
|
||||
[HttpPost]
|
||||
public IActionResult Edit(int id, SymptomViewModel model)
|
||||
public IActionResult Edit(int id, SymptomFormModel model, int[] selectedDiagnoses)
|
||||
{
|
||||
if (HttpContext.Request.Method == "GET")
|
||||
{
|
||||
var obj = _symptomLogic.ReadElement(new SymptomSearchModel { Id = id });
|
||||
model = new()
|
||||
{
|
||||
SymptomViewModel = obj,
|
||||
Diagnoses = _diagnoseLogic.ReadList().Select(x => (x, obj.SymptomDiagnoses.ContainsKey(x.Id))).ToList()
|
||||
};
|
||||
ViewData["Title"] = "Редактировать симптом";
|
||||
return View("SymptomForm", obj);
|
||||
return View("SymptomForm", model);
|
||||
}
|
||||
else
|
||||
{
|
||||
var allDiagnoses = _diagnoseLogic.ReadList();
|
||||
SymptomBindingModel symptom = new SymptomBindingModel
|
||||
{
|
||||
Id = model.Id,
|
||||
Name = model.Name,
|
||||
Comment = model.Comment,
|
||||
Id = id,
|
||||
Name = model.SymptomViewModel.Name,
|
||||
Comment = model.SymptomViewModel.Comment,
|
||||
SymptomDiagnoses = selectedDiagnoses
|
||||
.ToDictionary(
|
||||
x => x,
|
||||
x => allDiagnoses.Where(y => y.Id == x) as IDiagnoseModel
|
||||
)
|
||||
};
|
||||
_symptomLogic.Update(symptom);
|
||||
return RedirectToAction("Index");
|
||||
|
@ -5,7 +5,6 @@ namespace PolyclinicWebAppImplementer.Models
|
||||
public class SymptomFormModel
|
||||
{
|
||||
public SymptomViewModel? SymptomViewModel { get; set; }
|
||||
public List<DiagnoseViewModel> SelectecDiagnoses { get; set; } = new();
|
||||
public List<DiagnoseViewModel> AvailableDiagnoses { get; set; } = new();
|
||||
public List<(DiagnoseViewModel Diagnose, bool IsChecked)> Diagnoses { get; set; } = new();
|
||||
}
|
||||
}
|
||||
|
@ -4,20 +4,20 @@
|
||||
<form class="d-flex flex-column" method="post">
|
||||
<input type="hidden" readonly asp-for="Id" />
|
||||
<div class="row mb-5">
|
||||
<div class="col-3">Название:</div>
|
||||
<div class="col-8"><input required asp-for="Name" /></div>
|
||||
<div class="col">Название:</div>
|
||||
<div class="col"><input required asp-for="Name" /></div>
|
||||
</div>
|
||||
<div class="row mb-5">
|
||||
<div class="col-3">Коментарий:</div>
|
||||
<div class="col-8"><textarea asp-for="Comment"></textarea></div>
|
||||
<div class="col">Коментарий:</div>
|
||||
<div class="col"><textarea asp-for="Comment"></textarea></div>
|
||||
</div>
|
||||
<div class="row mb-5">
|
||||
<div class="col-3">Начало:</div>
|
||||
<div class="col-8"><input required type="date" asp-for="DateStartDiagnose" /></div>
|
||||
<div class="col">Начало:</div>
|
||||
<div class="col"><input required type="date" asp-for="DateStartDiagnose" /></div>
|
||||
</div>
|
||||
<div class="row mb-5">
|
||||
<div class="col-3">Конец:</div>
|
||||
<div class="col-8"><input type="date" asp-for="DateStopDiagnose" /></div>
|
||||
<div class="col">Конец:</div>
|
||||
<div class="col"><input type="date" asp-for="DateStopDiagnose" /></div>
|
||||
</div>
|
||||
<div class="row mb-5">
|
||||
<div class="col-4">
|
||||
|
@ -4,42 +4,27 @@
|
||||
<form class="d-flex flex-column" method="post">
|
||||
<div class="row mb-5">
|
||||
<div class="col-3">Название:</div>
|
||||
<div class="col-8"><input type="text" asp-for="SymptomViewModel.Name" /></div>
|
||||
<div class="col-8"><input required type="text" asp-for="SymptomViewModel.Name" /></div>
|
||||
</div>
|
||||
<div class="row mb-5">
|
||||
<div class="col-3">Коментарий:</div>
|
||||
<div class="col-8"><textarea asp-for="SymptomViewModel.Comment"></textarea></div>
|
||||
</div>
|
||||
<div class="row mb-5">
|
||||
<div class="col-3 d-flex align-content-center">
|
||||
<h5 class="me-2">Болезни</h5>
|
||||
<select id="diagnoseId" name="diagnoseId" class="me-2">
|
||||
<option value="">Выберите болезнь</option>
|
||||
@foreach (var availableDiagnose in Model.AvailableDiagnoses)
|
||||
{
|
||||
<option value="@availableDiagnose.Id">@availableDiagnose.Name</option>
|
||||
}
|
||||
</select>
|
||||
<button class="btn btn-success" type="button">
|
||||
Добавить
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row mb-5 overflow-auto" style="max-height: 100px; max-width: 500px;">
|
||||
<ol>
|
||||
@{
|
||||
int count = 7;
|
||||
for (int i = 0; i < count; i++)
|
||||
@foreach (var item in Model.Diagnoses)
|
||||
{
|
||||
<li class="mb-2 ps-1 ms-1">
|
||||
<a asp-action="Symptom" class="text-decoration-none">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-trash-fill text-danger " viewBox="0 0 16 16">
|
||||
<path d="M2.5 1a1 1 0 0 0-1 1v1a1 1 0 0 0 1 1H3v9a2 2 0 0 0 2 2h6a2 2 0 0 0 2-2V4h.5a1 1 0 0 0 1-1V2a1 1 0 0 0-1-1H10a1 1 0 0 0-1-1H7a1 1 0 0 0-1 1zm3 4a.5.5 0 0 1 .5.5v7a.5.5 0 0 1-1 0v-7a.5.5 0 0 1 .5-.5M8 5a.5.5 0 0 1 .5.5v7a.5.5 0 0 1-1 0v-7A.5.5 0 0 1 8 5m3 .5v7a.5.5 0 0 1-1 0v-7a.5.5 0 0 1 1 0" />
|
||||
</svg>
|
||||
</a>
|
||||
<span>Выбранная болезнь</span>
|
||||
</li>
|
||||
@if (item.IsChecked)
|
||||
{
|
||||
<input type="checkbox" id="diagnose-@item.Diagnose.Id" name="selectedDiagnoses" value="@item.Diagnose.Id" checked />
|
||||
}
|
||||
else
|
||||
{
|
||||
<input type="checkbox" id="diagnose-@item.Diagnose.Id" name="selectedDiagnoses" value="@item.Diagnose.Id" />
|
||||
}
|
||||
<label for="diagnose-@item.Diagnose.Id">@item.Diagnose.Name</label>
|
||||
</li>
|
||||
}
|
||||
</ol>
|
||||
</div>
|
||||
|
@ -32,7 +32,7 @@
|
||||
<h3 class="col-3">
|
||||
Выбор процедуры:
|
||||
</h3>
|
||||
<select id="procedureId" name="procedureId" style="width: 45vh" multiple>
|
||||
<select id="procedureId" name="procedureId" style="width: 45vh">
|
||||
<option value="">Выберите процедуру/ы</option>
|
||||
@foreach (var item in ViewBag.Procedures)
|
||||
{
|
||||
@ -52,7 +52,7 @@
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (var item in ViewBag.RecipeProcedures)
|
||||
@foreach (var item in ViewBag.Procedures)
|
||||
{
|
||||
<tr>
|
||||
<td>Процедура № @item.Id @item.Name</td>
|
||||
|
Loading…
Reference in New Issue
Block a user