2023-05-17 17:59:48 +04:00
|
|
|
using CanteenBusinessLogic.BusinessLogics;
|
2023-05-14 22:24:37 +04:00
|
|
|
using CanteenContracts.BindingModels;
|
2023-04-09 19:05:54 +04:00
|
|
|
using CanteenContracts.BusinessLogicsContracts;
|
2023-05-16 19:13:19 +04:00
|
|
|
using CanteenContracts.SearchModel;
|
2023-04-09 19:05:54 +04:00
|
|
|
using CanteenContracts.View;
|
2023-05-17 17:59:48 +04:00
|
|
|
using CanteenContracts.ViewModels;
|
2023-05-17 17:02:26 +04:00
|
|
|
using CanteenDataModels.Models;
|
2023-04-09 19:05:54 +04:00
|
|
|
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;
|
2023-05-14 22:24:37 +04:00
|
|
|
private readonly ITablewareLogic _tableware;
|
2023-05-17 17:59:48 +04:00
|
|
|
private readonly IGraphicLogic _gl;
|
2023-04-09 19:05:54 +04:00
|
|
|
|
2023-05-17 17:59:48 +04:00
|
|
|
public MainController(ILogger<MainController> logger, ICookLogic cook, IDishLogic dish, IProductLogic product, ITablewareLogic tableware, IGraphicLogic gl)
|
2023-04-09 19:05:54 +04:00
|
|
|
{
|
|
|
|
_logger = logger;
|
|
|
|
_cook = cook;
|
|
|
|
_dish = dish;
|
|
|
|
_product = product;
|
2023-05-14 22:24:37 +04:00
|
|
|
_tableware = tableware;
|
2023-05-17 17:59:48 +04:00
|
|
|
_gl = gl;
|
2023-04-09 19:05:54 +04:00
|
|
|
}
|
2023-05-18 01:40:11 +04:00
|
|
|
|
2023-04-09 19:05:54 +04:00
|
|
|
[HttpGet]
|
2023-05-18 01:40:11 +04:00
|
|
|
public List<TablewareViewModel>? GetTablewareList()
|
2023-04-09 19:05:54 +04:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2023-05-18 01:40:11 +04:00
|
|
|
return _tableware.ReadList(null);
|
2023-04-09 19:05:54 +04:00
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
|
|
|
_logger.LogError(ex, "Error during loading list of bouquets");
|
|
|
|
throw;
|
|
|
|
}
|
|
|
|
}
|
2023-05-18 01:40:11 +04:00
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
public void CreateTableware(TablewareBindingModel model)
|
2023-05-17 17:02:26 +04:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2023-05-18 01:40:11 +04:00
|
|
|
_tableware.Create(model);
|
2023-05-17 17:02:26 +04:00
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
|
|
|
_logger.LogError(ex, "Error during loading list of bouquets");
|
|
|
|
throw;
|
|
|
|
}
|
|
|
|
}
|
2023-05-18 01:40:11 +04:00
|
|
|
|
2023-05-17 17:02:26 +04:00
|
|
|
[HttpGet]
|
2023-05-18 01:40:11 +04:00
|
|
|
public List<CookViewModel>? GetCookList(int managerId)
|
2023-05-14 22:24:37 +04:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2023-05-18 01:40:11 +04:00
|
|
|
return _cook.ReadList(new CookSearchModel { ManagerId = managerId });
|
2023-05-14 22:24:37 +04:00
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
|
|
|
_logger.LogError(ex, "Error during loading list of bouquets");
|
|
|
|
throw;
|
|
|
|
}
|
|
|
|
}
|
2023-05-18 01:40:11 +04:00
|
|
|
|
2023-05-14 22:24:37 +04:00
|
|
|
[HttpPost]
|
2023-05-18 01:40:11 +04:00
|
|
|
public void CookCreate(CookBindingModel model)
|
2023-05-14 22:24:37 +04:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2023-05-18 01:40:11 +04:00
|
|
|
_cook.Create(model);
|
2023-05-14 22:24:37 +04:00
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
|
|
|
_logger.LogError(ex, "Error during loading list of bouquets");
|
|
|
|
throw;
|
|
|
|
}
|
|
|
|
}
|
2023-05-18 01:40:11 +04:00
|
|
|
|
2023-05-16 19:13:19 +04:00
|
|
|
[HttpPost]
|
2023-05-18 01:40:11 +04:00
|
|
|
public void CookDelete(CookBindingModel model)
|
2023-05-16 19:13:19 +04:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2023-05-18 01:40:11 +04:00
|
|
|
_cook.Delete(model);
|
2023-05-16 19:13:19 +04:00
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
|
|
|
_logger.LogError(ex, "Error during loading list of bouquets");
|
|
|
|
throw;
|
|
|
|
}
|
|
|
|
}
|
2023-05-17 17:02:26 +04:00
|
|
|
|
2023-05-16 19:13:19 +04:00
|
|
|
[HttpPost]
|
2023-05-18 01:40:11 +04:00
|
|
|
public void CookUpdate(CookBindingModel model)
|
2023-05-16 19:13:19 +04:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2023-05-18 01:40:11 +04:00
|
|
|
_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 });
|
2023-05-16 19:13:19 +04:00
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
|
|
|
_logger.LogError(ex, "Error during loading list of bouquets");
|
|
|
|
throw;
|
|
|
|
}
|
|
|
|
}
|
2023-05-17 17:02:26 +04:00
|
|
|
|
2023-05-16 19:13:19 +04:00
|
|
|
[HttpPost]
|
2023-05-18 01:40:11 +04:00
|
|
|
public void DishCreate(DishBindingModel model)
|
2023-05-16 19:13:19 +04:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
_dish.Create(model);
|
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
|
|
|
_logger.LogError(ex, "Error during loading list of bouquets");
|
|
|
|
throw;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
[HttpPost]
|
2023-05-18 01:40:11 +04:00
|
|
|
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)
|
2023-05-16 19:13:19 +04:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
_product.Create(model);
|
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
|
|
|
_logger.LogError(ex, "Error during loading list of bouquets");
|
|
|
|
throw;
|
|
|
|
}
|
|
|
|
}
|
2023-05-18 01:40:11 +04:00
|
|
|
[HttpPost]
|
|
|
|
public void ProductDelete(ProductBindingModel model)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
_product.Delete(model);
|
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
|
|
|
_logger.LogError(ex, "Error during loading list of bouquets");
|
|
|
|
throw;
|
|
|
|
}
|
|
|
|
}
|
2023-05-17 17:02:26 +04:00
|
|
|
|
|
|
|
[HttpPost]
|
2023-05-18 01:40:11 +04:00
|
|
|
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)
|
2023-05-17 17:02:26 +04:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
_product.AddCooksToProduct(model.Item1, model.Item2);
|
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
|
|
|
_logger.LogError(ex, "Error during loading list of bouquets");
|
|
|
|
throw;
|
|
|
|
}
|
|
|
|
}
|
2023-05-18 01:40:11 +04:00
|
|
|
|
2023-05-17 17:59:48 +04:00
|
|
|
[HttpGet]
|
|
|
|
public GraphicViewModel[] GetGraphic()
|
|
|
|
{
|
|
|
|
return new GraphicViewModel[]
|
|
|
|
{
|
|
|
|
_gl.GetGraphicByCount(),
|
|
|
|
_gl.GetGraphicByPrice()
|
|
|
|
};
|
|
|
|
}
|
2023-04-09 19:05:54 +04:00
|
|
|
}
|
|
|
|
}
|