PIbd-22_Chernyshev_Shabunov.../ComputerShopRestApi/Controllers/UserController.cs

107 lines
2.1 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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;
}
}
}
}