CourseWorkElectronicsShop/ElectronicsShop/ElectronicsShopRestAPI/Controllers/ClientController.cs

82 lines
2.0 KiB
C#
Raw Normal View History

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-05-27 14:57:41 +04:00
2024-06-01 05:00:05 +04:00
public ClientController(ILogger<ClientController> logger, IClientLogic logic, IPaymeantLogic payLogic) {
2024-05-27 14:57:41 +04:00
_logger = logger;
_logic = logic;
2024-06-01 05:00:05 +04:00
_payLogic = payLogic;
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
[HttpPost]
public void CreatePaymeant (PaymeantBindingModel model) {
try {
_payLogic.CreatePay(model);
}
catch (Exception ex) {
_logger.LogError(ex, "Ошибка создания оплаты");
}
}
2024-06-01 05:23:37 +04:00
[HttpPost]
public List<PaymeantViewModel>? GetPaymeants(int _clientID) {
try {
return _payLogic.ReadList(new PaymeantSearchModel { ClientID = _clientID });
}
catch (Exception ex) {
_logger.LogError(ex, $"Ошибка получения списка оплат клиента id = {_clientID}");
throw;
}
}
2024-05-27 14:57:41 +04:00
}
}