using CarShowroomContracts.BusinessLogic; using CarShowroomDataModels.Dtos; using CarShowroomDataModels.SearchModel; using CarShowroomDataModels.Views; using Microsoft.AspNetCore.Mvc; namespace CarShowroomRestApi.Controllers { [Route("api/[controller]/[action]")] [ApiController] public class ClientController : Controller { private readonly ILogger _logger; private readonly IClientLogic _logic; public ClientController(ILogger logger, IClientLogic client) { _logger = logger; _logic = client; } [HttpGet] public List? GetClientList() { try { return _logic.ReadList(null); } catch (Exception ex) { _logger.LogError(ex, "Ошибка получения списка клиентов"); throw; } } [HttpGet] public ClientView? GetClient(int ClientId) { try { return _logic.ReadElement(new ClientSearch { Id = ClientId }); } catch (Exception ex) { _logger.LogError(ex, "Ошибка получения клиента по Id={Id}", ClientId); throw; } } [HttpPost] public void CreateClient(ClientDto model) { try { _logic.Create(model); } catch (Exception ex) { _logger.LogError(ex, "Ошибка создания клиента"); throw; } } [HttpPut] public void UpdateClient(ClientDto model) { try { _logic.Update(model); } catch (Exception ex) { _logger.LogError(ex, "Ошибка обновления клиента"); throw; } } [HttpDelete] public void DeleteClient(ClientDto model) { try { _logic.Delete(model); } catch (Exception ex) { _logger.LogError(ex, "Ошибка удаления клиента"); throw; } } } }