CourseWorkElectronicsShop/ElectronicsShop/ElectronicsShopRestAPI/Controllers/ClientController.cs

123 lines
3.2 KiB
C#
Raw Normal View History

2024-07-09 19:40:24 +04:00
using DocumentFormat.OpenXml.Drawing.Diagrams;
using DocumentFormat.OpenXml.Packaging;
using ElectronicsShopContracts.BindingModels;
2024-05-27 14:57:41 +04:00
using ElectronicsShopContracts.BusinessLogicContracts;
using ElectronicsShopContracts.SearchModels;
using ElectronicsShopContracts.ViewModels;
using Microsoft.AspNetCore.Mvc;
namespace ElectronicsShopRestAPI.Controllers {
[Route("api/[controller]/[action]")]
[ApiController]
public class ClientController : Controller {
private readonly ILogger _logger;
private readonly IClientLogic _logic;
2024-06-01 05:00:05 +04:00
private readonly IPaymeantLogic _payLogic;
2024-06-02 09:03:59 +04:00
private readonly IReportClientLogic _reportLogic;
2024-05-27 14:57:41 +04:00
2024-06-02 09:03:59 +04:00
public ClientController(ILogger<ClientController> logger, IClientLogic logic, IPaymeantLogic payLogic, IReportClientLogic reportlogic) {
2024-05-27 14:57:41 +04:00
_logger = logger;
_logic = logic;
2024-06-01 05:00:05 +04:00
_payLogic = payLogic;
2024-06-02 09:03:59 +04:00
_reportLogic = reportlogic;
2024-05-27 14:57:41 +04:00
}
[HttpGet]
public ClientViewModel? Login(string email, string password) {
try {
return _logic.ReadElemet(new ClientSearchModel {
Email = email,
Passwrod = password
});
}
catch (Exception ex) {
_logger.LogError(ex, "Ошибка входа в систему");
throw;
}
}
[HttpPost]
public void Register(ClientBindingModel model) {
try {
_logic.Create(model);
}
catch (Exception ex) {
_logger.LogError(ex, "Ошибка регистрации");
throw;
}
}
[HttpPost]
public void UpdateData(ClientBindingModel model) {
try {
_logic.Update(model);
}
catch (Exception ex) {
_logger.LogError(ex, "Ошибка обновления данных");
throw;
}
}
2024-06-01 05:00:05 +04:00
2024-06-01 06:50:29 +04:00
[HttpPost]
2024-06-01 05:00:05 +04:00
public void CreatePaymeant (PaymeantBindingModel model) {
try {
_payLogic.CreatePay(model);
}
catch (Exception ex) {
_logger.LogError(ex, "Ошибка создания оплаты");
}
}
2024-06-01 06:32:19 +04:00
[HttpGet]
2024-06-01 05:23:37 +04:00
public List<PaymeantViewModel>? GetPaymeants(int _clientID) {
try {
2024-06-01 06:32:19 +04:00
return _payLogic?.ReadList(new PaymeantSearchModel { ClientID = _clientID });
2024-06-01 05:23:37 +04:00
}
catch (Exception ex) {
_logger.LogError(ex, $"Ошибка получения списка оплат клиента id = {_clientID}");
throw;
}
}
2024-06-06 17:21:39 +04:00
[HttpGet]
2024-06-02 09:03:59 +04:00
public List<ReportPaymeantsViewModel>? GetReport(DateTime _start, DateTime _end) {
2024-06-06 17:21:39 +04:00
try {
var dataSource = _reportLogic.GetPaymeants(new ReportBindingModel {
DateFrom = _start,
DateTo = _end
});
return dataSource;
}
catch (Exception ex) {
_logger.LogError(ex, $"Ошибка получения данных");
throw;
}
2024-06-02 09:03:59 +04:00
}
2024-07-09 19:40:24 +04:00
[HttpGet]
public byte[] CreateXlsxReport (int _clientID) {
try {
2024-07-10 18:32:46 +04:00
var document = _reportLogic.SavePaymeantToExcelFile (_clientID);
return document;
}
catch (Exception ex) {
_logger.LogError(ex, $"Ошибка создания файла");
throw;
}
}
[HttpGet]
public byte[] CreateDocxReport (int _clientID) {
try {
var document = _reportLogic.SavePaymeantToWordFile (_clientID);
2024-07-09 19:40:24 +04:00
return document;
}
catch (Exception ex) {
_logger.LogError(ex, $"Ошибка создания файла");
throw;
}
}
2024-06-02 09:03:59 +04:00
}
2024-05-27 14:57:41 +04:00
}