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 ServiceController : Controller { private readonly ILogger _logger; private readonly IServiceLogic _logic; public ServiceController(ILogger logger, IServiceLogic service) { _logger = logger; _logic = service; } [HttpGet] public List? GetServiceList() { try { return _logic.ReadList(null); } catch (Exception ex) { _logger.LogError(ex, "Ошибка получения списка услуг"); throw; } } [HttpGet] public ServiceView? GetService(int ServiceId) { try { return _logic.ReadElement(new ServiceSearch { Id = ServiceId }); } catch (Exception ex) { _logger.LogError(ex, "Ошибка получения услуги по Id={Id}", ServiceId); throw; } } [HttpPost] public void CreateService(ServiceDto model) { try { _logic.Create(model); } catch (Exception ex) { _logger.LogError(ex, "Ошибка создания услуги"); throw; } } [HttpPut] public void UpdateService(ServiceDto model) { try { _logic.Update(model); } catch (Exception ex) { _logger.LogError(ex, "Ошибка обновления услуги"); throw; } } [HttpDelete] public void DeleteService(ServiceDto model) { try { _logic.Delete(model); } catch (Exception ex) { _logger.LogError(ex, "Ошибка удаления услуги"); throw; } } } }