150 lines
4.1 KiB
C#
150 lines
4.1 KiB
C#
using CanteenContracts.BindingModels;
|
|
using CanteenContracts.BusinessLogicsContracts;
|
|
using CanteenContracts.SearchModel;
|
|
using CanteenContracts.View;
|
|
using CanteenDataModels.Models;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace CanteenRestApi.Controllers
|
|
{
|
|
[Route("api/[controller]/[action]")]
|
|
[ApiController]
|
|
public class MainController : ControllerBase
|
|
{
|
|
private readonly ILogger _logger;
|
|
private readonly ICookLogic _cook;
|
|
private readonly IDishLogic _dish;
|
|
private readonly IProductLogic _product;
|
|
private readonly ITablewareLogic _tableware;
|
|
|
|
public MainController(ILogger<MainController> logger, ICookLogic cook, IDishLogic dish, IProductLogic product, ITablewareLogic tableware)
|
|
{
|
|
_logger = logger;
|
|
_cook = cook;
|
|
_dish = dish;
|
|
_product = product;
|
|
_tableware = tableware;
|
|
}
|
|
|
|
[HttpGet]
|
|
public List<CookViewModel>? GetCookList(int managerId)
|
|
{
|
|
try
|
|
{
|
|
return _cook.ReadList(new CookSearchModel { ManagerId = managerId});
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "Error during loading list of bouquets");
|
|
throw;
|
|
}
|
|
}
|
|
[HttpGet]
|
|
public List<ProductViewModel>? GetProductList(int managerId)
|
|
{
|
|
try
|
|
{
|
|
return _product.ReadList(new ProductSearchModel { ManagerId = managerId });
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "Error during loading list of bouquets");
|
|
throw;
|
|
}
|
|
}
|
|
[HttpGet]
|
|
public List<TablewareViewModel>? GetTablewareList()
|
|
{
|
|
try
|
|
{
|
|
return _tableware.ReadList(null);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "Error during loading list of bouquets");
|
|
throw;
|
|
}
|
|
}
|
|
[HttpPost]
|
|
public void CreateTableware(TablewareBindingModel model)
|
|
{
|
|
try
|
|
{
|
|
_tableware.Create(model);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "Error during loading list of bouquets");
|
|
throw;
|
|
}
|
|
}
|
|
[HttpPost]
|
|
public void CreateCook(CookBindingModel model)
|
|
{
|
|
try
|
|
{
|
|
_cook.Create(model);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "Error during loading list of bouquets");
|
|
throw;
|
|
}
|
|
}
|
|
|
|
[HttpPost]
|
|
public void DeleteCook(CookBindingModel model)
|
|
{
|
|
try
|
|
{
|
|
_cook.Delete(model);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "Error during loading list of bouquets");
|
|
throw;
|
|
}
|
|
}
|
|
|
|
[HttpPost]
|
|
public void CreateDish(DishBindingModel model)
|
|
{
|
|
try
|
|
{
|
|
_dish.Create(model);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "Error during loading list of bouquets");
|
|
throw;
|
|
}
|
|
}
|
|
[HttpPost]
|
|
public void CreateProduct(ProductBindingModel model)
|
|
{
|
|
try
|
|
{
|
|
_product.Create(model);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "Error during loading list of bouquets");
|
|
throw;
|
|
}
|
|
}
|
|
|
|
[HttpPost]
|
|
public void AddCooksToProduct(Tuple<ProductSearchModel, CookViewModel> model)
|
|
{
|
|
try
|
|
{
|
|
_product.AddCooksToProduct(model.Item1, model.Item2);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "Error during loading list of bouquets");
|
|
throw;
|
|
}
|
|
}
|
|
}
|
|
} |