2024-05-29 23:12:32 +04:00
|
|
|
|
using DocumentFormat.OpenXml.Office2010.Excel;
|
|
|
|
|
using Microsoft.AspNetCore.Http;
|
2024-05-01 23:10:05 +04:00
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using System.Diagnostics;
|
2024-05-29 14:44:16 +04:00
|
|
|
|
using VeterinaryClinicBusinessLogics.BusinessLogics;
|
|
|
|
|
using VeterinaryClinicContracts.BindingModels;
|
|
|
|
|
using VeterinaryClinicContracts.BusinessLogicsContracts;
|
|
|
|
|
using VeterinaryClinicContracts.SearchModels;
|
2024-05-29 23:12:32 +04:00
|
|
|
|
using VeterinaryClinicDatabaseImplement.Models;
|
2024-05-29 14:44:16 +04:00
|
|
|
|
using VeterinaryClinicDataModels.Models;
|
2024-05-01 23:10:05 +04:00
|
|
|
|
using VeterinaryClinicWebApp.Models;
|
|
|
|
|
|
|
|
|
|
namespace VeterinaryClinicWebApp.Controllers
|
|
|
|
|
{
|
|
|
|
|
public class VisitController : Controller
|
|
|
|
|
{
|
|
|
|
|
private readonly ILogger<VisitController> _logger;
|
2024-05-29 14:44:16 +04:00
|
|
|
|
|
|
|
|
|
private readonly IVisitLogic _visitLogic;
|
|
|
|
|
|
|
|
|
|
private readonly IAnimalLogic _animalLogic;
|
|
|
|
|
|
|
|
|
|
private readonly IServiceLogic _serviceLogic;
|
|
|
|
|
public VisitController(ILogger<VisitController> logger, IVisitLogic visitLogic, IAnimalLogic animalLogic, IServiceLogic serviceLogic)
|
2024-05-01 23:10:05 +04:00
|
|
|
|
{
|
|
|
|
|
_logger = logger;
|
2024-05-29 14:44:16 +04:00
|
|
|
|
_visitLogic = visitLogic;
|
|
|
|
|
_animalLogic = animalLogic;
|
|
|
|
|
_serviceLogic = serviceLogic;
|
2024-05-01 23:10:05 +04:00
|
|
|
|
}
|
|
|
|
|
|
2024-05-29 14:44:16 +04:00
|
|
|
|
/// <summary>
|
2024-05-29 16:14:54 +04:00
|
|
|
|
/// Вывести список визитов
|
2024-05-29 14:44:16 +04:00
|
|
|
|
/// </summary>
|
|
|
|
|
public IActionResult Visits()
|
2024-05-01 23:10:05 +04:00
|
|
|
|
{
|
2024-05-29 14:44:16 +04:00
|
|
|
|
if (APIClient.User == null)
|
|
|
|
|
{
|
|
|
|
|
return Redirect("~/Home/Enter");
|
|
|
|
|
}
|
2024-05-01 23:10:05 +04:00
|
|
|
|
|
2024-05-29 14:44:16 +04:00
|
|
|
|
return View(_visitLogic.ReadList(new VisitSearchModel
|
|
|
|
|
{
|
|
|
|
|
UserId = APIClient.User.Id,
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2024-05-29 16:14:54 +04:00
|
|
|
|
/// Создать визит
|
2024-05-29 14:44:16 +04:00
|
|
|
|
/// </summary>
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public IActionResult CreateVisit()
|
|
|
|
|
{
|
|
|
|
|
if (APIClient.User == null)
|
|
|
|
|
{
|
|
|
|
|
return Redirect("~/Home/Enter");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ViewBag.Services = _serviceLogic.ReadList(null);
|
|
|
|
|
|
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
2024-05-29 23:12:32 +04:00
|
|
|
|
public void CreateVisit(DateTime dateVisit, List<int> service)
|
2024-05-29 14:44:16 +04:00
|
|
|
|
{
|
|
|
|
|
if (APIClient.User == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Необходимо авторизоваться!");
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-30 01:20:47 +04:00
|
|
|
|
if (dateVisit == DateTime.MinValue)
|
2024-05-29 14:44:16 +04:00
|
|
|
|
{
|
|
|
|
|
throw new Exception("Введены не все данные!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Dictionary<int, IServiceModel> visitServices = new Dictionary<int, IServiceModel>();
|
|
|
|
|
foreach (var serviceId in service)
|
|
|
|
|
{
|
|
|
|
|
visitServices.Add(serviceId, _serviceLogic.ReadElement(new ServiceSearchModel { Id = serviceId })!);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_visitLogic.Create(new VisitBindingModel
|
|
|
|
|
{
|
|
|
|
|
Date = dateVisit,
|
|
|
|
|
VisitServices = visitServices,
|
|
|
|
|
UserId = APIClient.User.Id
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Response.Redirect("/Visit/Visits");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2024-05-29 16:14:54 +04:00
|
|
|
|
/// Редактировать визит
|
2024-05-29 14:44:16 +04:00
|
|
|
|
/// </summary>
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public IActionResult UpdateVisit(int id)
|
|
|
|
|
{
|
|
|
|
|
if (APIClient.User == null)
|
|
|
|
|
{
|
|
|
|
|
return Redirect("~/Home/Enter");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ViewBag.Services = _serviceLogic.ReadList(null);
|
|
|
|
|
|
|
|
|
|
return View(_visitLogic.ReadElement(new VisitSearchModel
|
|
|
|
|
{
|
|
|
|
|
Id = id
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
2024-05-29 23:12:32 +04:00
|
|
|
|
public void UpdateVisit(int id, DateTime dateVisit, List<int> service)
|
2024-05-29 14:44:16 +04:00
|
|
|
|
{
|
|
|
|
|
if (APIClient.User == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Необходимо авторизоваться!");
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-30 01:20:47 +04:00
|
|
|
|
if (dateVisit == DateTime.MinValue)
|
2024-05-29 14:44:16 +04:00
|
|
|
|
{
|
|
|
|
|
throw new Exception("Введены не все данные!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Dictionary<int, IServiceModel> visitServices = new Dictionary<int, IServiceModel>();
|
|
|
|
|
foreach (var serviceId in service)
|
|
|
|
|
{
|
|
|
|
|
visitServices.Add(serviceId, _serviceLogic.ReadElement(new ServiceSearchModel { Id = serviceId })!);
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-29 23:12:32 +04:00
|
|
|
|
var visit = _visitLogic.ReadElement(new VisitSearchModel { Id = id });
|
|
|
|
|
_visitLogic.Update(new VisitBindingModel
|
2024-05-29 14:44:16 +04:00
|
|
|
|
{
|
|
|
|
|
Id = id,
|
|
|
|
|
Date = dateVisit,
|
|
|
|
|
VisitServices = visitServices,
|
2024-05-29 23:12:32 +04:00
|
|
|
|
VisitAnimals = visit!.VisitAnimals,
|
|
|
|
|
UserId = APIClient.User.Id
|
2024-05-29 14:44:16 +04:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Response.Redirect("/Visit/Visits");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2024-05-29 16:14:54 +04:00
|
|
|
|
/// Удалить визит
|
2024-05-29 14:44:16 +04:00
|
|
|
|
/// </summary>
|
2024-05-29 16:14:54 +04:00
|
|
|
|
[HttpPost]
|
|
|
|
|
public void DeleteVisit(int id)
|
|
|
|
|
{
|
|
|
|
|
if (APIClient.User == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Необходимо авторизоваться!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_visitLogic.Delete(new VisitBindingModel
|
|
|
|
|
{
|
|
|
|
|
Id = id
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Response.Redirect("/Visit/Visits");
|
|
|
|
|
}
|
2024-05-29 23:12:32 +04:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Выписать рецепт пациенту
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
/// <exception cref="Exception"></exception>
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public IActionResult CreateVisitAnimal()
|
|
|
|
|
{
|
|
|
|
|
if (APIClient.User == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Необходимо авторизоваться!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ViewBag.Visits = _visitLogic.ReadList(new VisitSearchModel
|
|
|
|
|
{
|
|
|
|
|
UserId = APIClient.User.Id
|
|
|
|
|
});
|
|
|
|
|
ViewBag.Animals = _animalLogic.ReadList(new AnimalSearchModel
|
|
|
|
|
{
|
|
|
|
|
UserId = APIClient.User.Id
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Выписать рецепт пациенту
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <exception cref="Exception"></exception>
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public void CreateVisitAnimal(int visitId, List<int> animals)
|
|
|
|
|
{
|
|
|
|
|
if (APIClient.User == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Необходимо авторизоваться!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (visitId <= 0 || animals == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Введены не все данные!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Dictionary<int, IAnimalModel> visitAnimals = new Dictionary<int, IAnimalModel>();
|
|
|
|
|
foreach (var animalId in animals)
|
|
|
|
|
{
|
|
|
|
|
visitAnimals.Add(animalId, _animalLogic.ReadElement(new AnimalSearchModel { Id = animalId })!);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var visit = _visitLogic.ReadElement(new VisitSearchModel { Id = visitId });
|
|
|
|
|
|
|
|
|
|
_visitLogic.Update(new VisitBindingModel
|
|
|
|
|
{
|
|
|
|
|
Id = visit!.Id,
|
|
|
|
|
Date = visit!.Date,
|
|
|
|
|
VisitServices = visit!.VisitServices,
|
|
|
|
|
VisitAnimals = visitAnimals,
|
|
|
|
|
UserId = APIClient.User.Id
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Response.Redirect("/Visit/Visits");
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-05-01 23:10:05 +04:00
|
|
|
|
}
|