using CaseAccountingContracts.BindingModels; using CaseAccountingContracts.ViewModels; using CaseAccountingCustomerView.Models; using CaseAccountingDataModels.Enum; using Microsoft.AspNetCore.Mvc; using System.Diagnostics; namespace CaseAccountingCustomerView.Controllers { public class HomeController : Controller { public HomeController() { } public IActionResult Index() { if (APIUser.User == null) { return Redirect("~/Home/Login"); } return View(); } public IActionResult Login() { return View(); } public IActionResult Registration() { return View(); } [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.Customer}"); 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.Customer }); Response.Redirect("Login"); return; } public IActionResult Lawyers( ) { if (APIUser.User == null) { return Redirect("~/Home/Enter"); } ViewBag.Lawyers = APIUser.GetRequest> ($"api/lawyer/getallbyuser?userId={APIUser.User.Id}"); return View(); } public IActionResult Specializations() { if (APIUser.User == null) { return Redirect("~/Home/Enter"); } ViewBag.Specializations = APIUser.GetRequest> ($"api/specialization/getallbyuser?userId={APIUser.User.Id}"); return View(); } public IActionResult Contracts() { if (APIUser.User == null) { return Redirect("~/Home/Enter"); } ViewBag.Contracts = APIUser.GetRequest> ($"api/contract/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 }); } [HttpPost] public int[]? SpecializationCaselist([FromBody] LawyerHearingListBindingModel listModel) { if (APIUser.User == null) { return Array.Empty(); } byte[]? file = APIUser.PostRequestWithResult ("api/reportprovider/specializationcaselist", listModel); return file!.Select(b => (int)b).ToArray(); } public IActionResult HearingLawyerList() { return View(); } } }