2024-04-27 22:46:09 +04:00
|
|
|
|
using ComputerShopContracts.BindingModels;
|
|
|
|
|
using ComputerShopContracts.BusinessLogicContracts;
|
|
|
|
|
using ComputerShopContracts.SearchModels;
|
|
|
|
|
using ComputerShopContracts.ViewModels;
|
2024-05-28 19:40:32 +04:00
|
|
|
|
using ComputerShopBusinessLogic.MailWorker;
|
2024-04-28 21:00:55 +04:00
|
|
|
|
using ComputerShopDatabaseImplement.Models;
|
2024-05-26 19:33:48 +04:00
|
|
|
|
using ComputerShopDataModels.Enums;
|
2024-04-27 22:46:09 +04:00
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
|
|
|
|
|
namespace ComputerShopRestApi.Controllers
|
|
|
|
|
{
|
|
|
|
|
[Route("api/[controller]/[action]")]
|
|
|
|
|
[ApiController]
|
|
|
|
|
public class OrderController : Controller
|
|
|
|
|
{
|
|
|
|
|
private readonly ILogger _logger;
|
|
|
|
|
|
|
|
|
|
private readonly IOrderLogic _logic;
|
|
|
|
|
|
2024-05-28 14:34:16 +04:00
|
|
|
|
private readonly IReportImplementerLogic _reportLogic;
|
|
|
|
|
|
2024-05-28 19:40:32 +04:00
|
|
|
|
private readonly AbstractMailWorker _mailWorker;
|
|
|
|
|
|
|
|
|
|
public OrderController(IOrderLogic logic, ILogger<OrderController> logger, IReportImplementerLogic reportLogic, AbstractMailWorker mailWorker)
|
2024-04-27 22:46:09 +04:00
|
|
|
|
{
|
|
|
|
|
_logger = logger;
|
|
|
|
|
_logic = logic;
|
2024-05-28 14:34:16 +04:00
|
|
|
|
_reportLogic = reportLogic;
|
2024-05-28 19:40:32 +04:00
|
|
|
|
_mailWorker = mailWorker;
|
2024-04-27 22:46:09 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public OrderViewModel? GetOrder(int id)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return _logic.ReadElement(new OrderSearchModel
|
|
|
|
|
{
|
|
|
|
|
Id = id
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка получения заказа");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-04-28 21:00:55 +04:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Получение заказов по id пользователя (полный список, кот. будет выводиться)
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="userId"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public List<OrderViewModel>? GetOrders(int? userId)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return _logic.ReadList(new OrderSearchModel { UserId = userId });
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка получения списка заказов клиента id={Id}", userId);
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-28 14:34:16 +04:00
|
|
|
|
[HttpPost]
|
|
|
|
|
public void CreateReportToWordFile(ReportBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_reportLogic.SaveReportOrderAssembliesToWordFile(model);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка создания отчета");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-05-26 19:33:48 +04:00
|
|
|
|
|
2024-05-28 14:34:16 +04:00
|
|
|
|
[HttpPost]
|
|
|
|
|
public void CreateReportToExcelFile(ReportBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_reportLogic.SaveReportOrderAssembliesToExcelFile(model);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка создания отчета");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-28 15:31:13 +04:00
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public void CreateReportToPDFFile(ReportBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_reportLogic.SaveReportOrdersByDatesToPdfFile(model);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка создания отчета");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-05-28 14:34:16 +04:00
|
|
|
|
|
2024-05-28 19:40:32 +04:00
|
|
|
|
[HttpPost]
|
|
|
|
|
public void SendPDFToMail(MailSendInfoBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_mailWorker.MailSendAsync(model);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка отправки письма");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
2024-04-27 22:46:09 +04:00
|
|
|
|
public void CreateOrder(OrderBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_logic.Create(model);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка создания заказа");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public void UpdateOrder(OrderBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_logic.Update(model);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка обновления заказа");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-04-30 22:44:30 +04:00
|
|
|
|
|
2024-05-26 19:33:48 +04:00
|
|
|
|
[HttpPost]
|
2024-04-27 22:46:09 +04:00
|
|
|
|
public void DeleteOrder(OrderBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_logic.Delete(model);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка удаления заказа");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|