using Microsoft.AspNetCore.Mvc; using SchoolAgainStudyContracts.BindingModel; using StudentWebClient.Models; using System.Diagnostics; namespace StudentWebClient.Controllers { public class HomeController : Controller { private readonly ILogger _logger; public HomeController(ILogger logger) { _logger = logger; } public IActionResult Index() { if (APIClient.Student == null) { return Redirect("~/Home/Enter"); } return View(); } [HttpGet] public IActionResult Privacy() { if (APIClient.Student == null) { return Redirect("~/Home/Enter"); } return View(APIClient.Student); } [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] public IActionResult Error() { return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier }); } [HttpPost] public void Privacy(string name, string email,string login, string password, int scClass) { if (APIClient.Student == null) { throw new Exception("Вы как суда попали? Суда вход только авторизованным"); } if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(name) || string.IsNullOrEmpty(email) || scClass<=0 || scClass > 11) { throw new Exception("Введите данные"); } APIClient.PostRequest("api/client/updatedata", new StudentBindingModel { Id = APIClient.Student.Id, Name = name, Email = login, Password = password, Login = login, Class = scClass }); APIClient.Student.Name = name; APIClient.Student.Email = email; APIClient.Student.Password = password; APIClient.Student.Login = login; APIClient.Student.Class = scClass; Response.Redirect("Index"); } } }