Сделал полный круд для медикаментов
This commit is contained in:
parent
8003d8f7f9
commit
1ff125d5a9
@ -233,7 +233,6 @@ View(APIPharmacist.GetRequest<List<MedicineViewModel>>($"api/medicine/getmedicin
|
||||
return default;
|
||||
}
|
||||
string table = "";
|
||||
result.Item1.MedicineAnimals.Clear();
|
||||
for (int i = 0; i < result.Item2.Count; i++)
|
||||
{
|
||||
var animal = result.Item2[i];
|
||||
|
@ -16,7 +16,7 @@
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\VetClinicContracts\VetClinicContracts.csproj" />
|
||||
<ProjectReference Include="..\VetClinicDataBaseImplement\VetClinicDataBaseImplement.csproj" />
|
||||
<ProjectReference Include="..\VetClinicRestApi\VetClinicRestApi.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
@ -13,9 +13,6 @@
|
||||
<div class="col-8">
|
||||
<select id="medicine" name="medicine" class="form-control" asp-items="@(new SelectList(@ViewBag.Medicines, "Id", "MedicineName"))"></select>
|
||||
</div>
|
||||
<div class="col-8">
|
||||
<select id="animal" name="animal" class="form-control" asp-items="@(new SelectList(@ViewBag.Animals, "Id", "AnimalName"))"></select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-4">Название:</div>
|
||||
@ -36,6 +33,10 @@
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-8"></div>
|
||||
<div class="col-4"><input type="submit" value="Сохранить" class="btn btn-primary" /></div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
@section Scripts
|
||||
@ -51,14 +52,6 @@
|
||||
success: function (result) {
|
||||
$('#name').val(result.item1.medicineName);
|
||||
$('#price').val(result.item1.price);
|
||||
// @foreach (var animal in ViewBag.Animals)
|
||||
// {
|
||||
// $($"#select option[value={animal.Id}]").prop('selected', false);
|
||||
// }
|
||||
// @foreach (var animal in result.Item2)
|
||||
// {
|
||||
// $($"#select option[value={animal.id}]").prop('selected', true);
|
||||
// }
|
||||
}
|
||||
});
|
||||
};
|
||||
|
@ -7,7 +7,7 @@ using VetClinicDataModels.Models;
|
||||
|
||||
namespace VetClinicContracts.BindingModels
|
||||
{
|
||||
public class AnimalBindingModel
|
||||
public class AnimalBindingModel : IAnimalModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public int AdminId { get; set; }
|
||||
|
@ -15,8 +15,6 @@ namespace VetClinicContracts.ViewModels
|
||||
public string MedicineName { get; set; } = string.Empty;
|
||||
[DisplayName("Цена медикамента")]
|
||||
public double Price { get; set; }
|
||||
[DisplayName("Фармацевт")]
|
||||
public string PharmacistFIO { get; set; } = string.Empty;
|
||||
public int PharmacistId { get; set; }
|
||||
public Dictionary<int, IAnimalModel> MedicineAnimals { get; set; } = new();
|
||||
}
|
||||
|
@ -19,7 +19,6 @@ namespace VetClinicDataBaseImplement.Implements
|
||||
using var context = new VetClinicDatabase();
|
||||
return context.Medicines.Include(x => x.Pharmacist).Include(x => x.Animals)
|
||||
.ThenInclude(x => x.Animal)
|
||||
.ToList()
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
@ -30,7 +29,6 @@ namespace VetClinicDataBaseImplement.Implements
|
||||
.ThenInclude(x => x.Animal)
|
||||
.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,6 @@ namespace VetClinicDataBaseImplement.Models
|
||||
MedicineName = MedicineName,
|
||||
Price = Price,
|
||||
MedicineAnimals = MedicineAnimals,
|
||||
PharmacistFIO = Pharmacist.PharmacistFIO
|
||||
};
|
||||
public void UpdateAnimals(VetClinicDatabase context,
|
||||
MedicineBindingModel model)
|
||||
|
@ -27,7 +27,9 @@ namespace VetClinicRestApi.Controllers
|
||||
var elem = _medicine.ReadElement(new MedicineSearchModel { Id = medicineId });
|
||||
if (elem == null)
|
||||
return null;
|
||||
return Tuple.Create(elem, elem.MedicineAnimals.Select(x => x.Value.AnimalName).ToList());
|
||||
var res = Tuple.Create(elem, elem.MedicineAnimals.Select(x => x.Value.AnimalName).ToList());
|
||||
res.Item1.MedicineAnimals = null;
|
||||
return res;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@ -36,11 +38,14 @@ namespace VetClinicRestApi.Controllers
|
||||
}
|
||||
}
|
||||
[HttpGet]
|
||||
public List<MedicineViewModel> GetMedicines(int pharmacistId)
|
||||
public List<MedicineViewModel>? GetMedicines(int pharmacistId)
|
||||
{
|
||||
try
|
||||
{
|
||||
return _medicine.ReadList(new MedicineSearchModel { PharmacistId = pharmacistId});
|
||||
var res = _medicine.ReadList(new MedicineSearchModel { PharmacistId = pharmacistId });
|
||||
foreach (var medicine in res)
|
||||
medicine.MedicineAnimals = null;
|
||||
return res;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@ -67,7 +72,6 @@ namespace VetClinicRestApi.Controllers
|
||||
{
|
||||
try
|
||||
{
|
||||
model.MedicineAnimals = null!;
|
||||
return _medicine.Update(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
Loading…
Reference in New Issue
Block a user