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 SaleController : Controller { private readonly ILogger _logger; private readonly ISaleLogic _logic; public SaleController(ILogger logger, ISaleLogic sale) { _logger = logger; _logic = sale; } [HttpGet] public List? GetSaleList() { try { return _logic.ReadList(null); } catch (Exception ex) { _logger.LogError(ex, "Ошибка получения списка продаж"); throw; } } [HttpGet] public SaleView? GetSale(int SaleId) { try { return _logic.ReadElement(new SaleSearch { Id = SaleId }); } catch (Exception ex) { _logger.LogError(ex, "Ошибка получения продажи по Id={Id}", SaleId); throw; } } [HttpPost] public void CreateSale(SaleDto model) { try { _logic.Create(model); } catch (Exception ex) { _logger.LogError(ex, "Ошибка создания продажи"); throw; } } [HttpPut] public void UpdateSale(SaleDto model) { try { _logic.Update(model); } catch (Exception ex) { _logger.LogError(ex, "Ошибка обновления продажи"); throw; } } [HttpDelete] public void DeleteSale(SaleDto model) { try { _logic.Delete(model); } catch (Exception ex) { _logger.LogError(ex, "Ошибка удаления продажи"); throw; } } } }