97 lines
2.6 KiB
C#
97 lines
2.6 KiB
C#
|
using Microsoft.AspNetCore.Mvc;
|
|||
|
using Microsoft.AspNetCore.Mvc.Formatters;
|
|||
|
using ServiceSourceClientApp.Models;
|
|||
|
using ServiceSourceExecutorApp;
|
|||
|
using ServiceStationContracts.BindingModels;
|
|||
|
using ServiceStationContracts.ViewModels;
|
|||
|
using System.Diagnostics;
|
|||
|
|
|||
|
namespace ServiceSourceClientApp.Controllers {
|
|||
|
public class HomeController : Controller {
|
|||
|
private readonly ILogger<HomeController> _logger;
|
|||
|
|
|||
|
public HomeController(ILogger<HomeController> logger) {
|
|||
|
_logger = logger;
|
|||
|
}
|
|||
|
|
|||
|
[HttpGet]
|
|||
|
public IActionResult Index() {
|
|||
|
if (APIClient.executor == null) {
|
|||
|
return Redirect("~/Home/Enter");
|
|||
|
}
|
|||
|
return View();
|
|||
|
}
|
|||
|
|
|||
|
[HttpGet]
|
|||
|
public IActionResult Enter() {
|
|||
|
return View();
|
|||
|
}
|
|||
|
|
|||
|
[HttpPost]
|
|||
|
public void Enter(string email, string password) {
|
|||
|
if (string.IsNullOrEmpty(email) || string.IsNullOrEmpty(password)) {
|
|||
|
throw new Exception("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
|||
|
}
|
|||
|
APIClient.executor = APIClient.GetRequest<ExecutorViewModel>($"api/main/Login?email={email}&password={password}");
|
|||
|
if (APIClient.executor == null) {
|
|||
|
throw new Exception("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
|||
|
}
|
|||
|
Response.Redirect("Index");
|
|||
|
}
|
|||
|
|
|||
|
[HttpGet]
|
|||
|
public IActionResult Register() {
|
|||
|
return View();
|
|||
|
}
|
|||
|
|
|||
|
[HttpPost]
|
|||
|
public void Register(string email, string password, string fio) {
|
|||
|
if (string.IsNullOrEmpty(email) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(fio)) {
|
|||
|
throw new Exception("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>, <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD>");
|
|||
|
}
|
|||
|
APIClient.PostRequest("api/Main/Register", new ExecutorBindingModel {
|
|||
|
Email = email,
|
|||
|
Password = password,
|
|||
|
FIO = fio
|
|||
|
});
|
|||
|
Response.Redirect("Enter");
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
[HttpGet]
|
|||
|
public IActionResult Privacy() {
|
|||
|
if (APIClient.executor == null) {
|
|||
|
return Redirect("~/Home/Enter");
|
|||
|
}
|
|||
|
return View(APIClient.executor);
|
|||
|
}
|
|||
|
|
|||
|
[HttpPost]
|
|||
|
public void Privacy(string email, string password, string fio) {
|
|||
|
if (APIClient.executor == null) {
|
|||
|
Response.Redirect("~/Home/Enter");
|
|||
|
return;
|
|||
|
}
|
|||
|
if (string.IsNullOrEmpty(email) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(fio)) {
|
|||
|
throw new Exception("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>, <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD>");
|
|||
|
}
|
|||
|
APIClient.PostRequest("api/Main/UpdateData", new ExecutorBindingModel {
|
|||
|
Id = APIClient.executor.Id,
|
|||
|
Email = email,
|
|||
|
Password = password,
|
|||
|
FIO = fio
|
|||
|
});
|
|||
|
|
|||
|
APIClient.executor.FIO = fio;
|
|||
|
APIClient.executor.Email = email;
|
|||
|
APIClient.executor.Password = password;
|
|||
|
Response.Redirect("Index");
|
|||
|
}
|
|||
|
|
|||
|
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
|||
|
public IActionResult Error() {
|
|||
|
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
|
|||
|
}
|
|||
|
}
|
|||
|
}
|