using CaseAccountingContracts.BindingModels; using CaseAccountingContracts.ViewModels; using CaseAccountingDataModels.Enum; using CaseAccountingProviderView.Models; using Microsoft.AspNetCore.Mvc; using System.Diagnostics; namespace CaseAccountingProviderView.Controllers { public class HomeController : Controller { private readonly ILogger _logger; public HomeController(ILogger logger) { _logger = logger; } public IActionResult Index() { if (APIUser.User == null) { return Redirect("~/Home/Login"); } return View(); } public IActionResult Login() { return View(); } public IActionResult Registration() { return View(); } public IActionResult SpecializationCaselist() { return View(); } [HttpPost] public int[]? SpecializationCaselist([FromBody] CaseSpecializationListBindingModel listModel) { if (APIUser.User == null) { return Array.Empty(); } byte[]? file = APIUser.PostRequestWithResult ("api/reportprovider/specializationcaselist", listModel); return file!.Select(b => (int)b).ToArray(); } [HttpPost] public void Login(string login, string password) { if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password)) { throw new Exception("Введите логин и пароль"); } APIUser.User = APIUser.GetRequest($"api/user/login?login={login}&password={password}&role={Role.Provider}"); if (APIUser.User == null) { throw new Exception("Неверный логин/пароль"); } Response.Redirect("Index"); } [HttpPost] public void Registration(string login, string password) { if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password)) { throw new Exception("Введите логин и пароль"); } APIUser.PostRequest("api/user/register", new UserBindingModel { Login = login, Password = password, Role = Role.Provider }); Response.Redirect("Login"); return; } public IActionResult Cases() { if (APIUser.User == null) { return Redirect("~/Home/Enter"); } ViewBag.Cases = APIUser.GetRequest> ($"api/case/getallbyuser?userId={APIUser.User.Id}"); return View(); } public IActionResult Deals() { if (APIUser.User == null) { return Redirect("~/Home/Enter"); } ViewBag.Deals = APIUser.GetRequest> ($"api/deal/getallbyuser?userId={APIUser.User.Id}"); return View(); } public IActionResult Hearings() { if (APIUser.User == null) { return Redirect("~/Home/Enter"); } ViewBag.Hearings = APIUser.GetRequest> ($"api/hearing/getallbyuser?userId={APIUser.User.Id}"); return View(); } [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] public IActionResult Error() { return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier }); } } }