106 lines
2.2 KiB
C#
106 lines
2.2 KiB
C#
using IceCreamShopContracts.BindingModels;
|
||
using IceCreamShopContracts.BusinessLogicsContracts;
|
||
using IceCreamShopContracts.SearchModels;
|
||
using IceCreamShopContracts.ViewModels;
|
||
using IceCreamShopDataModels.Models;
|
||
using Microsoft.AspNetCore.Http;
|
||
using Microsoft.AspNetCore.Mvc;
|
||
|
||
namespace IceCreamShopRestApi.Controllers
|
||
{
|
||
[Route("api/[controller]/[action]")]
|
||
[ApiController]
|
||
public class ShopController : ControllerBase
|
||
{
|
||
private readonly ILogger _logger;
|
||
private readonly IShopLogic _logic;
|
||
public ShopController(IShopLogic logic, ILogger<ShopController>
|
||
logger)
|
||
{
|
||
_logger = logger;
|
||
_logic = logic;
|
||
}
|
||
[HttpGet]
|
||
public ShopViewModel GetShop(ShopSearchModel model)
|
||
{
|
||
try
|
||
{
|
||
return _logic.ReadElement(model);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
_logger.LogError(ex, "Ошибка получения списка магазинов");
|
||
throw;
|
||
}
|
||
}
|
||
[HttpGet]
|
||
public List<ShopViewModel> GetShops()
|
||
{
|
||
try
|
||
{
|
||
return _logic.ReadList(null);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
_logger.LogError(ex, "Ошибка получения списка магазинов");
|
||
throw;
|
||
}
|
||
}
|
||
[HttpPost]
|
||
public bool CreateShop(ShopBindingModel model)
|
||
{
|
||
try
|
||
{
|
||
return _logic.Create(model);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
_logger.LogError(ex, "Не удалось создать магазин");
|
||
throw;
|
||
}
|
||
}
|
||
|
||
[HttpPost]
|
||
public bool UpdateShop(ShopBindingModel model)
|
||
{
|
||
try
|
||
{
|
||
return _logic.Update(model);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
_logger.LogError(ex, "Не удалось обновить магазин");
|
||
throw;
|
||
}
|
||
}
|
||
|
||
[HttpPost]
|
||
public bool DeleteShop(ShopBindingModel model)
|
||
{
|
||
try
|
||
{
|
||
return _logic.Delete(model);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
_logger.LogError(ex, "Не удалось удалить магазин");
|
||
throw;
|
||
}
|
||
}
|
||
|
||
[HttpPost]
|
||
public bool MakeSupply(Tuple<ShopSearchModel, IIceCreamModel, int> model)
|
||
{
|
||
try
|
||
{
|
||
return _logic.MakeSupply(model.Item1, model.Item2, model.Item3);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
_logger.LogError(ex, "Не удалось сделать поставку в магазин");
|
||
throw;
|
||
}
|
||
}
|
||
}
|
||
}
|