2024-05-29 17:52:23 +04:00
|
|
|
|
using ComputerShopBusinessLogic.MailWorker;
|
|
|
|
|
using ComputerShopContracts.BindingModels;
|
2024-05-02 00:10:15 +04:00
|
|
|
|
using ComputerShopContracts.BusinessLogicContracts;
|
|
|
|
|
using ComputerShopContracts.SearchModels;
|
|
|
|
|
using ComputerShopContracts.ViewModels;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
|
|
|
|
|
namespace ComputerShopRestApi.Controllers
|
|
|
|
|
{
|
|
|
|
|
[Route("api/[controller]/[action]")]
|
|
|
|
|
[ApiController]
|
|
|
|
|
public class ComponentController : Controller
|
|
|
|
|
{
|
|
|
|
|
private readonly ILogger _logger;
|
|
|
|
|
private readonly IComponentLogic _componentLogic;
|
2024-05-29 17:52:23 +04:00
|
|
|
|
private readonly IReportGuarantorLogic _reportLogic;
|
|
|
|
|
private readonly AbstractMailWorker _mailWorker;
|
2024-05-02 00:10:15 +04:00
|
|
|
|
|
2024-05-29 17:52:23 +04:00
|
|
|
|
public ComponentController(IComponentLogic Logic, ILogger<ComponentController> Logger, IReportGuarantorLogic ReportLogic, AbstractMailWorker MailWorker)
|
2024-05-02 00:10:15 +04:00
|
|
|
|
{
|
|
|
|
|
_logger = Logger;
|
|
|
|
|
_componentLogic = Logic;
|
2024-05-29 17:52:23 +04:00
|
|
|
|
_reportLogic = ReportLogic;
|
|
|
|
|
_mailWorker = MailWorker;
|
2024-05-02 00:10:15 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public ComponentViewModel? GetComponent(int Id)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return _componentLogic.ReadElement(new ComponentSearchModel
|
|
|
|
|
{
|
|
|
|
|
Id = Id
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка получения комплектующей");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public List<ComponentViewModel>? GetComponents(int? UserId)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return _componentLogic.ReadList(new ComponentSearchModel
|
|
|
|
|
{
|
|
|
|
|
UserId = UserId
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка получения списка комплектующих пользователя с Id = {Id}", UserId);
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public void CreateComponent(ComponentBindingModel Model)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_componentLogic.Create(Model);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка создания комплектующей");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public void UpdateComponent(ComponentBindingModel Model)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_componentLogic.Update(Model);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка обновления комплектующей");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-29 01:02:20 +04:00
|
|
|
|
[HttpPost]
|
2024-05-02 00:10:15 +04:00
|
|
|
|
public void DeleteComponent(ComponentBindingModel Model)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_componentLogic.Delete(Model);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка удаления комплектующей");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-05-29 17:52:23 +04:00
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public void CreateReportToWordFile(ReportBindingModel Model)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_reportLogic.SaveReportToWordFile(Model);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка создания отчета");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public void CreateReportToExcelFile(ReportBindingModel Model)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_reportLogic.SaveReportToExcelFile(Model);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка создания отчета");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public void CreateReportToPdfFile(ReportBindingModel Model)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);
|
|
|
|
|
_reportLogic.SaveReportComponentsByRequestDateToPdfFile(Model);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка создания отчета");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public void SendPdfToMail(MailSendInfoBindingModel Model)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_mailWorker.MailSendAsync(Model);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка отправки письма");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-05-02 00:10:15 +04:00
|
|
|
|
}
|
|
|
|
|
}
|