From c7c55114e8c943cb6fab584d91b7ec79af0b0e4e Mon Sep 17 00:00:00 2001 From: antoc0der <1@DESKTOP-K1L8ND3> Date: Mon, 29 Apr 2024 20:07:18 +0400 Subject: [PATCH] =?UTF-8?q?=D0=BF=D0=BE=D1=80=D1=83=D1=87=D0=B8=D1=82?= =?UTF-8?q?=D0=B5=D0=BB=D1=8C=20=D1=81=D0=B4=D0=B5=D0=BB=D0=B0=D0=BB=20?= =?UTF-8?q?=D1=84=D0=BE=D1=80=D0=BC=D1=8B=20=D0=B4=D0=BB=D1=8F=20=D0=BB?= =?UTF-8?q?=D0=B5=D0=BA=D0=B0=D1=80=D1=81=D1=82=D0=B2.=20=D0=BE=D1=81?= =?UTF-8?q?=D1=82=D0=B0=D0=BB=D0=BE=D1=81=D1=8C=20=D1=82=D0=BE=D0=BB=D1=8C?= =?UTF-8?q?=D0=BA=D0=BE=20=D1=81=D0=B5=D1=80=D0=B2=D0=B8=D1=81=D1=8B=20?= =?UTF-8?q?=D0=B8=20=D0=BF=D0=B5=D1=80=D0=B5=D1=81=D0=BE=D0=B1=D1=80=D0=B0?= =?UTF-8?q?=D1=82=D1=8C=20=D0=BC=D0=B8=D0=B3=D1=80=D0=B0=D1=86=D0=B8=D1=8E?= =?UTF-8?q?.=20=D0=BD=D1=83=20=D0=B8=20=D0=BE=D1=82=D0=B4=D0=B5=D0=B1?= =?UTF-8?q?=D0=B0=D0=B6=D0=B8=D1=82=D1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/HomeController.cs | 128 +++++++++++++++++- .../Views/Home/CreateDrug.cshtml | 44 ++++++ .../Views/Home/DeleteDrug.cshtml | 18 +++ .../Views/Home/Drugs.cshtml | 53 ++++++++ .../Views/Home/UpdateDrug.cshtml | 77 +++++++++++ .../Views/Shared/_Layout.cshtml | 3 + 6 files changed, 316 insertions(+), 7 deletions(-) create mode 100644 VeterinaryView/VeterinaryShowDoctorApp/Views/Home/CreateDrug.cshtml create mode 100644 VeterinaryView/VeterinaryShowDoctorApp/Views/Home/DeleteDrug.cshtml create mode 100644 VeterinaryView/VeterinaryShowDoctorApp/Views/Home/Drugs.cshtml create mode 100644 VeterinaryView/VeterinaryShowDoctorApp/Views/Home/UpdateDrug.cshtml diff --git a/VeterinaryView/VeterinaryShowDoctorApp/Controllers/HomeController.cs b/VeterinaryView/VeterinaryShowDoctorApp/Controllers/HomeController.cs index 5219ce1..4eb35bc 100644 --- a/VeterinaryView/VeterinaryShowDoctorApp/Controllers/HomeController.cs +++ b/VeterinaryView/VeterinaryShowDoctorApp/Controllers/HomeController.cs @@ -3,7 +3,10 @@ using System.Diagnostics; using VeterinaryShowDoctorApp.Models; using VeterinaryContracts.ViewModels; using VeterinaryContracts.BindingModels; - +using System.Text; +using VeterinaryDataModels; +using VeterinaryContracts.SearchModels; +using VeterinaryContracts.StorageContracts; namespace VeterinaryShowDoctorApp.Controllers { @@ -190,36 +193,147 @@ namespace VeterinaryShowDoctorApp.Controllers Response.Redirect("Index"); } + + public IActionResult Drugs() + { + if (APIDoctor.Doctor == null) + { + return Redirect("~/Home/Enter"); + } + return View(APIDoctor.GetRequest>($"api/drug/getdrugs?doctorid={APIDoctor.Doctor.Id}")); + + } + + public IActionResult CreateDrug() { if (APIDoctor.Doctor == null) { return Redirect("~/Home/Enter"); } + ViewBag.Medications = APIDoctor.GetRequest>($"api/medication/getmedications"); + return View(); } + + [HttpPost] - public void CreateDrug(string name, int price) + public void CreateDrug(string name, List medications, int count) { if (APIDoctor.Doctor == null) { throw new Exception("Вы как суда попали? Суда вход только авторизованным"); } - if (string.IsNullOrEmpty(name) || price <= 0) + double _price=0; + if (string.IsNullOrEmpty(name) || count <=0) { throw new Exception("Ошибка в введенных данных"); } - APIDoctor.PostRequest("api/medication/createmedication", new MedicationBindingModel + Dictionary a = new Dictionary(); + foreach (int medication in medications) { - MedicationName = name, - Price = price, - DoctorId = APIDoctor.Doctor.Id + a.Add(medication, new MedicationSearchModel { Id = medication } as IMedicationModel); + } + foreach (var elem in a) + { + _price += elem.Value.Price; + } + + APIDoctor.PostRequest("api/drug/createdrug", new DrugBindingModel + { + DrugName = name, + Price = Math.Round(_price, 2), + DrugMedications = a, + Count = count }); Response.Redirect("Index"); } + public IActionResult DeleteDrug() + { + if (APIDoctor.Doctor == null) + { + return Redirect("~/Home/Enter"); + } + ViewBag.Drugs = APIDoctor.GetRequest>($"api/drug/getdrugs?doctorid={APIDoctor.Doctor.Id}"); + return View(); + } + [HttpPost] + public void DeleteDrug(int drug) + { + if (APIDoctor.Doctor == null) + { + throw new Exception("Вы как суда попали? Суда вход только авторизованным"); + } + APIDoctor.PostRequest("api/drug/deletedrug", new DrugBindingModel + { + Id = drug + }); + Response.Redirect("Index"); + } + + public IActionResult UpdateDrug() + { + if (APIDoctor.Doctor == null) + { + return Redirect("~/Home/Enter"); + } + ViewBag.Drugs = APIDoctor.GetRequest>($"api/drug/getdrugs?doctorid={APIDoctor.Doctor.Id}"); + ViewBag.Medications = APIDoctor.GetRequest>($"api/medication/getmedications"); + return View(); + } + + [HttpPost] + public void UpdateDrug(int drug, string name, List medications, int count) + { + if (APIDoctor.Doctor == null) + { + throw new Exception("Вы как суда попали? Суда вход только авторизованным"); + } + double _price=0; + if (string.IsNullOrEmpty(name) || count <= 0) + { + throw new Exception("Ошибка в введенных данных"); + } + Dictionary a = new Dictionary(); + foreach (int medication in medications) + { + a.Add(medication, new MedicationSearchModel { Id = medication } as IMedicationModel); + } + foreach (var elem in a) + { + _price += elem.Value.Price; + } + APIDoctor.PostRequest("api/drug/updatedrug", new DrugBindingModel + { + Id = drug, + DrugName = name, + Price = Math.Round(_price, 2), + DrugMedications = a, + Count = count + }); + Response.Redirect("Index"); + } + + [HttpGet] + public Tuple>? GetDrug(int drugId) + { + if (APIDoctor.Doctor == null) + { + throw new Exception("Вы как суда попали? Суда вход только авторизованным"); + } + var result = APIDoctor.GetRequest>>($"api/drug/getdrug?drugid={drugId}"); + if (result == null) + { + return default; + } + + return result; + } + + [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] public IActionResult Error() diff --git a/VeterinaryView/VeterinaryShowDoctorApp/Views/Home/CreateDrug.cshtml b/VeterinaryView/VeterinaryShowDoctorApp/Views/Home/CreateDrug.cshtml new file mode 100644 index 0000000..32ab979 --- /dev/null +++ b/VeterinaryView/VeterinaryShowDoctorApp/Views/Home/CreateDrug.cshtml @@ -0,0 +1,44 @@ +@{ + ViewData["Title"] = "CreateDrug"; +} + +
+

Создание лекарства

+
+
+
+
Название:
+
+ +
+
+
+
Цена:
+
+ +
+
+
+
Количество:
+
+ +
+
+
+
Медикаменты:
+
+ +
+
+
+
+
+ +
+
+
diff --git a/VeterinaryView/VeterinaryShowDoctorApp/Views/Home/DeleteDrug.cshtml b/VeterinaryView/VeterinaryShowDoctorApp/Views/Home/DeleteDrug.cshtml new file mode 100644 index 0000000..109e10e --- /dev/null +++ b/VeterinaryView/VeterinaryShowDoctorApp/Views/Home/DeleteDrug.cshtml @@ -0,0 +1,18 @@ +@{ + ViewData["Title"] = "DeleteDrug"; +} +
+

Удаление лекарства

+
+
+
+
Лекарство:
+
+ +
+
+
+
+
+
+
s diff --git a/VeterinaryView/VeterinaryShowDoctorApp/Views/Home/Drugs.cshtml b/VeterinaryView/VeterinaryShowDoctorApp/Views/Home/Drugs.cshtml new file mode 100644 index 0000000..7ba8ff4 --- /dev/null +++ b/VeterinaryView/VeterinaryShowDoctorApp/Views/Home/Drugs.cshtml @@ -0,0 +1,53 @@ +@using VeterinaryContracts.ViewModels +@model List +@{ + ViewData["Title"] = "Drugs"; +} +
+

Лекарства

+
+
+ @{ + if (Model == null) + { +

Авторизируйтесь

+ return; + } +

+ Создать лекарство + Обновить лекарство + Удалить лекарство +

+ + + + + + + + + + @foreach (var item in Model) + { + + + + + + } + +
+ Номер + + Название + + Цена +
+ @Html.DisplayFor(modelItem =>item.Id) + + @Html.DisplayFor(modelItem =>item.DrugName) + + @Html.DisplayFor(modelItem =>item.Price) +
+ } +
diff --git a/VeterinaryView/VeterinaryShowDoctorApp/Views/Home/UpdateDrug.cshtml b/VeterinaryView/VeterinaryShowDoctorApp/Views/Home/UpdateDrug.cshtml new file mode 100644 index 0000000..be694a8 --- /dev/null +++ b/VeterinaryView/VeterinaryShowDoctorApp/Views/Home/UpdateDrug.cshtml @@ -0,0 +1,77 @@ +@using VeterinaryContracts.ViewModels; + +@{ + ViewData["Title"] = "UpdateDrug"; +} + +
+

Редактирование лекарства

+
+
+
+
Услуга:
+
+ +
+
+
+
Название:
+
+
+
+
Цена:
+
+
+
+
Количество:
+
+
+
+
+
Медикаменты:
+
+ +
+
+
+
+
+
+
+ +@section Scripts + { + +} diff --git a/VeterinaryView/VeterinaryShowDoctorApp/Views/Shared/_Layout.cshtml b/VeterinaryView/VeterinaryShowDoctorApp/Views/Shared/_Layout.cshtml index 5b718f1..64ac521 100644 --- a/VeterinaryView/VeterinaryShowDoctorApp/Views/Shared/_Layout.cshtml +++ b/VeterinaryView/VeterinaryShowDoctorApp/Views/Shared/_Layout.cshtml @@ -31,6 +31,9 @@ +