Compare commits
No commits in common. "2f2f6aa4bcc8c212e129afb06d1a569c6019825a" and "f09946ecd5416dea4a76f49dbc0aa0892734e5ef" have entirely different histories.
2f2f6aa4bc
...
f09946ecd5
@ -376,7 +376,7 @@ View(APIPharmacist.GetRequest<List<ServiceViewModel>>($"api/service/getservices?
|
||||
Dictionary<int, IMedicineModel> a = new Dictionary<int, IMedicineModel>();
|
||||
foreach (int medicine in medicines)
|
||||
{
|
||||
a.Add(medicine, new MedicineSearchModel { Id = medicine } as IMedicineModel);
|
||||
a.Add(medicine, new AnimalSearchModel { Id = medicine } as IMedicineModel);
|
||||
}
|
||||
|
||||
APIPharmacist.PostRequest("api/service/createservice", new ServiceBindingModel
|
||||
@ -490,7 +490,7 @@ View(APIPharmacist.GetRequest<List<ServiceViewModel>>($"api/service/getservices?
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
var res = APIPharmacist.GetRequest<List<GuidanceViewModel>>($"api/guidance/getguidances?pharmacistid={APIPharmacist.Pharmacist.Id}");
|
||||
var res = APIPharmacist.GetRequest<List<GuidanceViewModel>>($"api/guidance/getguidances");
|
||||
return
|
||||
View(res);
|
||||
|
||||
@ -499,7 +499,7 @@ View(res);
|
||||
[HttpGet]
|
||||
public IActionResult CreateGuidance()
|
||||
{
|
||||
ViewBag.Services = APIPharmacist.GetRequest<List<ServiceViewModel>>($"api/service/getservices?pharmacistid={APIPharmacist.Pharmacist.Id}");
|
||||
ViewBag.Services = APIPharmacist.GetRequest<List<ServiceViewModel>>("api/service/getservices");
|
||||
return View();
|
||||
}
|
||||
[HttpPost]
|
||||
@ -524,8 +524,8 @@ View(res);
|
||||
[HttpGet]
|
||||
public IActionResult UpdateGuidance()
|
||||
{
|
||||
ViewBag.Services = APIPharmacist.GetRequest<List<ServiceViewModel>>($"api/service/getservices?pharmacistid={APIPharmacist.Pharmacist.Id}");
|
||||
ViewBag.Guidances = APIPharmacist.GetRequest<List<GuidanceViewModel>>($"api/guidance/getguidances?pharmacistid={APIPharmacist.Pharmacist.Id}");
|
||||
ViewBag.Services = APIPharmacist.GetRequest<List<ServiceViewModel>>("api/service/getservices");
|
||||
ViewBag.Guidances = APIPharmacist.GetRequest<List<GuidanceViewModel>>($"api/guidance/getguidances");
|
||||
return View();
|
||||
}
|
||||
[HttpPost]
|
||||
@ -552,7 +552,7 @@ View(res);
|
||||
[HttpGet]
|
||||
public IActionResult DeleteGuidance()
|
||||
{
|
||||
ViewBag.Guidances = APIPharmacist.GetRequest<List<GuidanceViewModel>>($"api/guidance/getguidances?pharmacistid={APIPharmacist.Pharmacist.Id}");
|
||||
ViewBag.Guidances = APIPharmacist.GetRequest<List<GuidanceViewModel>>($"api/guidance/getguidances");
|
||||
return View();
|
||||
}
|
||||
|
||||
|
@ -22,7 +22,7 @@
|
||||
<select name="animals" class="form-control" multiple size="5" id="animals">
|
||||
@foreach (var animal in ViewBag.Animals)
|
||||
{
|
||||
<option value="@animal.Id" data-name="@animal.AnimalName">@animal.AnimalName</option>
|
||||
<option value="@animal.Id" id="@animal.AnimalName">@animal.AnimalName</option>
|
||||
}
|
||||
</select>
|
||||
</div>
|
||||
@ -50,7 +50,7 @@
|
||||
$('#price').val(result.item1.price);
|
||||
$.map(result.item2, function (n) {
|
||||
console.log("#" + n);
|
||||
$(`option[data-name=${n}]`).attr("selected", "selected")
|
||||
$("#" + n).attr("selected", "selected")
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -52,7 +52,7 @@ btn-primary" />
|
||||
success: function (result) {
|
||||
console.log(result.item2);
|
||||
$('#text').val(result.text);
|
||||
$(`option[data-name=${result.serviceId}]`).attr("selected", "selected")
|
||||
$("#" + result.serviceId).attr("selected", "selected")
|
||||
}
|
||||
|
||||
});
|
||||
|
@ -28,7 +28,7 @@
|
||||
<select name="medicines" class="form-control" multiple size="5" id="medicines">
|
||||
@foreach (var medicine in ViewBag.Medicines)
|
||||
{
|
||||
<option value="@medicine.Id" data-name="@medicine.MedicineName">@medicine.MedicineName</option>
|
||||
<option value="@medicine.Id" id="@medicine.MedicineName">@medicine.MedicineName</option>
|
||||
}
|
||||
</select>
|
||||
</div>
|
||||
@ -56,7 +56,7 @@
|
||||
$('#price').val(result.item1.price);
|
||||
$.map(result.item2, function ( n ) {
|
||||
console.log("#" + n);
|
||||
$(`option[data-name=${n}]`).attr("selected", "selected")
|
||||
$("#" + n).attr("selected", "selected")
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -4,8 +4,6 @@ using System.Diagnostics;
|
||||
using VetClinicContracts.BindingModels;
|
||||
using VetClinicContracts.ViewModels;
|
||||
using VetClinicDataModels.Models;
|
||||
using System.Text;
|
||||
using VetClinicContracts.SearchModels;
|
||||
|
||||
|
||||
namespace VetClinicAdminApp.Controllers
|
||||
@ -26,7 +24,7 @@ namespace VetClinicAdminApp.Controllers
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
return
|
||||
View(APIAdmin.GetRequest<List<VisitViewModel>>($"api/visit/getvisits?adminId={APIAdmin.Admin.Id}"));
|
||||
View(APIAdmin.GetRequest<List<VisitViewModel>>($"api/visit/getvisits?vistId={APIAdmin.Admin.Id}"));
|
||||
|
||||
}
|
||||
public IActionResult IndexAnimals()
|
||||
@ -36,7 +34,7 @@ View(APIAdmin.GetRequest<List<VisitViewModel>>($"api/visit/getvisits?adminId={AP
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
return
|
||||
View(APIAdmin.GetRequest<List<AnimalViewModel>>($"api/animal/getanimallist?adminId={APIAdmin.Admin.Id}"));
|
||||
View(APIAdmin.GetRequest<List<AnimalViewModel>>($"api/animal/getanimallist?animalId={APIAdmin.Admin.Id}"));
|
||||
|
||||
}
|
||||
public IActionResult IndexVaccinations()
|
||||
@ -65,12 +63,12 @@ View(APIAdmin.GetRequest<List<VaccinationViewModel>>($"api/vaccination/getvaccin
|
||||
{
|
||||
if (APIAdmin.Admin == null)
|
||||
{
|
||||
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
|
||||
throw new Exception("Âû êàê ñóäà ïîïàëè? Ñóäà âõîä òîëüêî àâòîðèçîâàííûì");
|
||||
}
|
||||
if (string.IsNullOrEmpty(login) ||
|
||||
string.IsNullOrEmpty(password) || string.IsNullOrEmpty(fio))
|
||||
{
|
||||
throw new Exception("Введите email, пароль и ФИО");
|
||||
throw new Exception("Ââåäèòå email, ïàðîëü è ÔÈÎ");
|
||||
}
|
||||
APIAdmin.PostRequest("api/admin/updatedata", new
|
||||
AdminBindingModel
|
||||
@ -97,13 +95,13 @@ View(APIAdmin.GetRequest<List<VaccinationViewModel>>($"api/vaccination/getvaccin
|
||||
if (string.IsNullOrEmpty(login) ||
|
||||
string.IsNullOrEmpty(password))
|
||||
{
|
||||
throw new Exception("Введите email и пароль");
|
||||
throw new Exception("Ââåäèòå email è ïàðîëü");
|
||||
}
|
||||
APIAdmin.Admin =
|
||||
APIAdmin.GetRequest<AdminViewModel>($"api/admin/login?login={login}&password={password}");
|
||||
if (APIAdmin.Admin == null)
|
||||
{
|
||||
throw new Exception("Неверный логин/пароль");
|
||||
throw new Exception("Íåâåðíûé ëîãèí/ïàðîëü");
|
||||
}
|
||||
Response.Redirect("Index");
|
||||
}
|
||||
@ -118,7 +116,7 @@ View(APIAdmin.GetRequest<List<VaccinationViewModel>>($"api/vaccination/getvaccin
|
||||
if (string.IsNullOrEmpty(login) ||
|
||||
string.IsNullOrEmpty(password) || string.IsNullOrEmpty(fio))
|
||||
{
|
||||
throw new Exception("Введите логин, пароль и ФИО");
|
||||
throw new Exception("Ââåäèòå ëîãèí, ïàðîëü è ÔÈÎ");
|
||||
}
|
||||
APIAdmin.PostRequest("api/admin/register", new
|
||||
AdminBindingModel
|
||||
@ -158,11 +156,11 @@ View(APIAdmin.GetRequest<List<VaccinationViewModel>>($"api/vaccination/getvaccin
|
||||
{
|
||||
if (APIAdmin.Admin == null)
|
||||
{
|
||||
throw new Exception("Вы как сюда попали? Сюда вход только авторизованным");
|
||||
throw new Exception("Âû êàê ñþäà ïîïàëè? Ñþäà âõîä òîëüêî àâòîðèçîâàííûì");
|
||||
}
|
||||
if (string.IsNullOrEmpty(name))
|
||||
{
|
||||
throw new Exception("Ошибка в введенных данных");
|
||||
throw new Exception("Îøèáêà â ââåäåííûõ äàííûõ");
|
||||
}
|
||||
APIAdmin.PostRequest("api/visit/createvisit", new VisitBindingModel
|
||||
{
|
||||
@ -177,11 +175,11 @@ View(APIAdmin.GetRequest<List<VaccinationViewModel>>($"api/vaccination/getvaccin
|
||||
{
|
||||
if (APIAdmin.Admin == null)
|
||||
{
|
||||
throw new Exception("Вы как сюда попали? Сюда вход только авторизованным");
|
||||
throw new Exception("Âû êàê ñþäà ïîïàëè? Ñþäà âõîä òîëüêî àâòîðèçîâàííûì");
|
||||
}
|
||||
if (string.IsNullOrEmpty(animalname))
|
||||
{
|
||||
throw new Exception("Ошибка в введенных данных");
|
||||
throw new Exception("Îøèáêà â ââåäåííûõ äàííûõ");
|
||||
}
|
||||
APIAdmin.PostRequest("api/animal/createanimal", new AnimalBindingModel
|
||||
{
|
||||
@ -196,11 +194,11 @@ View(APIAdmin.GetRequest<List<VaccinationViewModel>>($"api/vaccination/getvaccin
|
||||
{
|
||||
if (APIAdmin.Admin == null)
|
||||
{
|
||||
throw new Exception("Вы как сюда попали? Сюда вход только авторизованным");
|
||||
throw new Exception("Âû êàê ñþäà ïîïàëè? Ñþäà âõîä òîëüêî àâòîðèçîâàííûì");
|
||||
}
|
||||
if (string.IsNullOrEmpty(name))
|
||||
{
|
||||
throw new Exception("Ошибка в введенных данных");
|
||||
throw new Exception("Îøèáêà â ââåäåííûõ äàííûõ");
|
||||
}
|
||||
if (cost <= 0)
|
||||
{
|
||||
@ -227,11 +225,11 @@ View(APIAdmin.GetRequest<List<VaccinationViewModel>>($"api/vaccination/getvaccin
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void Delete(int visit)
|
||||
public void DeleteVisit(int visit)
|
||||
{
|
||||
if (APIAdmin.Admin == null)
|
||||
{
|
||||
throw new Exception("Вы как сюда попали? Сюда вход только авторизованным");
|
||||
throw new Exception("Âû êàê ñþäà ïîïàëè? Ñþäà âõîä òîëüêî àâòîðèçîâàííûì");
|
||||
}
|
||||
APIAdmin.PostRequest("api/visit/deletevisit", new VisitBindingModel
|
||||
{
|
||||
@ -292,7 +290,7 @@ View(APIAdmin.GetRequest<List<VaccinationViewModel>>($"api/vaccination/getvaccin
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
ViewBag.Visits = APIAdmin.GetRequest<List<VisitViewModel>>("api/visit/getvisits");
|
||||
ViewBag.Medicines = APIAdmin.GetRequest<List<MedicineViewModel>>("api/visit/getvisits");
|
||||
return View();
|
||||
}
|
||||
|
||||
@ -301,11 +299,11 @@ View(APIAdmin.GetRequest<List<VaccinationViewModel>>($"api/vaccination/getvaccin
|
||||
{
|
||||
if (APIAdmin.Admin == null)
|
||||
{
|
||||
throw new Exception("Вы как сюда попали? Сюда вход только авторизованным");
|
||||
throw new Exception("Âû êàê ñþäà ïîïàëè? Ñþäà âõîä òîëüêî àâòîðèçîâàííûì");
|
||||
}
|
||||
if (string.IsNullOrEmpty(name))
|
||||
{
|
||||
throw new Exception("Ошибка в введенных данных");
|
||||
throw new Exception("Îøèáêà â ââåäåííûõ äàííûõ");
|
||||
}
|
||||
APIAdmin.PostRequest("api/visit/updatevisit", new VisitBindingModel
|
||||
{
|
||||
@ -332,7 +330,6 @@ View(APIAdmin.GetRequest<List<VaccinationViewModel>>($"api/vaccination/getvaccin
|
||||
{
|
||||
throw new Exception("Вы как сюда попали? Сюда вход только авторизованным");
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(name))
|
||||
{
|
||||
throw new Exception("Ошибка в введенных данных");
|
||||
@ -346,82 +343,6 @@ View(APIAdmin.GetRequest<List<VaccinationViewModel>>($"api/vaccination/getvaccin
|
||||
});
|
||||
Response.Redirect("IndexAnimals");
|
||||
}
|
||||
public IActionResult VisitAnimals()
|
||||
{
|
||||
if (APIAdmin.Admin == null)
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
ViewBag.Animals = APIAdmin.GetRequest<List<AnimalViewModel>>($"api/animal/getanimallist?adminid={APIAdmin.Admin.Id}");
|
||||
ViewBag.Visits = APIAdmin.GetRequest<List<VisitViewModel>>($"api/visit/getvisits");
|
||||
return View();
|
||||
}
|
||||
[HttpPost]
|
||||
public void VisitAnimals(int animal, string name, string family,
|
||||
List<int> visits)
|
||||
{
|
||||
if (APIAdmin.Admin == null)
|
||||
{
|
||||
throw new Exception("Вы как сюда попали? Сюда вход только авторизованным");
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(name) || string.IsNullOrEmpty(family))
|
||||
{
|
||||
throw new Exception("Ошибка в введенных данных");
|
||||
}
|
||||
Dictionary<int, IVisitModel> v = new Dictionary<int, IVisitModel>();
|
||||
foreach (int visit in visits)
|
||||
{
|
||||
v.Add(visit, new VisitSearchModel { Id = visit } as IVisitModel);
|
||||
}
|
||||
APIAdmin.PostRequest("api/animal/updateanimal?isconnection=true", new AnimalBindingModel
|
||||
{
|
||||
Id = animal,
|
||||
AnimalName = name,
|
||||
Family = family,
|
||||
AdminId = APIAdmin.Admin.Id,
|
||||
VisitAnimals = v
|
||||
});
|
||||
Response.Redirect("IndexAnimals");
|
||||
}
|
||||
public IActionResult ServiceVisits()
|
||||
{
|
||||
if (APIAdmin.Admin == null)
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
ViewBag.Visits = APIAdmin.GetRequest<List<VisitViewModel>>($"api/visit/getvisits?adminid={APIAdmin.Admin.Id}");
|
||||
ViewBag.Services = APIAdmin.GetRequest<List<ServiceViewModel>>($"api/service/getservices");
|
||||
return View();
|
||||
}
|
||||
[HttpPost]
|
||||
public void ServiceVisits(int visit, string name, DateTime date,
|
||||
List<int> services)
|
||||
{
|
||||
if (APIAdmin.Admin == null)
|
||||
{
|
||||
throw new Exception("Вы как сюда попали? Сюда вход только авторизованным");
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(name) || date == new DateTime())
|
||||
{
|
||||
throw new Exception("Ошибка в введенных данных");
|
||||
}
|
||||
Dictionary<int, IServiceModel> s = new Dictionary<int, IServiceModel>();
|
||||
foreach (int service in services)
|
||||
{
|
||||
s.Add(service, new ServiceSearchModel { Id = service } as IServiceModel);
|
||||
}
|
||||
APIAdmin.PostRequest("api/visit/updatevisit?isconnection=true", new VisitBindingModel
|
||||
{
|
||||
Id = visit,
|
||||
NameVisit = name,
|
||||
DateVisit = date,
|
||||
AdminId = APIAdmin.Admin.Id,
|
||||
ServiceVisits = s
|
||||
});
|
||||
Response.Redirect("Index");
|
||||
}
|
||||
public IActionResult UpdateVaccination()
|
||||
{
|
||||
if (APIAdmin.Admin == null)
|
||||
@ -462,49 +383,27 @@ View(APIAdmin.GetRequest<List<VaccinationViewModel>>($"api/vaccination/getvaccin
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public Tuple<VisitViewModel, List<string>>? GetVisit(int visitId)
|
||||
public Tuple<VisitViewModel, string>? GetVisit(int visitId)
|
||||
{
|
||||
if (APIAdmin.Admin == null)
|
||||
{
|
||||
throw new Exception("Вы как сюда попали? Сюда вход только авторизованным");
|
||||
throw new Exception("Âû êàê ñþäà ïîïàëè? Ñþäà âõîä òîëüêî àâòîðèçîâàííûì");
|
||||
}
|
||||
var result = APIAdmin.GetRequest<Tuple<VisitViewModel, List<string>>>($"api/visit/getvisit?visitid={visitId}");
|
||||
if (result == null)
|
||||
{
|
||||
return default;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
[HttpGet]
|
||||
public Tuple<AnimalViewModel, List<string>>? GetAnimal(int animalId)
|
||||
{
|
||||
if (APIAdmin.Admin == null)
|
||||
string table = "";
|
||||
result.Item1.VisitAnimals.Clear();
|
||||
for (int i = 0; i < result.Item2.Count; i++)
|
||||
{
|
||||
throw new Exception("Вы как сюда попали? Сюда вход только авторизованным");
|
||||
var animal = result.Item2[i];
|
||||
table += "<tr>";
|
||||
table += $"<td>{animal}</td>";
|
||||
table += "</tr>";
|
||||
}
|
||||
var result = APIAdmin.GetRequest<Tuple<AnimalViewModel, List<string>>>($"api/animal/getanimal?animalid={animalId}");
|
||||
if (result == null)
|
||||
{
|
||||
return default;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
[HttpGet]
|
||||
public Tuple<ServiceViewModel, List<string>>? GetService(int serviceId)
|
||||
{
|
||||
if (APIAdmin.Admin == null)
|
||||
{
|
||||
throw new Exception("Вы как сюда попали? Сюда вход только авторизованным");
|
||||
}
|
||||
var result = APIAdmin.GetRequest<Tuple<ServiceViewModel, List<string>>>($"api/service/getservice?serviceid={serviceId}");
|
||||
if (result == null)
|
||||
{
|
||||
return default;
|
||||
}
|
||||
|
||||
return result;
|
||||
return Tuple.Create(result.Item1, table);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -10,13 +10,13 @@
|
||||
<div class="row">
|
||||
<div class="col-4">Название:</div>
|
||||
<div class="col-8">
|
||||
<input type="text" name="name" />
|
||||
<input id="title" type="text" name="title" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-4">Дата:</div>
|
||||
<div class="col-8">
|
||||
<input type="datetime" id="datetime" name="date" />
|
||||
<input type="date" id="date" name="date"/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
|
@ -1,18 +0,0 @@
|
||||
@{
|
||||
ViewData["Title"] = "Delete";
|
||||
}
|
||||
<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="visit" name="visit" class="form-control" asp-items="@(new SelectList(@ViewBag.Visits, "Id", "NameVisit"))"></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>
|
@ -17,11 +17,7 @@
|
||||
<h3 class="display-4">Авторизируйтесь</h3>
|
||||
return;
|
||||
}
|
||||
<p>
|
||||
<a asp-action="Update">Редактировать визит</a>
|
||||
<a asp-action="Delete">Удалить визит</a>
|
||||
<a asp-action="ServiceVisits">Связать визит и услуги</a>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<a asp-action="Create">Создать визит</a>
|
||||
</p>
|
||||
|
@ -19,7 +19,6 @@
|
||||
}
|
||||
<p>
|
||||
<a asp-action="UpdateAnimal">Редактировать животное</a>
|
||||
<a asp-action="VisitAnimals">Связать животных и визиты </a>
|
||||
<a asp-action="DeleteAnimal">Удалить животное</a>
|
||||
</p>
|
||||
<p>
|
||||
|
@ -1,65 +0,0 @@
|
||||
@using VetClinicContracts.ViewModels;
|
||||
|
||||
@{
|
||||
ViewData["Title"] = "ServiceVisits";
|
||||
}
|
||||
|
||||
<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="visit" name="visit" class="form-control" asp-items="@(new SelectList(@ViewBag.Visits, "Id", "NameVisit"))"></select>
|
||||
</div>
|
||||
</div>
|
||||
<input style = "visibility: hidden" type="text" name="name" id="name" class="form-control" />
|
||||
<input style="visibility: hidden" type="datetime" id="datetime" name="date" class="form-control" />
|
||||
<div class="row">
|
||||
<div class="col-4">Услуги:</div>
|
||||
<div class="col-8">
|
||||
<select name="services" class="form-control" multiple size="5" id="services">
|
||||
@foreach (var service in ViewBag.Services)
|
||||
{
|
||||
<option value="@service.Id" id="@service.ServicesName">@service.ServicesName</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 animal = $('#visit').val();
|
||||
$("#services option:selected").removeAttr("selected");
|
||||
if (animal) {
|
||||
$.ajax({
|
||||
method: "GET",
|
||||
url: "/Home/GetVisit",
|
||||
data: { animalId: animal },
|
||||
success: function (result) {
|
||||
console.log(result.item2);
|
||||
$('#name').val(result.item1.visitName);
|
||||
$('#date').val(result.item1.date);
|
||||
$.map(result.item2, function (n) {
|
||||
console.log("#" + n);
|
||||
$("#" + n).attr("selected", "selected")
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
};
|
||||
}
|
||||
check();
|
||||
$('#visit').on('change', function () {
|
||||
check();
|
||||
});
|
||||
</script>
|
||||
}
|
@ -1,58 +0,0 @@
|
||||
@using VetClinicContracts.ViewModels;
|
||||
|
||||
@{
|
||||
ViewData["Title"] = "Update";
|
||||
}
|
||||
|
||||
<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="visit" name="visit" class="form-control" asp-items="@(new SelectList(@ViewBag.Visits, "Id", "NameVisit"))"></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">
|
||||
<input type="datetime" id="datetime" name="date" />
|
||||
</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 visit = $('#visit').val();
|
||||
if (visit) {
|
||||
$.ajax({
|
||||
method: "GET",
|
||||
url: "/Home/GetVisit",
|
||||
data: { visitId: visit },
|
||||
success: function (result) {
|
||||
$('#name').val(result.item1.vistName);
|
||||
$('#date').val(result.item1.date);
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
check();
|
||||
$('#visit').on('change', function () {
|
||||
check();
|
||||
});
|
||||
</script>
|
||||
}
|
@ -1,65 +0,0 @@
|
||||
@using VetClinicContracts.ViewModels;
|
||||
|
||||
@{
|
||||
ViewData["Title"] = "VisitAnimals";
|
||||
}
|
||||
|
||||
<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="animal" name="animal" class="form-control" asp-items="@(new SelectList(@ViewBag.Animals, "Id", "AnimalName"))"></select>
|
||||
</div>
|
||||
</div>
|
||||
<input style = "visibility: hidden" type="text" name="name" id="name" class="form-control" />
|
||||
<input style = "visibility: hidden" type="text" id="family" name="family" class="form-control" />
|
||||
<div class="row">
|
||||
<div class="col-4">Визиты:</div>
|
||||
<div class="col-8">
|
||||
<select name="visits" class="form-control" multiple size="5" id="visits">
|
||||
@foreach (var visit in ViewBag.Visits)
|
||||
{
|
||||
<option value="@visit.Id" id="@visit.NameVisit">@visit.NameVisit</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 animal = $('#animal').val();
|
||||
$("#visits option:selected").removeAttr("selected");
|
||||
if (animal) {
|
||||
$.ajax({
|
||||
method: "GET",
|
||||
url: "/Home/GetAnimal",
|
||||
data: { animalId: animal },
|
||||
success: function (result) {
|
||||
console.log(result.item2);
|
||||
$('#name').val(result.item1.animalName);
|
||||
$('#family').val(result.item1.family);
|
||||
$.map(result.item2, function (n) {
|
||||
console.log("#" + n);
|
||||
$("#" + n).attr("selected", "selected")
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
};
|
||||
}
|
||||
check();
|
||||
$('#animal').on('change', function () {
|
||||
check();
|
||||
});
|
||||
</script>
|
||||
}
|
@ -103,7 +103,7 @@ namespace VetClinicBusinessLogic.BusinessLogics
|
||||
throw new ArgumentNullException("Отсутствие пароля в учётной записи", nameof(model.Password));
|
||||
}
|
||||
|
||||
_logger.LogInformation("Admin. AdminFIO:{AdminFIO}. Email:{Email}. Password:{Password}. Id:{Id}",
|
||||
_logger.LogInformation("WorkPiece. AdminFIO:{AdminFIO}. Email:{Email}. Password:{Password}. Id:{Id}",
|
||||
model.AdminFIO, model.Email, model.Password, model.Id);
|
||||
var element = _adminStorage.GetElement(new AdminSearchModel
|
||||
{
|
||||
|
@ -46,7 +46,7 @@ namespace VetClinicBusinessLogic.BusinessLogics
|
||||
return element;
|
||||
}
|
||||
|
||||
public bool Create(AnimalBindingModel model)
|
||||
public bool CreateAnimal(AnimalBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
|
||||
@ -58,7 +58,7 @@ namespace VetClinicBusinessLogic.BusinessLogics
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Update(AnimalBindingModel model)
|
||||
public bool UpdateAnimal(AnimalBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_animalStorage.Update(model) == null)
|
||||
@ -69,7 +69,7 @@ namespace VetClinicBusinessLogic.BusinessLogics
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Delete(AnimalBindingModel model)
|
||||
public bool DeleteAnimal(AnimalBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
_logger.LogInformation("Delete. Id:{Id}", model.Id);
|
||||
@ -90,7 +90,7 @@ namespace VetClinicBusinessLogic.BusinessLogics
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.AnimalName))
|
||||
if (model.AnimalName == "")
|
||||
{
|
||||
throw new ArgumentNullException("Имя не должно быть пустым", nameof(model.AnimalName));
|
||||
}
|
||||
@ -98,17 +98,12 @@ namespace VetClinicBusinessLogic.BusinessLogics
|
||||
{
|
||||
throw new ArgumentNullException("Некорректный идентификатор у клиента", nameof(model.AdminId));
|
||||
}
|
||||
|
||||
|
||||
var element = _animalStorage.GetElement(new AnimalSearchModel
|
||||
{
|
||||
AnimalName = model.AnimalName
|
||||
|
||||
Id = model.Id
|
||||
});
|
||||
if (element != null && element.Id != model.Id)
|
||||
{
|
||||
throw new InvalidOperationException("Животное с таким названием уже есть");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -4,7 +4,6 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Linq;
|
||||
using VetClinicContracts.BindingModels;
|
||||
using VetClinicContracts.BusinessLogicsContracts;
|
||||
using VetClinicContracts.SearchModels;
|
||||
@ -108,16 +107,6 @@ namespace VetClinicBusinessLogic.BusinessLogics
|
||||
}
|
||||
|
||||
_logger.LogInformation("Vaccination. NameVaccination:{NameVaccination}. CostVaccination:{CostVaccination}", model.NameVaccination, model.CostVaccination);
|
||||
var element = _vaccinationStorage.GetElement(new VaccinationSearchModel
|
||||
{
|
||||
NameVaccination = model.NameVaccination,
|
||||
DateStamp = model.DateStamp,
|
||||
AnimalId = model.AnimalId,
|
||||
});
|
||||
if (element != null && element.Id != model.Id)
|
||||
{
|
||||
throw new InvalidOperationException("Прививка для этого услуги с таким текстом уже есть");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -101,12 +101,8 @@ true)
|
||||
throw new ArgumentNullException("Нет названия визита",
|
||||
nameof(model.NameVisit));
|
||||
}
|
||||
if (model.DateVisit != null)
|
||||
{
|
||||
throw new ArgumentNullException("Нет времени визита",
|
||||
nameof(model.DateVisit));
|
||||
}
|
||||
_logger.LogInformation("Visit. Visit:{NameVisit}. DateVisit:{ DateVisit } Id: { Id}", model.NameVisit, model.DateVisit, model.Id);
|
||||
|
||||
_logger.LogInformation("Medicine. Medicine:{NameVisit}. Id: { Id}", model.NameVisit, model.Id);
|
||||
var element = _visitStorage.GetElement(new VisitSearchModel
|
||||
{
|
||||
NameVisit = model.NameVisit
|
||||
|
@ -1,8 +1,6 @@
|
||||
using VetClinicDataModels.Models;
|
||||
|
||||
namespace VetClinicContracts.BindingModels
|
||||
namespace VetClinicContracts.BindingModels
|
||||
{
|
||||
public class AdminBindingModel : IAdminModel
|
||||
public class AdminBindingModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string AdminFIO { get; set; } = string.Empty;
|
||||
|
@ -12,7 +12,6 @@ namespace VetClinicContracts.BindingModels
|
||||
public int Id { get; set; }
|
||||
public int AdminId { get; set; }
|
||||
|
||||
public Dictionary<int, IVisitModel> VisitAnimals { get; set; } = new();
|
||||
public string AnimalName { get; set; } = string.Empty;
|
||||
|
||||
public string? Family { get; set; } = string.Empty;
|
||||
|
@ -7,10 +7,12 @@ using VetClinicDataModels.Models;
|
||||
|
||||
namespace VetClinicContracts.BindingModels
|
||||
{
|
||||
public class VisitBindingModel : IVisitModel
|
||||
public class VisitBindingModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public int AdminId { get; set; }
|
||||
public Dictionary<int, IAnimalModel> VisitAnimals { get; set; } = new();
|
||||
|
||||
public Dictionary<int, IServiceModel> ServiceVisits { get; set; } = new ();
|
||||
public string NameVisit { get; set; } = string.Empty;
|
||||
public DateTime DateVisit { get; set; }
|
||||
|
@ -13,8 +13,8 @@ namespace VetClinicContracts.BusinessLogicsContracts
|
||||
{
|
||||
List<AnimalViewModel>? ReadList(AnimalSearchModel? model);
|
||||
AnimalViewModel? ReadElement(AnimalSearchModel model);
|
||||
bool Create(AnimalBindingModel model);
|
||||
bool Update(AnimalBindingModel model);
|
||||
bool Delete(AnimalBindingModel model);
|
||||
bool CreateAnimal(AnimalBindingModel model);
|
||||
bool UpdateAnimal(AnimalBindingModel model);
|
||||
bool DeleteAnimal(AnimalBindingModel model);
|
||||
}
|
||||
}
|
||||
|
@ -10,7 +10,6 @@ namespace VetClinicContracts.SearchModels
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
public string? Text { get; set; }
|
||||
public int? PharmacistId { get; set; }
|
||||
public DateTime? DateFrom { get; set; }
|
||||
public DateTime? DateTo { get; set; }
|
||||
public int? ServiceId { get; set; }
|
||||
|
@ -12,7 +12,6 @@ namespace VetClinicContracts.SearchModels
|
||||
public string? NameVaccination { get; set; }
|
||||
public double? CostVaccination { get; set; }
|
||||
|
||||
public DateTime? DateStamp { get; set; }
|
||||
public DateTime? DateFrom { get; set; }
|
||||
public DateTime? DateTo { get; set; }
|
||||
|
||||
|
@ -19,7 +19,5 @@ namespace VetClinicContracts.ViewModels
|
||||
[DisplayName("Семейство")]
|
||||
|
||||
public string? Family { get; set; } = string.Empty;
|
||||
|
||||
public Dictionary<int, IVisitModel> VisitAnimals { get; set; } = new();
|
||||
}
|
||||
}
|
||||
|
@ -14,14 +14,21 @@ namespace VetClinicContracts.ViewModels
|
||||
public int Id { get; set; }
|
||||
|
||||
public int AdminId { get; set; }
|
||||
|
||||
[DisplayName("Животное")]
|
||||
public string AnimalName { get; set; } = string.Empty;
|
||||
|
||||
[DisplayName("Название визита")]
|
||||
public string NameVisit { get; set; } = string.Empty;
|
||||
|
||||
[DisplayName("Админ")]
|
||||
public string AdminFIO { get; set; } = string.Empty;
|
||||
|
||||
[DisplayName("Название услуг")]
|
||||
public string ServiceName { get; set; } = string.Empty;
|
||||
|
||||
[DisplayName("Дата визита")]
|
||||
public DateTime DateVisit { get; set; }
|
||||
|
||||
public Dictionary<int, IAnimalModel> VisitAnimals { get; set; } = new();
|
||||
|
||||
public Dictionary<int, IServiceModel> ServiceVisits { get; set; } = new();
|
||||
}
|
||||
|
@ -35,17 +35,23 @@ namespace VetClinicDataBaseImplement.Implements
|
||||
public AdminViewModel? GetElement(AdminSearchModel model)
|
||||
{
|
||||
using var context = new VetClinicDatabase();
|
||||
if (string.IsNullOrEmpty(model.AdminFIO) && string.IsNullOrEmpty(model.Email) &&
|
||||
!model.Id.HasValue)
|
||||
if (model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
return context.Admins
|
||||
.Include(x => x.Visits)
|
||||
.Include(x => x.Animals)
|
||||
.FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)
|
||||
?.GetViewModel;
|
||||
}
|
||||
|
||||
return context.Admins
|
||||
.FirstOrDefault(x => (string.IsNullOrEmpty(model.AdminFIO) || x.AdminFIO == model.AdminFIO) &&
|
||||
(!model.Id.HasValue || x.Id == model.Id) && (string.IsNullOrEmpty(model.Email) || x.Email == model.Email) &&
|
||||
(string.IsNullOrEmpty(model.Password) || x.Password == model.Password))
|
||||
?.GetViewModel;
|
||||
else if (!string.IsNullOrEmpty(model.Email) && !string.IsNullOrEmpty(model.Password))
|
||||
{
|
||||
return context.Admins
|
||||
.Include(x => x.Visits)
|
||||
.Include(x => x.Animals)
|
||||
.FirstOrDefault(x => (x.Email == model.Email && x.Password == model.Password))
|
||||
?.GetViewModel;
|
||||
}
|
||||
return new();
|
||||
}
|
||||
|
||||
public List<AdminViewModel> GetFilteredList(AdminSearchModel model)
|
||||
|
@ -16,21 +16,22 @@ namespace VetClinicBaseImplement.Implements
|
||||
|
||||
return context.Animals
|
||||
.Include(x => x.Admin)
|
||||
.Include(x => x.Visits)
|
||||
.ThenInclude(x => x.Visit)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
public List<AnimalViewModel> GetFilteredList(AnimalSearchModel model)
|
||||
{
|
||||
|
||||
if (string.IsNullOrEmpty(model.AnimalName))
|
||||
{
|
||||
return new();
|
||||
}
|
||||
using var context = new VetClinicDatabase();
|
||||
return context.Animals.Include(x => x.Admin).Include(x => x.Visits)
|
||||
.ThenInclude(x => x.Visit)
|
||||
.Where(x => (string.IsNullOrEmpty(model.AnimalName) || x.AnimalName.Contains(model.AnimalName))
|
||||
&& (!model.AdminId.HasValue || x.AdminId == model.AdminId))
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
return context.Animals
|
||||
.Include(x => x.Admin)
|
||||
.Where(x => x.AnimalName.Contains(model.AnimalName))
|
||||
.ToList()
|
||||
.Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
public AnimalViewModel? GetElement(AnimalSearchModel model)
|
||||
{
|
||||
@ -41,8 +42,6 @@ namespace VetClinicBaseImplement.Implements
|
||||
using var context = new VetClinicDatabase();
|
||||
return context.Animals
|
||||
.Include(x => x.Admin)
|
||||
.Include(x => x.Visits)
|
||||
.ThenInclude(x => x.Visit)
|
||||
.Include(x => x.Vaccinations)
|
||||
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.AnimalName) && x.AnimalName == model.AnimalName) || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
|
||||
}
|
||||
@ -55,7 +54,6 @@ namespace VetClinicBaseImplement.Implements
|
||||
return null;
|
||||
}
|
||||
context.Animals.Add(newAnimal);
|
||||
|
||||
context.SaveChanges();
|
||||
return newAnimal.GetViewModel;
|
||||
}
|
||||
@ -66,21 +64,13 @@ namespace VetClinicBaseImplement.Implements
|
||||
|
||||
try
|
||||
{
|
||||
var animal = context.Animals.Include(x => x.Admin)
|
||||
.Include(x => x.Visits)
|
||||
.ThenInclude(x => x.Visit).FirstOrDefault(rec =>
|
||||
rec.Id == model.Id);
|
||||
var animal = context.Animals.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
if (animal == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
animal.Update(model);
|
||||
context.SaveChanges();
|
||||
if (model.VisitAnimals != null)
|
||||
{
|
||||
animal.UpdateVisits(context, model);
|
||||
}
|
||||
|
||||
transaction.Commit();
|
||||
return animal.GetViewModel;
|
||||
}
|
||||
@ -95,7 +85,6 @@ namespace VetClinicBaseImplement.Implements
|
||||
using var context = new VetClinicDatabase();
|
||||
var element = context.Animals
|
||||
.Include(x => x.Vaccinations)
|
||||
.Include(x => x.Visits).ThenInclude(x => x.Visit)
|
||||
.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
|
||||
if (element != null)
|
||||
|
@ -25,7 +25,7 @@ namespace VetClinicDataBaseImplement.Implements
|
||||
using var context = new VetClinicDatabase();
|
||||
return context.Guidances.Include(x => x.Service).Where(x => (!model.Id.HasValue || model.Id == x.Id)
|
||||
&& (!model.ServiceId.HasValue || model.ServiceId == x.ServiceId) && (!model.DateFrom.HasValue || model.DateFrom <= x.Date)
|
||||
&& (!model.DateTo.HasValue || model.DateTo >= x.Date) && (!model.PharmacistId.HasValue || model.PharmacistId == x.Service.PharmacistId))
|
||||
&& (!model.DateTo.HasValue || model.DateTo >= x.Date))
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
@ -21,7 +21,8 @@ namespace VetClinicDataBaseImplement.Implements
|
||||
return context.Visits
|
||||
|
||||
.Include(x => x.Admin)
|
||||
|
||||
.Include(x => x.Animals)
|
||||
.ThenInclude(x => x.Animal)
|
||||
.Include(x => x.Services)
|
||||
.ThenInclude(x => x.Service)
|
||||
.Select(x => x.GetViewModel)
|
||||
@ -29,13 +30,22 @@ namespace VetClinicDataBaseImplement.Implements
|
||||
}
|
||||
public List<VisitViewModel> GetFilteredList(VisitSearchModel model)
|
||||
{
|
||||
|
||||
if (string.IsNullOrEmpty(model.NameVisit))
|
||||
{
|
||||
return new();
|
||||
}
|
||||
using var context = new VetClinicDatabase();
|
||||
return context.Visits.Include(x => x.Admin).Include(x => x.Services)
|
||||
return context.Visits
|
||||
.Include(x => x.Admin)
|
||||
.Include(x => x.Animals)
|
||||
.ThenInclude(x => x.Animal)
|
||||
.Where(x => x.NameVisit.Contains(model.NameVisit))
|
||||
.Include(x => x.Services)
|
||||
.ThenInclude(x => x.Service)
|
||||
.Where(x => (string.IsNullOrEmpty(model.NameVisit) || x.NameVisit.Contains(model.NameVisit))
|
||||
&& (!model.AdminId.HasValue || x.AdminId == model.AdminId))
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
.Where(x => x.NameVisit.Contains(model.NameVisit))
|
||||
.ToList()
|
||||
.Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
public VisitViewModel? GetElement(VisitSearchModel model)
|
||||
{
|
||||
@ -46,13 +56,11 @@ namespace VetClinicDataBaseImplement.Implements
|
||||
using var context = new VetClinicDatabase();
|
||||
return context.Visits
|
||||
.Include(x => x.Admin)
|
||||
.Include(x => x.Animals)
|
||||
.ThenInclude(x => x.Animal)
|
||||
.Include(x => x.Services)
|
||||
.ThenInclude(x => x.Service)
|
||||
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.NameVisit) &&
|
||||
x.NameVisit == model.NameVisit) ||
|
||||
(model.Id.HasValue && x.Id ==
|
||||
model.Id))
|
||||
?.GetViewModel;
|
||||
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.NameVisit) && x.NameVisit == model.NameVisit) || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
|
||||
}
|
||||
public VisitViewModel? Insert(VisitBindingModel model)
|
||||
{
|
||||
@ -80,8 +88,7 @@ namespace VetClinicDataBaseImplement.Implements
|
||||
}
|
||||
visit.Update(model);
|
||||
context.SaveChanges();
|
||||
if (model.ServiceVisits != null)
|
||||
visit.UpdateServices(context, model);
|
||||
visit.UpdateAnimals(context, model);
|
||||
transaction.Commit();
|
||||
return visit.GetViewModel;
|
||||
}
|
||||
@ -95,10 +102,11 @@ namespace VetClinicDataBaseImplement.Implements
|
||||
{
|
||||
using var context = new VetClinicDatabase();
|
||||
var element = context.Visits
|
||||
.Include(x => x.Admin)
|
||||
.Include(x => x.Animals).ThenInclude(x => x.Animal)
|
||||
.Include(x => x.Services).ThenInclude(x => x.Service)
|
||||
.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
|
||||
|
||||
|
||||
if (element != null)
|
||||
{
|
||||
|
||||
|
@ -37,22 +37,7 @@ namespace VetClinicDataBaseImplement.Models
|
||||
|
||||
[ForeignKey("AnimalId")]
|
||||
public virtual List<MedicineAnimal> Medicines { get; set; } = new();
|
||||
|
||||
public Dictionary<int, IVisitModel>? _visitAnimals = null;
|
||||
|
||||
[NotMapped]
|
||||
public Dictionary<int, IVisitModel> VisitAnimals
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_visitAnimals == null)
|
||||
{
|
||||
_visitAnimals = Visits.ToDictionary(recPC => recPC.VisitId, recPC =>
|
||||
recPC.Visit as IVisitModel);
|
||||
}
|
||||
return _visitAnimals;
|
||||
}
|
||||
}
|
||||
|
||||
public static Animal? Create(VetClinicDatabase context, AnimalBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
@ -65,10 +50,7 @@ namespace VetClinicDataBaseImplement.Models
|
||||
AdminId = model.AdminId,
|
||||
AnimalName = model.AnimalName,
|
||||
Family = model.Family,
|
||||
Visits = model.VisitAnimals.Select(x => new VisitAnimal
|
||||
{
|
||||
Visit = context.Visits.First(y => y.Id == x.Key)
|
||||
}).ToList()
|
||||
|
||||
};
|
||||
}
|
||||
public void Update(AnimalBindingModel? model)
|
||||
@ -83,37 +65,11 @@ namespace VetClinicDataBaseImplement.Models
|
||||
public AnimalViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
VisitAnimals = VisitAnimals,
|
||||
AdminId = AdminId,
|
||||
AnimalName = AnimalName,
|
||||
Family = Family
|
||||
|
||||
};
|
||||
public void UpdateVisits(VetClinicDatabase context, AnimalBindingModel model)
|
||||
{
|
||||
var visitAnimals = context.VisitAnimals.Where(rec => rec.AnimalId == model.Id).ToList();
|
||||
if (visitAnimals != null)
|
||||
{
|
||||
context.VisitAnimals.RemoveRange(visitAnimals.Where(rec => !model.VisitAnimals.ContainsKey(rec.VisitId)));
|
||||
context.SaveChanges();
|
||||
foreach (var visit in visitAnimals)
|
||||
{
|
||||
model.VisitAnimals.Remove(visit.VisitId);
|
||||
}
|
||||
context.SaveChanges();
|
||||
}
|
||||
var animal = context.Animals.First(x => x.Id == Id);
|
||||
foreach (var pc in model.VisitAnimals)
|
||||
{
|
||||
context.VisitAnimals.Add(new VisitAnimal
|
||||
{
|
||||
Animal = animal,
|
||||
Visit = context.Visits.First(x => x.Id == pc.Key),
|
||||
|
||||
});
|
||||
context.SaveChanges();
|
||||
}
|
||||
_visitAnimals = null;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -31,11 +31,23 @@ namespace VetClinicDataBaseImplement.Models
|
||||
[ForeignKey("VisitId")]
|
||||
public virtual List<VisitService> Services { get; set; } = new();
|
||||
public virtual Admin Admin { get; set; }
|
||||
|
||||
public Dictionary<int, IAnimalModel>? _visitAnimals = null;
|
||||
|
||||
public Dictionary<int, IServiceModel>? _serviceVisits = null;
|
||||
|
||||
|
||||
[NotMapped]
|
||||
public Dictionary<int, IAnimalModel> VisitAnimals
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_visitAnimals == null)
|
||||
{
|
||||
_visitAnimals = Animals.ToDictionary(recPC => recPC.AnimalId, recPC =>
|
||||
recPC.Animal as IAnimalModel);
|
||||
}
|
||||
return _visitAnimals;
|
||||
}
|
||||
}
|
||||
[NotMapped]
|
||||
public Dictionary<int, IServiceModel> ServiceVisits
|
||||
{
|
||||
@ -62,6 +74,10 @@ namespace VetClinicDataBaseImplement.Models
|
||||
|
||||
NameVisit = model.NameVisit,
|
||||
DateVisit = model.DateVisit,
|
||||
Animals = model.VisitAnimals.Select(x => new VisitAnimal
|
||||
{
|
||||
Animal = context.Animals.First(y => y.Id == x.Key)
|
||||
}).ToList(),
|
||||
Services = model.ServiceVisits.Select(x => new VisitService
|
||||
{
|
||||
Service = context.Services.First(y => y.Id == x.Key)
|
||||
@ -80,26 +96,43 @@ namespace VetClinicDataBaseImplement.Models
|
||||
public VisitViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
|
||||
VisitAnimals = VisitAnimals,
|
||||
AdminId = AdminId,
|
||||
NameVisit = NameVisit,
|
||||
DateVisit = DateVisit,
|
||||
ServiceVisits = ServiceVisits
|
||||
|
||||
};
|
||||
public void UpdateAnimals(VetClinicDatabase context, VisitBindingModel model)
|
||||
{
|
||||
var visitAnimals = context.VisitAnimals.Where(rec => rec.VisitId == model.Id).ToList();
|
||||
if (visitAnimals != null)
|
||||
{ // удалили те, которых нет в модели
|
||||
context.VisitAnimals.RemoveRange(visitAnimals.Where(rec => !model.VisitAnimals.ContainsKey(rec.AnimalId)));
|
||||
context.SaveChanges();
|
||||
|
||||
public void UpdateServices(VetClinicDatabase context, VisitBindingModel model)
|
||||
}
|
||||
var visit = context.Visits.First(x => x.Id == Id);
|
||||
foreach (var pc in model.VisitAnimals)
|
||||
{
|
||||
context.VisitAnimals.Add(new VisitAnimal
|
||||
{
|
||||
Visit = visit,
|
||||
Animal = context.Animals.First(x => x.Id == pc.Key),
|
||||
|
||||
});
|
||||
context.SaveChanges();
|
||||
}
|
||||
_visitAnimals = null;
|
||||
}
|
||||
public void UpdateService(VetClinicDatabase context, VisitBindingModel model)
|
||||
{
|
||||
var serviceVisits = context.ServiceVisits.Where(rec => rec.VisitId == model.Id).ToList();
|
||||
if (serviceVisits != null)
|
||||
{ // удалили те, которых нет в модели
|
||||
context.ServiceVisits.RemoveRange(serviceVisits.Where(rec => !model.ServiceVisits.ContainsKey(rec.ServiceId)));
|
||||
context.SaveChanges();
|
||||
foreach (var service in serviceVisits)
|
||||
{
|
||||
model.ServiceVisits.Remove(service.ServiceId);
|
||||
}
|
||||
context.SaveChanges();
|
||||
|
||||
}
|
||||
var visit = context.Visits.First(x => x.Id == Id);
|
||||
foreach (var pc in model.ServiceVisits)
|
||||
|
@ -11,7 +11,5 @@ namespace VetClinicDataModels.Models
|
||||
int AdminId { get; }
|
||||
string AnimalName { get; }
|
||||
string? Family { get; }
|
||||
|
||||
Dictionary<int, IVisitModel> VisitAnimals { get; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ namespace VetClinicDataModels.Models
|
||||
{
|
||||
public interface IVaccinationModel : IId
|
||||
{
|
||||
int Id { get; }
|
||||
int AnimalId { get; }
|
||||
string NameVaccination { get; }
|
||||
double CostVaccination { get; }
|
||||
|
@ -8,9 +8,12 @@ namespace VetClinicDataModels.Models
|
||||
{
|
||||
public interface IVisitModel : IId
|
||||
{
|
||||
int Id { get;}
|
||||
int AdminId { get; }
|
||||
string NameVisit { get;}
|
||||
DateTime DateVisit { get; }
|
||||
Dictionary<int,IAnimalModel> VisitAnimals { get; }
|
||||
|
||||
Dictionary<int, IServiceModel> ServiceVisits { get; }
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,6 @@ using VetClinicContracts.BindingModels;
|
||||
using VetClinicContracts.BusinessLogicsContracts;
|
||||
using VetClinicContracts.SearchModels;
|
||||
using VetClinicContracts.ViewModels;
|
||||
using VetClinicDataBaseImplement.Models;
|
||||
|
||||
namespace VetClinicRestApi.Controllers
|
||||
{
|
||||
@ -21,16 +20,14 @@ namespace VetClinicRestApi.Controllers
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public Tuple<AnimalViewModel, List<string>>? GetAnimal(int animalId)
|
||||
public AnimalViewModel? GetAnimal(int animalId)
|
||||
{
|
||||
try
|
||||
{
|
||||
var elem = _animal.ReadElement(new AnimalSearchModel { Id = animalId });
|
||||
if (elem == null)
|
||||
return null;
|
||||
var res = Tuple.Create(elem, elem.VisitAnimals.Select(x => x.Value.NameVisit).ToList());
|
||||
res.Item1.VisitAnimals = null!;
|
||||
return res;
|
||||
return _animal.ReadElement(new AnimalSearchModel
|
||||
{
|
||||
Id = animalId
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@ -40,18 +37,11 @@ namespace VetClinicRestApi.Controllers
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public List<AnimalViewModel>? GetAnimalList(int? adminId = null)
|
||||
public List<AnimalViewModel>? GetAnimalList()
|
||||
{
|
||||
try
|
||||
try
|
||||
{
|
||||
List<AnimalViewModel> res;
|
||||
if (!adminId.HasValue)
|
||||
res = _animal.ReadList(null);
|
||||
else
|
||||
res = _animal.ReadList(new AnimalSearchModel { AdminId = adminId });
|
||||
foreach (var animal in res)
|
||||
animal.VisitAnimals = null!;
|
||||
return res;
|
||||
return _animal.ReadList(null);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@ -64,7 +54,7 @@ namespace VetClinicRestApi.Controllers
|
||||
{
|
||||
try
|
||||
{
|
||||
return _animal.Create(model);
|
||||
return _animal.CreateAnimal(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@ -74,13 +64,11 @@ namespace VetClinicRestApi.Controllers
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public bool UpdateAnimal(bool isConnection,AnimalBindingModel model)
|
||||
public bool UpdateAnimal(AnimalBindingModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!isConnection)
|
||||
model.VisitAnimals = null!;
|
||||
return _animal.Update(model);
|
||||
return _animal.UpdateAnimal(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@ -94,7 +82,7 @@ namespace VetClinicRestApi.Controllers
|
||||
{
|
||||
try
|
||||
{
|
||||
return _animal.Delete(model);
|
||||
return _animal.DeleteAnimal(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
@ -27,6 +27,8 @@ namespace VetClinicRestApi.Controllers
|
||||
try
|
||||
{
|
||||
var elem = _guidance.ReadElement(new GuidanceSearchModel { Id = guidanceId });
|
||||
if (elem == null)
|
||||
return null;
|
||||
return elem;
|
||||
}
|
||||
catch (Exception ex)
|
||||
@ -36,20 +38,20 @@ namespace VetClinicRestApi.Controllers
|
||||
}
|
||||
}
|
||||
[HttpGet]
|
||||
public List<GuidanceViewModel>? GetGuidances(int? pharmacistId = null)
|
||||
public List<GuidanceViewModel>? GetGuidances(int? serviceId = null)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!pharmacistId.HasValue)
|
||||
if (!serviceId.HasValue)
|
||||
return _guidance.ReadList(null);
|
||||
return _guidance.ReadList(new GuidanceSearchModel
|
||||
{
|
||||
PharmacistId = pharmacistId
|
||||
ServiceId = serviceId
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка получения списка рекомендааций пользователя id ={ Id}", pharmacistId);
|
||||
_logger.LogError(ex, "Ошибка получения списка рекомендааций услуги id ={ Id}", serviceId);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
@ -49,7 +49,7 @@ namespace VetClinicRestApi.Controllers
|
||||
else
|
||||
res = _medicine.ReadList(new MedicineSearchModel { PharmacistId = pharmacistId });
|
||||
foreach (var medicine in res)
|
||||
medicine.MedicineAnimals = null!;
|
||||
medicine.MedicineAnimals = null;
|
||||
return res;
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
@ -23,12 +23,10 @@ namespace VetClinicRestApi.Controllers
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public List<VaccinationViewModel>? GetVaccinations(int? animalId)
|
||||
public List<VaccinationViewModel>? GetVaccinations(int animalId)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!animalId.HasValue)
|
||||
return _vaccination.ReadList(null);
|
||||
return _vaccination.ReadList(new VaccinationSearchModel
|
||||
{
|
||||
AnimalId = animalId
|
||||
|
@ -4,7 +4,6 @@ using VetClinicContracts.BindingModels;
|
||||
using VetClinicContracts.BusinessLogicsContracts;
|
||||
using VetClinicContracts.SearchModels;
|
||||
using VetClinicContracts.ViewModels;
|
||||
using VetClinicDataBaseImplement.Models;
|
||||
|
||||
namespace VetClinicRestApi.Controllers
|
||||
{
|
||||
@ -28,9 +27,7 @@ namespace VetClinicRestApi.Controllers
|
||||
var elem = _visit.ReadElement(new VisitSearchModel { Id = VisitId });
|
||||
if (elem == null)
|
||||
return null;
|
||||
var res = Tuple.Create(elem, elem.ServiceVisits.Select(x => x.Value.ServiceName).ToList());
|
||||
res.Item1.ServiceVisits = null;
|
||||
return res;
|
||||
return Tuple.Create(elem, elem.VisitAnimals.Select(x => x.Value.AnimalName).ToList());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@ -39,22 +36,15 @@ namespace VetClinicRestApi.Controllers
|
||||
}
|
||||
}
|
||||
[HttpGet]
|
||||
public List<VisitViewModel> GetVisits(int? adminId = null)
|
||||
public List<VisitViewModel> GetVisits(int adminId)
|
||||
{
|
||||
try
|
||||
{
|
||||
List<VisitViewModel> res;
|
||||
if (!adminId.HasValue)
|
||||
res = _visit.ReadList(null);
|
||||
else
|
||||
res = _visit.ReadList(new VisitSearchModel { AdminId = adminId });
|
||||
foreach (var visit in res)
|
||||
visit.ServiceVisits = null!;
|
||||
return res;
|
||||
return _visit.ReadList(new VisitSearchModel { AdminId = adminId});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка получения списка визитов");
|
||||
_logger.LogError(ex, "Ошибка получения списка визитовв");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
@ -73,12 +63,11 @@ namespace VetClinicRestApi.Controllers
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public bool UpdateVisit(bool isConnection,VisitBindingModel model)
|
||||
public bool UpdateVisit(VisitBindingModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!isConnection)
|
||||
model.ServiceVisits = null!;
|
||||
model.VisitAnimals = null!;
|
||||
return _visit.Update(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
Loading…
Reference in New Issue
Block a user