фиксы

This commit is contained in:
gg12 darfren 2024-04-26 17:42:37 +04:00
parent 79c33f3f0d
commit 4fc5af7e05
4 changed files with 14 additions and 9 deletions

View File

@ -146,7 +146,7 @@ View(APIPharmacist.GetRequest<List<MedicineViewModel>>($"api/medicine/getmedicin
{
return Redirect("~/Home/Enter");
}
ViewBag.Medicines = APIPharmacist.GetRequest<List<MedicineViewModel>>("api/medicine/getmedicines");
ViewBag.Medicines = APIPharmacist.GetRequest<List<MedicineViewModel>>($"api/medicine/getmedicines?pharmacistid={APIPharmacist.Pharmacist.Id}");
return View();
}
@ -170,7 +170,7 @@ View(APIPharmacist.GetRequest<List<MedicineViewModel>>($"api/medicine/getmedicin
{
return Redirect("~/Home/Enter");
}
ViewBag.Medicines = APIPharmacist.GetRequest<List<MedicineViewModel>>("api/medicine/getmedicines");
ViewBag.Medicines = APIPharmacist.GetRequest<List<MedicineViewModel>>($"api/medicine/getmedicines?pharmacistid={APIPharmacist.Pharmacist.Id}");
return View();
}
@ -190,6 +190,7 @@ View(APIPharmacist.GetRequest<List<MedicineViewModel>>($"api/medicine/getmedicin
Id = medicine,
MedicineName = name,
Price = price,
PharmacistId = APIPharmacist.Pharmacist.Id
});
Response.Redirect("Index");
}

View File

@ -51,15 +51,15 @@
url: "/Home/GetMedicine",
data: { medicineId: medicine },
success: function (result) {
$('#name').val(result.item1.MedicineName);
$('#price').val(result.item1.Price);
$('#name').val(result.item1.medicineName);
$('#price').val(result.item1.price);
$('#table-elements').html(result.item2);
}
});
};
}
check();
$('#shop').on('change', function () {
$('#medicine').on('change', function () {
check();
});
</script>

View File

@ -28,8 +28,8 @@ namespace VetClinicDataBaseImplement.Implements
using var context = new VetClinicDatabase();
return context.Medicines.Include(x => x.Pharmacist).Include(x => x.Animals)
.ThenInclude(x => x.Animal)
.Where(x => (string.IsNullOrEmpty(model.MedicineName) || x.MedicineName.Contains(model.MedicineName)
&& (!model.PharmacistId.HasValue || x.PharmacistId == model.PharmacistId)))
.Where(x => (string.IsNullOrEmpty(model.MedicineName) || x.MedicineName.Contains(model.MedicineName))
&& (!model.PharmacistId.HasValue || x.PharmacistId == model.PharmacistId))
.ToList()
.Select(x => x.GetViewModel)
.ToList();
@ -69,7 +69,9 @@ namespace VetClinicDataBaseImplement.Implements
using var transaction = context.Database.BeginTransaction();
try
{
var medicine = context.Medicines.FirstOrDefault(rec =>
var medicine = context.Medicines.Include(x => x.Pharmacist)
.Include(x => x.Animals)
.ThenInclude(x => x.Animal).FirstOrDefault(rec =>
rec.Id == model.Id);
if (medicine == null)
{
@ -90,7 +92,7 @@ namespace VetClinicDataBaseImplement.Implements
public MedicineViewModel? Delete(MedicineBindingModel model)
{
using var context = new VetClinicDatabase();
var element = context.Medicines
var element = context.Medicines.Include(x => x.Pharmacist)
.Include(x => x.Animals).ThenInclude(x => x.Animal)
.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)

View File

@ -73,6 +73,8 @@ namespace VetClinicDataBaseImplement.Models
public void UpdateAnimals(VetClinicDatabase context,
MedicineBindingModel model)
{
if (model.MedicineAnimals == null)
return;
var medicineAnimals = context.MedicineAnimals.Where(rec =>
rec.MedicineId == model.Id).ToList();
if (medicineAnimals != null && medicineAnimals.Count > 0)