96 lines
2.4 KiB
C#
96 lines
2.4 KiB
C#
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<SaleController> logger, ISaleLogic sale)
|
|
{
|
|
_logger = logger;
|
|
_logic = sale;
|
|
}
|
|
|
|
[HttpGet]
|
|
public List<SaleView>? 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;
|
|
}
|
|
}
|
|
}
|
|
}
|