PIbd-21_Pyatakov_KM_Markov_.../UniversityRestAPI/Controllers/UserController.cs

68 lines
1.1 KiB
C#

using Microsoft.AspNetCore.Mvc;
using UniversityContracts.BindingModels;
using UniversityContracts.BusinessLogicContracts;
using UniversityContracts.SearchModels;
using UniversityContracts.ViewModels;
using UniversityDataBaseImplemet.Models;
using UniversityModels.Enums;
namespace UniversityRestAPI.Controllers
{
[Route("api/[controller]/[action]")]
[ApiController]
public class UserController : Controller
{
private readonly IUserLogic _logic;
public UserController(IUserLogic logic, ILogger<UserController> logger)
{
_logic = logic;
}
[HttpGet]
public UserViewModel? Login(string login, string password, Role role)
{
try
{
return _logic.ReadElement(new UserSearchModel
{
Login = login,
Password = password,
Role = role
});
}
catch (Exception ex)
{
throw;
}
}
[HttpPost]
public void Register(UserBindingModel model)
{
try
{
_logic.Create(model);
}
catch (Exception ex)
{
throw;
}
}
[HttpPost]
public void UpdateData(UserBindingModel model)
{
try
{
_logic.Update(model);
}
catch (Exception ex)
{
throw;
}
}
}
}