CourseWorkElectronicsShop/ElectronicsShop/ElectronicsShopRestAPI/Controllers/ClientController.cs
Илья Федотов 642291fa0a xlsx reports exports
2024-07-09 19:40:24 +04:00

111 lines
2.9 KiB
C#

using DocumentFormat.OpenXml.Drawing.Diagrams;
using DocumentFormat.OpenXml.Packaging;
using ElectronicsShopContracts.BindingModels;
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;
private readonly IPaymeantLogic _payLogic;
private readonly IReportClientLogic _reportLogic;
public ClientController(ILogger<ClientController> logger, IClientLogic logic, IPaymeantLogic payLogic, IReportClientLogic reportlogic) {
_logger = logger;
_logic = logic;
_payLogic = payLogic;
_reportLogic = reportlogic;
}
[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;
}
}
[HttpPost]
public void CreatePaymeant (PaymeantBindingModel model) {
try {
_payLogic.CreatePay(model);
}
catch (Exception ex) {
_logger.LogError(ex, "Ошибка создания оплаты");
}
}
[HttpGet]
public List<PaymeantViewModel>? GetPaymeants(int _clientID) {
try {
return _payLogic?.ReadList(new PaymeantSearchModel { ClientID = _clientID });
}
catch (Exception ex) {
_logger.LogError(ex, $"Ошибка получения списка оплат клиента id = {_clientID}");
throw;
}
}
[HttpGet]
public List<ReportPaymeantsViewModel>? GetReport(DateTime _start, DateTime _end) {
try {
var dataSource = _reportLogic.GetPaymeants(new ReportBindingModel {
DateFrom = _start,
DateTo = _end
});
return dataSource;
}
catch (Exception ex) {
_logger.LogError(ex, $"Ошибка получения данных");
throw;
}
}
[HttpGet]
public byte[] CreateXlsxReport (int _clientID) {
try {
var document = _reportLogic.SavePaymeantToExcelFile (null, _clientID);
return document;
}
catch (Exception ex) {
_logger.LogError(ex, $"Ошибка создания файла");
throw;
}
}
}
}