переделал форму
This commit is contained in:
parent
7214604c67
commit
51b0308ea8
@ -1,6 +1,8 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using NPOI.SS.UserModel;
|
||||
using PharmacistApp.Models;
|
||||
using System.Diagnostics;
|
||||
using System.Text;
|
||||
using VetClinicContracts.BindingModels;
|
||||
using VetClinicContracts.SearchModels;
|
||||
using VetClinicContracts.ViewModels;
|
||||
@ -45,12 +47,12 @@ View(APIPharmacist.GetRequest<List<MedicineViewModel>>($"api/medicine/getmedicin
|
||||
{
|
||||
if (APIPharmacist.Pharmacist == null)
|
||||
{
|
||||
throw new Exception("Âû êàê ñóäà ïîïàëè? Ñóäà âõîä òîëüêî àâòîðèçîâàííûì");
|
||||
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
|
||||
}
|
||||
if (string.IsNullOrEmpty(email) ||
|
||||
string.IsNullOrEmpty(password) || string.IsNullOrEmpty(fio))
|
||||
{
|
||||
throw new Exception("Ââåäèòå email, ïàðîëü è ÔÈÎ");
|
||||
throw new Exception("Введите email, пароль и ФИО");
|
||||
}
|
||||
APIPharmacist.PostRequest("api/pharmacist/updatedata", new
|
||||
PharmacistBindingModel
|
||||
@ -77,13 +79,13 @@ View(APIPharmacist.GetRequest<List<MedicineViewModel>>($"api/medicine/getmedicin
|
||||
if (string.IsNullOrEmpty(email) ||
|
||||
string.IsNullOrEmpty(password))
|
||||
{
|
||||
throw new Exception("Ââåäèòå email è ïàðîëü");
|
||||
throw new Exception("Введите email и пароль");
|
||||
}
|
||||
APIPharmacist.Pharmacist =
|
||||
APIPharmacist.GetRequest<PharmacistViewModel>($"api/pharmacist/login?email={email}&password={password}");
|
||||
if (APIPharmacist.Pharmacist == null)
|
||||
{
|
||||
throw new Exception("Íåâåðíûé ëîãèí/ïàðîëü");
|
||||
throw new Exception("Неверный логин/пароль");
|
||||
}
|
||||
Response.Redirect("Index");
|
||||
}
|
||||
@ -98,7 +100,7 @@ View(APIPharmacist.GetRequest<List<MedicineViewModel>>($"api/medicine/getmedicin
|
||||
if (string.IsNullOrEmpty(email) ||
|
||||
string.IsNullOrEmpty(password) || string.IsNullOrEmpty(fio))
|
||||
{
|
||||
throw new Exception("Ââåäèòå ëîãèí, ïàðîëü è ÔÈÎ");
|
||||
throw new Exception("Введите логин, пароль и ФИО");
|
||||
}
|
||||
APIPharmacist.PostRequest("api/pharmacist/register", new
|
||||
PharmacistBindingModel
|
||||
@ -117,20 +119,25 @@ View(APIPharmacist.GetRequest<List<MedicineViewModel>>($"api/medicine/getmedicin
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
ViewBag.Animals = APIPharmacist.GetRequest<List<AnimalViewModel>>($"api/animal/getanimallist");
|
||||
|
||||
return View();
|
||||
}
|
||||
|
||||
|
||||
|
||||
[HttpPost]
|
||||
public void CreateMedicine(string name, string price, List<int> animals)
|
||||
public void CreateMedicine(string name, string price)
|
||||
{
|
||||
if (APIPharmacist.Pharmacist == null)
|
||||
{
|
||||
throw new Exception("Âû êàê ñþäà ïîïàëè? Ñþäà âõîä òîëüêî àâòîðèçîâàííûì");
|
||||
throw new Exception("Вы как сюда попали? Сюда вход только авторизованным");
|
||||
}
|
||||
StringBuilder st = new StringBuilder(price);
|
||||
for (int i = 0; i < price.Length; i++)
|
||||
{
|
||||
if (price[i] == '.')
|
||||
st[i] = ',';
|
||||
}
|
||||
price = st.ToString();
|
||||
double _price;
|
||||
try
|
||||
{
|
||||
@ -138,24 +145,18 @@ View(APIPharmacist.GetRequest<List<MedicineViewModel>>($"api/medicine/getmedicin
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
throw new Exception("Îøèáêà â ââåäåííûõ äàííûõ");
|
||||
throw new Exception("Ошибка в введенных данных");
|
||||
}
|
||||
if (string.IsNullOrEmpty(name) || _price <= 0)
|
||||
{
|
||||
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);
|
||||
throw new Exception("Ошибка в введенных данных");
|
||||
}
|
||||
|
||||
APIPharmacist.PostRequest("api/medicine/createmedicine", new MedicineBindingModel
|
||||
{
|
||||
MedicineName = name,
|
||||
Price = Math.Round(_price, 2),
|
||||
PharmacistId = APIPharmacist.Pharmacist.Id,
|
||||
MedicineAnimals = a
|
||||
PharmacistId = APIPharmacist.Pharmacist.Id
|
||||
}) ;
|
||||
Response.Redirect("Index");
|
||||
}
|
||||
@ -175,7 +176,7 @@ View(APIPharmacist.GetRequest<List<MedicineViewModel>>($"api/medicine/getmedicin
|
||||
{
|
||||
if (APIPharmacist.Pharmacist == null)
|
||||
{
|
||||
throw new Exception("Âû êàê ñþäà ïîïàëè? Ñþäà âõîä òîëüêî àâòîðèçîâàííûì");
|
||||
throw new Exception("Вы как сюда попали? Сюда вход только авторизованным");
|
||||
}
|
||||
APIPharmacist.PostRequest("api/medicine/deletemedicine", new MedicineBindingModel
|
||||
{
|
||||
@ -191,18 +192,23 @@ 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/getanimallist");
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void UpdateMedicine(int medicine, string name, string price,
|
||||
List<int> animals)
|
||||
public void UpdateMedicine(int medicine, string name, string price)
|
||||
{
|
||||
if (APIPharmacist.Pharmacist == null)
|
||||
{
|
||||
throw new Exception("Âû êàê ñþäà ïîïàëè? Ñþäà âõîä òîëüêî àâòîðèçîâàííûì");
|
||||
throw new Exception("Вы как сюда попали? Сюда вход только авторизованным");
|
||||
}
|
||||
StringBuilder st = new StringBuilder(price);
|
||||
for (int i = 0; i < price.Length; i++)
|
||||
{
|
||||
if (price[i] == '.')
|
||||
st[i] = ',';
|
||||
}
|
||||
price = st.ToString();
|
||||
double _price;
|
||||
try
|
||||
{
|
||||
@ -210,18 +216,68 @@ View(APIPharmacist.GetRequest<List<MedicineViewModel>>($"api/medicine/getmedicin
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new Exception("Îøèáêà â ââåäåííûõ äàííûõ");
|
||||
throw new Exception("Ошибка в введенных данных");
|
||||
}
|
||||
if (string.IsNullOrEmpty(name) || _price <= 0)
|
||||
{
|
||||
throw new Exception("Îøèáêà â ââåäåííûõ äàííûõ");
|
||||
throw new Exception("Ошибка в введенных данных");
|
||||
}
|
||||
APIPharmacist.PostRequest("api/medicine/updatemedicine?isconnection=false", new MedicineBindingModel
|
||||
{
|
||||
Id = medicine,
|
||||
MedicineName = name,
|
||||
Price = Math.Round(_price, 2),
|
||||
PharmacistId = APIPharmacist.Pharmacist.Id,
|
||||
});
|
||||
Response.Redirect("Index");
|
||||
}
|
||||
|
||||
public IActionResult MedicineAnimals()
|
||||
{
|
||||
if (APIPharmacist.Pharmacist == null)
|
||||
{
|
||||
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/getanimallist");
|
||||
return View();
|
||||
}
|
||||
|
||||
|
||||
[HttpPost]
|
||||
public void MedicineAnimals(int medicine, string name, string price,
|
||||
List<int> animals)
|
||||
{
|
||||
if (APIPharmacist.Pharmacist == null)
|
||||
{
|
||||
throw new Exception("Вы как сюда попали? Сюда вход только авторизованным");
|
||||
}
|
||||
StringBuilder st = new StringBuilder(price);
|
||||
for(int i = 0; i < price.Length; i++)
|
||||
{
|
||||
if (price[i] == '.')
|
||||
st[i] = ',';
|
||||
}
|
||||
price = st.ToString();
|
||||
double _price;
|
||||
try
|
||||
{
|
||||
_price = Convert.ToDouble(price);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new Exception("Ошибка в введенных данных");
|
||||
}
|
||||
if (string.IsNullOrEmpty(name) || _price <= 0)
|
||||
{
|
||||
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
|
||||
APIPharmacist.PostRequest("api/medicine/updatemedicine?isconnection=true", new MedicineBindingModel
|
||||
{
|
||||
Id = medicine,
|
||||
MedicineName = name,
|
||||
@ -243,7 +299,7 @@ View(APIPharmacist.GetRequest<List<MedicineViewModel>>($"api/medicine/getmedicin
|
||||
{
|
||||
if (APIPharmacist.Pharmacist == null)
|
||||
{
|
||||
throw new Exception("Âû êàê ñþäà ïîïàëè? Ñþäà âõîä òîëüêî àâòîðèçîâàííûì");
|
||||
throw new Exception("Вы как сюда попали? Сюда вход только авторизованным");
|
||||
}
|
||||
var result = APIPharmacist.GetRequest<Tuple<MedicineViewModel, List<string>>>($"api/medicine/getmedicine?medicineid={medicineId}");
|
||||
if (result == null)
|
||||
@ -259,7 +315,7 @@ View(APIPharmacist.GetRequest<List<MedicineViewModel>>($"api/medicine/getmedicin
|
||||
{
|
||||
if (APIPharmacist.Pharmacist == null)
|
||||
{
|
||||
throw new Exception("Âû êàê ñþäà ïîïàëè? Ñþäà âõîä òîëüêî àâòîðèçîâàííûì");
|
||||
throw new Exception("Вы как сюда попали? Сюда вход только авторизованным");
|
||||
}
|
||||
var result = APIPharmacist.GetRequest<AnimalViewModel>($"api/animal/getanimal?animalid={animalId}");
|
||||
return result;
|
||||
|
@ -18,17 +18,6 @@
|
||||
<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">
|
||||
|
@ -17,6 +17,7 @@
|
||||
<a asp-action="CreateMedicine">Создать медикамент</a>
|
||||
<a asp-action="UpdateMedicine">Обновить медикамент</a>
|
||||
<a asp-action="DeleteMedicine">Удалить медикамент</a>
|
||||
<a asp-action="MedicineAnimals">Связать медикаменты и животных</a>
|
||||
</p>
|
||||
<table class="table">
|
||||
<thead>
|
||||
|
65
VetClinic/PharmacistApp/Views/Home/MedicineAnimals.cshtml
Normal file
65
VetClinic/PharmacistApp/Views/Home/MedicineAnimals.cshtml
Normal file
@ -0,0 +1,65 @@
|
||||
@using VetClinicContracts.ViewModels;
|
||||
|
||||
@{
|
||||
ViewData["Title"] = "MedicineAnimals";
|
||||
}
|
||||
|
||||
<div class="text-center">
|
||||
<h2 class="display-4">Связывание медикамента и животного</h2>
|
||||
</div>
|
||||
<form method="post">
|
||||
<div class="row">
|
||||
<div class="col-4">Медикамент:</div>
|
||||
<div class="col-8">
|
||||
<select id="medicine" name="medicine" class="form-control" asp-items="@(new SelectList(@ViewBag.Medicines, "Id", "MedicineName"))"></select>
|
||||
</div>
|
||||
</div>
|
||||
<input style = "visibility: hidden" type="text" name="name" id="name" class="form-control" />
|
||||
<input style = "visibility: hidden" type="text" id="price" name="price" class="form-control" />
|
||||
<div class="row">
|
||||
<div class="col-4">Животные:</div>
|
||||
<div class="col-8">
|
||||
<select name="animals" class="form-control" multiple size="5" id="animals">
|
||||
@foreach (var animal in ViewBag.Animals)
|
||||
{
|
||||
<option value="@animal.Id" id="@animal.AnimalName">@animal.AnimalName</option>
|
||||
}
|
||||
</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
|
||||
{
|
||||
<script>
|
||||
function check() {
|
||||
var medicine = $('#medicine').val();
|
||||
$("#animals option:selected").removeAttr("selected");
|
||||
if (medicine) {
|
||||
$.ajax({
|
||||
method: "GET",
|
||||
url: "/Home/GetMedicine",
|
||||
data: { medicineId: medicine },
|
||||
success: function (result) {
|
||||
console.log(result.item2);
|
||||
$('#name').val(result.item1.medicineName);
|
||||
$('#price').val(result.item1.price);
|
||||
$.map(result.item2, function (n) {
|
||||
console.log("#" + n);
|
||||
$("#" + n).attr("selected", "selected")
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
};
|
||||
}
|
||||
check();
|
||||
$('#medicine').on('change', function () {
|
||||
check();
|
||||
});
|
||||
</script>
|
||||
}
|
@ -22,17 +22,6 @@
|
||||
<div class="col-4">Цена:</div>
|
||||
<div class="col-8"><input type="text" id="price" name="price" class="form-control" /></div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-4">Животные:</div>
|
||||
<div class="col-8">
|
||||
<select name="animals" class="form-control" multiple size="5" id="animals">
|
||||
@foreach (var animal in ViewBag.Animals)
|
||||
{
|
||||
<option value="@animal.Id" id="@animal.AnimalName">@animal.AnimalName</option>
|
||||
}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-8"></div>
|
||||
<div class="col-4"><input type="submit" value="Сохранить" class="btn btn-primary" /></div>
|
||||
@ -54,10 +43,6 @@
|
||||
console.log(result.item2);
|
||||
$('#name').val(result.item1.medicineName);
|
||||
$('#price').val(result.item1.price);
|
||||
$.map(result.item2, function ( n ) {
|
||||
console.log("#" + n);
|
||||
$("#" + n).attr("selected", "selected")
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
|
@ -77,7 +77,8 @@ namespace VetClinicDataBaseImplement.Implements
|
||||
}
|
||||
medicine.Update(model);
|
||||
context.SaveChanges();
|
||||
medicine.UpdateAnimals(context, model);
|
||||
if(model.MedicineAnimals != null)
|
||||
medicine.UpdateAnimals(context, model);
|
||||
transaction.Commit();
|
||||
return medicine.GetViewModel;
|
||||
}
|
||||
|
@ -68,10 +68,12 @@ namespace VetClinicRestApi.Controllers
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public bool UpdateMedicine(MedicineBindingModel model)
|
||||
public bool UpdateMedicine(bool isConnection, MedicineBindingModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!isConnection)
|
||||
model.MedicineAnimals = null!;
|
||||
return _medicine.Update(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
Loading…
Reference in New Issue
Block a user