жду контроллер животного
This commit is contained in:
parent
e7d7f4d3a9
commit
7d8ea70e32
@ -2,6 +2,7 @@ using Microsoft.AspNetCore.Mvc;
|
||||
using PharmacistApp.Models;
|
||||
using System.Diagnostics;
|
||||
using VetClinicContracts.BindingModels;
|
||||
using VetClinicContracts.SearchModels;
|
||||
using VetClinicContracts.ViewModels;
|
||||
using VetClinicDataBaseImplement.Models;
|
||||
using VetClinicDataModels.Models;
|
||||
@ -116,13 +117,15 @@ View(APIPharmacist.GetRequest<List<MedicineViewModel>>($"api/medicine/getmedicin
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
ViewBag.Animals = APIPharmacist.GetRequest<List<AnimalViewModel>>($"api/animal/getanimals");
|
||||
|
||||
return View();
|
||||
}
|
||||
|
||||
|
||||
|
||||
[HttpPost]
|
||||
public void CreateMedicine(string name, int price)
|
||||
public void CreateMedicine(string name, int price, List<int> animals)
|
||||
{
|
||||
if (APIPharmacist.Pharmacist == null)
|
||||
{
|
||||
@ -132,11 +135,18 @@ View(APIPharmacist.GetRequest<List<MedicineViewModel>>($"api/medicine/getmedicin
|
||||
{
|
||||
throw new Exception("Îøèáêà â ââåäåííûõ äàííûõ");
|
||||
}
|
||||
Dictionary<int, IAnimalModel> a = new Dictionary<int, IAnimalModel>();
|
||||
foreach (int animal in animals)
|
||||
{
|
||||
a.Add(animal, new AnimalSearchModel { Id = animal } as IAnimalModel);
|
||||
}
|
||||
|
||||
APIPharmacist.PostRequest("api/medicine/createmedicine", new MedicineBindingModel
|
||||
{
|
||||
MedicineName = name,
|
||||
Price = price,
|
||||
PharmacistId = APIPharmacist.Pharmacist.Id
|
||||
PharmacistId = APIPharmacist.Pharmacist.Id,
|
||||
MedicineAnimals = a
|
||||
}) ;
|
||||
Response.Redirect("Index");
|
||||
}
|
||||
@ -172,12 +182,13 @@ View(APIPharmacist.GetRequest<List<MedicineViewModel>>($"api/medicine/getmedicin
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
ViewBag.Medicines = APIPharmacist.GetRequest<List<MedicineViewModel>>($"api/medicine/getmedicines?pharmacistid={APIPharmacist.Pharmacist.Id}");
|
||||
ViewBag.Animals = APIPharmacist.GetRequest<List<AnimalViewModel>>($"api/animal/getanimals");
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void UpdateMedicine(int medicine, string name, int price,
|
||||
Dictionary<int, IAnimalModel> medicineAnimals = null)
|
||||
List<int> animals)
|
||||
{
|
||||
if (APIPharmacist.Pharmacist == null)
|
||||
{
|
||||
@ -187,13 +198,18 @@ View(APIPharmacist.GetRequest<List<MedicineViewModel>>($"api/medicine/getmedicin
|
||||
{
|
||||
throw new Exception("Îøèáêà â ââåäåííûõ äàííûõ");
|
||||
}
|
||||
Dictionary<int, IAnimalModel> a = new Dictionary<int, IAnimalModel>();
|
||||
foreach (int animal in animals)
|
||||
{
|
||||
a.Add(animal, new AnimalSearchModel { Id = animal } as IAnimalModel);
|
||||
}
|
||||
APIPharmacist.PostRequest("api/medicine/updatemedicine", new MedicineBindingModel
|
||||
{
|
||||
Id = medicine,
|
||||
MedicineName = name,
|
||||
Price = price,
|
||||
PharmacistId = APIPharmacist.Pharmacist.Id,
|
||||
MedicineAnimals = medicineAnimals
|
||||
MedicineAnimals = a
|
||||
});
|
||||
Response.Redirect("Index");
|
||||
}
|
||||
|
@ -18,6 +18,17 @@
|
||||
<input type="text" name="price" id="price" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-4">Животные:</div>
|
||||
<div class="col-8">
|
||||
<select name="animals" class="form-control" multiple size="6" id="animals">
|
||||
@foreach (var animal in ViewBag.Animals)
|
||||
{
|
||||
<option value="@animal.Id">@animal.AnimalName</option>
|
||||
}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-8"></div>
|
||||
<div class="col-4">
|
||||
|
@ -25,21 +25,16 @@
|
||||
<div class="col-4">Цена:</div>
|
||||
<div class="col-8"><input type="number" id="price" name="price" class="form-control" /></div>
|
||||
</div>
|
||||
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>
|
||||
Животное
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="table-elements">
|
||||
</tbody>
|
||||
</table>
|
||||
<div class="row">
|
||||
<div class="col-8"></div>
|
||||
<div class="col-4"><input type="submit" value="Сохранить" class="btn btn-primary" /></div>
|
||||
<div class="col-4">Животные:</div>
|
||||
<div class="col-8">
|
||||
<select name="animals" class="form-control" multiple size="6" id="animals">
|
||||
@foreach (var animal in ViewBag.Animals)
|
||||
{
|
||||
<option value="@animal.Id">@animal.AnimalName</option>
|
||||
}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
@ -56,7 +51,15 @@
|
||||
success: function (result) {
|
||||
$('#name').val(result.item1.medicineName);
|
||||
$('#price').val(result.item1.price);
|
||||
$('#table-elements').html(result.item2);
|
||||
$('#animals-elements').html
|
||||
@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);
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user