81 lines
1.4 KiB
C#
81 lines
1.4 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;
|
|
}
|
|
}
|
|
|
|
[HttpGet]
|
|
public UserViewModel? Get(int id)
|
|
{
|
|
try
|
|
{
|
|
return _logic.ReadElement(new UserSearchModel { Id = id });
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
[HttpPost]
|
|
public void Register(UserBindingModel model)
|
|
{
|
|
try
|
|
{
|
|
_logic.Create(model);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
[HttpPost]
|
|
public UserViewModel Update(UserBindingModel model)
|
|
{
|
|
try
|
|
{
|
|
return _logic.Update(model);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
}
|
|
}
|