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 ModelController : Controller { private readonly ILogger _logger; private readonly IModelLogic _logic; public ModelController(ILogger logger, IModelLogic model) { _logger = logger; _logic = model; } [HttpGet] public List? GetModelList() { try { return _logic.ReadList(null); } catch (Exception ex) { _logger.LogError(ex, "Ошибка получения списка моделей"); throw; } } [HttpGet] public ModelView? GetModel(int ModelId) { try { return _logic.ReadElement(new ModelSearch { Id = ModelId }); } catch (Exception ex) { _logger.LogError(ex, "Ошибка получения модели по Id={Id}", ModelId); throw; } } [HttpPost] public void CreateModel(ModelDto model) { try { _logic.Create(model); } catch (Exception ex) { _logger.LogError(ex, "Ошибка создания модели"); throw; } } [HttpPut] public void UpdateModel(ModelDto model) { try { _logic.Update(model); } catch (Exception ex) { _logger.LogError(ex, "Ошибка обновления модели"); throw; } } [HttpDelete] public void DeleteModel(ModelDto model) { try { _logic.Delete(model); } catch (Exception ex) { _logger.LogError(ex, "Ошибка удаления модели"); throw; } } } }