From ac470df39d11ca7f20541ff20304cd47a2dd8cf1 Mon Sep 17 00:00:00 2001 From: Alenka Date: Thu, 2 May 2024 15:55:50 +0400 Subject: [PATCH] =?UTF-8?q?=D0=A2=D1=80=D0=AD=D1=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogics/ReportLogicPharmacist.cs | 89 +++++++++++++++++++ .../BindingModels/ListRecipesBindingModel.cs | 14 +++ .../IReportLogicPharmacist.cs | 18 ++++ .../ViewModels/ListRecipeViewModel.cs | 14 +++ .../Views/Shared/_Layout.cshtml | 8 +- 5 files changed, 139 insertions(+), 4 deletions(-) create mode 100644 Hospital/HospitalBusinessLogic/BusinessLogics/ReportLogicPharmacist.cs create mode 100644 Hospital/HospitalContracts/BindingModels/ListRecipesBindingModel.cs create mode 100644 Hospital/HospitalContracts/BusinessLogicContracts/IReportLogicPharmacist.cs create mode 100644 Hospital/HospitalContracts/ViewModels/ListRecipeViewModel.cs diff --git a/Hospital/HospitalBusinessLogic/BusinessLogics/ReportLogicPharmacist.cs b/Hospital/HospitalBusinessLogic/BusinessLogics/ReportLogicPharmacist.cs new file mode 100644 index 0000000..4e0ac27 --- /dev/null +++ b/Hospital/HospitalBusinessLogic/BusinessLogics/ReportLogicPharmacist.cs @@ -0,0 +1,89 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using VetClinicBusinessLogic.OfficePackage; +using VetClinicBusinessLogic.OfficePackage.HelperModels; +using VetClinicContracts.BindingModels; +using VetClinicContracts.BusinessLogicsContracts; +using VetClinicContracts.SearchModels; +using VetClinicContracts.StoragesContracts; +using VetClinicContracts.ViewModels; + +namespace VetClinicBusinessLogic.BusinessLogics +{ + public class ReportLogicPharmacist : IReportLogicPharmacist + { + private readonly IServiceStorage _serviceStorage; + private readonly IMedicineStorage _medicineStorage; + private readonly IAnimalStorage _animalStorage; + private readonly AbstractSaveToExcelPharmacist _saveToExcel; + private readonly AbstractSaveToWordPharmacist _saveToWord; + public ReportLogicPharmacist(IServiceStorage serviceStorage, IMedicineStorage medicineStorage, IAnimalStorage animalStorage, + AbstractSaveToExcelPharmacist saveToExcel, AbstractSaveToWordPharmacist saveToWord) + { + _serviceStorage = serviceStorage; + _medicineStorage = medicineStorage; + _animalStorage = animalStorage; + _saveToExcel = saveToExcel; + _saveToWord = saveToWord; + } + + public List GetServiceAnimals(List services) + { + List ans = new(); + foreach (var service in services) + { + var medicines = _medicineStorage.GetFilteredList(new MedicineSearchModel { ServiceId = service }); + Dictionary counter = new(); + foreach (var medicine in medicines) + { + var animals = _animalStorage.GetFilteredList(new AnimalSearchModel { MedicineId = medicine.Id }); + foreach (var animal in animals) + { + if (!counter.ContainsKey(animal.Id)) + counter.Add(animal.Id, 1); + else + { + counter[animal.Id]++; + } + } + } + List res = new(); + foreach (var cnt in counter) + { + if (cnt.Value != medicines.Count) + continue; + res.Add(_animalStorage.GetElement(new AnimalSearchModel { Id = cnt.Key })); + } + ans.Add(new ListAnimalsViewModel + { + ServiceName = _serviceStorage.GetElement(new ServiceSearchModel { Id = service }).ServiceName, + Animals = res + }); + } + return ans; + } + + public void SaveAnimalsToExcelFile(ListAnimalsBindingModel model) + { + _saveToExcel.CreateReport(new ExcelInfoPharmacist + { + FileName = model.FileName, + Title = "Список животных для услуг", + ServicesAnimals = GetServiceAnimals(model.Services) + }); + } + + public void SaveAnimalsToWordFile(ListAnimalsBindingModel model) + { + _saveToWord.CreateDoc(new WordInfoPharmacist + { + FileName = model.FileName, + Title = "Список животных для услуг", + ServicesAnimals = GetServiceAnimals(model.Services) + }); + } + } +} diff --git a/Hospital/HospitalContracts/BindingModels/ListRecipesBindingModel.cs b/Hospital/HospitalContracts/BindingModels/ListRecipesBindingModel.cs new file mode 100644 index 0000000..42d569a --- /dev/null +++ b/Hospital/HospitalContracts/BindingModels/ListRecipesBindingModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HospitalContracts.BindingModels +{ + public class ListRecipesBindingModel + { + public string FileName { get; set; } = string.Empty; + public List Procedures { get; set; } = new(); + } +} diff --git a/Hospital/HospitalContracts/BusinessLogicContracts/IReportLogicPharmacist.cs b/Hospital/HospitalContracts/BusinessLogicContracts/IReportLogicPharmacist.cs new file mode 100644 index 0000000..8158896 --- /dev/null +++ b/Hospital/HospitalContracts/BusinessLogicContracts/IReportLogicPharmacist.cs @@ -0,0 +1,18 @@ +using HospitalContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using HospitalContracts.BindingModels; +using HospitalContracts.ViewModels; + +namespace HospitalContracts.BusinessLogicsContracts +{ + public interface IReportLogicPharmacist //В процессе + { + List GetServiceAnimals(List services); + void SaveAnimalsToWordFile(ListRecipesBindingModel model); + void SaveAnimalsToExcelFile(ListRecipesBindingModel model); + } +} diff --git a/Hospital/HospitalContracts/ViewModels/ListRecipeViewModel.cs b/Hospital/HospitalContracts/ViewModels/ListRecipeViewModel.cs new file mode 100644 index 0000000..dd33a56 --- /dev/null +++ b/Hospital/HospitalContracts/ViewModels/ListRecipeViewModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HospitalContracts.ViewModels +{ + public class ListAnimalsViewModel + { + public string ProcedureName { get; set; } = string.Empty; + public List Animals { get; set; } = new(); + } +} diff --git a/Hospital/HospitalDoctorApp/Views/Shared/_Layout.cshtml b/Hospital/HospitalDoctorApp/Views/Shared/_Layout.cshtml index 9d8d68b..bb5bd21 100644 --- a/Hospital/HospitalDoctorApp/Views/Shared/_Layout.cshtml +++ b/Hospital/HospitalDoctorApp/Views/Shared/_Layout.cshtml @@ -3,16 +3,16 @@ - @ViewData["Title"] - HospitalPharmacistApp + @ViewData["Title"] - HospitalDoctorApp - +