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