ISEbd-21_Agliullov.D.A._Con.../ConfectioneryRestApi/Controllers/ShopController.cs
Данияр Аглиуллов a41ba7b7d1 fix
2023-03-05 13:43:17 +04:00

66 lines
1.6 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using ConfectioneryContracts.BindingModels;
using ConfectioneryContracts.BusinessLogicsContracts;
using ConfectioneryContracts.SearchModels;
using ConfectioneryContracts.ViewModels;
using ConfectioneryDataModels.Models;
using Microsoft.AspNetCore.Mvc;
namespace ConfectioneryRestApi.Controllers
{
[Route("api/[controller]/[action]")]
[ApiController]
public class ShopController : Controller
{
private readonly ILogger _logger;
private readonly IShopLogic _logic;
public ShopController(IShopLogic logic, ILogger<ShopController> logger)
{
_logger = logger;
_logic = logic;
}
[HttpGet]
public List<ShopViewModel>? GetShops()
{
try
{
return _logic.ReadList(null);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения списка магазинов");
throw;
}
}
[HttpPost]
public void CRUDShop(Action action)
{
try
{
action.Invoke();
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка операции CRUD - {operation} с магазином", action.Method.Name);
throw;
}
}
[HttpPost]
public void UpdateShop(ShopBindingModel model) => CRUDShop(() => _logic.Update(model));
[HttpPost]
public void CreateShop(ShopBindingModel model) => CRUDShop(() => _logic.Create(model));
[HttpPost]
public void DeleteShop(ShopBindingModel model) => CRUDShop(() => _logic.Delete(model));
[HttpPost]
public void AddPastryInShop(Tuple<ShopSearchModel, IPastryModel, int> countPastryForShop)
{
CRUDShop(() => _logic.AddPastry(countPastryForShop.Item1, countPastryForShop.Item2, countPastryForShop.Item3));
}
}
}