109 lines
3.3 KiB
C#
Raw Normal View History

2023-05-17 17:48:12 +04:00
using HospitalContracts.BindingModels;
using HospitalContracts.ViewModels;
using HospitalDatabaseImplement;
using HospitalWeb.Models;
using Microsoft.AspNetCore.Mvc;
using System.Diagnostics;
namespace HospitalWeb.Controllers
{
public class HomeController : Controller
{
private readonly ILogger<HomeController> _logger;
public HomeController(ILogger<HomeController> logger)
{
2023-05-17 17:48:12 +04:00
_logger = logger;
}
public IActionResult Index()
{
2023-05-19 14:45:26 +04:00
return View();
}
2023-05-17 17:48:12 +04:00
[HttpGet]
public IActionResult Privacy()
2023-05-17 17:48:12 +04:00
{
if (APIClient.Apothecary == null)
{
return Redirect("~/Home/Enter");
}
return View(APIClient.Apothecary);
}
[HttpPost]
public void Privacy(string login, string password)
{
if (APIClient.Apothecary == null)
{
throw new Exception("Доступно только авторизованным пользователям");
}
if (string.IsNullOrEmpty(login) ||
string.IsNullOrEmpty(password))
{
throw new Exception("Введите логин и пароль");
}
APIClient.PostRequest("api/apothecary/updatedata", new
ApothecaryBindingModel
{
Id = APIClient.Apothecary.Id,
Login = login,
Password = password
});
APIClient.Apothecary.Login = login;
APIClient.Apothecary.Password = password;
Response.Redirect("Index");
}
[HttpGet]
public IActionResult Enter()
{
return View();
}
2023-05-17 17:48:12 +04:00
[HttpPost]
public void Enter(string login, string password)
{
if (string.IsNullOrEmpty(login) ||
string.IsNullOrEmpty(password))
{
throw new Exception("Введите логин и пароль");
}
APIClient.Apothecary =
APIClient.GetRequest<ApothecaryViewModel>($"api/apothecary/login?login={login}&password={password}");
if (APIClient.Apothecary == null)
{
throw new Exception("Неверный логин/пароль");
}
Response.Redirect("Index");
}
[HttpGet]
public IActionResult Register()
{
return View();
}
[HttpPost]
public void Register(string login, string password)
{
if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password))
{
throw new Exception("Введите логин и пароль");
}
APIClient.PostRequest("api/apothecary/register", new
ApothecaryBindingModel
{
Login = login,
Password = password
});
Response.Redirect("Enter");
return;
}
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public IActionResult Error()
{
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
}
}
}