Завтра доделаю

This commit is contained in:
gg12 darfren 2024-04-28 21:05:43 +04:00
parent 62570a8348
commit 0f1757fc1d
11 changed files with 307 additions and 15 deletions

View File

@ -484,5 +484,107 @@ View(APIPharmacist.GetRequest<List<ServiceViewModel>>($"api/service/getservices?
return result;
}
public IActionResult Guidances()
{
if (APIPharmacist.Pharmacist == null)
{
return Redirect("~/Home/Enter");
}
var res = APIPharmacist.GetRequest<List<GuidanceViewModel>>($"api/guidance/getguidances");
return
View(res);
}
[HttpGet]
public IActionResult CreateGuidance()
{
ViewBag.Services = APIPharmacist.GetRequest<List<ServiceViewModel>>("api/service/getservices");
return View();
}
[HttpPost]
public void CreateGuidance(int service, string text)
{
if (APIPharmacist.Pharmacist == null)
{
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
}
if (string.IsNullOrEmpty(text))
{
throw new Exception("Рекомендация не может быть пустой");
}
APIPharmacist.PostRequest("api/guidance/createguidance", new
GuidanceBindingModel
{
ServiceId = service,
Text = text,
});
Response.Redirect("Index");
}
[HttpGet]
public IActionResult UpdateGuidance()
{
ViewBag.Services = APIPharmacist.GetRequest<List<ServiceViewModel>>("api/service/getservices");
ViewBag.Guidances = APIPharmacist.GetRequest<List<GuidanceViewModel>>($"api/guidance/getguidances");
return View();
}
[HttpPost]
public void UpdateGuidance(int guidance, int service, string text)
{
if (APIPharmacist.Pharmacist == null)
{
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
}
if (string.IsNullOrEmpty(text))
{
throw new Exception("Рекомендация не может быть пустой");
}
APIPharmacist.PostRequest("api/guidance/updateguidance", new
GuidanceBindingModel
{
Id = guidance,
ServiceId = service,
Text = text,
});
Response.Redirect("Index");
}
[HttpGet]
public IActionResult DeleteGuidance()
{
ViewBag.Guidances = APIPharmacist.GetRequest<List<GuidanceViewModel>>($"api/guidance/getguidances");
return View();
}
[HttpPost]
public void DeleteGuidance(int guidance, int service, string text)
{
if (APIPharmacist.Pharmacist == null)
{
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
}
APIPharmacist.PostRequest("api/guidance/deleteguidance", new
GuidanceBindingModel
{
Id = guidance
});
Response.Redirect("Index");
}
[HttpGet]
public GuidanceViewModel GetGuidance(int guidanceId)
{
if (APIPharmacist.Pharmacist == null)
{
throw new Exception("Âû êàê ñþäà ïîïàëè? Ñþäà âõîä òîëüêî àâòîðèçîâàííûì");
}
var result = APIPharmacist.GetRequest<GuidanceViewModel>($"api/guidance/getguidance?guidanceid={guidanceId}");
if (result == null)
{
return default;
}
return result;
}
}
}

View File

@ -0,0 +1,29 @@
@{
ViewData["Title"] = "CreateGuidance";
}
<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="service" name="service" class="form-control" asp-items="@(new SelectList(@ViewBag.Services,"Id", "ServiceName"))"></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,18 @@
@{
ViewData["Title"] = "DeleteGuidance";
}
<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="guidance" name="guidance" class="form-control" asp-items="@(new SelectList(@ViewBag.Guidances, "Id", "GuidanceName"))"></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,56 @@
@using VetClinicContracts.ViewModels
@model List<GuidanceViewModel>
@{
ViewData["Title"] = "Guidances";
}
<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="CreateGuidance">Создать рекомендацию</a>
<a asp-action="UpdateGuidance">Обновить рекомендацию</a>
<a asp-action="DeleteGuidance">Удалить рекомендацию</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.Date)
</td>
<td>
@Html.DisplayFor(modelItem =>
item.Text)
</td>
</tr>
}
</tbody>
</table>
}
</div>

View File

@ -0,0 +1,59 @@
@{
ViewData["Title"] = "UpdateGuidance";
}
<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="guidance" name="guidance" class="form-control" asp-items="@(new SelectList(@ViewBag.Guidances,"Id", "Text"))"></select>
</div>
</div>
<div class="row">
<div class="col-4">Услуга:</div>
<div class="col-8">
<select id="service" name="service" class="form-control" asp-items="@(new SelectList(@ViewBag.Services,"Id", "ServiceName"))"></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 guidance = $('#guidance').val();
if (guidance) {
$.ajax({
method: "GET",
url: "/Home/GetGuidance",
data: { guidanceId: guidance },
success: function (result) {
console.log(result.item2);
$('#text').val(result.text);
$("#" + result.serviceId).attr("selected", "selected")
}
});
};
}
check();
$('#guidance').on('change', function () {
check();
});
</script>

View File

@ -3,7 +3,7 @@
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>@ViewData["Title"] - IceCreamShopClientApp</title>
<title>@ViewData["Title"] - PharmacistApp </title>
<link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css" />
<link rel="stylesheet" href="~/css/site.css" />
<script src="~/lib/jquery/dist/jquery.min.js"></script>
@ -26,6 +26,9 @@
<li class="nav-item">
<a class="nav-link text-dark" asparea="" asp-controller="Home" asp-action="Services">Услуги</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" asparea="" asp-controller="Home" asp-action="Guidances">Рекомендации</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" asparea="" asp-controller="Home" asp-action="Privacy">Личные данные</a>
</li>
@ -47,7 +50,7 @@
</div>
<footer class="border-top footer text-muted">
<div class="container">
&copy; 2024 - Магазин мороженного - <a asp-area="" aspcontroller="Home" asp-action="Privacy">Личные данные</a>
&copy; 2024 - Ветклиника - <a asp-area="" aspcontroller="Home" asp-action="Privacy">Личные данные</a>
</div>
</footer>
<script src="~/js/site.js" asp-append-version="true"></script>

View File

@ -11,7 +11,7 @@ namespace VetClinicContracts.BindingModels
{
public int Id { get; set; }
public string Text { get; set; } = string.Empty;
public DateTime Date { get; set; }
public DateTime Date { get; set; } = DateTime.Now;
public int ServiceId { get; set; }
}
}

View File

@ -51,16 +51,15 @@ namespace VetClinicDataBaseImplement.Implements
public GuidanceViewModel? Update(GuidanceBindingModel model)
{
using var context = new VetClinicDatabase();
var element = context.Guidances
.Include(x => x.Service)
.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
var order = context.Guidances.Include(x => x.Service).FirstOrDefault(x => x.Id ==
model.Id);
if (order == null)
{
context.Guidances.Remove(element);
context.SaveChanges();
return element.GetViewModel;
return null;
}
return null;
order.Update(model);
context.SaveChanges();
return order.GetViewModel;
}
public GuidanceViewModel? Delete(GuidanceBindingModel model)
{

View File

@ -21,12 +21,29 @@ namespace VetClinicRestApi.Controllers
_logger = logger;
_guidance = guidance;
}
[HttpGet]
public List<GuidanceViewModel>? GetGuidances(int serviceId)
public GuidanceViewModel GetGuidance(int guidanceId)
{
try
{
var elem = _guidance.ReadElement(new GuidanceSearchModel { Id = guidanceId });
if (elem == null)
return null;
return elem;
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения рекомендации по id={Id}", guidanceId);
throw;
}
}
[HttpGet]
public List<GuidanceViewModel>? GetGuidances(int? serviceId = null)
{
try
{
if (!serviceId.HasValue)
return _guidance.ReadList(null);
return _guidance.ReadList(new GuidanceSearchModel
{
ServiceId = serviceId

View File

@ -4,6 +4,7 @@ using VetClinicContracts.BindingModels;
using VetClinicContracts.BusinessLogicsContracts;
using VetClinicContracts.SearchModels;
using VetClinicContracts.ViewModels;
using VetClinicDataBaseImplement.Models;
namespace VetClinicRestApi.Controllers
{
@ -42,7 +43,11 @@ namespace VetClinicRestApi.Controllers
{
try
{
var res = _medicine.ReadList(new MedicineSearchModel { PharmacistId = pharmacistId });
List<MedicineViewModel> res;
if (!pharmacistId.HasValue)
res = _medicine.ReadList(null);
else
res = _medicine.ReadList(new MedicineSearchModel { PharmacistId = pharmacistId });
foreach (var medicine in res)
medicine.MedicineAnimals = null;
return res;

View File

@ -43,7 +43,11 @@ namespace VetClinicRestApi.Controllers
{
try
{
var res = _service.ReadList(new ServiceSearchModel { PharmacistId = pharmacistId });
List<ServiceViewModel> res;
if (!pharmacistId.HasValue)
res = _service.ReadList(null);
else
res = _service.ReadList(new ServiceSearchModel { PharmacistId = pharmacistId });
foreach (var service in res)
service.ServiceMedicines = null;
return res;