поручитель в дурке
This commit is contained in:
parent
e5e2469371
commit
978acd58b6
@ -0,0 +1,86 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using VeterinaryBusinessLogic.OfficePackage.Implements;
|
||||
using VeterinaryContracts.BusinessLogicContracts;
|
||||
using VeterinaryContracts.BindingModels;
|
||||
using VeterinaryContracts.StorageContracts;
|
||||
using VeterinaryContracts.ViewModels;
|
||||
using VeterinaryContracts.SearchModels;
|
||||
|
||||
namespace VeterinaryBusinessLogic.BusinessLogic
|
||||
{
|
||||
public class ReportLogicDoctor : IReportLogicDoctor
|
||||
{
|
||||
private readonly IDrugStorage _drugStorage;
|
||||
private readonly IMedicationStorage _medicationStorage;
|
||||
private readonly AbstractSaveToExcelDoctor _saveToExcel;
|
||||
private readonly AbstractSaveToWordDoctor _saveToWord;
|
||||
public ReportLogicDoctor(IPurchaseStorage purchaseStorage, IDrugStorage drugStorage, IMedicationStorage medicationStorage,
|
||||
AbstractSaveToExcelDoctor saveToExcel, AbstractSaveToWordDoctor saveToWord)
|
||||
{
|
||||
_drugStorage = drugStorage;
|
||||
_medicationStorage = medicationStorage;
|
||||
_saveToExcel = saveToExcel;
|
||||
_saveToWord = saveToWord;
|
||||
}
|
||||
public void SavePurchasesToExcelFile(ReportPurchaseMedicationBindingModel model)
|
||||
{
|
||||
_saveToExcel.CreateReport(new ExcelInfoDoctor
|
||||
{
|
||||
FileName = model.FileName,
|
||||
Title = "Список покупок по медикаментам",
|
||||
PurchaseMedications = GetPurchaseMedications(model.Medications)
|
||||
});
|
||||
}
|
||||
|
||||
public void SavePurchasesToWordFile(ReportPurchaseMedicationBindingModel model)
|
||||
{
|
||||
_saveToWord.CreateDoc(new WordInfoDoctor
|
||||
{
|
||||
FileName = model.FileName,
|
||||
Title = "Список покупок по медикаментам",
|
||||
PurchaseMedications = GetPurchaseMedications(model.Medications)
|
||||
});
|
||||
}
|
||||
|
||||
public List<ReportPurchaseMedicationViewModel> GetPurchaseMedications(List<int> medications)
|
||||
{
|
||||
List<ReportPurchaseMedicationViewModel> servs = new();
|
||||
List<Tuple<MedicationViewModel, List<Tuple<DrugViewModel, List<PurchaseViewModel>>>>> response =
|
||||
_medicationStorage.GetReportInfo(new ListPurchasesSearchModel { medicationsIds = medications });
|
||||
|
||||
foreach (var medication in response)
|
||||
{
|
||||
Dictionary<int, (PurchaseViewModel, int)> counter = new();
|
||||
foreach (var drug in medication.Item2)
|
||||
{
|
||||
foreach (var purchase in drug.Item2)
|
||||
{
|
||||
if (!counter.ContainsKey(purchase.Id))
|
||||
counter.Add(purchase.Id, (purchase, 1));
|
||||
else
|
||||
{
|
||||
counter[purchase.Id] = (counter[purchase.Id].Item1, counter[purchase.Id].Item2 + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
List<PurchaseViewModel> res = new();
|
||||
foreach (var cont in counter)
|
||||
{
|
||||
if (cont.Value.Item2 != medication.Item2.Count)
|
||||
continue;
|
||||
res.Add(cont.Value.Item1);
|
||||
}
|
||||
servs.Add(new ReportPurchaseMedicationViewModel
|
||||
{
|
||||
MedicationName = medication.Item1.MedicationName,
|
||||
Purchases = res
|
||||
});
|
||||
}
|
||||
return servs;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace VeterinaryContracts.BindingModels
|
||||
{
|
||||
public class ReportPurchaseMedicationBindingModel
|
||||
{
|
||||
public string FileName { get; set; } = string.Empty;
|
||||
public List<int> Medications { get; set; } = new();
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using VeterinaryContracts.BindingModels;
|
||||
using VeterinaryContracts.ViewModels;
|
||||
|
||||
|
||||
namespace VeterinaryContracts.BusinessLogicContracts
|
||||
{
|
||||
public interface IReportLogicDoctor
|
||||
{// will be done later
|
||||
List<ReportPurchaseMedicationViewModel> GetPurchaseMedications(List<int> medications);
|
||||
void SavePurchasesToWordFile(ReportPurchaseMedicationBindingModel model);
|
||||
void SavePurchasesToExcelFile(ReportPurchaseMedicationBindingModel model);
|
||||
}
|
||||
}
|
@ -10,6 +10,5 @@ namespace VeterinaryContracts.SearchModels
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
public string? DrugName { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace VeterinaryContracts.SearchModels
|
||||
{
|
||||
public class ListPurchasesSearchModel
|
||||
{
|
||||
public List<int>? medicationsIds { get; set; }
|
||||
}
|
||||
}
|
@ -7,5 +7,6 @@
|
||||
public int? DrugId { get; set; }
|
||||
public DateTime? DateCreate { get; set; }
|
||||
public DateTime? DateImplement { get; set;}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -13,6 +13,7 @@ namespace VeterinaryContracts.StorageContracts
|
||||
{
|
||||
List<MedicationViewModel> GetFullList();
|
||||
List<MedicationViewModel> GetFilteredList(MedicationSearchModel model);
|
||||
List<Tuple<MedicationViewModel, List<Tuple<DrugViewModel, List<PurchaseViewModel>>>>> GetReportInfo(ListPurchasesSearchModel model);
|
||||
MedicationViewModel? GetElement(MedicationSearchModel model);
|
||||
MedicationViewModel? Insert(MedicationBindingModel model);
|
||||
MedicationViewModel? Update(MedicationBindingModel model);
|
||||
|
@ -1,15 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace VeterinaryContracts.ViewModels
|
||||
{
|
||||
public class ReportPurchaseMedicationModel
|
||||
{
|
||||
public string FlowerName { get; set; } = string.Empty;
|
||||
public int TotalCount { get; set; }
|
||||
public List<Tuple<string, int>> Components { get; set; } = new();
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace VeterinaryContracts.ViewModels
|
||||
{
|
||||
public class ReportPurchaseMedicationViewModel
|
||||
{
|
||||
public string MedicationName { get; set; } = string.Empty;
|
||||
public List<PurchaseViewModel> Purchases { get; set; } = new();
|
||||
}
|
||||
}
|
@ -10,7 +10,7 @@ using VeterinaryContracts.SearchModels;
|
||||
using VeterinaryContracts.ViewModels;
|
||||
using VeterinaryDatabaseImplement.Models;
|
||||
using VeterinaryDatabaseImplement;
|
||||
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace VeterinaryDatabaseImplement.Implements
|
||||
{
|
||||
@ -82,5 +82,23 @@ namespace VeterinaryDatabaseImplement.Implements
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<Tuple<MedicationViewModel, List<Tuple<DrugViewModel, List<PurchaseViewModel>>>>> GetReportInfo(ListPurchasesSearchModel model)
|
||||
{
|
||||
if (model.medicationsIds == null)
|
||||
{
|
||||
return new();
|
||||
}
|
||||
using var context = new VeterinaryDatabase();
|
||||
return context.Medications
|
||||
.Where(pet => model.medicationsIds.Contains(pet.Id))
|
||||
.Select(pet => new Tuple<PetViewModel, List<Tuple<VisitViewModel, List<ServiceViewModel>>>>(pet.GetViewModel,
|
||||
context.VisitPets.Include(visit => visit.Visit)
|
||||
.Include(visit => visit.Pet).Where(visit => pet.Id == visit.PetId).
|
||||
Select(visit => new Tuple<VisitViewModel, List<ServiceViewModel>>(visit.Visit.GetViewModel,
|
||||
context.Services.Include(x => x.Visits).Where(x => x.MedicineId == visit.Medicine.Id).
|
||||
Select(x => x.Animal.GetViewModel).ToList())).ToList())).ToList();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -59,5 +59,6 @@ namespace VeterinaryRestApi.Controllers
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user