SUBD_PIbd-23_ZakharovRA/CarShowroom/CarShowroomRestApi/Controllers/MakeController.cs
2024-05-06 11:31:59 +04:00

96 lines
2.3 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 MakeController : Controller
{
private readonly ILogger _logger;
private readonly IMakeLogic _logic;
public MakeController(ILogger<MakeController> logger, IMakeLogic make)
{
_logger = logger;
_logic = make;
}
[HttpGet]
public List<MakeView>? GetMakeList()
{
try
{
return _logic.ReadList(null);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения списка марок");
throw;
}
}
[HttpGet]
public MakeView? GetMake(int MakeId)
{
try
{
return _logic.ReadElement(new MakeSearch
{
Id = MakeId
});
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения марки по Id={Id}", MakeId);
throw;
}
}
[HttpPost]
public void CreateMake(MakeDto model)
{
try
{
_logic.Create(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка создания марки");
throw;
}
}
[HttpPut]
public void UpdateMake(MakeDto model)
{
try
{
_logic.Update(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка обновления марки");
throw;
}
}
[HttpDelete]
public void DeleteMake(MakeDto model)
{
try
{
_logic.Delete(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка удаления марки");
throw;
}
}
}
}