107 lines
2.1 KiB
C#
107 lines
2.1 KiB
C#
using ComputerShopContracts.BindingModels;
|
||
using ComputerShopContracts.BusinessLogicContracts;
|
||
using ComputerShopContracts.SearchModels;
|
||
using ComputerShopContracts.ViewModels;
|
||
using ComputerShopDataModels.Enums;
|
||
using Microsoft.AspNetCore.Mvc;
|
||
|
||
namespace ComputerShopRestApi.Controllers
|
||
{
|
||
[Route("api/[controller]/[action]")]
|
||
[ApiController]
|
||
public class UserController : Controller
|
||
{
|
||
private readonly ILogger _logger;
|
||
private readonly IUserLogic _logic;
|
||
|
||
public UserController(IUserLogic logic, ILogger<UserController> logger)
|
||
{
|
||
_logic = logic;
|
||
_logger = logger;
|
||
}
|
||
|
||
|
||
[HttpGet]
|
||
public UserViewModel? LoginImplementer(string login, string password)
|
||
{
|
||
try
|
||
{
|
||
return _logic.ReadElement(new UserSearchModel
|
||
{
|
||
Login = login,
|
||
Password = password,
|
||
Role = UserRole.Исполнитель
|
||
});
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
_logger.LogError(ex, "Ошибка входа в систему");
|
||
throw;
|
||
}
|
||
}
|
||
|
||
[HttpGet]
|
||
public UserViewModel? LoginGuarantor(string login, string password)
|
||
{
|
||
try
|
||
{
|
||
return _logic.ReadElement(new UserSearchModel
|
||
{
|
||
Login = login,
|
||
Password = password,
|
||
Role = UserRole.Поручитель
|
||
});
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
_logger.LogError(ex, "Ошибка входа в систему");
|
||
throw;
|
||
}
|
||
}
|
||
|
||
[HttpPost]
|
||
public void RegisterImplementer(UserBindingModel model)
|
||
{
|
||
try
|
||
{
|
||
model.Role = UserRole.Исполнитель;
|
||
_logic.Create(model);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
_logger.LogError(ex, "Ошибка регистрации");
|
||
throw;
|
||
}
|
||
}
|
||
|
||
[HttpPost]
|
||
public void RegisterGuarantor(UserBindingModel model)
|
||
{
|
||
try
|
||
{
|
||
model.Role = UserRole.Поручитель;
|
||
_logic.Create(model);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
_logger.LogError(ex, "Ошибка регистрации");
|
||
throw;
|
||
}
|
||
}
|
||
|
||
[HttpPost]
|
||
public void UpdateData(UserBindingModel model)
|
||
{
|
||
try
|
||
{
|
||
_logic.Update(model);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
_logger.LogError(ex, "Ошибка обновления данных");
|
||
throw;
|
||
}
|
||
}
|
||
}
|
||
}
|