From 62570a8348aee843384df8b414a38e763a936670 Mon Sep 17 00:00:00 2001 From: gg12 darfren Date: Sun, 28 Apr 2024 17:34:36 +0400 Subject: [PATCH] =?UTF-8?q?=D0=A1=D0=B4=D0=B5=D0=BB=D0=B0=D0=BB=20=D1=84?= =?UTF-8?q?=D0=BE=D1=80=D0=BC=D0=BE=D1=87=D0=BA=D1=83=20=D1=83=D1=81=D0=BB?= =?UTF-8?q?=D1=83=D0=B3=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/HomeController.cs | 282 ++++++++++-------- .../Views/Home/CreateService.cshtml | 39 +++ .../Views/Home/DeleteMedicine.cshtml | 2 +- .../Views/Home/DeleteService.cshtml | 18 ++ .../PharmacistApp/Views/Home/Services.cshtml | 56 ++++ .../Views/Home/UpdateService.cshtml | 71 +++++ .../PharmacistApp/Views/Shared/_Layout.cshtml | 3 + .../Models/Service.cs | 2 + .../Controllers/MedicineController.cs | 4 +- .../Controllers/ServiceController.cs | 13 +- 10 files changed, 352 insertions(+), 138 deletions(-) create mode 100644 VetClinic/PharmacistApp/Views/Home/CreateService.cshtml create mode 100644 VetClinic/PharmacistApp/Views/Home/DeleteService.cshtml create mode 100644 VetClinic/PharmacistApp/Views/Home/Services.cshtml create mode 100644 VetClinic/PharmacistApp/Views/Home/UpdateService.cshtml diff --git a/VetClinic/PharmacistApp/Controllers/HomeController.cs b/VetClinic/PharmacistApp/Controllers/HomeController.cs index d328c24..d5ba3f9 100644 --- a/VetClinic/PharmacistApp/Controllers/HomeController.cs +++ b/VetClinic/PharmacistApp/Controllers/HomeController.cs @@ -321,148 +321,168 @@ View(APIPharmacist.GetRequest>($"api/medicine/getmedicin return result; } - //public IActionResult CreateService() - //{ - // if (APIPharmacist.Pharmacist == null) - // { - // return Redirect("~/Home/Enter"); - // } - // ViewBag.Medicines = APIPharmacist.GetRequest>($"api/animal/getmedicines"); + public IActionResult Services() + { + if (APIPharmacist.Pharmacist == null) + { + return Redirect("~/Home/Enter"); + } + return +View(APIPharmacist.GetRequest>($"api/service/getservices?pharmacistid={APIPharmacist.Pharmacist.Id}")); - // return View(); - //} + } + + + public IActionResult CreateService() + { + if (APIPharmacist.Pharmacist == null) + { + return Redirect("~/Home/Enter"); + } + ViewBag.Medicines = APIPharmacist.GetRequest>($"api/medicine/getmedicines"); + + return View(); + } - //[HttpPost] - //public void CreateService(string name, string price, List medicines) - //{ - // if (APIPharmacist.Pharmacist == null) - // { - // throw new Exception("Âû êàê ñþäà ïîïàëè? Ñþäà âõîä òîëüêî àâòîðèçîâàííûì"); - // } - // double _price; - // try - // { - // _price = Convert.ToDouble(price); - // } - // catch (Exception ex) - // { - // throw new Exception("Îøèáêà â ââåäåííûõ äàííûõ"); - // } - // if (string.IsNullOrEmpty(name) || _price <= 0) - // { - // throw new Exception("Îøèáêà â ââåäåííûõ äàííûõ"); - // } - // Dictionary a = new Dictionary(); - // foreach (int medicine in medicines) - // { - // a.Add(medicine, new AnimalSearchModel { Id = medicine } as IMedicineModel); - // } + [HttpPost] + public void CreateService(string name, string price, List medicines) + { + if (APIPharmacist.Pharmacist == null) + { + throw new Exception("Âû êàê ñþäà ïîïàëè? Ñþäà âõîä òîëüêî àâòîðèçîâàííûì"); + } + StringBuilder st = new StringBuilder(price); + for (int i = 0; i < price.Length; i++) + { + if (price[i] == '.') + st[i] = ','; + } + price = st.ToString(); + double _price; + try + { + _price = Convert.ToDouble(price); + } + catch (Exception ex) + { + throw new Exception("Îøèáêà â ââåäåííûõ äàííûõ"); + } + if (string.IsNullOrEmpty(name) || _price <= 0) + { + throw new Exception("Îøèáêà â ââåäåííûõ äàííûõ"); + } + Dictionary a = new Dictionary(); + foreach (int medicine in medicines) + { + a.Add(medicine, new AnimalSearchModel { Id = medicine } as IMedicineModel); + } - // APIPharmacist.PostRequest("api/service/createservice", new ServiceBindingModel - // { - // ServiceName = name, - // Price = Math.Round(_price, 2), - // PharmacistId = APIPharmacist.Pharmacist.Id, - // ServiceMedicines = a - // }); - // Response.Redirect("Index"); - //} + APIPharmacist.PostRequest("api/service/createservice", new ServiceBindingModel + { + ServiceName = name, + Price = Math.Round(_price, 2), + PharmacistId = APIPharmacist.Pharmacist.Id, + ServiceMedicines = a + }); + Response.Redirect("Index"); + } - //public IActionResult DeleteMedicine() - //{ - // if (APIPharmacist.Pharmacist == null) - // { - // return Redirect("~/Home/Enter"); - // } - // ViewBag.Medicines = APIPharmacist.GetRequest>($"api/medicine/getmedicines?pharmacistid={APIPharmacist.Pharmacist.Id}"); - // return View(); - //} + public IActionResult DeleteService() + { + if (APIPharmacist.Pharmacist == null) + { + return Redirect("~/Home/Enter"); + } + ViewBag.Services = APIPharmacist.GetRequest>($"api/service/getservices?pharmacistid={APIPharmacist.Pharmacist.Id}"); + return View(); + } - //[HttpPost] - //public void DeleteMedicine(int medicine) - //{ - // if (APIPharmacist.Pharmacist == null) - // { - // throw new Exception("Âû êàê ñþäà ïîïàëè? Ñþäà âõîä òîëüêî àâòîðèçîâàííûì"); - // } - // APIPharmacist.PostRequest("api/medicine/deletemedicine", new MedicineBindingModel - // { - // Id = medicine - // }); - // Response.Redirect("Index"); - //} + [HttpPost] + public void DeleteService(int service) + { + if (APIPharmacist.Pharmacist == null) + { + throw new Exception("Âû êàê ñþäà ïîïàëè? Ñþäà âõîä òîëüêî àâòîðèçîâàííûì"); + } + APIPharmacist.PostRequest("api/service/deleteservice", new ServiceBindingModel + { + Id = service + }); + Response.Redirect("Index"); + } - //public IActionResult UpdateMedicine() - //{ - // if (APIPharmacist.Pharmacist == null) - // { - // return Redirect("~/Home/Enter"); - // } - // ViewBag.Medicines = APIPharmacist.GetRequest>($"api/medicine/getmedicines?pharmacistid={APIPharmacist.Pharmacist.Id}"); - // ViewBag.Animals = APIPharmacist.GetRequest>($"api/animal/getanimallist"); - // return View(); - //} + public IActionResult UpdateService() + { + if (APIPharmacist.Pharmacist == null) + { + return Redirect("~/Home/Enter"); + } + ViewBag.Services = APIPharmacist.GetRequest>($"api/service/getservices?pharmacistid={APIPharmacist.Pharmacist.Id}"); + ViewBag.Medicines = APIPharmacist.GetRequest>($"api/medicine/getmedicines"); + return View(); + } - //[HttpPost] - //public void UpdateMedicine(int medicine, string name, string price, - // List animals) - //{ - // if (APIPharmacist.Pharmacist == null) - // { - // throw new Exception("Âû êàê ñþäà ïîïàëè? Ñþäà âõîä òîëüêî àâòîðèçîâàííûì"); - // } - // double _price; - // try - // { - // _price = Convert.ToDouble(price); - // } - // catch (Exception ex) - // { - // throw new Exception("Îøèáêà â ââåäåííûõ äàííûõ"); - // } - // if (string.IsNullOrEmpty(name) || _price <= 0) - // { - // throw new Exception("Îøèáêà â ââåäåííûõ äàííûõ"); - // } - // Dictionary a = new Dictionary(); - // foreach (int animal in animals) - // { - // a.Add(animal, new AnimalSearchModel { Id = animal } as IAnimalModel); - // } - // APIPharmacist.PostRequest("api/medicine/updatemedicine", new MedicineBindingModel - // { - // Id = medicine, - // MedicineName = name, - // Price = Math.Round(_price, 2), - // PharmacistId = APIPharmacist.Pharmacist.Id, - // MedicineAnimals = a - // }); - // Response.Redirect("Index"); - //} + [HttpPost] + public void UpdateService(int service, string name, string price, + List medicines) + { + if (APIPharmacist.Pharmacist == null) + { + throw new Exception("Âû êàê ñþäà ïîïàëè? Ñþäà âõîä òîëüêî àâòîðèçîâàííûì"); + } + StringBuilder st = new StringBuilder(price); + for (int i = 0; i < price.Length; i++) + { + if (price[i] == '.') + st[i] = ','; + } + price = st.ToString(); + double _price; + try + { + _price = Convert.ToDouble(price); + } + catch (Exception ex) + { + throw new Exception("Îøèáêà â ââåäåííûõ äàííûõ"); + } + if (string.IsNullOrEmpty(name) || _price <= 0) + { + throw new Exception("Îøèáêà â ââåäåííûõ äàííûõ"); + } + Dictionary a = new Dictionary(); + foreach (int medicine in medicines) + { + a.Add(medicine, new MedicineSearchModel { Id = medicine } as IMedicineModel); + } + APIPharmacist.PostRequest("api/service/updateservice", new ServiceBindingModel + { + Id = service, + ServiceName = name, + Price = Math.Round(_price, 2), + PharmacistId = APIPharmacist.Pharmacist.Id, + ServiceMedicines = a + }); + Response.Redirect("Index"); + } - //[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] - //public IActionResult Error() - //{ - // return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier }); - //} + [HttpGet] + public Tuple>? GetService(int serviceId) + { + if (APIPharmacist.Pharmacist == null) + { + throw new Exception("Âû êàê ñþäà ïîïàëè? Ñþäà âõîä òîëüêî àâòîðèçîâàííûì"); + } + var result = APIPharmacist.GetRequest>>($"api/service/getservice?serviceid={serviceId}"); + if (result == null) + { + return default; + } - //[HttpGet] - //public Tuple>? GetMedicine(int medicineId) - //{ - // if (APIPharmacist.Pharmacist == null) - // { - // throw new Exception("Âû êàê ñþäà ïîïàëè? Ñþäà âõîä òîëüêî àâòîðèçîâàííûì"); - // } - // var result = APIPharmacist.GetRequest>>($"api/medicine/getmedicine?medicineid={medicineId}"); - // if (result == null) - // { - // return default; - // } - - // return result; - //} + return result; + } } } diff --git a/VetClinic/PharmacistApp/Views/Home/CreateService.cshtml b/VetClinic/PharmacistApp/Views/Home/CreateService.cshtml new file mode 100644 index 0000000..7e6bba2 --- /dev/null +++ b/VetClinic/PharmacistApp/Views/Home/CreateService.cshtml @@ -0,0 +1,39 @@ +@{ + ViewData["Title"] = "CreateService"; +} + +
+

Создание услуги

+
+
+
+
Название:
+
+ +
+
+
+
Цена:
+
+ +
+
+
+
Медикаменты:
+
+ +
+
+
+
+
+ +
+
+
\ No newline at end of file diff --git a/VetClinic/PharmacistApp/Views/Home/DeleteMedicine.cshtml b/VetClinic/PharmacistApp/Views/Home/DeleteMedicine.cshtml index 5de55a9..8b47b88 100644 --- a/VetClinic/PharmacistApp/Views/Home/DeleteMedicine.cshtml +++ b/VetClinic/PharmacistApp/Views/Home/DeleteMedicine.cshtml @@ -1,5 +1,5 @@ @{ - ViewData["Title"] = "Delete"; + ViewData["Title"] = "DeleteMedicine"; }

Удаление медикамента

diff --git a/VetClinic/PharmacistApp/Views/Home/DeleteService.cshtml b/VetClinic/PharmacistApp/Views/Home/DeleteService.cshtml new file mode 100644 index 0000000..f68aec8 --- /dev/null +++ b/VetClinic/PharmacistApp/Views/Home/DeleteService.cshtml @@ -0,0 +1,18 @@ +@{ + ViewData["Title"] = "DeleteService"; +} +
+

Удаление услуги

+
+
+
+
Услуга:
+
+ +
+
+
+
+
+
+
s diff --git a/VetClinic/PharmacistApp/Views/Home/Services.cshtml b/VetClinic/PharmacistApp/Views/Home/Services.cshtml new file mode 100644 index 0000000..db5ce83 --- /dev/null +++ b/VetClinic/PharmacistApp/Views/Home/Services.cshtml @@ -0,0 +1,56 @@ +@using VetClinicContracts.ViewModels +@model List +@{ + ViewData["Title"] = "Services"; +} +
+

Услуги

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

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

+ return; + } +

+ Создать услугу + Обновить услугу + Удалить услугу +

+ + + + + + + + + + @foreach (var item in Model) + { + + + + + + } + +
+ Номер + + Название + + Цена +
+ @Html.DisplayFor(modelItem => + item.Id) + + @Html.DisplayFor(modelItem => + item.ServiceName) + + @Html.DisplayFor(modelItem => + item.Price) +
+ } +
\ No newline at end of file diff --git a/VetClinic/PharmacistApp/Views/Home/UpdateService.cshtml b/VetClinic/PharmacistApp/Views/Home/UpdateService.cshtml new file mode 100644 index 0000000..e11acc4 --- /dev/null +++ b/VetClinic/PharmacistApp/Views/Home/UpdateService.cshtml @@ -0,0 +1,71 @@ +@using VetClinicContracts.ViewModels; + +@{ + ViewData["Title"] = "UpdateService"; +} + +
+

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

+
+
+
+
Услуга:
+
+ +
+
+
+
Название:
+
+
+
+
Цена:
+
+
+
+
Медикаменты:
+
+ +
+
+
+
+
+
+
+ +@section Scripts +{ + +} \ No newline at end of file diff --git a/VetClinic/PharmacistApp/Views/Shared/_Layout.cshtml b/VetClinic/PharmacistApp/Views/Shared/_Layout.cshtml index 6a922ea..002d16d 100644 --- a/VetClinic/PharmacistApp/Views/Shared/_Layout.cshtml +++ b/VetClinic/PharmacistApp/Views/Shared/_Layout.cshtml @@ -23,6 +23,9 @@ + diff --git a/VetClinic/VetClinicDataBaseImplement/Models/Service.cs b/VetClinic/VetClinicDataBaseImplement/Models/Service.cs index 3d565c8..67a60a5 100644 --- a/VetClinic/VetClinicDataBaseImplement/Models/Service.cs +++ b/VetClinic/VetClinicDataBaseImplement/Models/Service.cs @@ -52,6 +52,8 @@ namespace VetClinicDataBaseImplement.Models Id = model.Id, ServiceName = model.ServiceName, Price = model.Price, + PharmacistId = model.PharmacistId, + Pharmacist = context.Pharmacists.First(x => x.Id == model.PharmacistId), Medicines = model.ServiceMedicines.Select(x => new ServiceMedicine { diff --git a/VetClinic/VetClinicRestApi/Controllers/MedicineController.cs b/VetClinic/VetClinicRestApi/Controllers/MedicineController.cs index 2591766..bdc2915 100644 --- a/VetClinic/VetClinicRestApi/Controllers/MedicineController.cs +++ b/VetClinic/VetClinicRestApi/Controllers/MedicineController.cs @@ -28,7 +28,7 @@ namespace VetClinicRestApi.Controllers if (elem == null) return null; var res = Tuple.Create(elem, elem.MedicineAnimals.Select(x => x.Value.AnimalName).ToList()); - res.Item1.MedicineAnimals = null; + res.Item1.MedicineAnimals = null!; return res; } catch (Exception ex) @@ -38,7 +38,7 @@ namespace VetClinicRestApi.Controllers } } [HttpGet] - public List? GetMedicines(int pharmacistId) + public List? GetMedicines(int? pharmacistId = null) { try { diff --git a/VetClinic/VetClinicRestApi/Controllers/ServiceController.cs b/VetClinic/VetClinicRestApi/Controllers/ServiceController.cs index 15908c0..4109232 100644 --- a/VetClinic/VetClinicRestApi/Controllers/ServiceController.cs +++ b/VetClinic/VetClinicRestApi/Controllers/ServiceController.cs @@ -4,6 +4,7 @@ using VetClinicContracts.BindingModels; using VetClinicContracts.BusinessLogicsContracts; using VetClinicContracts.SearchModels; using VetClinicContracts.ViewModels; +using VetClinicDataBaseImplement.Models; namespace VetClinicRestApi.Controllers { @@ -27,7 +28,9 @@ namespace VetClinicRestApi.Controllers var elem = _service.ReadElement(new ServiceSearchModel { Id = serviceId }); if (elem == null) return null; - return Tuple.Create(elem, elem.ServiceMedicines.Select(x => x.Value.MedicineName).ToList()); + var res = Tuple.Create(elem, elem.ServiceMedicines.Select(x => x.Value.MedicineName).ToList()); + res.Item1.ServiceMedicines = null!; + return res; } catch (Exception ex) { @@ -36,11 +39,14 @@ namespace VetClinicRestApi.Controllers } } [HttpGet] - public List GetServices(int pharmacistId) + public List GetServices(int? pharmacistId = null) { try { - return _service.ReadList(new ServiceSearchModel { PharmacistId = pharmacistId }); + var res = _service.ReadList(new ServiceSearchModel { PharmacistId = pharmacistId }); + foreach (var service in res) + service.ServiceMedicines = null; + return res; } catch (Exception ex) { @@ -67,7 +73,6 @@ namespace VetClinicRestApi.Controllers { try { - model.ServiceMedicines = null!; return _service.Update(model); } catch (Exception ex)