264 lines
7.0 KiB
C#
264 lines
7.0 KiB
C#
using CanteenBusinessLogic.BusinessLogics;
|
|
using CanteenContracts.BindingModels;
|
|
using CanteenContracts.BusinessLogicsContracts;
|
|
using CanteenContracts.SearchModel;
|
|
using CanteenContracts.View;
|
|
using CanteenContracts.ViewModels;
|
|
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;
|
|
private readonly IGraphicLogic _gl;
|
|
|
|
public MainController(ILogger<MainController> logger, ICookLogic cook, IDishLogic dish, IProductLogic product, ITablewareLogic tableware, IGraphicLogic gl)
|
|
{
|
|
_logger = logger;
|
|
_cook = cook;
|
|
_dish = dish;
|
|
_product = product;
|
|
_tableware = tableware;
|
|
_gl = gl;
|
|
}
|
|
|
|
[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;
|
|
}
|
|
}
|
|
|
|
[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;
|
|
}
|
|
}
|
|
|
|
[HttpPost]
|
|
public void CookCreate(CookBindingModel model)
|
|
{
|
|
try
|
|
{
|
|
_cook.Create(model);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "Error during loading list of bouquets");
|
|
throw;
|
|
}
|
|
}
|
|
|
|
[HttpPost]
|
|
public void CookDelete(CookBindingModel model)
|
|
{
|
|
try
|
|
{
|
|
_cook.Delete(model);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "Error during loading list of bouquets");
|
|
throw;
|
|
}
|
|
}
|
|
|
|
[HttpPost]
|
|
public void CookUpdate(CookBindingModel model)
|
|
{
|
|
try
|
|
{
|
|
_cook.Update(model);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "Error during loading list of bouquets");
|
|
throw;
|
|
}
|
|
}
|
|
|
|
[HttpGet]
|
|
public List<DishViewModel>? GetDishList(int managerId)
|
|
{
|
|
try
|
|
{
|
|
return _dish.ReadList(new DishSearchModel { ManagerId = managerId });
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "Error during loading list of bouquets");
|
|
throw;
|
|
}
|
|
}
|
|
|
|
[HttpPost]
|
|
public void DishCreate(DishBindingModel model)
|
|
{
|
|
try
|
|
{
|
|
_dish.Create(model);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "Error during loading list of bouquets");
|
|
throw;
|
|
}
|
|
}
|
|
[HttpPost]
|
|
public void DishDelete(DishBindingModel model)
|
|
{
|
|
try
|
|
{
|
|
_dish.Delete(model);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "Error during loading list of bouquets");
|
|
throw;
|
|
}
|
|
}
|
|
|
|
[HttpPost]
|
|
public void DishUpdate(DishBindingModel model)
|
|
{
|
|
try
|
|
{
|
|
_dish.Update(model);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "Error during loading list of bouquets");
|
|
throw;
|
|
}
|
|
}
|
|
[HttpPost]
|
|
public void DishAddProducts(Tuple<DishSearchModel, ProductViewModel, int> model)
|
|
{
|
|
try
|
|
{
|
|
_dish.AddCooksToProduct(model.Item1, model.Item2, model.Item3);
|
|
}
|
|
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;
|
|
}
|
|
}
|
|
|
|
[HttpPost]
|
|
public void ProductCreate(ProductBindingModel model)
|
|
{
|
|
try
|
|
{
|
|
_product.Create(model);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "Error during loading list of bouquets");
|
|
throw;
|
|
}
|
|
}
|
|
[HttpPost]
|
|
public void ProductDelete(ProductBindingModel model)
|
|
{
|
|
try
|
|
{
|
|
_product.Delete(model);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "Error during loading list of bouquets");
|
|
throw;
|
|
}
|
|
}
|
|
|
|
[HttpPost]
|
|
public void ProductUpdate(ProductBindingModel model)
|
|
{
|
|
try
|
|
{
|
|
_product.Update(model);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "Error during loading list of bouquets");
|
|
throw;
|
|
}
|
|
}
|
|
|
|
[HttpPost]
|
|
public void ProductAddCooks(Tuple<ProductSearchModel, CookViewModel> model)
|
|
{
|
|
try
|
|
{
|
|
_product.AddCooksToProduct(model.Item1, model.Item2);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "Error during loading list of bouquets");
|
|
throw;
|
|
}
|
|
}
|
|
|
|
[HttpGet]
|
|
public GraphicViewModel[] GetGraphic()
|
|
{
|
|
return new GraphicViewModel[]
|
|
{
|
|
_gl.GetGraphicByCount(),
|
|
_gl.GetGraphicByPrice()
|
|
};
|
|
}
|
|
}
|
|
} |