Merge branch 'Worker'

This commit is contained in:
goblinrf 2024-05-02 21:50:16 +04:00
commit c0fe740dc9
13 changed files with 174 additions and 3 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 ListServicesBindingModel
{
public string FileName { get; set; } = string.Empty;
public List<int> Animals { get; set; } = new();
}
}

View File

@ -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<int> Visits { get; set; } = new();
DateTime DateFrom { get; set; } = DateTime.Now;
DateTime DateTo { get; set; } = DateTime.Now;
}
}

View File

@ -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<ListAnimalsViewModel> GetServiceAnimals(List<int> animals);
void SaveServicesToWordFile(ListServicesBindingModel model);
void SaveServicesToExcelFile(ListServicesBindingModel model);
}
}

View File

@ -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; }
}
}

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

View File

@ -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<int>? visitsIds { get; set; }
public DateTime? DateFrom { get; set; }
public DateTime? DateTo { get; set; }
}
}

View File

@ -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; }
}
}

View File

@ -13,6 +13,7 @@ namespace VetClinicContracts.StoragesContracts
{
List<AnimalViewModel> GetFullList();
List<AnimalViewModel> GetFilteredList(AnimalSearchModel model);
List<Tuple<AnimalViewModel, List<Tuple<MedicineViewModel, List<ServiceViewModel>>>>> GetReportInfo(ListServicesSearchModel model);
AnimalViewModel? GetElement(AnimalSearchModel model);
AnimalViewModel? Insert(AnimalBindingModel model);
AnimalViewModel? Update(AnimalBindingModel model);

View File

@ -13,6 +13,10 @@ namespace VetClinicContracts.StoragesContracts
{
List<VisitViewModel> GetFullList();
List<VisitViewModel> GetFilteredList(VisitSearchModel model);
public List<Tuple<VisitViewModel, List<Tuple<AnimalViewModel, List<VaccinationViewModel>>>>> GetVaccinationsInfo(MedicineVaccinationsSearchModel model);
public List<Tuple<VisitViewModel, List<Tuple<AnimalViewModel, List<MedicineViewModel>>>>> GetMedicinesInfo(MedicineVaccinationsSearchModel model);
VisitViewModel? GetElement(VisitSearchModel model);
VisitViewModel? Insert(VisitBindingModel model);
VisitViewModel? Update(VisitBindingModel model);

View File

@ -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<ServiceViewModel> Services { get; set; } = new();
}
}

View File

@ -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<MedicineViewModel> Medicines { get; set; } = new();
public List<VaccinationViewModel> Vaccinations { get; set; } = new();
public DateTime DateFrom { get; set; } = DateTime.Now;
public DateTime DateTo { get; set; } = DateTime.Now;
}
}

View File

@ -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<Tuple<AnimalViewModel, List<Tuple<MedicineViewModel, List<ServiceViewModel>>>>> 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<AnimalViewModel, List<Tuple<MedicineViewModel, List<ServiceViewModel>>>>(animal.GetViewModel,
context.MedicineAnimals.Include(medicine => medicine.Medicine)
.Include(medicine => medicine.Animal).Where(medicine => animal.Id == medicine.AnimalId).
Select(medicine => new Tuple<MedicineViewModel, List<ServiceViewModel>>(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)

View File

@ -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<Tuple<VisitViewModel, List<Tuple<AnimalViewModel, List<VaccinationViewModel>>>>> 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<VisitViewModel, List<Tuple<AnimalViewModel, List<VaccinationViewModel>>>>(visit.GetViewModel,
context.VisitAnimals.Include(animal => animal.Animal)
.Include(animal => animal.Visit).Where(animal => visit.Id == animal.VisitId).
Select(animal => new Tuple<AnimalViewModel, List<VaccinationViewModel>>(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<Tuple<VisitViewModel, List<Tuple<AnimalViewModel, List<MedicineViewModel>>>>> 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<VisitViewModel, List<Tuple<AnimalViewModel, List<MedicineViewModel>>>>(visit.GetViewModel,
context.VisitAnimals.Include(animal => animal.Animal)
.Include(animal => animal.Visit).Where(animal => visit.Id == animal.VisitId).
Select(animal => new Tuple<AnimalViewModel, List<MedicineViewModel>>(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)