поручитель: всё кроме формы создания услуги
This commit is contained in:
parent
6cee54fb4a
commit
f57a380c66
@ -83,7 +83,6 @@ namespace VeterinaryShowDoctorApp.Controllers
|
||||
}
|
||||
Response.Redirect("Index");
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult Register()
|
||||
{
|
||||
@ -107,7 +106,7 @@ namespace VeterinaryShowDoctorApp.Controllers
|
||||
Response.Redirect("Enter");
|
||||
return;
|
||||
}
|
||||
|
||||
// medications
|
||||
public IActionResult CreateMedication()
|
||||
{
|
||||
if (APIDoctor.Doctor == null)
|
||||
@ -116,7 +115,6 @@ namespace VeterinaryShowDoctorApp.Controllers
|
||||
}
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void CreateMedication(string name, int price)
|
||||
{
|
||||
@ -137,7 +135,6 @@ namespace VeterinaryShowDoctorApp.Controllers
|
||||
Response.Redirect("Index");
|
||||
}
|
||||
|
||||
|
||||
public IActionResult DeleteMedication()
|
||||
{
|
||||
if (APIDoctor.Doctor == null)
|
||||
@ -147,7 +144,6 @@ namespace VeterinaryShowDoctorApp.Controllers
|
||||
ViewBag.Medications = APIDoctor.GetRequest<List<MedicationViewModel>>($"api/medication/getmedications?doctorid={APIDoctor.Doctor.Id}");
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void DeleteMedication(int medication)
|
||||
{
|
||||
@ -161,7 +157,6 @@ namespace VeterinaryShowDoctorApp.Controllers
|
||||
});
|
||||
Response.Redirect("Index");
|
||||
}
|
||||
|
||||
public IActionResult UpdateMedication()
|
||||
{
|
||||
if (APIDoctor.Doctor == null)
|
||||
@ -171,7 +166,6 @@ namespace VeterinaryShowDoctorApp.Controllers
|
||||
ViewBag.Medications = APIDoctor.GetRequest<List<MedicationViewModel>>($"api/medication/getmedications?doctorid={APIDoctor.Doctor.Id}");
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void UpdateMedication(int medication, string name, int price)
|
||||
{
|
||||
@ -192,8 +186,7 @@ namespace VeterinaryShowDoctorApp.Controllers
|
||||
});
|
||||
Response.Redirect("Index");
|
||||
}
|
||||
|
||||
|
||||
// drugs
|
||||
public IActionResult Drugs()
|
||||
{
|
||||
if (APIDoctor.Doctor == null)
|
||||
@ -204,7 +197,6 @@ namespace VeterinaryShowDoctorApp.Controllers
|
||||
|
||||
}
|
||||
|
||||
|
||||
public IActionResult CreateDrug()
|
||||
{
|
||||
if (APIDoctor.Doctor == null)
|
||||
@ -216,8 +208,6 @@ namespace VeterinaryShowDoctorApp.Controllers
|
||||
return View();
|
||||
}
|
||||
|
||||
|
||||
|
||||
[HttpPost]
|
||||
public void CreateDrug(string name, List<int> medications, int count)
|
||||
{
|
||||
@ -332,8 +322,123 @@ namespace VeterinaryShowDoctorApp.Controllers
|
||||
|
||||
return result;
|
||||
}
|
||||
// services
|
||||
public IActionResult Services()
|
||||
{
|
||||
if (APIDoctor.Doctor == null)
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
return View(APIDoctor.GetRequest<List<DrugViewModel>>($"api/service/getservices?doctorid={APIDoctor.Doctor.Id}"));
|
||||
|
||||
|
||||
}
|
||||
public IActionResult CreateService()
|
||||
{
|
||||
if (APIDoctor.Doctor == null)
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
ViewBag.Medications = APIDoctor.GetRequest<List<MedicationViewModel>>($"api/medication/getmedications");
|
||||
|
||||
return View();
|
||||
}
|
||||
[HttpPost]
|
||||
public void CreateService(string name, List<int> medications, int visit)
|
||||
{
|
||||
if (APIDoctor.Doctor == null)
|
||||
{
|
||||
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
|
||||
}
|
||||
if (string.IsNullOrEmpty(name))
|
||||
{
|
||||
throw new Exception("Ошибка в введенных данных");
|
||||
}
|
||||
Dictionary<int, IMedicationModel> a = new Dictionary<int, IMedicationModel>();
|
||||
foreach (int medication in medications)
|
||||
{
|
||||
a.Add(medication, new MedicationSearchModel { Id = medication } as IMedicationModel);
|
||||
}
|
||||
|
||||
APIDoctor.PostRequest("api/service/createservice", new ServiceBindingModel
|
||||
{
|
||||
ServiceName = name,
|
||||
ServiceMedications = a,
|
||||
VisitId = visit
|
||||
});
|
||||
Response.Redirect("Index");
|
||||
}
|
||||
public IActionResult DeleteService()
|
||||
{
|
||||
if (APIDoctor.Doctor == null)
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
ViewBag.Services = APIDoctor.GetRequest<List<ServiceViewModel>>($"api/service/getservices?doctorid={APIDoctor.Doctor.Id}");
|
||||
return View();
|
||||
}
|
||||
[HttpPost]
|
||||
public void DeleteService(int service)
|
||||
{
|
||||
if (APIDoctor.Doctor == null)
|
||||
{
|
||||
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
|
||||
}
|
||||
APIDoctor.PostRequest("api/service/deleteservice", new ServiceBindingModel
|
||||
{
|
||||
Id = service
|
||||
});
|
||||
Response.Redirect("Index");
|
||||
}
|
||||
public IActionResult UpdateService()
|
||||
{
|
||||
if (APIDoctor.Doctor == null)
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
ViewBag.Services = APIDoctor.GetRequest<List<ServiceViewModel>>($"api/drug/getservices?doctorid={APIDoctor.Doctor.Id}");
|
||||
ViewBag.Medications = APIDoctor.GetRequest<List<MedicationViewModel>>($"api/medication/getmedications");
|
||||
return View();
|
||||
}
|
||||
// возможно нужно прописать визит айди
|
||||
[HttpPost]
|
||||
public void UpdateService(int service, string name, List<int> medications)
|
||||
{
|
||||
if (APIDoctor.Doctor == null)
|
||||
{
|
||||
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
|
||||
}
|
||||
if (string.IsNullOrEmpty(name))
|
||||
{
|
||||
throw new Exception("Ошибка в введенных данных");
|
||||
}
|
||||
Dictionary<int, IMedicationModel> a = new Dictionary<int, IMedicationModel>();
|
||||
foreach (int medication in medications)
|
||||
{
|
||||
a.Add(medication, new MedicationSearchModel { Id = medication } as IMedicationModel);
|
||||
}
|
||||
APIDoctor.PostRequest("api/drug/updateservice", new ServiceBindingModel
|
||||
{
|
||||
Id = service,
|
||||
ServiceName = name,
|
||||
ServiceMedications = a
|
||||
});
|
||||
Response.Redirect("Index");
|
||||
}
|
||||
[HttpGet]
|
||||
public Tuple<ServiceViewModel, List<string>>? GetService(int serviceId)
|
||||
{
|
||||
if (APIDoctor.Doctor == null)
|
||||
{
|
||||
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
|
||||
}
|
||||
var result = APIDoctor.GetRequest<Tuple<ServiceViewModel, List<string>>>($"api/service/getservice?serviceid={serviceId}");
|
||||
if (result == null)
|
||||
{
|
||||
return default;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
||||
public IActionResult Error()
|
||||
|
@ -0,0 +1,57 @@
|
||||
@{
|
||||
ViewData["Title"] = "CreateService";
|
||||
}
|
||||
|
||||
<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">
|
||||
<input type="text" name="name" id="name" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-4">Визиты:</div>
|
||||
<div class="col-8">
|
||||
<select id="visit" name="visit" class="form-control" asp-items="@(new SelectList(@ViewBag.Visits,"Id", "VisitName"))"></select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-4">Медикаменты:</div>
|
||||
<div class="col-8">
|
||||
<select name="medications" class="form-control" multiple size="6" id="medications">
|
||||
@foreach (var medication in ViewBag.Medications)
|
||||
{
|
||||
<option value="@medication.Id">@medication.MedicationName</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>
|
||||
<script>
|
||||
$('#visit').on('change', function () {
|
||||
check();
|
||||
});
|
||||
|
||||
function check() {
|
||||
var visit = $('#visit').val();
|
||||
if (visit) {
|
||||
$.ajax({
|
||||
method: "POST",
|
||||
url: "/Home/GetService",
|
||||
data: {visit: visit },
|
||||
success: function (result) {
|
||||
$("#sum").val(result);
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
</script>
|
@ -15,4 +15,4 @@
|
||||
<div class="col-4"></div>
|
||||
<div class="col-8"><input type="submit" value="Удалить" class="btn btn-danger" /></div>
|
||||
</div>
|
||||
</form>s
|
||||
</form>
|
||||
|
@ -0,0 +1,18 @@
|
||||
@{
|
||||
ViewData["Title"] = "DeleteService";
|
||||
}
|
||||
<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="service" name="service" class="form-control" asp-items="@(new SelectList(@ViewBag.Services, "Id", "ServiceName"))"></select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-4"></div>
|
||||
<div class="col-8"><input type="submit" value="Удалить" class="btn btn-danger" /></div>
|
||||
</div>
|
||||
</form>
|
@ -0,0 +1,47 @@
|
||||
@using VeterinaryContracts.ViewModels
|
||||
@model List<ServiceViewModel>
|
||||
@{
|
||||
ViewData["Title"] = "Services";
|
||||
}
|
||||
<div class="text-center">
|
||||
<h1 class="display-4">Услуги</h1>
|
||||
</div>
|
||||
<div class="text-center">
|
||||
@{
|
||||
if (Model == null)
|
||||
{
|
||||
<h3 class="display-4">Авторизируйтесь</h3>
|
||||
return;
|
||||
}
|
||||
<p>
|
||||
<a asp-action="CreateService">Создать услугу</a>
|
||||
<a asp-action="UpdateService">Обновить услугу</a>
|
||||
<a asp-action="DeleteService">Удалить услугу</a>
|
||||
</p>
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>
|
||||
Номер
|
||||
</th>
|
||||
<th>
|
||||
Название
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (var item in Model)
|
||||
{
|
||||
<tr>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem =>item.Id)
|
||||
</td>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem =>item.ServiceName)
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
}
|
||||
</div>
|
@ -0,0 +1,66 @@
|
||||
@using VeterinaryContracts.ViewModels;
|
||||
|
||||
@{
|
||||
ViewData["Title"] = "UpdateService";
|
||||
}
|
||||
|
||||
<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="service" name="service" class="form-control" asp-items="@(new SelectList(@ViewBag.Services, "Id", "ServiceName"))"></select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-4">Название:</div>
|
||||
<div class="col-8"><input type="text" name="name" id="name" class="form-control" /></div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-4">Медикаменты:</div>
|
||||
<div class="col-8">
|
||||
<select name="medications" class="form-control" multiple size="5" id="medications">
|
||||
@foreach (var medication in ViewBag.Medications)
|
||||
{
|
||||
<option value="@medication.Id" id="@medication.MedicationName">@medication.MedicationName</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 service = $('#service').val();
|
||||
$("#medications option:selected").removeAttr("selected");
|
||||
if (service) {
|
||||
$.ajax({
|
||||
method: "GET",
|
||||
url: "/Home/GetService",
|
||||
data: { serviceId: service },
|
||||
success: function (result) {
|
||||
console.log(result.item2);
|
||||
$('#name').val(result.item1.serviceName);
|
||||
$.map(result.item2, function (n) {
|
||||
console.log("#" + n);
|
||||
$("#" + n).attr("selected", "selected")
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
};
|
||||
}
|
||||
check();
|
||||
$('#service').on('change', function () {
|
||||
check();
|
||||
});
|
||||
</script>
|
||||
}
|
Loading…
Reference in New Issue
Block a user