using HospitalContracts.BindingModels; using HospitalContracts.ViewModels; using HospitalDataModels.Enums; using HospitalWebApp.Models; using Microsoft.AspNetCore.Mvc; using System.Diagnostics; namespace HospitalWebApp.Controllers { /// /// Главный контроллер /// public class HomeController : Controller { /// /// Логгер /// private readonly ILogger _logger; /// /// Конструктор /// /// public HomeController(ILogger logger) { _logger = logger; } /// /// Домашняя страница /// /// [HttpGet] public IActionResult MainPage() { if (APIClient.Doctor == null) { return Redirect("~/Home/Enter"); } return View(APIClient.Doctor); } /// /// Личные данные доктора /// /// [HttpGet] public IActionResult Privacy() { if (APIClient.Doctor == null) { return Redirect("~/Home/Enter"); } return View(APIClient.Doctor); } /// /// Личные данные доктора /// /// /// /// /// /// [HttpPost] public void Privacy(string fullname, DoctorPost post, string email, string password) { if (APIClient.Doctor == null) { throw new Exception("Необходимо авторизоваться!"); } if (string.IsNullOrEmpty(fullname) || string.IsNullOrEmpty(email) || string.IsNullOrEmpty(password)) { throw new Exception("Введены не все данные!"); } APIClient.PostRequest("api/doctor/update", new DoctorBindingModel { Id = APIClient.Doctor.Id, FullName = fullname, Post = post, Email = email, Password = password }); APIClient.Doctor.FullName = fullname; APIClient.Doctor.Post = post; APIClient.Doctor.Email = email; APIClient.Doctor.Password = password; Response.Redirect("Privacy"); } /// /// Аутентификация /// /// [HttpGet] public IActionResult Enter() { return View(); } /// /// Аутентификация /// /// /// /// [HttpPost] public void Enter(string email, string password) { if (string.IsNullOrEmpty(email) || string.IsNullOrEmpty(password)) { throw new Exception("Введены не все данные!"); } APIClient.Doctor = APIClient.GetRequest($"api/doctor/login?email={email}&password={password}"); if (APIClient.Doctor == null) { throw new Exception("Неверный логин/пароль"); } Response.Redirect("MainPage"); } /// /// Регистрация /// /// [HttpGet] public IActionResult Register() { return View(); } /// /// Регистрация /// /// /// /// /// /// [HttpPost] public void Register(string fullname, DoctorPost post, string email, string password) { if (string.IsNullOrEmpty(fullname) || string.IsNullOrEmpty(email) || string.IsNullOrEmpty(password)) { throw new Exception("Введены не все данные!"); } APIClient.PostRequest("api/doctor/register", new DoctorBindingModel { FullName = fullname, Post = post, Email = email, Password = password }); Response.Redirect("Enter"); } /// /// Ошибка /// /// [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] public IActionResult Error() { return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier }); } } }