PIbd-21_BatylkinaAO_MusoevD.../Canteen/CanteenRestApi/Controllers/MainController.cs

573 lines
16 KiB
C#
Raw Normal View History

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;
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-20 00:18:48 +04:00
private readonly IOrderLogic _order;
private readonly ILunchLogic _lunch;
2023-05-17 17:59:48 +04:00
private readonly IGraphicLogic _gl;
2023-05-20 12:11:48 +04:00
private readonly IReportLogic _reportLogic;
2023-04-09 19:05:54 +04:00
2023-05-20 12:11:48 +04:00
public MainController(ILogger<MainController> logger, IReportLogic reportLogic, ICookLogic cook, IDishLogic dish, IProductLogic product, ITablewareLogic tableware, IOrderLogic order, IGraphicLogic gl, ILunchLogic lunch)
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-20 00:18:48 +04:00
_order = order;
2023-05-17 17:59:48 +04:00
_gl = gl;
2023-05-20 00:18:48 +04:00
_lunch = lunch;
2023-05-20 12:11:48 +04:00
_reportLogic = reportLogic;
}
[HttpPost]
public void SavePDF(ReportBindingModel model)
{
try
{
_reportLogic.saveLunchesToPdfFile(new ReportBindingModel()
{
DateAfter = model.DateAfter,
DateBefore = model.DateBefore,
FileName = model.FileName,
VisitorId = model.VisitorId,
lunches = _lunch.ReadList(new LunchSearchModel { VisitorId = model.VisitorId}),
});
}
catch (Exception ex)
{
_logger.LogError(ex, "Error during loading list of bouquets");
throw;
}
}
[HttpPost]
public IActionResult SaveXSL(ReportBindingModel model)
{
try
{
var excelFileName = $"{model.FileName}.xlsx";
var excelFilePath = excelFileName;
_reportLogic.saveCooksToExcel(new ReportBindingModel()
{
DateAfter = model.DateAfter,
DateBefore = model.DateBefore,
FileName = excelFilePath,
VisitorId = model.VisitorId,
lunches = _lunch.ReadList(new LunchSearchModel { VisitorId = model.VisitorId }),
});
byte[] fileBytes = System.IO.File.ReadAllBytes(excelFilePath);
return File(fileBytes, "application/octet-stream", excelFileName);
}
catch (Exception ex)
{
_logger.LogError(ex, "Error during loading list of bouquets");
throw;
}
}
[HttpPost]
public void SaveWORD(ReportBindingModel model)
{
try
{
_reportLogic.saveCooksToWord(new ReportBindingModel()
{
DateAfter = model.DateAfter,
DateBefore = model.DateBefore,
FileName = model.FileName,
VisitorId = model.VisitorId,
lunches = _lunch.ReadList(new LunchSearchModel { VisitorId = model.VisitorId }),
});
}
catch (Exception ex)
{
_logger.LogError(ex, "Error during loading list of bouquets");
throw;
}
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-19 03:39:58 +04:00
public List<TablewareViewModel>? GetTablewareList(int visitorId)
2023-04-09 19:05:54 +04:00
{
try
{
2023-05-19 03:39:58 +04:00
return _tableware.ReadList(new TablewareSearchModel { VisitorId = visitorId });
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-19 03:39:58 +04:00
[HttpPost]
public void DeleteTableware(TablewareBindingModel model)
{
try
{
_tableware.Delete(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Error during loading list of bouquets");
throw;
}
}
[HttpPost]
public void UpdateTableware(TablewareBindingModel model)
{
try
{
_tableware.Update(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Error during loading list of bouquets");
throw;
}
}
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-20 00:18:48 +04:00
[HttpGet]
public List<CookViewModel>? GetCookFullList()
{
try
{
return _cook.ReadList(null);
}
catch (Exception ex)
{
_logger.LogError(ex, "Error during loading list of bouquets");
throw;
}
}
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;
}
}
[HttpPost]
2023-05-18 01:40:11 +04:00
public void CookDelete(CookBindingModel model)
{
try
{
2023-05-18 01:40:11 +04:00
_cook.Delete(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 CookUpdate(CookBindingModel model)
{
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 });
}
catch (Exception ex)
{
_logger.LogError(ex, "Error during loading list of bouquets");
throw;
}
}
2023-05-19 03:39:58 +04:00
[HttpGet]
public DishViewModel? GetDish(int Id)
{
try
{
return _dish.ReadElement(new DishSearchModel { Id = Id });
}
catch (Exception ex)
{
_logger.LogError(ex, "Error during loading list of bouquets");
throw;
}
}
[HttpPost]
2023-05-18 01:40:11 +04:00
public void DishCreate(DishBindingModel model)
{
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]
2023-05-19 03:39:58 +04:00
public void DishAddProducts(Tuple<DishBindingModel, ProductViewModel, int> model)
2023-05-18 01:40:11 +04:00
{
try
{
2023-05-19 03:39:58 +04:00
_dish.AddProductsToDish(model.Item1, model.Item2, model.Item3);
2023-05-18 01:40:11 +04:00
}
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;
}
}
2023-05-19 03:39:58 +04:00
[HttpGet]
2023-05-20 00:18:48 +04:00
public List<ProductViewModel>? GetProductFullList()
{
try
{
return _product.ReadList(null);
}
catch (Exception ex)
{
_logger.LogError(ex, "Error during loading list of bouquets");
throw;
}
}
[HttpGet]
2023-05-19 03:39:58 +04:00
public ProductViewModel? GetProduct(int Id)
{
try
{
return _product.ReadElement(new ProductSearchModel { Id = Id });
}
catch (Exception ex)
{
_logger.LogError(ex, "Error during loading list of bouquets");
throw;
}
}
2023-05-18 01:40:11 +04:00
[HttpPost]
public void ProductCreate(ProductBindingModel model)
{
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-17 17:59:48 +04:00
[HttpGet]
2023-05-20 00:18:48 +04:00
public List<OrderViewModel>? GetOrderList(int visitorId)
{
try
{
return _order.ReadList(new OrderSearchModel { VisitorId = visitorId });
}
catch (Exception ex)
{
_logger.LogError(ex, "Error during loading list of bouquets");
throw;
}
}
[HttpGet]
public OrderViewModel? GetOrder(int Id)
{
try
{
return _order.ReadElement(new OrderSearchModel { Id = Id });
}
catch (Exception ex)
{
_logger.LogError(ex, "Error during loading list of bouquets");
throw;
}
}
[HttpPost]
public void CreateOrder(OrderBindingModel model)
{
try
{
_order.Create(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Error during loading list of bouquets");
throw;
}
}
[HttpPost]
public void DeleteOrder(OrderBindingModel model)
{
try
{
_order.Delete(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Error during loading list of bouquets");
throw;
}
}
[HttpPost]
public void UpdateOrder(OrderBindingModel model)
{
try
{
_order.Update(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Error during loading list of bouquets");
throw;
}
}
[HttpPost]
public void OrderAddTablewares(Tuple<OrderBindingModel, TablewareBindingModel, int> model)
{
try
{
_order.UpdateTablewares(model.Item1, model.Item2, model.Item3);
}
catch (Exception ex)
{
_logger.LogError(ex, "Error during loading list of bouquets");
throw;
}
}
[HttpPost]
public void OrderAddCooks(Tuple<OrderBindingModel, CookBindingModel> model)
{
try
{
_order.UpdateCooks(model.Item1, model.Item2);
}
catch (Exception ex)
{
_logger.LogError(ex, "Error during loading list of bouquets");
throw;
}
}
[HttpPost]
public void CreateLunch(LunchBindingModel model)
{
try
{
_lunch.Create(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Error during loading list of bouquets");
throw;
}
}
[HttpPost]
public void DeleteLunch(LunchBindingModel model)
{
try
{
_lunch.Delete(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Error during loading list of bouquets");
throw;
}
}
[HttpPost]
public void UpdateLunch(LunchBindingModel model)
{
try
{
_lunch.Update(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Error during loading list of bouquets");
throw;
}
}
[HttpPost]
public void LunchAddOrders(Tuple<LunchBindingModel, OrderBindingModel> model)
{
try
{
_lunch.UpdateOrders(model.Item1, model.Item2);
}
catch (Exception ex)
{
_logger.LogError(ex, "Error during loading list of bouquets");
throw;
}
}
[HttpPost]
public void LunchAddProducts(Tuple<LunchBindingModel, ProductBindingModel, int> model)
{
try
{
_lunch.UpdateProducts(model.Item1, model.Item2, model.Item3);
}
catch (Exception ex)
{
_logger.LogError(ex, "Error during loading list of bouquets");
throw;
}
}
[HttpGet]
public List<LunchViewModel>? GetLunchList(int visitorId)
{
try
{
return _lunch.ReadList(new LunchSearchModel { VisitorId = visitorId });
}
catch (Exception ex)
{
_logger.LogError(ex, "Error during loading list of bouquets");
throw;
}
}
[HttpGet]
2023-05-17 17:59:48 +04:00
public GraphicViewModel[] GetGraphic()
{
return new GraphicViewModel[]
{
_gl.GetGraphicByCount(),
_gl.GetGraphicByPrice()
};
}
2023-04-09 19:05:54 +04:00
}
}