diff --git a/VeterinaryClinic/VeterinaryClinicBusinessLogics/BusinessLogics/ReportLogic.cs b/VeterinaryClinic/VeterinaryClinicBusinessLogics/BusinessLogics/ReportLogic.cs index 410524d..d8a4d2a 100644 --- a/VeterinaryClinic/VeterinaryClinicBusinessLogics/BusinessLogics/ReportLogic.cs +++ b/VeterinaryClinic/VeterinaryClinicBusinessLogics/BusinessLogics/ReportLogic.cs @@ -10,6 +10,7 @@ using VeterinaryClinicContracts.BusinessLogicsContracts; using VeterinaryClinicContracts.SearchModels; using VeterinaryClinicContracts.StoragesContracts; using VeterinaryClinicContracts.ViewModels; +using VeterinaryClinicDataModels.Models; namespace VeterinaryClinicBusinessLogics.BusinessLogics { @@ -73,35 +74,38 @@ namespace VeterinaryClinicBusinessLogics.BusinessLogics // Проходим по списку полученных животных foreach (var animal in animals) { - // Создаём запись - var record = new ReportAnimalServicesViewModel + if (model.VisitAnimals.ContainsKey(animal.Id)) { - Animal = animal, - // HashSet используется для того, чтобы не повторялись процедуры - Services = new HashSet() - }; - - // Проходим по списку всех визитов - foreach (var visit in visits) - { - // Проверяем есть ли у визита текущее животное - if (visit.VisitAnimals.ContainsKey(animal.Id)) + // Создаём запись + var record = new ReportAnimalServicesViewModel { - // Если есть, то проходим по списку всех услуг визита - foreach (var serviceId in visit.VisitServices.Keys) + Animal = animal, + // HashSet используется для того, чтобы не повторялись процедуры + Services = new HashSet() + }; + + // Проходим по списку всех визитов + foreach (var visit in visits) + { + // Проверяем есть ли у визита текущее животное + if (visit.VisitAnimals.ContainsKey(animal.Id)) { - // Находим услугу и добавляем в список услуг - var service = _serviceStorage.GetElement(new ServiceSearchModel + // Если есть, то проходим по списку всех услуг визита + foreach (var serviceId in visit.VisitServices.Keys) { - Id = serviceId - }); - record.Services.Add(service!); + // Находим услугу и добавляем в список услуг + var service = _serviceStorage.GetElement(new ServiceSearchModel + { + Id = serviceId + }); + record.Services.Add(service!); + } } } - } - // Добавляем запись - result.Add(record); + // Добавляем запись + result.Add(record); + } } return result; diff --git a/VeterinaryClinic/VeterinaryClinicContracts/BindingModels/ReportBindingModel.cs b/VeterinaryClinic/VeterinaryClinicContracts/BindingModels/ReportBindingModel.cs index 84e4c40..b46071f 100644 --- a/VeterinaryClinic/VeterinaryClinicContracts/BindingModels/ReportBindingModel.cs +++ b/VeterinaryClinic/VeterinaryClinicContracts/BindingModels/ReportBindingModel.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using VeterinaryClinicDataModels.Models; namespace VeterinaryClinicContracts.BindingModels { @@ -30,5 +31,7 @@ namespace VeterinaryClinicContracts.BindingModels /// Идентификатор пользователя /// public int UserId { get; set; } + + public Dictionary VisitAnimals { get; set; } = new(); } } diff --git a/VeterinaryClinic/VeterinaryClinicWebApp/Controllers/HomeController.cs b/VeterinaryClinic/VeterinaryClinicWebApp/Controllers/HomeController.cs index 22c2702..5829627 100644 --- a/VeterinaryClinic/VeterinaryClinicWebApp/Controllers/HomeController.cs +++ b/VeterinaryClinic/VeterinaryClinicWebApp/Controllers/HomeController.cs @@ -5,6 +5,7 @@ using VeterinaryClinicContracts.BindingModels; using VeterinaryClinicContracts.BusinessLogicsContracts; using VeterinaryClinicContracts.SearchModels; using VeterinaryClinicDataModels.Enums; +using VeterinaryClinicDataModels.Models; using VeterinaryClinicWebApp.Models; using static System.Runtime.InteropServices.JavaScript.JSType; @@ -189,6 +190,11 @@ public class HomeController : Controller return Redirect("~/Home/Enter"); } + ViewBag.Animals = _animalLogic.ReadList(new AnimalSearchModel + { + UserId = APIClient.User.Id + }); + return View(); } @@ -222,17 +228,24 @@ public class HomeController : Controller /// Word /// [HttpPost] - public void CreateReportWord() + public void CreateReportWord(List animals) { if (APIClient.User == null) { throw new Exception(" !"); } + Dictionary visitAnimals = new Dictionary(); + foreach (var animalId in animals) + { + visitAnimals.Add(animalId, _animalLogic.ReadElement(new AnimalSearchModel { Id = animalId })!); + } + _reportLogic.SaveAnimalServicesToWordFile(new ReportBindingModel { FileName = $@"D:\ {DateTime.Now.ToString("dd-MM-yyyy HH-mm-ss")}.docx", - UserId = APIClient.User.Id + UserId = APIClient.User.Id, + VisitAnimals = visitAnimals }); Response.Redirect("/Home/Reports"); @@ -242,17 +255,24 @@ public class HomeController : Controller /// Excel /// [HttpPost] - public void CreateReportExcel() + public void CreateReportExcel(List animals) { if (APIClient.User == null) { throw new Exception(" !"); } + Dictionary visitAnimals = new Dictionary(); + foreach (var animalId in animals) + { + visitAnimals.Add(animalId, _animalLogic.ReadElement(new AnimalSearchModel { Id = animalId })!); + } + _reportLogic.SaveAnimalServicesToExcelFile(new ReportBindingModel { FileName = $@"D:\ {DateTime.Now.ToString("dd-MM-yyyy HH-mm-ss")}.xlsx", - UserId = APIClient.User.Id + UserId = APIClient.User.Id, + VisitAnimals = visitAnimals }); Response.Redirect("/Home/Reports"); diff --git a/VeterinaryClinic/VeterinaryClinicWebApp/Views/Home/Reports.cshtml b/VeterinaryClinic/VeterinaryClinicWebApp/Views/Home/Reports.cshtml index 5960612..2153f46 100644 --- a/VeterinaryClinic/VeterinaryClinicWebApp/Views/Home/Reports.cshtml +++ b/VeterinaryClinic/VeterinaryClinicWebApp/Views/Home/Reports.cshtml @@ -13,6 +13,18 @@
+ +
+
Животные:
+
+ +
+