From 4ad498b0287397db185832aad8a7b23b32335570 Mon Sep 17 00:00:00 2001 From: antoc0der <1@DESKTOP-K1L8ND3> Date: Wed, 1 May 2024 18:03:26 +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=D0=A7=D0=BE=3F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/VisitController.cs | 15 +++++++++++++ .../VeterinaryShowDoctorApp/APIDoctor.cs | 4 +--- .../Controllers/HomeController.cs | 11 ++++++++++ .../VeterinaryShowDoctorApp/Program.cs | 1 - .../Views/Home/CreateService.cshtml | 21 +------------------ .../VeterinaryShowOwnerApp/APIOwner.cs | 12 +++++------ .../Controllers/HomeController.cs | 2 +- 7 files changed, 35 insertions(+), 31 deletions(-) diff --git a/VeterinaryView/VeterinaryRestApi/Controllers/VisitController.cs b/VeterinaryView/VeterinaryRestApi/Controllers/VisitController.cs index 396bd79..6fbb295 100644 --- a/VeterinaryView/VeterinaryRestApi/Controllers/VisitController.cs +++ b/VeterinaryView/VeterinaryRestApi/Controllers/VisitController.cs @@ -47,6 +47,21 @@ namespace VeterinaryRestApi.Controllers throw; } } + + [HttpGet] + public List GetAllVisits() + { + try + { + return _visit.ReadList(null); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения списка визитов"); + throw; + } + } + [HttpPost] public bool CreateVisit(VisitBindingModel model) { diff --git a/VeterinaryView/VeterinaryShowDoctorApp/APIDoctor.cs b/VeterinaryView/VeterinaryShowDoctorApp/APIDoctor.cs index ebc32a5..f316aa6 100644 --- a/VeterinaryView/VeterinaryShowDoctorApp/APIDoctor.cs +++ b/VeterinaryView/VeterinaryShowDoctorApp/APIDoctor.cs @@ -3,7 +3,6 @@ using System.Text; using VeterinaryContracts.ViewModels; using Newtonsoft.Json; - namespace VeterinaryShowDoctorApp { public static class APIDoctor @@ -33,8 +32,7 @@ namespace VeterinaryShowDoctorApp public static void PostRequest(string requestUrl, T model) { var json = JsonConvert.SerializeObject(model); - var data = new StringContent(json, Encoding.UTF8, - "application/json"); + var data = new StringContent(json, Encoding.UTF8,"application/json"); var response = _doctor.PostAsync(requestUrl, data); var result = response.Result.Content.ReadAsStringAsync().Result; if (!response.Result.IsSuccessStatusCode) diff --git a/VeterinaryView/VeterinaryShowDoctorApp/Controllers/HomeController.cs b/VeterinaryView/VeterinaryShowDoctorApp/Controllers/HomeController.cs index 748f193..1064978 100644 --- a/VeterinaryView/VeterinaryShowDoctorApp/Controllers/HomeController.cs +++ b/VeterinaryView/VeterinaryShowDoctorApp/Controllers/HomeController.cs @@ -333,6 +333,7 @@ namespace VeterinaryShowDoctorApp.Controllers return Redirect("~/Home/Enter"); } ViewBag.Medications = APIDoctor.GetRequest>($"api/medication/getmedications"); + ViewBag.Visits = APIDoctor.GetRequest>($"api/visit/getallvisits"); return View(); } @@ -439,5 +440,15 @@ namespace VeterinaryShowDoctorApp.Controllers { return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier }); } + // визиты + public IActionResult Visits() + { + if (APIDoctor.Doctor == null) + { + return Redirect("~/Home/Enter"); + } + return View(APIDoctor.GetRequest>($"api/visit/getallvisits")); + + } } } \ No newline at end of file diff --git a/VeterinaryView/VeterinaryShowDoctorApp/Program.cs b/VeterinaryView/VeterinaryShowDoctorApp/Program.cs index 4e91254..8457773 100644 --- a/VeterinaryView/VeterinaryShowDoctorApp/Program.cs +++ b/VeterinaryView/VeterinaryShowDoctorApp/Program.cs @@ -1,6 +1,5 @@ using VeterinaryShowDoctorApp; - var builder = WebApplication.CreateBuilder(args); // Add services to the container. diff --git a/VeterinaryView/VeterinaryShowDoctorApp/Views/Home/CreateService.cshtml b/VeterinaryView/VeterinaryShowDoctorApp/Views/Home/CreateService.cshtml index 886dd80..392dbdf 100644 --- a/VeterinaryView/VeterinaryShowDoctorApp/Views/Home/CreateService.cshtml +++ b/VeterinaryView/VeterinaryShowDoctorApp/Views/Home/CreateService.cshtml @@ -15,7 +15,7 @@
Визиты:
- +
@@ -36,22 +36,3 @@
- \ No newline at end of file diff --git a/VeterinaryView/VeterinaryShowOwnerApp/APIOwner.cs b/VeterinaryView/VeterinaryShowOwnerApp/APIOwner.cs index b726146..de33c09 100644 --- a/VeterinaryView/VeterinaryShowOwnerApp/APIOwner.cs +++ b/VeterinaryView/VeterinaryShowOwnerApp/APIOwner.cs @@ -7,18 +7,18 @@ namespace VeterinaryShowOwnerApp { public static class APIOwner { - private static readonly HttpClient _client = new(); + private static readonly HttpClient _owner = new(); public static OwnerViewModel? Owner { get; set; } = null; public static void Connect(IConfiguration configuration) { - _client.BaseAddress = new Uri(configuration["IPAddress"]); - _client.DefaultRequestHeaders.Accept.Clear(); - _client.DefaultRequestHeaders.Accept.Add(new + _owner.BaseAddress = new Uri(configuration["IPAddress"]); + _owner.DefaultRequestHeaders.Accept.Clear(); + _owner.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); } public static T? GetRequest(string requestUrl) { - var response = _client.GetAsync(requestUrl); + var response = _owner.GetAsync(requestUrl); var result = response.Result.Content.ReadAsStringAsync().Result; if (response.Result.IsSuccessStatusCode) { @@ -33,7 +33,7 @@ namespace VeterinaryShowOwnerApp { var json = JsonConvert.SerializeObject(model); var data = new StringContent(json, Encoding.UTF8, "application/json"); - var response = _client.PostAsync(requestUrl, data); + var response = _owner.PostAsync(requestUrl, data); var result = response.Result.Content.ReadAsStringAsync().Result; if (!response.Result.IsSuccessStatusCode) { diff --git a/VeterinaryView/VeterinaryShowOwnerApp/Controllers/HomeController.cs b/VeterinaryView/VeterinaryShowOwnerApp/Controllers/HomeController.cs index d0d6cb5..dbf93ce 100644 --- a/VeterinaryView/VeterinaryShowOwnerApp/Controllers/HomeController.cs +++ b/VeterinaryView/VeterinaryShowOwnerApp/Controllers/HomeController.cs @@ -261,7 +261,7 @@ namespace VeterinaryShowOwnerApp.Controllers } [HttpPost] - public void DeleteDrug(int visit) + public void DeleteVisit(int visit) { if (APIOwner.Owner == null) {