PIbd-21_MasenkinMS_Aircraft.../AircraftPlant/AircraftPlantRestApi/Controllers/ClientController.cs
2024-04-07 00:02:29 +04:00

98 lines
2.7 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using AircraftPlantContracts.BindingModels;
using AircraftPlantContracts.BusinessLogicsContracts;
using AircraftPlantContracts.SearchModels;
using AircraftPlantContracts.ViewModels;
using Microsoft.AspNetCore.Mvc;
namespace AircraftPlantRestApi.Controllers
{
/// <summary>
/// Контроллер для работы с клиентами
/// </summary>
[Route("api/[controller]/[action]")]
[ApiController]
public class ClientController : Controller
{
/// <summary>
/// Логгер
/// </summary>
private readonly ILogger _logger;
/// <summary>
/// Бизнес-логика для клиентов
/// </summary>
private readonly IClientLogic _logic;
/// <summary>
/// Конструктор
/// </summary>
/// <param name="logic"></param>
/// <param name="logger"></param>
public ClientController(IClientLogic logic, ILogger<ClientController> logger)
{
_logger = logger;
_logic = logic;
}
/// <summary>
/// Вход в систему
/// </summary>
/// <param name="login"></param>
/// <param name="password"></param>
/// <returns></returns>
[HttpGet]
public ClientViewModel? Login(string login, string password)
{
try
{
return _logic.ReadElement(new ClientSearchModel
{
Email = login,
Password = password
});
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка входа в систему");
throw;
}
}
/// <summary>
/// Регистрация
/// </summary>
/// <param name="model"></param>
[HttpPost]
public void Register(ClientBindingModel model)
{
try
{
_logic.Create(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка регистрации");
throw;
}
}
/// <summary>
/// Обновление данных
/// </summary>
/// <param name="model"></param>
[HttpPost]
public void UpdateData(ClientBindingModel model)
{
try
{
_logic.Update(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка обновления данных");
throw;
}
}
}
}