fixfix fix
This commit is contained in:
parent
a7834c501b
commit
8664cf1b6b
@ -17,14 +17,13 @@ namespace VetclinicDatabaseImplement.Implements
|
||||
public List<MedicineViewModel> GetFullList()
|
||||
{
|
||||
using var context = new VetclinicDatabase();
|
||||
return context.Medicines.Select(x => x.GetViewModel).ToList();
|
||||
return context.Medicines
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
public List<MedicineViewModel> GetFilteredList(MedicineSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.MedicineName))
|
||||
{
|
||||
return new();
|
||||
}
|
||||
|
||||
using var context = new VetclinicDatabase();
|
||||
return context.Medicines.Where(x => x.DoctorId == model.DoctorId)
|
||||
.Where(x => String.IsNullOrEmpty(model.MedicineName) || x.MedicineName.Contains(model.MedicineName))
|
||||
@ -38,7 +37,12 @@ namespace VetclinicDatabaseImplement.Implements
|
||||
return null;
|
||||
}
|
||||
using var context = new VetclinicDatabase();
|
||||
return context.Medicines.FirstOrDefault(x => (!string.IsNullOrEmpty(model.MedicineName) && x.MedicineName == model.MedicineName) || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
|
||||
return context.Medicines
|
||||
.FirstOrDefault(x =>
|
||||
(!string.IsNullOrEmpty(model.MedicineName) && x.MedicineName ==
|
||||
model.MedicineName) ||
|
||||
(model.Id.HasValue && x.Id == model.Id))
|
||||
?.GetViewModel;
|
||||
}
|
||||
public MedicineViewModel? Insert(MedicineBindingModel model)
|
||||
{
|
||||
@ -55,26 +59,69 @@ namespace VetclinicDatabaseImplement.Implements
|
||||
public MedicineViewModel? Update(MedicineBindingModel model)
|
||||
{
|
||||
using var context = new VetclinicDatabase();
|
||||
var component = context.Medicines.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (component == null)
|
||||
var medication = context.Medicines.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (medication == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
component.Update(model);
|
||||
medication.Update(model);
|
||||
context.SaveChanges();
|
||||
return component.GetViewModel;
|
||||
return medication.GetViewModel;
|
||||
}
|
||||
public MedicineViewModel? Delete(MedicineBindingModel model)
|
||||
{
|
||||
using var context = new VetclinicDatabase();
|
||||
var element = context.Medicines.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
if (element == null)
|
||||
if (element != null)
|
||||
{
|
||||
return null;
|
||||
context.Medicines.Remove(element);
|
||||
context.SaveChanges();
|
||||
return element.GetViewModel;
|
||||
}
|
||||
context.Medicines.Remove(element);
|
||||
context.SaveChanges();
|
||||
return element.GetViewModel;
|
||||
return null;
|
||||
}
|
||||
|
||||
//public List<ReportPurchaseMedicineViewModel> GetReportMedicinePurchasesList(ListPurchasesSearchModel model)
|
||||
//{
|
||||
// if (model.medicationsIds == null)
|
||||
// {
|
||||
// return new();
|
||||
// }
|
||||
// using var context = new VetclinicDatabase();
|
||||
// return context.Medicines
|
||||
// .Where(medication => model.medicationsIds == null || model.medicationsIds.Contains(medication.Id))
|
||||
// .Select(medication => new ReportPurchaseMedicineViewModel()
|
||||
// {
|
||||
// MedicineName = medication.MedicineName,
|
||||
// Purchases = context.Purchases.Include(purchase => purchase.Drug).ThenInclude(drug => drug.Medicines)
|
||||
// .Where(purchase => purchase.Drug != null && purchase.Drug.Medicines.Any(m => m.MedicineId == medication.Id))
|
||||
// .Select(purchase => purchase.GetViewModel).ToList()
|
||||
// }).ToList();
|
||||
//}
|
||||
|
||||
//public List<ReportDrugsVisitsViewModel> GetReportDrugsVisits(ReportDrugsVisitsSearchModel model)
|
||||
//{
|
||||
// using var context = new VetclinicDatabase();
|
||||
|
||||
// return context.Medicines
|
||||
// .Select(pet => new ReportDrugsVisitsViewModel()
|
||||
// {
|
||||
// MedicineName = pet.MedicineName,
|
||||
// Drugs = context.Drugs
|
||||
// .Where(drug => model.DateFrom && drug.Medicines.Any(m => m.MedicineId == pet.Id))
|
||||
// .Select(drug => drug.GetViewModel)
|
||||
// .ToList(),
|
||||
// Visits = context.Services
|
||||
// .Include(service => service.Visit)
|
||||
// .Where(service => service.Visit != null && service.Visit.DateVisit <= model.DateTo &&
|
||||
// service.Visit.DateVisit >= model.DateFrom && service.Medicines.Any(m => m.MedicineId == pet.Id))
|
||||
// .Select(service => service.Visit.GetViewModel)
|
||||
// .ToList(),
|
||||
// })
|
||||
// .ToList();
|
||||
//}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user