fixfix
This commit is contained in:
parent
e93598700c
commit
a7834c501b
@ -17,7 +17,7 @@ namespace VetclinicDatabaseImplement.Implements
|
||||
public List<DrugViewModel> GetFullList()
|
||||
{
|
||||
using var context = new VetclinicDatabase();
|
||||
return context.Drugs.Include(x => x.Doctor)
|
||||
return context.Drugs
|
||||
.Include(x => x.Medicines)
|
||||
.ThenInclude(x => x.Medicine)
|
||||
.ToList()
|
||||
@ -27,11 +27,9 @@ namespace VetclinicDatabaseImplement.Implements
|
||||
public List<DrugViewModel> GetFilteredList(DrugSearchModel model)
|
||||
{
|
||||
using var context = new VetclinicDatabase();
|
||||
return context.Drugs.Include(x => x.Doctor)
|
||||
.Include(x => x.Medicines)
|
||||
return context.Drugs.Where(x => x.DoctorId == model.DoctorId).Include(x => x.Medicines)
|
||||
.ThenInclude(x => x.Medicine)
|
||||
.Where(x => (string.IsNullOrEmpty(model.DrugName) || x.DrugName.Contains(model.DrugName))
|
||||
&& (!model.DoctorId.HasValue || x.DoctorId == model.DoctorId))
|
||||
.Where(x => String.IsNullOrEmpty(model.DrugName) || x.DrugName.Contains(model.DrugName))
|
||||
.ToList()
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
@ -46,7 +44,7 @@ namespace VetclinicDatabaseImplement.Implements
|
||||
using var context = new VetclinicDatabase();
|
||||
return context.Drugs.Include(x => x.Doctor)
|
||||
.Include(x => x.Medicines)
|
||||
.ThenInclude(x => x.Medicine)
|
||||
.ThenInclude(x => x.Medicine)
|
||||
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.DrugName) &&
|
||||
x.DrugName == model.DrugName) ||
|
||||
(model.Id.HasValue && x.Id ==
|
||||
@ -71,18 +69,19 @@ namespace VetclinicDatabaseImplement.Implements
|
||||
using var transaction = context.Database.BeginTransaction();
|
||||
try
|
||||
{
|
||||
var service = context.Drugs.Include(x => x.Doctor)
|
||||
.Include(x => x.Medicines).ThenInclude(x => x.Medicine).FirstOrDefault(rec =>
|
||||
var drug = context.Drugs.FirstOrDefault(rec =>
|
||||
rec.Id == model.Id);
|
||||
if (service == null)
|
||||
if (drug == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
service.Update(model);
|
||||
|
||||
drug.UpdateMedicines(context, model); // работает
|
||||
context.SaveChanges();
|
||||
drug.Update(model);
|
||||
context.SaveChanges();
|
||||
service.UpdateMedicines(context, model);
|
||||
transaction.Commit();
|
||||
return service.GetViewModel;
|
||||
return drug.GetViewModel;
|
||||
}
|
||||
catch
|
||||
{
|
||||
@ -93,9 +92,8 @@ namespace VetclinicDatabaseImplement.Implements
|
||||
public DrugViewModel? Delete(DrugBindingModel model)
|
||||
{
|
||||
using var context = new VetclinicDatabase();
|
||||
var element = context.Drugs.Include(x => x.Doctor)
|
||||
.Include(x => x.Medicines)
|
||||
.ThenInclude(x => x.Medicine)
|
||||
var element = context.Drugs
|
||||
.Include(x => x.Medicines)
|
||||
.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
if (element != null)
|
||||
{
|
||||
|
@ -26,7 +26,10 @@ namespace VetclinicDatabaseImplement.Implements
|
||||
return new();
|
||||
}
|
||||
using var context = new VetclinicDatabase();
|
||||
return context.Medicines.Where(x => x.MedicineName.Contains(model.MedicineName)).Select(x => x.GetViewModel).ToList();
|
||||
return context.Medicines.Where(x => x.DoctorId == model.DoctorId)
|
||||
.Where(x => String.IsNullOrEmpty(model.MedicineName) || x.MedicineName.Contains(model.MedicineName))
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
public MedicineViewModel? GetElement(MedicineSearchModel model)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user