Это пипец товарищи

This commit is contained in:
gg12 darfren 2024-05-02 18:00:37 +04:00
parent c42ebc88c1
commit eba96483b4
4 changed files with 46 additions and 12 deletions

View File

@ -32,34 +32,36 @@ namespace VetClinicBusinessLogic.BusinessLogics
public List<ListAnimalsViewModel> GetServiceAnimals(List<int> services)
{
List<ListAnimalsViewModel> ans = new();
foreach(var service in services)
List<Tuple<ServiceViewModel, List<Tuple<MedicineViewModel, List<AnimalViewModel>>>>> response =
_serviceStorage.GetReportInfo(new ListAnimalsSearchModel { servicesIds = services});
foreach (var service in response)
{
var medicines = _medicineStorage.GetFilteredList(new MedicineSearchModel { ServiceId = service });
Dictionary<int, int> counter = new();
foreach(var medicine in medicines)
Dictionary<int, (AnimalViewModel, int)> counter = new();
foreach (var medicine in service.Item2)
{
var animals = _animalStorage.GetFilteredList(new AnimalSearchModel { MedicineId = medicine.Id });
foreach(var animal in animals)
foreach (var animal in medicine.Item2)
{
if (!counter.ContainsKey(animal.Id))
counter.Add(animal.Id, 1);
counter.Add(animal.Id, (animal, 1));
else
{
counter[animal.Id]++;
counter[animal.Id] = (counter[animal.Id].Item1, counter[animal.Id].Item2 + 1);
}
}
}
List<AnimalViewModel> res = new();
foreach(var cnt in counter)
foreach (var cnt in counter)
{
if (cnt.Value != medicines.Count)
if (cnt.Value.Item2 != service.Item2.Count)
continue;
res.Add(_animalStorage.GetElement(new AnimalSearchModel { Id = cnt.Key }));
res.Add(cnt.Value.Item1);
}
ans.Add(new ListAnimalsViewModel
{
ServiceName = _serviceStorage.GetElement(new ServiceSearchModel { Id = service}).ServiceName,
ServiceName = service.Item1.ServiceName,
Animals = res
});
}

View File

@ -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 ListAnimalsSearchModel
{
public List<int>? servicesIds { get; set; }
}
}

View File

@ -13,9 +13,11 @@ namespace VetClinicContracts.StoragesContracts
{
List<ServiceViewModel> GetFullList();
List<ServiceViewModel> GetFilteredList(ServiceSearchModel model);
public List<Tuple<ServiceViewModel, List<Tuple<MedicineViewModel, List<AnimalViewModel>>>>> GetReportInfo(ListAnimalsSearchModel model);
ServiceViewModel? GetElement(ServiceSearchModel model);
ServiceViewModel? Insert(ServiceBindingModel model);
ServiceViewModel? Update(ServiceBindingModel model);
ServiceViewModel? Delete(ServiceBindingModel model);
}
}

View File

@ -67,6 +67,23 @@ namespace VetClinicDataBaseImplement.Implements
context.SaveChanges();
return newService.GetViewModel;
}
public List<Tuple<ServiceViewModel, List<Tuple<MedicineViewModel, List<AnimalViewModel>>>>> GetReportInfo(ListAnimalsSearchModel model)
{
if (model.servicesIds == null)
{
return new();
}
using var context = new VetClinicDatabase();
return context.Services
.Where(service => model.servicesIds.Contains(service.Id))
.Select(service => new Tuple<ServiceViewModel, List<Tuple<MedicineViewModel, List<AnimalViewModel>>>>(service.GetViewModel,
context.ServiceMedicines.Include(medicine => medicine.Medicine)
.Include(medicine => medicine.Service).Where(medicine => service.Id == medicine.ServiceId).
Select(medicine => new Tuple<MedicineViewModel, List<AnimalViewModel>>(medicine.Medicine.GetViewModel,
context.MedicineAnimals.Include(x => x.Animal).Where(x => x.MedicineId == medicine.Medicine.Id).
Select(x => x.Animal.GetViewModel).ToList())).ToList())).ToList();
}
public ServiceViewModel? Update(ServiceBindingModel model)
{
using var context = new VetClinicDatabase();