diff --git a/VetClinic/VetClinicContracts/BindingModels/ListServicesBindingModel.cs b/VetClinic/VetClinicContracts/BindingModels/ListServicesBindingModel.cs new file mode 100644 index 0000000..46b39b2 --- /dev/null +++ b/VetClinic/VetClinicContracts/BindingModels/ListServicesBindingModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace VetClinicContracts.BindingModels +{ + public class ListServicesBindingModel + { + public string FileName { get; set; } = string.Empty; + public List Animals { get; set; } = new(); + } +} diff --git a/VetClinic/VetClinicContracts/BindingModels/MedicineVaccinationsBindingModel.cs b/VetClinic/VetClinicContracts/BindingModels/MedicineVaccinationsBindingModel.cs new file mode 100644 index 0000000..75e5cdd --- /dev/null +++ b/VetClinic/VetClinicContracts/BindingModels/MedicineVaccinationsBindingModel.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace VetClinicContracts.BindingModels +{ + public class MedicineVaccinationsBindingModel + { + public string FileName { get; set; } = string.Empty; + public List Visits { get; set; } = new(); + DateTime DateFrom { get; set; } = DateTime.Now; + DateTime DateTo { get; set; } = DateTime.Now; + } +} diff --git a/VetClinic/VetClinicContracts/BusinessLogicsContracts/IReportLogicAdmin.cs b/VetClinic/VetClinicContracts/BusinessLogicsContracts/IReportLogicAdmin.cs new file mode 100644 index 0000000..ee75480 --- /dev/null +++ b/VetClinic/VetClinicContracts/BusinessLogicsContracts/IReportLogicAdmin.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using VetClinicContracts.BindingModels; +using VetClinicContracts.ViewModels; + +namespace VetClinicContracts.BusinessLogicsContracts +{ + public interface IReportLogicAdmin //Будет дорабатываться + { + List GetServiceAnimals(List animals); + void SaveServicesToWordFile(ListServicesBindingModel model); + void SaveServicesToExcelFile(ListServicesBindingModel model); + } +} diff --git a/VetClinic/VetClinicContracts/SearchModels/AnimalSearchModel.cs b/VetClinic/VetClinicContracts/SearchModels/AnimalSearchModel.cs index 974212c..61a5ca5 100644 --- a/VetClinic/VetClinicContracts/SearchModels/AnimalSearchModel.cs +++ b/VetClinic/VetClinicContracts/SearchModels/AnimalSearchModel.cs @@ -14,5 +14,7 @@ namespace VetClinicContracts.SearchModels public string? AnimalName { get; set; } public string? Family { get; set; } public int? MedicineId { get; set; } + + public int? VisitId { get; set; } } } diff --git a/VetClinic/VetClinicContracts/SearchModels/ListServicesSearchModel.cs b/VetClinic/VetClinicContracts/SearchModels/ListServicesSearchModel.cs new file mode 100644 index 0000000..116911d --- /dev/null +++ b/VetClinic/VetClinicContracts/SearchModels/ListServicesSearchModel.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace VetClinicContracts.SearchModels +{ + public class ListServicesSearchModel + { + public List? animalsIds { get; set; } + } +} diff --git a/VetClinic/VetClinicContracts/SearchModels/MedicineVaccinationsSearchModel.cs b/VetClinic/VetClinicContracts/SearchModels/MedicineVaccinationsSearchModel.cs new file mode 100644 index 0000000..7167b63 --- /dev/null +++ b/VetClinic/VetClinicContracts/SearchModels/MedicineVaccinationsSearchModel.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace VetClinicContracts.SearchModels +{ + public class MedicineVaccinationsSearchModel + { + public List? visitsIds { get; set; } + public DateTime? DateFrom { get; set; } + public DateTime? DateTo { get; set; } + } +} diff --git a/VetClinic/VetClinicContracts/SearchModels/VisitSearchModel.cs b/VetClinic/VetClinicContracts/SearchModels/VisitSearchModel.cs index cf9c3e9..b28350f 100644 --- a/VetClinic/VetClinicContracts/SearchModels/VisitSearchModel.cs +++ b/VetClinic/VetClinicContracts/SearchModels/VisitSearchModel.cs @@ -17,5 +17,7 @@ namespace VetClinicContracts.SearchModels public DateTime? DateFrom { get; set; } public DateTime? DateTo { get; set; } public int? ServiceId { get; set; } + + public int? AnimalId { get; set; } } } diff --git a/VetClinic/VetClinicContracts/StoragesContracts/IAnimalStorage.cs b/VetClinic/VetClinicContracts/StoragesContracts/IAnimalStorage.cs index 189aed7..fb027e7 100644 --- a/VetClinic/VetClinicContracts/StoragesContracts/IAnimalStorage.cs +++ b/VetClinic/VetClinicContracts/StoragesContracts/IAnimalStorage.cs @@ -13,6 +13,7 @@ namespace VetClinicContracts.StoragesContracts { List GetFullList(); List GetFilteredList(AnimalSearchModel model); + List>>>> GetReportInfo(ListServicesSearchModel model); AnimalViewModel? GetElement(AnimalSearchModel model); AnimalViewModel? Insert(AnimalBindingModel model); AnimalViewModel? Update(AnimalBindingModel model); diff --git a/VetClinic/VetClinicContracts/StoragesContracts/IVisitStorage.cs b/VetClinic/VetClinicContracts/StoragesContracts/IVisitStorage.cs index 1cb302a..011eb5a 100644 --- a/VetClinic/VetClinicContracts/StoragesContracts/IVisitStorage.cs +++ b/VetClinic/VetClinicContracts/StoragesContracts/IVisitStorage.cs @@ -13,6 +13,10 @@ namespace VetClinicContracts.StoragesContracts { List GetFullList(); List GetFilteredList(VisitSearchModel model); + + public List>>>> GetVaccinationsInfo(MedicineVaccinationsSearchModel model); + public List>>>> GetMedicinesInfo(MedicineVaccinationsSearchModel model); + VisitViewModel? GetElement(VisitSearchModel model); VisitViewModel? Insert(VisitBindingModel model); VisitViewModel? Update(VisitBindingModel model); diff --git a/VetClinic/VetClinicContracts/ViewModels/ListServicesViewModel.cs b/VetClinic/VetClinicContracts/ViewModels/ListServicesViewModel.cs new file mode 100644 index 0000000..9232ccd --- /dev/null +++ b/VetClinic/VetClinicContracts/ViewModels/ListServicesViewModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace VetClinicContracts.ViewModels +{ + public class ListServicesViewModel + { + public string ServiceName { get; set; } = string.Empty; + public List Services { get; set; } = new(); + } +} diff --git a/VetClinic/VetClinicContracts/ViewModels/MedicineVaccinationViewModel.cs b/VetClinic/VetClinicContracts/ViewModels/MedicineVaccinationViewModel.cs new file mode 100644 index 0000000..24d7749 --- /dev/null +++ b/VetClinic/VetClinicContracts/ViewModels/MedicineVaccinationViewModel.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using VetClinicContracts.ViewModels; + +namespace VetClinicDataBaseImplement.Implements +{ + public class MedicineVaccinationViewModel + { + public string VisitName { get; set; } = string.Empty; + public List Medicines { get; set; } = new(); + public List Vaccinations { get; set; } = new(); + public DateTime DateFrom { get; set; } = DateTime.Now; + public DateTime DateTo { get; set; } = DateTime.Now; + } +} \ No newline at end of file diff --git a/VetClinic/VetClinicDataBaseImplement/Implements/AnimalStorage.cs b/VetClinic/VetClinicDataBaseImplement/Implements/AnimalStorage.cs index 0243a9d..ce929b8 100644 --- a/VetClinic/VetClinicDataBaseImplement/Implements/AnimalStorage.cs +++ b/VetClinic/VetClinicDataBaseImplement/Implements/AnimalStorage.cs @@ -5,6 +5,7 @@ using VetClinicContracts.ViewModels; using VetClinicDataBaseImplement.Models; using Microsoft.EntityFrameworkCore; using VetClinicDataBaseImplement; +using System.Linq; namespace VetClinicBaseImplement.Implements { @@ -28,11 +29,28 @@ namespace VetClinicBaseImplement.Implements return context.Animals.Include(x => x.Admin).Include(x => x.Visits) .ThenInclude(x => x.Visit).Include(x => x.Medicines).ThenInclude(x => x.Medicine) .Where(x => (string.IsNullOrEmpty(model.AnimalName) || x.AnimalName.Contains(model.AnimalName)) - && (!model.AdminId.HasValue || x.AdminId == model.AdminId) - && (!model.MedicineId.HasValue || x.Medicines.Select(x => x.MedicineId).ToList().Contains(model.MedicineId.Value))) + && (!model.AdminId.HasValue || x.AdminId == model.AdminId)) .Select(x => x.GetViewModel) .ToList(); } + + public List>>>> GetReportInfo(ListServicesSearchModel model) + { + if (model.animalsIds == null) + { + return new(); + } + using var context = new VetClinicDatabase(); + return context.Animals + .Where(animal => model.animalsIds.Contains(animal.Id)) + .Select(animal => new Tuple>>>(animal.GetViewModel, + context.MedicineAnimals.Include(medicine => medicine.Medicine) + .Include(medicine => medicine.Animal).Where(medicine => animal.Id == medicine.AnimalId). + Select(medicine => new Tuple>(medicine.Medicine.GetViewModel, + context.ServiceMedicines.Include(x => x.Service).Where(x => x.MedicineId == medicine.Medicine.Id). + Select(x => x.Service.GetViewModel).ToList())).ToList())).ToList(); + + } public AnimalViewModel? GetElement(AnimalSearchModel model) { if (!model.Id.HasValue) diff --git a/VetClinic/VetClinicDataBaseImplement/Implements/VisitStorage.cs b/VetClinic/VetClinicDataBaseImplement/Implements/VisitStorage.cs index 9efe5f6..b775af6 100644 --- a/VetClinic/VetClinicDataBaseImplement/Implements/VisitStorage.cs +++ b/VetClinic/VetClinicDataBaseImplement/Implements/VisitStorage.cs @@ -31,13 +31,50 @@ namespace VetClinicDataBaseImplement.Implements { using var context = new VetClinicDatabase(); return context.Visits.Include(x => x.Admin).Include(x => x.Services) - .ThenInclude(x => x.Service) + .ThenInclude(x => x.Service).Include(x => x.Animals).ThenInclude(x => x.Animal) .Where(x => (string.IsNullOrEmpty(model.NameVisit) || x.NameVisit.Contains(model.NameVisit)) && (!model.AdminId.HasValue || x.AdminId == model.AdminId) && (!model.ServiceId.HasValue || x.Services.Select(x => x.ServiceId).ToList().Contains(model.ServiceId.Value))) .Select(x => x.GetViewModel) .ToList(); } + + public List>>>> GetVaccinationsInfo(MedicineVaccinationsSearchModel model) + { + if (model.visitsIds == null) + { + return new(); + } + using var context = new VetClinicDatabase(); + return context.Visits + .Where(visit => model.visitsIds.Contains(visit.Id)) + .Select(visit => new Tuple>>>(visit.GetViewModel, + context.VisitAnimals.Include(animal => animal.Animal) + .Include(animal => animal.Visit).Where(animal => visit.Id == animal.VisitId). + Select(animal => new Tuple>(animal.Animal.GetViewModel, + context.Vaccinations.Include(x => x.Animal).Where(x => x.AnimalId == animal.AnimalId && x.DateStamp >= model.DateFrom && x.DateStamp <= model.DateTo). + Select(x => x.GetViewModel).ToList())).ToList()).ToList(); + + } + public List>>>> GetMedicinesInfo(MedicineVaccinationsSearchModel model) + { + if (model.visitsIds == null) + { + return new(); + } + using var context = new VetClinicDatabase(); + return context.Visits + .Where(visit => model.visitsIds.Contains(visit.Id)) + .Select(visit => new Tuple>>>(visit.GetViewModel, + context.VisitAnimals.Include(animal => animal.Animal) + .Include(animal => animal.Visit).Where(animal => visit.Id == animal.VisitId). + Select(animal => new Tuple>(animal.Animal.GetViewModel, + context.MedicineAnimals.Include(x => x.Medicine).Where(x => x.AnimalId == animal.AnimalId). + Select(x => x.Medicine.GetViewModel).ToList())).ToList())).ToList(); + + } + + public VisitViewModel? GetElement(VisitSearchModel model) { if (!model.Id.HasValue)