продолжаю делать приложение

This commit is contained in:
Alenka 2024-04-30 16:20:04 +04:00
parent c0d0b68892
commit 050762b81d
21 changed files with 649 additions and 109 deletions

View File

@ -1,107 +1 @@
using HospitalContracts.BindingModels;
using HospitalContracts.BusinessLogicContracts;
using HospitalContracts.SearchModels;
using HospitalContracts.ViewModels;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using HospitalDatabaseImplement.Models;
namespace HospitalRestApi.Controllers
{
[Route("api/[controller]/[action]")]
[ApiController]
public class MedicineController : Controller
{
private readonly ILogger _logger;
private readonly IMedicineLogic _medicine;
public MedicineController(ILogger<MedicineController> logger, IMedicineLogic medicine)
{
_logger = logger;
_medicine = medicine;
}
[HttpGet]
public Tuple<MedicineViewModel, List<string>>? GetMedicine(int medicineId)
{
try
{
var elem = _medicine.ReadElement(new MedicineSearchModel { Id = medicineId });
if (elem == null)
return null;
var res = Tuple.Create(elem, elem.ProcedureMedicines.Select(x => x.Value.AnimalName).ToList());
res.Item1.MedicineAnimals = null!;
return res;
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения медикамента по id={Id}", medicineId);
throw;
}
}
[HttpGet]
public List<MedicineViewModel>? GetMedicines(int? pharmacistId = null)
{
try
{
List<MedicineViewModel> res;
if (!pharmacistId.HasValue)
res = _medicine.ReadList(null);
else
res = _medicine.ReadList(new MedicineSearchModel { PharmacistId = pharmacistId });
foreach (var medicine in res)
medicine.ProcedureMedicines = null!;
return res;
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения списка медикаментов");
throw;
}
}
[HttpPost]
public bool CreateMedicine(MedicineBindingModel model)
{
try
{
return _medicine.Create(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Не удалось создать медикамент");
throw;
}
}
[HttpPost]
public bool UpdateMedicine(bool isConnection, MedicineBindingModel model)
{
try
{
if (!isConnection)
model.ProcedureMedicines = null!;
return _medicine.Update(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Не удалось обновить магазин");
throw;
}
}
[HttpPost]
public bool DeleteMedicine(MedicineBindingModel model)
{
try
{
return _medicine.Delete(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка удаления магазина");
throw;
}
}
}
}


View File

@ -12,6 +12,7 @@
<ItemGroup>
<ProjectReference Include="..\HospitalBusinessLogic\HospitalBusinessLogic.csproj" />
<ProjectReference Include="..\HospitalContracts\HospitalContracts.csproj" />
<ProjectReference Include="..\HospitalDatabaseImplement\HospitalDatabaseImplement.csproj" />
</ItemGroup>

View File

@ -1,19 +1,45 @@
using HospitalBusinessLogic.BusinessLogics;
using HospitalContracts.BusinessLogicContracts;
using HospitalContracts.StoragesContracts;
using HospitalDatabaseImplement.Implements;
using Microsoft.OpenApi.Models;
var builder = WebApplication.CreateBuilder(args);
builder.Logging.SetMinimumLevel(LogLevel.Trace);
//builder.Logging.AddLog4Net("log4net.config");
// Add services to the container.
builder.Services.AddTransient<IPharmacistStorage, PharmacistStorage>();
builder.Services.AddTransient<IMedicineStorage, MedicineStorage>();
builder.Services.AddTransient<IPharmacistLogic, PharmacistLogic>();
builder.Services.AddTransient<IMedicineLogic, MedicineLogic>();
builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
builder.Services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new OpenApiInfo { Title = "VetClinicRestApi", Version = "v1" });
});
var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "VetClinicRestApi v1"));
}
app.UseHttpsRedirection();

View File

@ -0,0 +1 @@


View File

@ -0,0 +1 @@


View File

@ -6,4 +6,21 @@
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<Content Remove="Views\Home\Registr.cshtml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Views\Home\Registr.cshtml" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\HospitalBusinessLogic\HospitalBusinessLogic.csproj" />
<ProjectReference Include="..\HospitalContracts\HospitalContracts.csproj" />
<ProjectReference Include="..\HospitalDatabaseImplement\HospitalDatabaseImplement.csproj" />
<ProjectReference Include="..\HospitalDataModels\HospitalDataModels.csproj" />
<ProjectReference Include="..\HospitalRestApi\HospitalRestApi.csproj" />
<ProjectReference Include="..\Hospital\HospitalView.csproj" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,29 @@
@{
ViewData["Title"] = "CreateDescriptionProcedure";
}
<div class="text-center">
<h2 class="display-4">Создание описание к процедуре</h2>
</div>
<form method="post">
<div class="row">
<div class="col-4">Процедура:</div>
<div class="col-8">
<select id="procedure" name="procedure" class="form-control" asp-items="@(new SelectList(@ViewBag.Procedures,"Id", "Name"))"></select>
</div>
</div>
<div class="row">
<div class="col-4">Текст:</div>
<div class="col-8">
<textarea id="text" name="text" rows="5" cols="80">
</textarea>
</div>
</div>
<div class="row">
<div class="col-8"></div>
<div class="col-4">
<input type="submit" value="Создать" class="btn
btn-primary" />
</div>
</div>
</form>

View File

@ -0,0 +1,34 @@
@{
ViewData["Title"] = "CreateProcedure";
}
<div class="text-center">
<h2 class="display-4">Создание процедуры</h2>
</div>
<form method="post">
<div class="row">
<div class="col-4">Название:</div>
<div class="col-8">
<input type="text" name="name" id="name" />
</div>
</div>
<div class="row">
<div class="col-4">Лекарства:</div>
<div class="col-8">
<select name="medicines" class="form-control" multiple size="6" id="medicines">
@foreach (var medicine in ViewBag.Medicines)
{
<option value="@medicine.Id">@medicine.MedicineName</option>
}
</select>
</div>
</div>
<div class="row">
<div class="col-8"></div>
<div class="col-4">
<input type="submit" value="Создать" class="btn
btn-primary" />
</div>
</div>
</form>

View File

@ -0,0 +1,18 @@
@{
ViewData["Title"] = "DeleteDescriptionProcedure";
}
<div class="text-center">
<h2 class="display-4">Удаление описания процедуры</h2>
</div>
<form method="post">
<div class="row">
<div class="col-4">Описание процедуры:</div>
<div class="col-8">
<select id="descriptionProcedure" name="descriptionProcedure" class="form-control" asp-items="@(new SelectList(@ViewBag.DescriptionProcedures, "Id", "Description"))"></select>
</div>
</div>
<div class="row">
<div class="col-4"></div>
<div class="col-8"><input type="submit" value="Удалить" class="btn btn-danger" /></div>
</div>
</form>

View File

@ -0,0 +1,18 @@
@{
ViewData["Title"] = "DeleteProcedure";
}
<div class="text-center">
<h2 class="display-4">Удаление процедуры</h2>
</div>
<form method="post">
<div class="row">
<div class="col-4">Процедура:</div>
<div class="col-8">
<select id="procedure" name="procedure" class="form-control" asp-items="@(new SelectList(@ViewBag.Procedures, "Id", "Name"))"></select>
</div>
</div>
<div class="row">
<div class="col-4"></div>
<div class="col-8"><input type="submit" value="Удалить" class="btn btn-danger" /></div>
</div>
</form>s

View File

@ -0,0 +1,53 @@
@using HospitalContracts.ViewModels
@model List<DescriptionProcedureViewModel>
@{
ViewData["Title"] = "DescriptionProcedure";
}
<div class="text-center">
<h1 class="display-4">Описание к процедуре</h1>
</div>
<div class="text-center">
@{
if (Model == null)
{
<h3 class="display-4">Авторизируйтесь</h3>
return;
}
<p>
<a asp-action="CreateDescriptionProcedure">Создать описание к процедуре</a>
<a asp-action="UpdateDescriptionProcedure">Обновить описание к процедуре</a>
<a asp-action="DeleteDescriptionProcedure">Удалить описание к процедуре</a>
</p>
<table class="table">
<thead>
<tr>
<th>
Номер
</th>
<th>
Описание
</th>
</tr>
</thead>
<tbody>
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem =>
item.Id)
</td>
<td>
@Html.DisplayFor(modelItem =>
item.Description)
</td>
</tr>
}
</tbody>
</table>
}
</div>

View File

@ -0,0 +1,58 @@
@using HospitalContracts.ViewModels
@model List<MedicineViewModel>
@{
ViewData["Title"] = "Home Page";
}
<div class="text-center">
<h1 class="display-4">Лекарства</h1>
</div>
<div class="text-center">
@{
if (Model == null)
{
<h3 class="display-4">Авторизируйтесь</h3>
return;
}
<p>
<a asp-action="CreateMedicine">Создать лекарство</a>
<a asp-action="UpdateMedicine">Обновить лекарство</a>
<a asp-action="DeleteMedicine">Удалить лекарство</a>
<a asp-action="MedicineAnimals">Связать лекарства и процедуры</a>
</p>
<table class="table">
<thead>
<tr>
<th>
Номер
</th>
<th>
Название
</th>
<th>
Цена
</th>
</tr>
</thead>
<tbody>
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem =>
item.Id)
</td>
<td>
@Html.DisplayFor(modelItem =>
item.Name)
</td>
<td>
@Html.DisplayFor(modelItem =>
item.Price)
</td>
</tr>
}
</tbody>
</table>
}
</div>

View File

@ -0,0 +1,65 @@
@using HospitalContracts.ViewModels;
@{
ViewData["Title"] = "MedicineRecipe";
}
<div class="text-center">
<h2 class="display-4">Связывание лекарства и рецепта</h2>
</div>
<form method="post">
<div class="row">
<div class="col-4">Лекарство:</div>
<div class="col-8">
<select id="medicine" name="medicine" class="form-control" asp-items="@(new SelectList(@ViewBag.Medicines, "Id", "Name"))"></select>
</div>
</div>
<input style = "visibility: hidden" type="text" name="name" id="name" class="form-control" />
<input style = "visibility: hidden" type="text" id="price" name="price" class="form-control" />
<div class="row">
<div class="col-4">Рецепт:</div>
<div class="col-8">
<select name="recipes" class="form-control" multiple size="5" id="recipes">
@foreach (var recipe in ViewBag.Recipes)
{
<option value="@recipe.Id" id="@recipe.recipeName">@recipe.RecipeName</option>
}
</select>
</div>
</div>
<div class="row">
<div class="col-8"></div>
<div class="col-4"><input type="submit" value="Сохранить" class="btn btn-primary" /></div>
</div>
</form>
@section Scripts
{
<script>
function check() {
var medicine = $('#medicine').val();
$("#recipes option:selected").removeAttr("selected");
if (medicine) {
$.ajax({
method: "GET",
url: "/Home/GetMedicine",
data: { medicineId: medicine },
success: function (result) {
console.log(result.item2);
$('#name').val(result.item1.medicineName);
$('#price').val(result.item1.price);
$.map(result.item2, function (n) {
console.log("#" + n);
$("#" + n).attr("selected", "selected")
});
}
});
};
}
check();
$('#medicine').on('change', function () {
check();
});
</script>
}

View File

@ -0,0 +1,28 @@
@using HospitalContracts.ViewModels
@model PharmacistViewModel
@{
ViewData["Title"] = "Privacy Policy";
}
<div class="text-center">
<h2 class="display-4">Личные данные</h2>
</div>
<form method="post">
<div class="row">
<div class="col-4">Login:</div>
<div class="col-8"><input type="text" name="login" value="@Model.Login" /></div>
</div>
<div class="row">
<div class="col-4">Пароль:</div>
<div class="col-8"><input type="password" name="password" value="@Model.Password" /></div>
</div>
<div class="row">
<div class="col-4">ФИО:</div>
<div class="col-8"><input type="text" name="fio" value="@Model.FIO" /></div>
</div>
<div class="row">
<div class="col-8"></div>
<div class="col-4"><input type="submit" value="Сохранить" class="btn btn-primary" /></div>
</div>
</form>

View File

@ -0,0 +1,51 @@
@using HospitalContracts.ViewModels
@model List<ProcedureViewModel>
@{
ViewData["Title"] = "Procedures";
}
<div class="text-center">
<h1 class="display-4">Процедуры</h1>
</div>
<div class="text-center">
@{
if (Model == null)
{
<h3 class="display-4">Авторизируйтесь</h3>
return;
}
<p>
<a asp-action="CreateProcedure">Создать процедуру</a>
<a asp-action="UpdateProcedure">Обновить процедуру</a>
<a asp-action="DeleteProcedure">Удалить процедуру</a>
</p>
<table class="table">
<thead>
<tr>
<th>
Номер
</th>
<th>
Название
</th>
</tr>
</thead>
<tbody>
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem =>
item.Id)
</td>
<td>
@Html.DisplayFor(modelItem =>
item.Name)
</td>
</tr>
}
</tbody>
</table>
}
</div>

View File

@ -0,0 +1,48 @@
@{
ViewData["Title"] = "Register";
}
< div class= "text-center" >
< h2 class= "display-4" > Регистрация </ h2 >
</ div >
< form method = "post" >
< div class= "row" >
< div class= "col-4" > Email:</ div >
< div class= "col-8" >< input type = "text" name = "email" /></ div >
</ div >
< div class= "row" >
< div class= "col-4" > Пароль:</ div >
< div class= "col-8" >< input type = "password" name = "password" /></ div >
</ div >
< div class= "row" >
< div class= "col-4" > ФИО:</ div >
< div class= "col-8" >< input type = "text" name = "fio" /></ div >
</ div >
< div class= "row" >
< div class= "col-8" ></ div >
< div class= "col-4" >
< input type = "submit" value = "Регистрация"
class= "btn btn-primary" />
</ div >
</ div >
</ form >

View File

@ -0,0 +1,65 @@
@{
ViewData["Title"] = "UpdateDescriptionProcedure";
}
<div class="text-center">
<h2 class="display-4">Обновление описания к процедуре</h2>
</div>
<form method="post">
<div class="row">
<div class="col-4">Описание:</div>
<div class="col-8">
<select id="descriptionProcedure" name="descriptionProcedure" class="form-control" asp-items="@(new SelectList(@ViewBag.DescriptionProcedures,"Id", "Text"))"></select>
</div>
</div>
<div class="row">
<div class="col-4">Процедура:</div>
<div class="col-8">
<select name="procedure" class="form-control" id="procedure">
@foreach (var procedure in ViewBag.Procedures)
{
<option value="@procedure.Id" id="@procedure.Id">@procedure.ProcedureName</option>
}
</select>
</div>
</div>
<div class="row">
<div class="col-4">Текст:</div>
<div class="col-8">
<textarea id="text" name="text" rows="5" cols="80">
</textarea>
</div>
</div>
<div class="row">
<div class="col-8"></div>
<div class="col-4">
<input type="submit" value="Создать" class="btn
btn-primary" />
</div>
</div>
</form>
<script>
function check() {
var descriptionProcedure = $('#descriptionProcedure').val();
$("#procedure option:selected").removeAttr("selected");
if (descriptionProcedure) {
$.ajax({
method: "GET",
url: "/Home/GetdescriptionProcedure",
data: { descriptionProcedureId: descriptionProcedure },
success: function (result) {
console.log(result.item2);
$('#text').val(result.text);
$("#" + result.procedureId).attr("selected", "selected")
}
});
};
}
check();
$('#descriptionProcedure').on('change', function () {
check();
});
</script>

View File

@ -0,0 +1,56 @@
@using HospitalContracts.ViewModels;
@{
ViewData["Title"] = "UpdateMedicine";
}
<div class="text-center">
<h2 class="display-4">Редактирование лекарства</h2>
</div>
<form method="post">
<div class="row">
<div class="col-4">Лекарство:</div>
<div class="col-8">
<select id="medicine" name="medicine" class="form-control" asp-items="@(new SelectList(@ViewBag.Medicines, "Id", "Name"))"></select>
</div>
</div>
<div class="row">
<div class="col-4">Название:</div>
<div class="col-8"><input type="text" name="name" id="name" class="form-control" /></div>
</div>
<div class="row">
<div class="col-4">Цена:</div>
<div class="col-8"><input type="text" id="price" name="price" class="form-control" /></div>
</div>
<div class="row">
<div class="col-8"></div>
<div class="col-4"><input type="submit" value="Сохранить" class="btn btn-primary" /></div>
</div>
</form>
@section Scripts
{
<script>
function check() {
var medicine = $('#medicine').val();
$("#animals option:selected").removeAttr("selected");
if (medicine) {
$.ajax({
method: "GET",
url: "/Home/GetMedicine",
data: { medicineId: medicine },
success: function (result) {
console.log(result.item2);
$('#name').val(result.item1.medicineName);
$('#price').val(result.item1.price);
}
});
};
}
check();
$('#medicine').on('change', function () {
check();
});
</script>
}

View File

@ -0,0 +1,71 @@
@using HospitalContracts.ViewModels;
@{
ViewData["Title"] = "UpdateProcedure";
}
<div class="text-center">
<h2 class="display-4">Редактирование процедуры</h2>
</div>
<form method="post">
<div class="row">
<div class="col-4">Процедура:</div>
<div class="col-8">
<select id="procedure" name="procedure" class="form-control" asp-items="@(new SelectList(@ViewBag.Procedures, "Id", "Name"))"></select>
</div>
</div>
<div class="row">
<div class="col-4">Название:</div>
<div class="col-8"><input type="text" name="name" id="name" class="form-control" /></div>
</div>
<div class="row">
<div class="col-4">Цена:</div>
<div class="col-8"><input type="text" id="price" name="price" class="form-control" /></div>
</div>
<div class="row">
<div class="col-4">Лекарства:</div>
<div class="col-8">
<select name="medicines" class="form-control" multiple size="5" id="medicines">
@foreach (var medicine in ViewBag.Medicines)
{
<option value="@medicine.Id" id="@medicine.MedicineName">@medicine.MedicineName</option>
}
</select>
</div>
</div>
<div class="row">
<div class="col-8"></div>
<div class="col-4"><input type="submit" value="Сохранить" class="btn btn-primary" /></div>
</div>
</form>
@section Scripts
{
<script>
function check() {
var procedure = $('#procedure').val();
$("#medicines option:selected").removeAttr("selected");
if (procedure) {
$.ajax({
method: "GET",
url: "/Home/Getprocedure",
data: { procedureId: procedure },
success: function (result) {
console.log(result.item2);
$('#name').val(result.item1.procedureName);
$.map(result.item2, function (n) {
console.log("#" + n);
$("#" + n).attr("selected", "selected")
});
}
});
};
}
check();
$('#procedure').on('change', function () {
check();
});
</script>
}

View File

@ -0,0 +1,3 @@
@using PharmacistApp
@using PharmacistApp.Models
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers

View File

@ -0,0 +1,3 @@
@{
Layout = "_Layout";
}