нужно переСОБРать бд

This commit is contained in:
antoc0der 2024-05-23 18:35:41 +04:00
parent df97bd6f43
commit 201a18f9bf
8 changed files with 19 additions and 8 deletions

View File

@ -18,5 +18,7 @@ namespace VeterinaryContracts.BindingModels
get;
set;
} = new();
public int DoctorId { get; set; }
}
}

View File

@ -10,5 +10,7 @@ namespace VeterinaryContracts.SearchModels
{
public int? Id { get; set; }
public string? DrugName { get; set; }
public int? DoctorId { get; set; }
}
}

View File

@ -23,5 +23,7 @@ namespace VeterinaryContracts.ViewModels
get;
set;
} = new();
public int DoctorId { get; set; }
}
}

View File

@ -12,5 +12,6 @@ namespace VeterinaryDataModels.Models
int Count { get; }
double Price { get; }
Dictionary<int, IMedicationModel> DrugMedications { get; }
}
int DoctorId { get; }
}
}

View File

@ -33,7 +33,7 @@ namespace VeterinaryDatabaseImplement.Implements
return new();
}
using var context = new VeterinaryDatabase();
return context.Drugs.Include(x => x.Medications)
return context.Drugs.Where(x => x.DoctorId == model.DoctorId).Include(x => x.Medications)
.ThenInclude(x => x.Medication)
.Where(x => x.DrugName.Contains(model.DrugName))
.ToList()

View File

@ -20,6 +20,8 @@ namespace VeterinaryDatabaseImplement.Models
public double Price { get; set; }
[Required]
public int Count { get; set; }
[Required]
public int DoctorId { get; private set; }
private Dictionary<int, IMedicationModel>? _drugMedications = null;
[NotMapped]
public Dictionary<int, IMedicationModel> DrugMedications
@ -47,6 +49,7 @@ namespace VeterinaryDatabaseImplement.Models
DrugName = model.DrugName,
Price = model.Price,
Count = model.Count,
DoctorId = model.DoctorId,
Medications = model.DrugMedications.Select(x => new DrugMedication
{
Medication = context.Medications.First(y => y.Id == x.Key)
@ -63,6 +66,7 @@ namespace VeterinaryDatabaseImplement.Models
Id = Id,
DrugName = DrugName,
Price = Price,
DoctorId=DoctorId,
DrugMedications = DrugMedications
};
public void UpdateMedications(VeterinaryDatabase context, DrugBindingModel model)

View File

@ -36,11 +36,11 @@ namespace VeterinaryRestApi.Controllers
}
}
[HttpGet]
public List<DrugViewModel> GetDrugs()
public List<DrugViewModel> GetDrugs(int doctorId)
{
try
{
return _drug.ReadList(null);
return _drug.ReadList(new DrugSearchModel { DoctorId = doctorId });
}
catch (Exception ex)
{
@ -94,7 +94,5 @@ namespace VeterinaryRestApi.Controllers
throw;
}
}
}
}

View File

@ -229,7 +229,8 @@ namespace VeterinaryShowDoctorApp.Controllers
DrugName = name,
Price = 0,
DrugMedications = a,
Count = count
Count = count,
DoctorId = APIDoctor.Doctor.Id
});
Response.Redirect("Index");
}
@ -358,7 +359,8 @@ namespace VeterinaryShowDoctorApp.Controllers
{
ServiceName = name,
ServiceMedications = a,
VisitId = visit
VisitId = visit,
DoctorId = APIDoctor.Doctor.Id
});
Response.Redirect("Index");
}