From 18ba6200b3fbdc49adc87e58bbbe1121f82f2e26 Mon Sep 17 00:00:00 2001 From: goblinrf Date: Mon, 29 Apr 2024 21:22:12 +0400 Subject: [PATCH] =?UTF-8?q?=20=D0=A5=D0=90=D0=A5=D0=90=D0=A5=D0=90=D0=A5?= =?UTF-8?q?=D0=90=D0=A5=D0=90=D0=A5=D0=90=20=D0=AF=20=D0=9E=D0=93=D0=A0?= =?UTF-8?q?=D0=90=D0=91=D0=98=D0=9B=20=D0=91=D0=90=D0=9D=D0=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/HomeController.cs | 157 ++++++++++++++---- .../Views/Home/Create.cshtml | 4 +- .../Views/Home/Delete.cshtml | 18 ++ .../VetClinicAdminApi/Views/Home/Index.cshtml | 6 +- .../Views/Home/IndexAnimals.cshtml | 1 + .../Views/Home/ServiceVisits.cshtml | 65 ++++++++ .../Views/Home/Update.cshtml | 58 +++++++ .../Views/Home/VisitAnimals.cshtml | 65 ++++++++ .../BusinessLogics/AdminLogic.cs | 2 +- .../BusinessLogics/AnimalLogic.cs | 19 ++- .../BusinessLogics/VaccinationLogic.cs | 11 ++ .../BusinessLogics/VisitLogic.cs | 8 +- .../BindingModels/AdminBindingModel.cs | 6 +- .../BindingModels/AnimalBindingModel.cs | 1 + .../BindingModels/VisitBindingModel.cs | 4 +- .../BusinessLogicsContracts/IAnimalLogic.cs | 6 +- .../SearchModels/VaccinationSearchModel.cs | 1 + .../ViewModels/AnimalViewModel.cs | 2 + .../ViewModels/VisitViewModel.cs | 11 +- .../Implements/AdminStorage.cs | 24 +-- .../Implements/AnimalStorage.cs | 31 ++-- .../Implements/VisitStorage.cs | 38 ++--- .../Models/Animal.cs | 46 ++++- .../Models/Visit.cs | 45 +---- .../VetClinicDatabase .cs | 2 +- .../Models/IAnimalModel.cs | 4 +- .../Models/IVaccinationModel.cs | 1 - .../VetClinicDataModels/Models/IVisitModel.cs | 3 - .../Controllers/AnimalContoller.cs | 32 ++-- .../Controllers/VisitController.cs | 17 +- 30 files changed, 515 insertions(+), 173 deletions(-) create mode 100644 VetClinic/VetClinicAdminApi/Views/Home/Delete.cshtml create mode 100644 VetClinic/VetClinicAdminApi/Views/Home/ServiceVisits.cshtml create mode 100644 VetClinic/VetClinicAdminApi/Views/Home/Update.cshtml create mode 100644 VetClinic/VetClinicAdminApi/Views/Home/VisitAnimals.cshtml diff --git a/VetClinic/VetClinicAdminApi/Controllers/HomeController.cs b/VetClinic/VetClinicAdminApi/Controllers/HomeController.cs index 6dbefc5..06790da 100644 --- a/VetClinic/VetClinicAdminApi/Controllers/HomeController.cs +++ b/VetClinic/VetClinicAdminApi/Controllers/HomeController.cs @@ -4,6 +4,8 @@ using System.Diagnostics; using VetClinicContracts.BindingModels; using VetClinicContracts.ViewModels; using VetClinicDataModels.Models; +using System.Text; +using VetClinicContracts.SearchModels; namespace VetClinicAdminApp.Controllers @@ -24,7 +26,7 @@ namespace VetClinicAdminApp.Controllers return Redirect("~/Home/Enter"); } return -View(APIAdmin.GetRequest>($"api/visit/getvisits?vistId={APIAdmin.Admin.Id}")); +View(APIAdmin.GetRequest>($"api/visit/getvisits?adminId={APIAdmin.Admin.Id}")); } public IActionResult IndexAnimals() @@ -34,7 +36,7 @@ View(APIAdmin.GetRequest>($"api/visit/getvisits?vistId={API return Redirect("~/Home/Enter"); } return -View(APIAdmin.GetRequest>($"api/animal/getanimallist?animalId={APIAdmin.Admin.Id}")); +View(APIAdmin.GetRequest>($"api/animal/getanimallist?adminId={APIAdmin.Admin.Id}")); } public IActionResult IndexVaccinations() @@ -63,12 +65,12 @@ View(APIAdmin.GetRequest>($"api/vaccination/getvaccin { if (APIAdmin.Admin == null) { - throw new Exception("Âû êàê ñóäà ïîïàëè? Ñóäà âõîä òîëüêî àâòîðèçîâàííûì"); + throw new Exception("Вы как суда попали? Суда вход только авторизованным"); } if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(fio)) { - throw new Exception("Ââåäèòå email, ïàðîëü è ÔÈÎ"); + throw new Exception("Введите email, пароль и ФИО"); } APIAdmin.PostRequest("api/admin/updatedata", new AdminBindingModel @@ -95,13 +97,13 @@ View(APIAdmin.GetRequest>($"api/vaccination/getvaccin if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password)) { - throw new Exception("Ââåäèòå email è ïàðîëü"); + throw new Exception("Введите email и пароль"); } APIAdmin.Admin = APIAdmin.GetRequest($"api/admin/login?login={login}&password={password}"); if (APIAdmin.Admin == null) { - throw new Exception("Íåâåðíûé ëîãèí/ïàðîëü"); + throw new Exception("Неверный логин/пароль"); } Response.Redirect("Index"); } @@ -116,7 +118,7 @@ View(APIAdmin.GetRequest>($"api/vaccination/getvaccin if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(fio)) { - throw new Exception("Ââåäèòå ëîãèí, ïàðîëü è ÔÈÎ"); + throw new Exception("Введите логин, пароль и ФИО"); } APIAdmin.PostRequest("api/admin/register", new AdminBindingModel @@ -156,11 +158,11 @@ View(APIAdmin.GetRequest>($"api/vaccination/getvaccin { if (APIAdmin.Admin == null) { - throw new Exception("Âû êàê ñþäà ïîïàëè? Ñþäà âõîä òîëüêî àâòîðèçîâàííûì"); + throw new Exception("Вы как сюда попали? Сюда вход только авторизованным"); } if (string.IsNullOrEmpty(name)) { - throw new Exception("Îøèáêà â ââåäåííûõ äàííûõ"); + throw new Exception("Ошибка в введенных данных"); } APIAdmin.PostRequest("api/visit/createvisit", new VisitBindingModel { @@ -175,11 +177,11 @@ View(APIAdmin.GetRequest>($"api/vaccination/getvaccin { if (APIAdmin.Admin == null) { - throw new Exception("Âû êàê ñþäà ïîïàëè? Ñþäà âõîä òîëüêî àâòîðèçîâàííûì"); + throw new Exception("Вы как сюда попали? Сюда вход только авторизованным"); } if (string.IsNullOrEmpty(animalname)) { - throw new Exception("Îøèáêà â ââåäåííûõ äàííûõ"); + throw new Exception("Ошибка в введенных данных"); } APIAdmin.PostRequest("api/animal/createanimal", new AnimalBindingModel { @@ -194,11 +196,11 @@ View(APIAdmin.GetRequest>($"api/vaccination/getvaccin { if (APIAdmin.Admin == null) { - throw new Exception("Âû êàê ñþäà ïîïàëè? Ñþäà âõîä òîëüêî àâòîðèçîâàííûì"); + throw new Exception("Вы как сюда попали? Сюда вход только авторизованным"); } if (string.IsNullOrEmpty(name)) { - throw new Exception("Îøèáêà â ââåäåííûõ äàííûõ"); + throw new Exception("Ошибка в введенных данных"); } if (cost <= 0) { @@ -225,11 +227,11 @@ View(APIAdmin.GetRequest>($"api/vaccination/getvaccin } [HttpPost] - public void DeleteVisit(int visit) + public void Delete(int visit) { if (APIAdmin.Admin == null) { - throw new Exception("Âû êàê ñþäà ïîïàëè? Ñþäà âõîä òîëüêî àâòîðèçîâàííûì"); + throw new Exception("Вы как сюда попали? Сюда вход только авторизованным"); } APIAdmin.PostRequest("api/visit/deletevisit", new VisitBindingModel { @@ -290,7 +292,7 @@ View(APIAdmin.GetRequest>($"api/vaccination/getvaccin { return Redirect("~/Home/Enter"); } - ViewBag.Medicines = APIAdmin.GetRequest>("api/visit/getvisits"); + ViewBag.Visits = APIAdmin.GetRequest>("api/visit/getvisits"); return View(); } @@ -299,11 +301,11 @@ View(APIAdmin.GetRequest>($"api/vaccination/getvaccin { if (APIAdmin.Admin == null) { - throw new Exception("Âû êàê ñþäà ïîïàëè? Ñþäà âõîä òîëüêî àâòîðèçîâàííûì"); + throw new Exception("Вы как сюда попали? Сюда вход только авторизованным"); } if (string.IsNullOrEmpty(name)) { - throw new Exception("Îøèáêà â ââåäåííûõ äàííûõ"); + throw new Exception("Ошибка в введенных данных"); } APIAdmin.PostRequest("api/visit/updatevisit", new VisitBindingModel { @@ -330,6 +332,7 @@ View(APIAdmin.GetRequest>($"api/vaccination/getvaccin { throw new Exception("Вы как сюда попали? Сюда вход только авторизованным"); } + if (string.IsNullOrEmpty(name)) { throw new Exception("Ошибка в введенных данных"); @@ -343,6 +346,82 @@ View(APIAdmin.GetRequest>($"api/vaccination/getvaccin }); Response.Redirect("IndexAnimals"); } + public IActionResult VisitAnimals() + { + if (APIAdmin.Admin == null) + { + return Redirect("~/Home/Enter"); + } + ViewBag.Animals = APIAdmin.GetRequest>($"api/animal/getanimallist?adminid={APIAdmin.Admin.Id}"); + ViewBag.Visits = APIAdmin.GetRequest>($"api/visit/getvisits"); + return View(); + } + [HttpPost] + public void VisitAnimals(int animal, string name, string family, + List visits) + { + if (APIAdmin.Admin == null) + { + throw new Exception("Вы как сюда попали? Сюда вход только авторизованным"); + } + + if (string.IsNullOrEmpty(name) || string.IsNullOrEmpty(family)) + { + throw new Exception("Ошибка в введенных данных"); + } + Dictionary v = new Dictionary(); + foreach (int visit in visits) + { + v.Add(visit, new VisitSearchModel { Id = visit } as IVisitModel); + } + APIAdmin.PostRequest("api/animal/updateanimal?isconnection=true", new AnimalBindingModel + { + Id = animal, + AnimalName = name, + Family = family, + AdminId = APIAdmin.Admin.Id, + VisitAnimals = v + }); + Response.Redirect("IndexAnimals"); + } + public IActionResult ServiceVisits() + { + if (APIAdmin.Admin == null) + { + return Redirect("~/Home/Enter"); + } + ViewBag.Visits = APIAdmin.GetRequest>($"api/visit/getvisits?adminid={APIAdmin.Admin.Id}"); + ViewBag.Services = APIAdmin.GetRequest>($"api/service/getservices"); + return View(); + } + [HttpPost] + public void ServiceVisits(int visit, string name, DateTime date, + List services) + { + if (APIAdmin.Admin == null) + { + throw new Exception("Вы как сюда попали? Сюда вход только авторизованным"); + } + + if (string.IsNullOrEmpty(name) || date == new DateTime()) + { + throw new Exception("Ошибка в введенных данных"); + } + Dictionary s = new Dictionary(); + foreach (int service in services) + { + s.Add(service, new ServiceSearchModel { Id = service } as IServiceModel); + } + APIAdmin.PostRequest("api/visit/updatevisit?isconnection=true", new VisitBindingModel + { + Id = visit, + NameVisit = name, + DateVisit = date, + AdminId = APIAdmin.Admin.Id, + ServiceVisits = s + }); + Response.Redirect("Index"); + } public IActionResult UpdateVaccination() { if (APIAdmin.Admin == null) @@ -383,27 +462,49 @@ View(APIAdmin.GetRequest>($"api/vaccination/getvaccin } [HttpGet] - public Tuple? GetVisit(int visitId) + public Tuple>? GetVisit(int visitId) { if (APIAdmin.Admin == null) { - throw new Exception("Âû êàê ñþäà ïîïàëè? Ñþäà âõîä òîëüêî àâòîðèçîâàííûì"); + throw new Exception("Вы как сюда попали? Сюда вход только авторизованным"); } var result = APIAdmin.GetRequest>>($"api/visit/getvisit?visitid={visitId}"); if (result == null) { return default; } - string table = ""; - result.Item1.VisitAnimals.Clear(); - for (int i = 0; i < result.Item2.Count; i++) + + return result; + } + [HttpGet] + public Tuple>? GetAnimal(int animalId) + { + if (APIAdmin.Admin == null) { - var animal = result.Item2[i]; - table += ""; - table += $"{animal}"; - table += ""; + throw new Exception("Вы как сюда попали? Сюда вход только авторизованным"); } - return Tuple.Create(result.Item1, table); + var result = APIAdmin.GetRequest>>($"api/animal/getanimal?animalid={animalId}"); + if (result == null) + { + return default; + } + + return result; + } + [HttpGet] + public Tuple>? GetService(int serviceId) + { + if (APIAdmin.Admin == null) + { + throw new Exception("Вы как сюда попали? Сюда вход только авторизованным"); + } + var result = APIAdmin.GetRequest>>($"api/service/getservice?serviceid={serviceId}"); + if (result == null) + { + return default; + } + + return result; } } } diff --git a/VetClinic/VetClinicAdminApi/Views/Home/Create.cshtml b/VetClinic/VetClinicAdminApi/Views/Home/Create.cshtml index 3c175db..d23f844 100644 --- a/VetClinic/VetClinicAdminApi/Views/Home/Create.cshtml +++ b/VetClinic/VetClinicAdminApi/Views/Home/Create.cshtml @@ -10,13 +10,13 @@
Название:
- +
Дата:
- +
diff --git a/VetClinic/VetClinicAdminApi/Views/Home/Delete.cshtml b/VetClinic/VetClinicAdminApi/Views/Home/Delete.cshtml new file mode 100644 index 0000000..ac844eb --- /dev/null +++ b/VetClinic/VetClinicAdminApi/Views/Home/Delete.cshtml @@ -0,0 +1,18 @@ +@{ + ViewData["Title"] = "Delete"; +} +
+

Удаление визита

+
+
+
+
Визиты:
+
+ +
+
+
+
+
+
+
\ No newline at end of file diff --git a/VetClinic/VetClinicAdminApi/Views/Home/Index.cshtml b/VetClinic/VetClinicAdminApi/Views/Home/Index.cshtml index bb9b3b7..6bd63b8 100644 --- a/VetClinic/VetClinicAdminApi/Views/Home/Index.cshtml +++ b/VetClinic/VetClinicAdminApi/Views/Home/Index.cshtml @@ -17,7 +17,11 @@

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

return; } - +

+ Редактировать визит + Удалить визит + Связать визит и услуги +

Создать визит

diff --git a/VetClinic/VetClinicAdminApi/Views/Home/IndexAnimals.cshtml b/VetClinic/VetClinicAdminApi/Views/Home/IndexAnimals.cshtml index f3aad95..aac98b7 100644 --- a/VetClinic/VetClinicAdminApi/Views/Home/IndexAnimals.cshtml +++ b/VetClinic/VetClinicAdminApi/Views/Home/IndexAnimals.cshtml @@ -19,6 +19,7 @@ }

Редактировать животное + Связать животных и визиты Удалить животное

diff --git a/VetClinic/VetClinicAdminApi/Views/Home/ServiceVisits.cshtml b/VetClinic/VetClinicAdminApi/Views/Home/ServiceVisits.cshtml new file mode 100644 index 0000000..a26f44b --- /dev/null +++ b/VetClinic/VetClinicAdminApi/Views/Home/ServiceVisits.cshtml @@ -0,0 +1,65 @@ +@using VetClinicContracts.ViewModels; + +@{ + ViewData["Title"] = "ServiceVisits"; +} + +

+

Связывание визита и услуги

+
+
+
+
Визит:
+
+ +
+
+ + +
+
Услуги:
+
+ +
+
+
+
+
+
+
+ +@section Scripts +{ + +} \ No newline at end of file diff --git a/VetClinic/VetClinicAdminApi/Views/Home/Update.cshtml b/VetClinic/VetClinicAdminApi/Views/Home/Update.cshtml new file mode 100644 index 0000000..9036d8d --- /dev/null +++ b/VetClinic/VetClinicAdminApi/Views/Home/Update.cshtml @@ -0,0 +1,58 @@ +@using VetClinicContracts.ViewModels; + +@{ + ViewData["Title"] = "Update"; +} + +
+

Редактирование визит

+
+
+
+
Визит:
+
+ +
+ +
+
+
Название:
+
+
+
+
Дата:
+
+ +
+
+ + +
+
+
+
+
+ +@section Scripts +{ + +} \ No newline at end of file diff --git a/VetClinic/VetClinicAdminApi/Views/Home/VisitAnimals.cshtml b/VetClinic/VetClinicAdminApi/Views/Home/VisitAnimals.cshtml new file mode 100644 index 0000000..f9d3ed4 --- /dev/null +++ b/VetClinic/VetClinicAdminApi/Views/Home/VisitAnimals.cshtml @@ -0,0 +1,65 @@ +@using VetClinicContracts.ViewModels; + +@{ + ViewData["Title"] = "VisitAnimals"; +} + +
+

Связывание животного и визита

+
+
+
+
Животное:
+
+ +
+
+ + +
+
Визиты:
+
+ +
+
+
+
+
+
+
+ +@section Scripts +{ + +} \ No newline at end of file diff --git a/VetClinic/VetClinicBusinessLogic/BusinessLogics/AdminLogic.cs b/VetClinic/VetClinicBusinessLogic/BusinessLogics/AdminLogic.cs index fdacde0..8f3a296 100644 --- a/VetClinic/VetClinicBusinessLogic/BusinessLogics/AdminLogic.cs +++ b/VetClinic/VetClinicBusinessLogic/BusinessLogics/AdminLogic.cs @@ -103,7 +103,7 @@ namespace VetClinicBusinessLogic.BusinessLogics throw new ArgumentNullException("Отсутствие пароля в учётной записи", nameof(model.Password)); } - _logger.LogInformation("WorkPiece. AdminFIO:{AdminFIO}. Email:{Email}. Password:{Password}. Id:{Id}", + _logger.LogInformation("Admin. AdminFIO:{AdminFIO}. Email:{Email}. Password:{Password}. Id:{Id}", model.AdminFIO, model.Email, model.Password, model.Id); var element = _adminStorage.GetElement(new AdminSearchModel { diff --git a/VetClinic/VetClinicBusinessLogic/BusinessLogics/AnimalLogic.cs b/VetClinic/VetClinicBusinessLogic/BusinessLogics/AnimalLogic.cs index 5a9eecf..3db659b 100644 --- a/VetClinic/VetClinicBusinessLogic/BusinessLogics/AnimalLogic.cs +++ b/VetClinic/VetClinicBusinessLogic/BusinessLogics/AnimalLogic.cs @@ -46,7 +46,7 @@ namespace VetClinicBusinessLogic.BusinessLogics return element; } - public bool CreateAnimal(AnimalBindingModel model) + public bool Create(AnimalBindingModel model) { CheckModel(model); @@ -58,7 +58,7 @@ namespace VetClinicBusinessLogic.BusinessLogics return true; } - public bool UpdateAnimal(AnimalBindingModel model) + public bool Update(AnimalBindingModel model) { CheckModel(model); if (_animalStorage.Update(model) == null) @@ -69,7 +69,7 @@ namespace VetClinicBusinessLogic.BusinessLogics return true; } - public bool DeleteAnimal(AnimalBindingModel model) + public bool Delete(AnimalBindingModel model) { CheckModel(model, false); _logger.LogInformation("Delete. Id:{Id}", model.Id); @@ -90,7 +90,7 @@ namespace VetClinicBusinessLogic.BusinessLogics { return; } - if (model.AnimalName == "") + if (string.IsNullOrEmpty(model.AnimalName)) { throw new ArgumentNullException("Имя не должно быть пустым", nameof(model.AnimalName)); } @@ -98,12 +98,17 @@ namespace VetClinicBusinessLogic.BusinessLogics { throw new ArgumentNullException("Некорректный идентификатор у клиента", nameof(model.AdminId)); } - + var element = _animalStorage.GetElement(new AnimalSearchModel { - Id = model.Id + AnimalName = model.AnimalName + }); - + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Животное с таким названием уже есть"); + } + } } } \ No newline at end of file diff --git a/VetClinic/VetClinicBusinessLogic/BusinessLogics/VaccinationLogic.cs b/VetClinic/VetClinicBusinessLogic/BusinessLogics/VaccinationLogic.cs index d10b4fa..525d92a 100644 --- a/VetClinic/VetClinicBusinessLogic/BusinessLogics/VaccinationLogic.cs +++ b/VetClinic/VetClinicBusinessLogic/BusinessLogics/VaccinationLogic.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using System.Xml.Linq; using VetClinicContracts.BindingModels; using VetClinicContracts.BusinessLogicsContracts; using VetClinicContracts.SearchModels; @@ -107,6 +108,16 @@ namespace VetClinicBusinessLogic.BusinessLogics } _logger.LogInformation("Vaccination. NameVaccination:{NameVaccination}. CostVaccination:{CostVaccination}", model.NameVaccination, model.CostVaccination); + var element = _vaccinationStorage.GetElement(new VaccinationSearchModel + { + NameVaccination = model.NameVaccination, + DateStamp = model.DateStamp, + AnimalId = model.AnimalId, + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Прививка для этого услуги с таким текстом уже есть"); + } } } } diff --git a/VetClinic/VetClinicBusinessLogic/BusinessLogics/VisitLogic.cs b/VetClinic/VetClinicBusinessLogic/BusinessLogics/VisitLogic.cs index 768129d..7269682 100644 --- a/VetClinic/VetClinicBusinessLogic/BusinessLogics/VisitLogic.cs +++ b/VetClinic/VetClinicBusinessLogic/BusinessLogics/VisitLogic.cs @@ -101,8 +101,12 @@ true) throw new ArgumentNullException("Нет названия визита", nameof(model.NameVisit)); } - - _logger.LogInformation("Medicine. Medicine:{NameVisit}. Id: { Id}", model.NameVisit, model.Id); + if (model.DateVisit != null) + { + throw new ArgumentNullException("Нет времени визита", + nameof(model.DateVisit)); + } + _logger.LogInformation("Visit. Visit:{NameVisit}. DateVisit:{ DateVisit } Id: { Id}", model.NameVisit, model.DateVisit, model.Id); var element = _visitStorage.GetElement(new VisitSearchModel { NameVisit = model.NameVisit diff --git a/VetClinic/VetClinicContracts/BindingModels/AdminBindingModel.cs b/VetClinic/VetClinicContracts/BindingModels/AdminBindingModel.cs index 89751c5..7399897 100644 --- a/VetClinic/VetClinicContracts/BindingModels/AdminBindingModel.cs +++ b/VetClinic/VetClinicContracts/BindingModels/AdminBindingModel.cs @@ -1,6 +1,8 @@ -namespace VetClinicContracts.BindingModels +using VetClinicDataModels.Models; + +namespace VetClinicContracts.BindingModels { - public class AdminBindingModel + public class AdminBindingModel : IAdminModel { public int Id { get; set; } public string AdminFIO { get; set; } = string.Empty; diff --git a/VetClinic/VetClinicContracts/BindingModels/AnimalBindingModel.cs b/VetClinic/VetClinicContracts/BindingModels/AnimalBindingModel.cs index b005b41..273115a 100644 --- a/VetClinic/VetClinicContracts/BindingModels/AnimalBindingModel.cs +++ b/VetClinic/VetClinicContracts/BindingModels/AnimalBindingModel.cs @@ -12,6 +12,7 @@ namespace VetClinicContracts.BindingModels public int Id { get; set; } public int AdminId { get; set; } + public Dictionary VisitAnimals { get; set; } = new(); public string AnimalName { get; set; } = string.Empty; public string? Family { get; set; } = string.Empty; diff --git a/VetClinic/VetClinicContracts/BindingModels/VisitBindingModel.cs b/VetClinic/VetClinicContracts/BindingModels/VisitBindingModel.cs index ee25936..68ee65b 100644 --- a/VetClinic/VetClinicContracts/BindingModels/VisitBindingModel.cs +++ b/VetClinic/VetClinicContracts/BindingModels/VisitBindingModel.cs @@ -7,12 +7,10 @@ using VetClinicDataModels.Models; namespace VetClinicContracts.BindingModels { - public class VisitBindingModel + public class VisitBindingModel : IVisitModel { public int Id { get; set; } public int AdminId { get; set; } - public Dictionary VisitAnimals { get; set; } = new(); - public Dictionary ServiceVisits { get; set; } = new (); public string NameVisit { get; set; } = string.Empty; public DateTime DateVisit { get; set; } diff --git a/VetClinic/VetClinicContracts/BusinessLogicsContracts/IAnimalLogic.cs b/VetClinic/VetClinicContracts/BusinessLogicsContracts/IAnimalLogic.cs index fdc877a..7cd5404 100644 --- a/VetClinic/VetClinicContracts/BusinessLogicsContracts/IAnimalLogic.cs +++ b/VetClinic/VetClinicContracts/BusinessLogicsContracts/IAnimalLogic.cs @@ -13,8 +13,8 @@ namespace VetClinicContracts.BusinessLogicsContracts { List? ReadList(AnimalSearchModel? model); AnimalViewModel? ReadElement(AnimalSearchModel model); - bool CreateAnimal(AnimalBindingModel model); - bool UpdateAnimal(AnimalBindingModel model); - bool DeleteAnimal(AnimalBindingModel model); + bool Create(AnimalBindingModel model); + bool Update(AnimalBindingModel model); + bool Delete(AnimalBindingModel model); } } diff --git a/VetClinic/VetClinicContracts/SearchModels/VaccinationSearchModel.cs b/VetClinic/VetClinicContracts/SearchModels/VaccinationSearchModel.cs index abb24fd..eea1372 100644 --- a/VetClinic/VetClinicContracts/SearchModels/VaccinationSearchModel.cs +++ b/VetClinic/VetClinicContracts/SearchModels/VaccinationSearchModel.cs @@ -12,6 +12,7 @@ namespace VetClinicContracts.SearchModels public string? NameVaccination { get; set; } public double? CostVaccination { get; set; } + public DateTime? DateStamp { get; set; } public DateTime? DateFrom { get; set; } public DateTime? DateTo { get; set; } diff --git a/VetClinic/VetClinicContracts/ViewModels/AnimalViewModel.cs b/VetClinic/VetClinicContracts/ViewModels/AnimalViewModel.cs index 2185243..cfea307 100644 --- a/VetClinic/VetClinicContracts/ViewModels/AnimalViewModel.cs +++ b/VetClinic/VetClinicContracts/ViewModels/AnimalViewModel.cs @@ -19,5 +19,7 @@ namespace VetClinicContracts.ViewModels [DisplayName("Семейство")] public string? Family { get; set; } = string.Empty; + + public Dictionary VisitAnimals { get; set; } = new(); } } diff --git a/VetClinic/VetClinicContracts/ViewModels/VisitViewModel.cs b/VetClinic/VetClinicContracts/ViewModels/VisitViewModel.cs index 171b7c0..6e60629 100644 --- a/VetClinic/VetClinicContracts/ViewModels/VisitViewModel.cs +++ b/VetClinic/VetClinicContracts/ViewModels/VisitViewModel.cs @@ -14,21 +14,14 @@ namespace VetClinicContracts.ViewModels public int Id { get; set; } public int AdminId { get; set; } - [DisplayName("Животное")] - public string AnimalName { get; set; } = string.Empty; + [DisplayName("Название визита")] public string NameVisit { get; set; } = string.Empty; - [DisplayName("Админ")] - public string AdminFIO { get; set; } = string.Empty; - - [DisplayName("Название услуг")] - public string ServiceName { get; set; } = string.Empty; - [DisplayName("Дата визита")] public DateTime DateVisit { get; set; } - public Dictionary VisitAnimals { get; set; } = new(); + public Dictionary ServiceVisits { get; set; } = new(); } diff --git a/VetClinic/VetClinicDataBaseImplement/Implements/AdminStorage.cs b/VetClinic/VetClinicDataBaseImplement/Implements/AdminStorage.cs index 1e1adf7..b33d66d 100644 --- a/VetClinic/VetClinicDataBaseImplement/Implements/AdminStorage.cs +++ b/VetClinic/VetClinicDataBaseImplement/Implements/AdminStorage.cs @@ -35,23 +35,17 @@ namespace VetClinicDataBaseImplement.Implements public AdminViewModel? GetElement(AdminSearchModel model) { using var context = new VetClinicDatabase(); - if (model.Id.HasValue) + if (string.IsNullOrEmpty(model.AdminFIO) && string.IsNullOrEmpty(model.Email) && + !model.Id.HasValue) { - return context.Admins - .Include(x => x.Visits) - .Include(x => x.Animals) - .FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id) - ?.GetViewModel; + return null; } - else if (!string.IsNullOrEmpty(model.Email) && !string.IsNullOrEmpty(model.Password)) - { - return context.Admins - .Include(x => x.Visits) - .Include(x => x.Animals) - .FirstOrDefault(x => (x.Email == model.Email && x.Password == model.Password)) - ?.GetViewModel; - } - return new(); + + return context.Admins + .FirstOrDefault(x => (string.IsNullOrEmpty(model.AdminFIO) || x.AdminFIO == model.AdminFIO) && + (!model.Id.HasValue || x.Id == model.Id) && (string.IsNullOrEmpty(model.Email) || x.Email == model.Email) && + (string.IsNullOrEmpty(model.Password) || x.Password == model.Password)) + ?.GetViewModel; } public List GetFilteredList(AdminSearchModel model) diff --git a/VetClinic/VetClinicDataBaseImplement/Implements/AnimalStorage.cs b/VetClinic/VetClinicDataBaseImplement/Implements/AnimalStorage.cs index 51cae3c..3eddc49 100644 --- a/VetClinic/VetClinicDataBaseImplement/Implements/AnimalStorage.cs +++ b/VetClinic/VetClinicDataBaseImplement/Implements/AnimalStorage.cs @@ -16,22 +16,21 @@ namespace VetClinicBaseImplement.Implements return context.Animals .Include(x => x.Admin) + .Include(x => x.Visits) + .ThenInclude(x => x.Visit) .Select(x => x.GetViewModel) .ToList(); } public List GetFilteredList(AnimalSearchModel model) { - if (string.IsNullOrEmpty(model.AnimalName)) - { - return new(); - } using var context = new VetClinicDatabase(); - return context.Animals - .Include(x => x.Admin) - .Where(x => x.AnimalName.Contains(model.AnimalName)) - .ToList() - .Select(x => x.GetViewModel).ToList(); + return context.Animals.Include(x => x.Admin).Include(x => x.Visits) + .ThenInclude(x => x.Visit) + .Where(x => (string.IsNullOrEmpty(model.AnimalName) || x.AnimalName.Contains(model.AnimalName)) + && (!model.AdminId.HasValue || x.AdminId == model.AdminId)) + .Select(x => x.GetViewModel) + .ToList(); } public AnimalViewModel? GetElement(AnimalSearchModel model) { @@ -42,6 +41,8 @@ namespace VetClinicBaseImplement.Implements using var context = new VetClinicDatabase(); return context.Animals .Include(x => x.Admin) + .Include(x => x.Visits) + .ThenInclude(x => x.Visit) .Include(x => x.Vaccinations) .FirstOrDefault(x => (!string.IsNullOrEmpty(model.AnimalName) && x.AnimalName == model.AnimalName) || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; } @@ -54,6 +55,7 @@ namespace VetClinicBaseImplement.Implements return null; } context.Animals.Add(newAnimal); + context.SaveChanges(); return newAnimal.GetViewModel; } @@ -64,13 +66,21 @@ namespace VetClinicBaseImplement.Implements try { - var animal = context.Animals.FirstOrDefault(rec => rec.Id == model.Id); + var animal = context.Animals.Include(x => x.Admin) + .Include(x => x.Visits) + .ThenInclude(x => x.Visit).FirstOrDefault(rec => + rec.Id == model.Id); if (animal == null) { return null; } animal.Update(model); context.SaveChanges(); + if (model.VisitAnimals != null) + { + animal.UpdateVisits(context, model); + } + transaction.Commit(); return animal.GetViewModel; } @@ -85,6 +95,7 @@ namespace VetClinicBaseImplement.Implements using var context = new VetClinicDatabase(); var element = context.Animals .Include(x => x.Vaccinations) + .Include(x => x.Visits).ThenInclude(x => x.Visit) .FirstOrDefault(rec => rec.Id == model.Id); if (element != null) diff --git a/VetClinic/VetClinicDataBaseImplement/Implements/VisitStorage.cs b/VetClinic/VetClinicDataBaseImplement/Implements/VisitStorage.cs index 7ac26a3..ef54e2f 100644 --- a/VetClinic/VetClinicDataBaseImplement/Implements/VisitStorage.cs +++ b/VetClinic/VetClinicDataBaseImplement/Implements/VisitStorage.cs @@ -21,8 +21,7 @@ namespace VetClinicDataBaseImplement.Implements return context.Visits .Include(x => x.Admin) - .Include(x => x.Animals) - .ThenInclude(x => x.Animal) + .Include(x => x.Services) .ThenInclude(x => x.Service) .Select(x => x.GetViewModel) @@ -30,22 +29,13 @@ namespace VetClinicDataBaseImplement.Implements } public List GetFilteredList(VisitSearchModel model) { - - if (string.IsNullOrEmpty(model.NameVisit)) - { - return new(); - } using var context = new VetClinicDatabase(); - return context.Visits - .Include(x => x.Admin) - .Include(x => x.Animals) - .ThenInclude(x => x.Animal) - .Where(x => x.NameVisit.Contains(model.NameVisit)) - .Include(x => x.Services) + return context.Visits.Include(x => x.Admin).Include(x => x.Services) .ThenInclude(x => x.Service) - .Where(x => x.NameVisit.Contains(model.NameVisit)) - .ToList() - .Select(x => x.GetViewModel).ToList(); + .Where(x => (string.IsNullOrEmpty(model.NameVisit) || x.NameVisit.Contains(model.NameVisit)) + && (!model.AdminId.HasValue || x.AdminId == model.AdminId)) + .Select(x => x.GetViewModel) + .ToList(); } public VisitViewModel? GetElement(VisitSearchModel model) { @@ -56,11 +46,13 @@ namespace VetClinicDataBaseImplement.Implements using var context = new VetClinicDatabase(); return context.Visits .Include(x => x.Admin) - .Include(x => x.Animals) - .ThenInclude(x => x.Animal) .Include(x => x.Services) .ThenInclude(x => x.Service) - .FirstOrDefault(x => (!string.IsNullOrEmpty(model.NameVisit) && x.NameVisit == model.NameVisit) || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; + .FirstOrDefault(x => (!string.IsNullOrEmpty(model.NameVisit) && + x.NameVisit == model.NameVisit) || + (model.Id.HasValue && x.Id == + model.Id)) + ?.GetViewModel; } public VisitViewModel? Insert(VisitBindingModel model) { @@ -88,7 +80,8 @@ namespace VetClinicDataBaseImplement.Implements } visit.Update(model); context.SaveChanges(); - visit.UpdateAnimals(context, model); + if (model.ServiceVisits != null) + visit.UpdateServices(context, model); transaction.Commit(); return visit.GetViewModel; } @@ -102,11 +95,10 @@ namespace VetClinicDataBaseImplement.Implements { using var context = new VetClinicDatabase(); var element = context.Visits - .Include(x => x.Animals).ThenInclude(x => x.Animal) + .Include(x => x.Admin) .Include(x => x.Services).ThenInclude(x => x.Service) .FirstOrDefault(rec => rec.Id == model.Id); - - + if (element != null) { diff --git a/VetClinic/VetClinicDataBaseImplement/Models/Animal.cs b/VetClinic/VetClinicDataBaseImplement/Models/Animal.cs index b6ab1dc..8221517 100644 --- a/VetClinic/VetClinicDataBaseImplement/Models/Animal.cs +++ b/VetClinic/VetClinicDataBaseImplement/Models/Animal.cs @@ -37,7 +37,22 @@ namespace VetClinicDataBaseImplement.Models [ForeignKey("AnimalId")] public virtual List Medicines { get; set; } = new(); - + + public Dictionary? _visitAnimals = null; + + [NotMapped] + public Dictionary VisitAnimals + { + get + { + if (_visitAnimals == null) + { + _visitAnimals = Visits.ToDictionary(recPC => recPC.VisitId, recPC => + recPC.Visit as IVisitModel); + } + return _visitAnimals; + } + } public static Animal? Create(VetClinicDatabase context, AnimalBindingModel? model) { if (model == null) @@ -50,7 +65,10 @@ namespace VetClinicDataBaseImplement.Models AdminId = model.AdminId, AnimalName = model.AnimalName, Family = model.Family, - + Visits = model.VisitAnimals.Select(x => new VisitAnimal + { + Visit = context.Visits.First(y => y.Id == x.Key) + }).ToList() }; } public void Update(AnimalBindingModel? model) @@ -65,11 +83,33 @@ namespace VetClinicDataBaseImplement.Models public AnimalViewModel GetViewModel => new() { Id = Id, + VisitAnimals = VisitAnimals, AdminId = AdminId, AnimalName = AnimalName, Family = Family }; - + public void UpdateVisits(VetClinicDatabase context, AnimalBindingModel model) + { + var visitAnimals = context.VisitAnimals.Where(rec => rec.AnimalId == model.Id).ToList(); + if (visitAnimals != null) + { // удалили те, которых нет в модели + context.VisitAnimals.RemoveRange(visitAnimals.Where(rec => !model.VisitAnimals.ContainsKey(rec.VisitId))); + context.SaveChanges(); + + } + var animal = context.Animals.First(x => x.Id == Id); + foreach (var pc in model.VisitAnimals) + { + context.VisitAnimals.Add(new VisitAnimal + { + Animal = animal, + Visit = context.Visits.First(x => x.Id == pc.Key), + + }); + context.SaveChanges(); + } + _visitAnimals = null; + } } } diff --git a/VetClinic/VetClinicDataBaseImplement/Models/Visit.cs b/VetClinic/VetClinicDataBaseImplement/Models/Visit.cs index cd89ad7..0741d33 100644 --- a/VetClinic/VetClinicDataBaseImplement/Models/Visit.cs +++ b/VetClinic/VetClinicDataBaseImplement/Models/Visit.cs @@ -31,23 +31,11 @@ namespace VetClinicDataBaseImplement.Models [ForeignKey("VisitId")] public virtual List Services { get; set; } = new(); public virtual Admin Admin { get; set; } - public Dictionary? _visitAnimals = null; + public Dictionary? _serviceVisits = null; - [NotMapped] - public Dictionary VisitAnimals - { - get - { - if (_visitAnimals == null) - { - _visitAnimals = Animals.ToDictionary(recPC => recPC.AnimalId, recPC => - recPC.Animal as IAnimalModel); - } - return _visitAnimals; - } - } + [NotMapped] public Dictionary ServiceVisits { @@ -74,10 +62,6 @@ namespace VetClinicDataBaseImplement.Models NameVisit = model.NameVisit, DateVisit = model.DateVisit, - Animals = model.VisitAnimals.Select(x => new VisitAnimal - { - Animal = context.Animals.First(y => y.Id == x.Key) - }).ToList(), Services = model.ServiceVisits.Select(x => new VisitService { Service = context.Services.First(y => y.Id == x.Key) @@ -96,36 +80,15 @@ namespace VetClinicDataBaseImplement.Models public VisitViewModel GetViewModel => new() { Id = Id, - VisitAnimals = VisitAnimals, + AdminId = AdminId, NameVisit = NameVisit, DateVisit = DateVisit, ServiceVisits = ServiceVisits }; - public void UpdateAnimals(VetClinicDatabase context, VisitBindingModel model) - { - var visitAnimals = context.VisitAnimals.Where(rec => rec.VisitId == model.Id).ToList(); - if (visitAnimals != null) - { // удалили те, которых нет в модели - context.VisitAnimals.RemoveRange(visitAnimals.Where(rec => !model.VisitAnimals.ContainsKey(rec.AnimalId))); - context.SaveChanges(); - } - var visit = context.Visits.First(x => x.Id == Id); - foreach (var pc in model.VisitAnimals) - { - context.VisitAnimals.Add(new VisitAnimal - { - Visit = visit, - Animal = context.Animals.First(x => x.Id == pc.Key), - - }); - context.SaveChanges(); - } - _visitAnimals = null; - } - public void UpdateService(VetClinicDatabase context, VisitBindingModel model) + public void UpdateServices(VetClinicDatabase context, VisitBindingModel model) { var serviceVisits = context.ServiceVisits.Where(rec => rec.VisitId == model.Id).ToList(); if (serviceVisits != null) diff --git a/VetClinic/VetClinicDataBaseImplement/VetClinicDatabase .cs b/VetClinic/VetClinicDataBaseImplement/VetClinicDatabase .cs index 3aa2bb9..1d9e6df 100644 --- a/VetClinic/VetClinicDataBaseImplement/VetClinicDatabase .cs +++ b/VetClinic/VetClinicDataBaseImplement/VetClinicDatabase .cs @@ -11,7 +11,7 @@ namespace VetClinicDataBaseImplement { if (optionsBuilder.IsConfigured == false) { - optionsBuilder.UseSqlServer(@"Data Source=localhost\SQLEXPRESS;Initial Catalog=VetClinicDatabase;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); + optionsBuilder.UseSqlServer(@"Data Source=localhost\SQLEXPRESS02;Initial Catalog=VetClinicDatabase;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); } base.OnConfiguring(optionsBuilder); } diff --git a/VetClinic/VetClinicDataModels/Models/IAnimalModel.cs b/VetClinic/VetClinicDataModels/Models/IAnimalModel.cs index 7882938..04636c8 100644 --- a/VetClinic/VetClinicDataModels/Models/IAnimalModel.cs +++ b/VetClinic/VetClinicDataModels/Models/IAnimalModel.cs @@ -11,5 +11,7 @@ namespace VetClinicDataModels.Models int AdminId { get; } string AnimalName { get; } string? Family { get; } - } + + Dictionary VisitAnimals { get; } + } } diff --git a/VetClinic/VetClinicDataModels/Models/IVaccinationModel.cs b/VetClinic/VetClinicDataModels/Models/IVaccinationModel.cs index 02bcb4b..e284af7 100644 --- a/VetClinic/VetClinicDataModels/Models/IVaccinationModel.cs +++ b/VetClinic/VetClinicDataModels/Models/IVaccinationModel.cs @@ -8,7 +8,6 @@ namespace VetClinicDataModels.Models { public interface IVaccinationModel : IId { - int Id { get; } int AnimalId { get; } string NameVaccination { get; } double CostVaccination { get; } diff --git a/VetClinic/VetClinicDataModels/Models/IVisitModel.cs b/VetClinic/VetClinicDataModels/Models/IVisitModel.cs index d569ba5..826b00b 100644 --- a/VetClinic/VetClinicDataModels/Models/IVisitModel.cs +++ b/VetClinic/VetClinicDataModels/Models/IVisitModel.cs @@ -8,12 +8,9 @@ namespace VetClinicDataModels.Models { public interface IVisitModel : IId { - int Id { get;} int AdminId { get; } string NameVisit { get;} DateTime DateVisit { get; } - Dictionary VisitAnimals { get; } - Dictionary ServiceVisits { get; } } } diff --git a/VetClinic/VetClinicRestApi/Controllers/AnimalContoller.cs b/VetClinic/VetClinicRestApi/Controllers/AnimalContoller.cs index 9f85853..1e5c2f9 100644 --- a/VetClinic/VetClinicRestApi/Controllers/AnimalContoller.cs +++ b/VetClinic/VetClinicRestApi/Controllers/AnimalContoller.cs @@ -4,6 +4,7 @@ using VetClinicContracts.BindingModels; using VetClinicContracts.BusinessLogicsContracts; using VetClinicContracts.SearchModels; using VetClinicContracts.ViewModels; +using VetClinicDataBaseImplement.Models; namespace VetClinicRestApi.Controllers { @@ -20,14 +21,16 @@ namespace VetClinicRestApi.Controllers } [HttpGet] - public AnimalViewModel? GetAnimal(int animalId) + public Tuple>? GetAnimal(int animalId) { try { - return _animal.ReadElement(new AnimalSearchModel - { - Id = animalId - }); + var elem = _animal.ReadElement(new AnimalSearchModel { Id = animalId }); + if (elem == null) + return null; + var res = Tuple.Create(elem, elem.VisitAnimals.Select(x => x.Value.NameVisit).ToList()); + res.Item1.VisitAnimals = null; + return res; } catch (Exception ex) { @@ -37,11 +40,14 @@ namespace VetClinicRestApi.Controllers } [HttpGet] - public List? GetAnimalList() + public List? GetAnimalList(int adminId) { - try + try { - return _animal.ReadList(null); + var res = _animal.ReadList(new AnimalSearchModel { AdminId = adminId }); + foreach (var animal in res) + animal.VisitAnimals = null; + return res; } catch (Exception ex) { @@ -54,7 +60,7 @@ namespace VetClinicRestApi.Controllers { try { - return _animal.CreateAnimal(model); + return _animal.Create(model); } catch (Exception ex) { @@ -64,11 +70,13 @@ namespace VetClinicRestApi.Controllers } [HttpPost] - public bool UpdateAnimal(AnimalBindingModel model) + public bool UpdateAnimal(bool isConnection,AnimalBindingModel model) { try { - return _animal.UpdateAnimal(model); + if (!isConnection) + model.VisitAnimals = null!; + return _animal.Update(model); } catch (Exception ex) { @@ -82,7 +90,7 @@ namespace VetClinicRestApi.Controllers { try { - return _animal.DeleteAnimal(model); + return _animal.Delete(model); } catch (Exception ex) { diff --git a/VetClinic/VetClinicRestApi/Controllers/VisitController.cs b/VetClinic/VetClinicRestApi/Controllers/VisitController.cs index 136cd53..78dcac9 100644 --- a/VetClinic/VetClinicRestApi/Controllers/VisitController.cs +++ b/VetClinic/VetClinicRestApi/Controllers/VisitController.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 = _visit.ReadElement(new VisitSearchModel { Id = VisitId }); if (elem == null) return null; - return Tuple.Create(elem, elem.VisitAnimals.Select(x => x.Value.AnimalName).ToList()); + var res = Tuple.Create(elem, elem.ServiceVisits.Select(x => x.Value.ServiceName).ToList()); + res.Item1.ServiceVisits = null; + return res; } catch (Exception ex) { @@ -40,11 +43,14 @@ namespace VetClinicRestApi.Controllers { try { - return _visit.ReadList(new VisitSearchModel { AdminId = adminId}); + var res = _visit.ReadList(new VisitSearchModel { AdminId = adminId }); + foreach (var visit in res) + visit.ServiceVisits = null; + return res; } catch (Exception ex) { - _logger.LogError(ex, "Ошибка получения списка визитовв"); + _logger.LogError(ex, "Ошибка получения списка животного"); throw; } } @@ -63,11 +69,12 @@ namespace VetClinicRestApi.Controllers } [HttpPost] - public bool UpdateVisit(VisitBindingModel model) + public bool UpdateVisit(bool isConnection,VisitBindingModel model) { try { - model.VisitAnimals = null!; + if (!isConnection) + model.ServiceVisits = null!; return _visit.Update(model); } catch (Exception ex)