СДЕЛАЛ СДЕЛАЛ СДЕЛАЛ

This commit is contained in:
gg12 darfren 2024-05-02 18:22:44 +04:00
parent eba96483b4
commit 98c303acae
5 changed files with 80 additions and 0 deletions

View File

@ -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 VisistsGuidesBindingModel
{
public string FileName { get; set; } = string.Empty;
public List<int> Medicines { get; set; } = new();
}
}

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 VisitServicesSearchModel
{
public List<int>? medicinesIds { get; set; }
}
}

View File

@ -17,5 +17,8 @@ namespace VetClinicContracts.StoragesContracts
MedicineViewModel? Insert(MedicineBindingModel model);
MedicineViewModel? Update(MedicineBindingModel model);
MedicineViewModel? Delete(MedicineBindingModel model);
public List<Tuple<MedicineViewModel, List<Tuple<ServiceViewModel, List<GuidanceViewModel>>>>> GetGuidancesInfo(VisitServicesSearchModel model);
public List<Tuple<MedicineViewModel, List<Tuple<ServiceViewModel, List<VisitViewModel>>>>> GetVisitsInfo(VisitServicesSearchModel model);
}
}

View File

@ -33,6 +33,40 @@ namespace VetClinicDataBaseImplement.Implements
.Select(x => x.GetViewModel)
.ToList();
}
public List<Tuple<MedicineViewModel, List<Tuple<ServiceViewModel, List<GuidanceViewModel>>>>> GetGuidancesInfo(VisitServicesSearchModel model)
{
if (model.medicinesIds == null)
{
return new();
}
using var context = new VetClinicDatabase();
return context.Medicines
.Where(medicine => model.medicinesIds.Contains(medicine.Id))
.Select(medicine => new Tuple<MedicineViewModel, List<Tuple<ServiceViewModel, List<GuidanceViewModel>>>>(medicine.GetViewModel,
context.ServiceMedicines.Include(service => service.Service)
.Include(service => service.Medicine).Where(service => medicine.Id == service.MedicineId).
Select(service => new Tuple<ServiceViewModel, List<GuidanceViewModel>>(service.Service.GetViewModel,
context.Guidances.Include(x => x.Service).Where(x => x.ServiceId == service.ServiceId).
Select(x => x.GetViewModel).ToList())).ToList())).ToList();
}
public List<Tuple<MedicineViewModel, List<Tuple<ServiceViewModel, List<VisitViewModel>>>>> GetVisitsInfo(VisitServicesSearchModel model)
{
if (model.medicinesIds == null)
{
return new();
}
using var context = new VetClinicDatabase();
return context.Medicines
.Where(medicine => model.medicinesIds.Contains(medicine.Id))
.Select(medicine => new Tuple<MedicineViewModel, List<Tuple<ServiceViewModel, List<VisitViewModel>>>>(medicine.GetViewModel,
context.ServiceMedicines.Include(service => service.Service)
.Include(service => service.Medicine).Where(service => medicine.Id == service.MedicineId).
Select(service => new Tuple<ServiceViewModel, List<VisitViewModel>>(service.Service.GetViewModel,
context.ServiceVisits.Include(x => x.Visit).Where(x => x.ServiceId == service.ServiceId).
Select(x => x.Visit.GetViewModel).ToList())).ToList())).ToList();
}
public MedicineViewModel? GetElement(MedicineSearchModel model)
{
if (string.IsNullOrEmpty(model.MedicineName) &&

View File

@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VetClinicContracts.ViewModels;
namespace VetClinicDataBaseImplement.Implements
{
public class VisitsGuidesViewModel
{
string MedicineName { get; set; } = string.Empty;
List<VisitViewModel> Visits { get; set; }
List<GuidanceViewModel> Guidances { get; set; }
}
}