CourseWork/University/UniversityClientApp/Controllers/HomeController.cs
2024-05-26 22:28:34 +04:00

103 lines
2.6 KiB
C#

using Microsoft.AspNetCore.Mvc;
using System.Diagnostics;
using UniversityClientApp.Models;
using UniversityClientAppStorekeeper;
using UniversityContracts.BindingModels;
using UniversityContracts.ViewModels;
using UniversityDataModels.Enums;
namespace UniversityClientApp.Controllers
{
public class HomeController : Controller
{
private readonly ILogger<HomeController> _logger;
public HomeController(ILogger<HomeController> logger)
{
_logger = logger;
}
public IActionResult Index()
{
if (APIStorekeeper.Client == null)
{
return Redirect("~/Home/Enter");
}
//return View(APIStorekeeper.GetRequest<List<OrderViewModel>>($"api/main/getorders?clientId={APIClient.Client.Id}"));
return View();
}
public IActionResult Privacy()
{
return View();
}
[HttpGet]
public IActionResult Enter()
{
return View();
}
[HttpPost]
public void Enter(string login, string password)
{
if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password))
{
throw new Exception("Ââåäèòå ëîãèí è ïàðîëü");
}
APIStorekeeper.Client = APIStorekeeper.GetRequest<UserViewModel>($"api/user/loginstorekeeper?login={login}&password={password}");
if (APIStorekeeper.Client == null)
{
throw new Exception("Íåâåðíûé ëîãèí/ïàðîëü");
}
Response.Redirect("Index");
}
[HttpGet]
public IActionResult Register()
{
return View();
}
[HttpPost]
public void Register(string login, string password, string email)
{
if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(email))
{
throw new Exception("Ââåäèòå ëîãèí, ïàðîëü è ÔÈÎ");
}
APIStorekeeper.PostRequest("api/user/registerstorekeeper", new UserBindingModel
{
Login = login,
Email = email,
Password = password,
Role = UserRole.Êëàäîâùèê
});
Response.Redirect("Enter");
return;
}
public IActionResult Disciplines()
{
return View();
}
public IActionResult Statements()
{
return View();
}
public IActionResult Teachers()
{
return View();
}
public IActionResult Report() {
return View();
}
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public IActionResult Error()
{
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
}
}
}