2024-05-27 14:57:41 +04:00
|
|
|
|
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;
|
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-02 09:03:59 +04:00
|
|
|
|
[HttpPost]
|
|
|
|
|
public List<ReportPaymeantsViewModel>? GetReport(DateTime _start, DateTime _end) {
|
|
|
|
|
var dataSource = _reportLogic.GetPaymeants(new ReportBindingModel { });
|
|
|
|
|
return dataSource;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-05-27 14:57:41 +04:00
|
|
|
|
}
|