From 531e1312a2fa248c8a1c9db5cd1e9ed4b15ffcd8 Mon Sep 17 00:00:00 2001 From: Yunusov_Niyaz Date: Mon, 27 May 2024 06:16:13 +0400 Subject: [PATCH] =?UTF-8?q?=D0=92=D1=81=D1=91,=20=D1=85=D0=B2=D0=B0=D1=82?= =?UTF-8?q?=D0=B8=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Implements/PurchaseStorage.cs | 5 ++--- .../Implements/VisitStorage.cs | 10 ++------- .../Controllers/PurchaseController.cs | 4 ++-- .../Controllers/VisitController.cs | 13 +++++++++++ .../Controllers/HomeController.cs | 22 +++++-------------- .../Views/Home/UpdateVisit.cshtml | 12 ---------- 6 files changed, 25 insertions(+), 41 deletions(-) diff --git a/VeterinaryView/VeterinaryDatabaseImplement/Implements/PurchaseStorage.cs b/VeterinaryView/VeterinaryDatabaseImplement/Implements/PurchaseStorage.cs index 2e54f44..e5f6013 100644 --- a/VeterinaryView/VeterinaryDatabaseImplement/Implements/PurchaseStorage.cs +++ b/VeterinaryView/VeterinaryDatabaseImplement/Implements/PurchaseStorage.cs @@ -12,15 +12,14 @@ namespace VeterinaryDatabaseImplement.Implements public List GetFullList() { using var context = new VeterinaryDatabase(); - return context.Purchases.Include(x => x.Pets).ThenInclude(x => x.Pet).Include(x => x.Owner) + return context.Purchases.Include(x => x.Owner).Include(x => x.Pets).ThenInclude(x => x.Pet) .Include(x => x.Drug).Select(x => x.GetViewModel) .ToList(); } public List GetFilteredList(PurchaseSearchModel model) { using var context = new VeterinaryDatabase(); - return context.Purchases.Include(x => x.Owner).Include(x => x.Pets).ThenInclude(x => x.Pet).Include(x => x.Drug) - .Where(x => x.OwnerId == model.OwnerId) + return context.Purchases.Where(x => x.OwnerId == model.OwnerId).Include(x => x.Owner).Include(x => x.Pets).ThenInclude(x => x.Pet).Include(x => x.Drug) .Where(x => ((!model.Id.HasValue || x.Id == model.Id) && (!model.DateCreate.HasValue || x.DateCreate >= model.DateCreate) && (!model.OwnerId.HasValue || x.OwnerId <= model.OwnerId) && diff --git a/VeterinaryView/VeterinaryDatabaseImplement/Implements/VisitStorage.cs b/VeterinaryView/VeterinaryDatabaseImplement/Implements/VisitStorage.cs index 017796f..88db3bd 100644 --- a/VeterinaryView/VeterinaryDatabaseImplement/Implements/VisitStorage.cs +++ b/VeterinaryView/VeterinaryDatabaseImplement/Implements/VisitStorage.cs @@ -20,13 +20,8 @@ namespace VeterinaryDatabaseImplement.Implements { using var context = new VeterinaryDatabase(); - return context.Visits.Include(x => x.Owner).Include(x => x.Pets).ThenInclude(x => x.Pet).Include(x => x.Doctor) - .Where(x => x.OwnerId == model.OwnerId) - .Where(x => ((!model.Id.HasValue || x.Id == model.Id) && - (string.IsNullOrEmpty(model.VisitName) || x.VisitName.Contains(model.VisitName)) && - (!model.DateVisit.HasValue || x.DateVisit >= model.DateVisit) && - (!model.OwnerId.HasValue || x.OwnerId <= model.OwnerId) && - (!model.DoctorId.HasValue || x.DoctorId == model.DoctorId))) + return context.Visits.Where(x => x.OwnerId == model.OwnerId).Include(x => x.Owner).Include(x => x.Pets).ThenInclude(x => x.Pet).Include(x => x.Doctor) + .Where(x => String.IsNullOrEmpty(model.VisitName) || x.VisitName.Contains(model.VisitName)).ToList() .Select(x => x.GetViewModel) .ToList(); } @@ -62,7 +57,6 @@ namespace VeterinaryDatabaseImplement.Implements return null; } visit.Update(model); - //visit.UpdateVisits(context, model); context.SaveChanges(); return visit.GetViewModel; } diff --git a/VeterinaryView/VeterinaryRestApi/Controllers/PurchaseController.cs b/VeterinaryView/VeterinaryRestApi/Controllers/PurchaseController.cs index 5521ed5..087b7e5 100644 --- a/VeterinaryView/VeterinaryRestApi/Controllers/PurchaseController.cs +++ b/VeterinaryView/VeterinaryRestApi/Controllers/PurchaseController.cs @@ -35,11 +35,11 @@ namespace VeterinaryRestApi.Controllers } } [HttpGet] - public List? GetPurchases() + public List? GetPurchases(int? ownerId) { try { - return _purchase.ReadList(null); + return _purchase.ReadList(new PurchaseSearchModel { Id = ownerId}); } catch (Exception ex) { diff --git a/VeterinaryView/VeterinaryRestApi/Controllers/VisitController.cs b/VeterinaryView/VeterinaryRestApi/Controllers/VisitController.cs index 68bd3db..b9801f1 100644 --- a/VeterinaryView/VeterinaryRestApi/Controllers/VisitController.cs +++ b/VeterinaryView/VeterinaryRestApi/Controllers/VisitController.cs @@ -99,5 +99,18 @@ namespace VeterinaryRestApi.Controllers throw; } } + [HttpPost] + public bool DeleteVisit(VisitBindingModel model) + { + try + { + return _visit.Delete(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления лекарства"); + throw; + } + } } } diff --git a/VeterinaryView/VeterinaryShowOwnerApp/Controllers/HomeController.cs b/VeterinaryView/VeterinaryShowOwnerApp/Controllers/HomeController.cs index 7dee0e7..e422640 100644 --- a/VeterinaryView/VeterinaryShowOwnerApp/Controllers/HomeController.cs +++ b/VeterinaryView/VeterinaryShowOwnerApp/Controllers/HomeController.cs @@ -222,7 +222,7 @@ namespace VeterinaryShowOwnerApp.Controllers { return Redirect("~/Home/Enter"); } - return View(APIOwner.GetRequest>($"api/visit/getallvisits?ownerid={APIOwner.Owner.Id}")); + return View(APIOwner.GetRequest>($"api/visit/getvisits?ownerid={APIOwner.Owner.Id}")); } public IActionResult CreateVisit() { @@ -282,7 +282,7 @@ namespace VeterinaryShowOwnerApp.Controllers { Id = visit }); - Response.Redirect("Index"); + Response.Redirect("Visits"); } public IActionResult UpdateVisit() { @@ -314,28 +314,18 @@ namespace VeterinaryShowOwnerApp.Controllers Response.Redirect("Visits"); } [HttpGet] - public Tuple>>? GetVisit(int visitId) + public Tuple? GetVisit(int visitId) { if (APIOwner.Owner == null) { throw new Exception("Вы как суда попали? Суда вход только авторизованным"); } - var result = APIOwner.GetRequest>>>($"api/visit/getvisit?visitid={visitId}"); + var result = APIOwner.GetRequest>($"api/visit/getvisit?visitid={visitId}"); if (result == null) { return default; } - string table = ""; - result.Item1.VisitPet.Clear(); - for (int i = 0; i < result.Item2.Count; i++) - { - var pet = result.Item2[i].Item1; - table += ""; - table += $"{pet}"; - table += ""; - } - //return Tuple.Create(result.Item1, table); - return null; + return result; } public IActionResult Purchases() { @@ -497,7 +487,7 @@ namespace VeterinaryShowOwnerApp.Controllers table += ""; table += "Дата"; table += "Животное"; - table += "Название посещенияы"; + table += "Название посещения"; table += "Лекарство"; table += ""; table += ""; diff --git a/VeterinaryView/VeterinaryShowOwnerApp/Views/Home/UpdateVisit.cshtml b/VeterinaryView/VeterinaryShowOwnerApp/Views/Home/UpdateVisit.cshtml index 0456ea6..7f9a9e2 100644 --- a/VeterinaryView/VeterinaryShowOwnerApp/Views/Home/UpdateVisit.cshtml +++ b/VeterinaryView/VeterinaryShowOwnerApp/Views/Home/UpdateVisit.cshtml @@ -18,17 +18,6 @@
Название:
- - - - - - - - -
- Животные -
@@ -47,7 +36,6 @@ data: { visitId: visit }, success: function (result) { $('#name').val(result.item1.visitName); - $('#table-elements').html(result.item2); } }); };