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 CarController : Controller { private readonly ILogger _logger; private readonly ICarLogic _logic; public CarController(ILogger logger, ICarLogic car) { _logger = logger; _logic = car; } [HttpGet] public List? GetCarList() { try { return _logic.ReadList(new CarSearch { IsSaled = false, }); } catch (Exception ex) { _logger.LogError(ex, "Ошибка получения списка машин"); throw; } } [HttpGet] public CarView? GetCar(int CarId) { try { return _logic.ReadElement(new CarSearch { Id = CarId }); } catch (Exception ex) { _logger.LogError(ex, "Ошибка получения машины по Id={Id}", CarId); throw; } } [HttpPost] public void CreateCar(CarDto model) { try { _logic.Create(model); } catch (Exception ex) { _logger.LogError(ex, "Ошибка создания машины"); throw; } } [HttpPut] public void UpdateCar(CarDto model) { try { _logic.Update(model); } catch (Exception ex) { _logger.LogError(ex, "Ошибка обновления машины"); throw; } } [HttpDelete] public void DeleteCar(CarDto model) { try { _logic.Delete(model); } catch (Exception ex) { _logger.LogError(ex, "Ошибка удаления машины"); throw; } } } }