2024-05-01 23:10:05 +04:00
|
|
|
|
using Microsoft.AspNetCore.Http;
|
|
|
|
|
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;
|
|
|
|
|
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>
|
|
|
|
|
/// Вывести список животных
|
|
|
|
|
/// </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>
|
|
|
|
|
/// Создать животного
|
|
|
|
|
/// </summary>
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public IActionResult CreateVisit()
|
|
|
|
|
{
|
|
|
|
|
if (APIClient.User == null)
|
|
|
|
|
{
|
|
|
|
|
return Redirect("~/Home/Enter");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ViewBag.Animals = _animalLogic.ReadList(new AnimalSearchModel
|
|
|
|
|
{
|
|
|
|
|
UserId = APIClient.User.Id,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
ViewBag.Services = _serviceLogic.ReadList(null);
|
|
|
|
|
|
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public void CreateVisit(DateTime dateVisit, List<int> animal, List<int> service)
|
|
|
|
|
{
|
|
|
|
|
if (APIClient.User == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Необходимо авторизоваться!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (dateVisit == DateTime.MinValue || animal == null || service == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Введены не все данные!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Dictionary<int, IAnimalModel> visitAnimals = new Dictionary<int, IAnimalModel>();
|
|
|
|
|
foreach (var animalId in animal)
|
|
|
|
|
{
|
|
|
|
|
visitAnimals.Add(animalId, _animalLogic.ReadElement(new AnimalSearchModel { Id = animalId })!);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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,
|
|
|
|
|
VisitAnimals = visitAnimals,
|
|
|
|
|
VisitServices = visitServices,
|
|
|
|
|
UserId = APIClient.User.Id
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Response.Redirect("/Visit/Visits");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Редактировать животного
|
|
|
|
|
/// </summary>
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public IActionResult UpdateVisit(int id)
|
|
|
|
|
{
|
|
|
|
|
if (APIClient.User == null)
|
|
|
|
|
{
|
|
|
|
|
return Redirect("~/Home/Enter");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ViewBag.Animals = _animalLogic.ReadList(new AnimalSearchModel
|
|
|
|
|
{
|
|
|
|
|
UserId = APIClient.User.Id,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
ViewBag.Services = _serviceLogic.ReadList(null);
|
|
|
|
|
|
|
|
|
|
return View(_visitLogic.ReadElement(new VisitSearchModel
|
|
|
|
|
{
|
|
|
|
|
Id = id
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public void UpdateVisit(int id, DateTime dateVisit, List<int> animal, List<int> service)
|
|
|
|
|
{
|
|
|
|
|
if (APIClient.User == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Необходимо авторизоваться!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (dateVisit == DateTime.MinValue || animal == null || service == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Введены не все данные!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Dictionary<int, IAnimalModel> visitAnimals = new Dictionary<int, IAnimalModel>();
|
|
|
|
|
foreach (var animalId in animal)
|
|
|
|
|
{
|
|
|
|
|
visitAnimals.Add(animalId, _animalLogic.ReadElement(new AnimalSearchModel { Id = animalId })!);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Dictionary<int, IServiceModel> visitServices = new Dictionary<int, IServiceModel>();
|
|
|
|
|
foreach (var serviceId in service)
|
|
|
|
|
{
|
|
|
|
|
visitServices.Add(serviceId, _serviceLogic.ReadElement(new ServiceSearchModel { Id = serviceId })!);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_visitLogic.Update(new VisitBindingModel
|
|
|
|
|
{
|
|
|
|
|
Id = id,
|
|
|
|
|
Date = dateVisit,
|
|
|
|
|
VisitAnimals = visitAnimals,
|
|
|
|
|
VisitServices = visitServices,
|
|
|
|
|
UserId = APIClient.User.Id
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Response.Redirect("/Visit/Visits");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Удалить животного
|
|
|
|
|
/// </summary>
|
|
|
|
|
}
|
2024-05-01 23:10:05 +04:00
|
|
|
|
}
|