2024-05-01 23:10:05 +04:00
|
|
|
|
using Microsoft.AspNetCore.Http;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using System.Diagnostics;
|
2024-05-29 11:23:13 +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 ServiceController : Controller
|
|
|
|
|
{
|
|
|
|
|
private readonly ILogger<ServiceController> _logger;
|
2024-05-29 11:23:13 +04:00
|
|
|
|
|
|
|
|
|
private readonly IServiceLogic _serviceLogic;
|
|
|
|
|
|
|
|
|
|
private readonly IMedicationLogic _medicationLogic;
|
|
|
|
|
public ServiceController(ILogger<ServiceController> logger, IServiceLogic serviceLogic, IMedicationLogic medicationLogic)
|
2024-05-01 23:10:05 +04:00
|
|
|
|
{
|
|
|
|
|
_logger = logger;
|
2024-05-29 11:23:13 +04:00
|
|
|
|
_serviceLogic = serviceLogic;
|
|
|
|
|
_medicationLogic = medicationLogic;
|
2024-05-01 23:10:05 +04:00
|
|
|
|
}
|
|
|
|
|
|
2024-05-29 11:23:13 +04:00
|
|
|
|
/// <summary>
|
2024-05-29 16:14:54 +04:00
|
|
|
|
/// Вывести список услуг
|
2024-05-29 11:23:13 +04:00
|
|
|
|
/// </summary>
|
|
|
|
|
[HttpGet]
|
2024-05-01 23:10:05 +04:00
|
|
|
|
public IActionResult Services()
|
|
|
|
|
{
|
2024-05-29 11:23:13 +04:00
|
|
|
|
if (APIClient.User == null)
|
|
|
|
|
{
|
|
|
|
|
return Redirect("~/Home/Enter");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return View(_serviceLogic.ReadList(null));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2024-05-29 16:14:54 +04:00
|
|
|
|
/// Создать услугу
|
2024-05-29 11:23:13 +04:00
|
|
|
|
/// </summary>
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public IActionResult CreateService()
|
|
|
|
|
{
|
|
|
|
|
if (APIClient.User == null)
|
|
|
|
|
{
|
|
|
|
|
return Redirect("~/Home/Enter");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ViewBag.Medications = _medicationLogic.ReadList(null);
|
|
|
|
|
|
2024-05-01 23:10:05 +04:00
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-29 11:23:13 +04:00
|
|
|
|
[HttpPost]
|
|
|
|
|
public void CreateService(string name, int cost, int medication)
|
2024-05-01 23:10:05 +04:00
|
|
|
|
{
|
2024-05-29 11:23:13 +04:00
|
|
|
|
if (APIClient.User == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Необходимо авторизоваться!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(name) || cost <= 0 || medication == 0)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Введены не все данные!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_serviceLogic.Create(new ServiceBindingModel
|
|
|
|
|
{
|
|
|
|
|
Name = name,
|
|
|
|
|
Cost = cost,
|
|
|
|
|
MedicationId = medication
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Response.Redirect("/Service/Services");
|
2024-05-01 23:10:05 +04:00
|
|
|
|
}
|
2024-05-29 11:23:13 +04:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
2024-05-29 16:14:54 +04:00
|
|
|
|
/// Редактировать услугу
|
2024-05-29 11:23:13 +04:00
|
|
|
|
/// </summary>
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public IActionResult UpdateService(int id)
|
|
|
|
|
{
|
|
|
|
|
if (APIClient.User == null)
|
|
|
|
|
{
|
|
|
|
|
return Redirect("~/Home/Enter");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ViewBag.Medications = _medicationLogic.ReadList(null);
|
|
|
|
|
|
|
|
|
|
return View(_serviceLogic.ReadElement(new ServiceSearchModel
|
|
|
|
|
{
|
|
|
|
|
Id = id
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public void UpdateService(int id, string name, int cost, int medication)
|
|
|
|
|
{
|
|
|
|
|
if (APIClient.User == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Необходимо авторизоваться!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(name) || cost <= 0 || medication == 0)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Введены не все данные!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_serviceLogic.Update(new ServiceBindingModel
|
|
|
|
|
{
|
|
|
|
|
Id = id,
|
|
|
|
|
Name = name,
|
|
|
|
|
Cost = cost,
|
|
|
|
|
MedicationId = medication
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Response.Redirect("/Service/Services");
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-29 16:14:54 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Удалить услугу
|
|
|
|
|
/// </summary>
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public void DeleteService(int id)
|
|
|
|
|
{
|
|
|
|
|
if (APIClient.User == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Необходимо авторизоваться!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_serviceLogic.Delete(new ServiceBindingModel
|
|
|
|
|
{
|
|
|
|
|
Id = id
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Response.Redirect("/Service/Services");
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-05-01 23:10:05 +04:00
|
|
|
|
}
|