using Microsoft.AspNetCore.Mvc; using SchoolClientApp.Models; using SchoolContracts.BindingModel; using SchoolContracts.ViewModels; using SchoolDatabaseImplement.Models; using System.Diagnostics; namespace SchoolClientApp.Controllers { public class HomeController : Controller { private readonly ILogger _logger; public HomeController(ILogger logger) { _logger = logger; } public IActionResult Index() { if(ClientApp.Client == null) { return Redirect("~/Home/Enter"); } return View(ClientApp.GetRequest>($"api/main/getorders?clientId={ClientApp.Client.Id}")); } public IActionResult Privacy() { if (ClientApp.Client == null) { return Redirect("~/Home/Enter"); } return View(ClientApp.Client); } [HttpPost] public void Privacy(string login, string password, string fio) { if (ClientApp.Client == null) { throw new Exception("Вы как суда попали? Суда вход только авторизованным"); } if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(fio)) { throw new Exception("Введите логин, пароль и ФИО"); } ClientApp.PostRequest("api/client/updatedata", new ClientBindingModel { Id = ClientApp.Client.Id, ClientName = fio, ClientEmail = login, ClientPassword = password }); ClientApp.Client.ClientName = fio; ClientApp.Client.ClientEmail = login; ClientApp.Client.ClientPassword = 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 }); } [HttpGet] public IActionResult Enter() { return View(); } [HttpPost] public void Enter(string login, string password) { if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password)) { throw new Exception("Введите логин и пароль"); } ClientApp.Client = ClientApp.GetRequest($"api/client/login?login={login}&password={password}"); if (ClientApp.Client == null) { throw new Exception("Неверный логин/пароль"); } Response.Redirect("Index"); } [HttpGet] public IActionResult Register() { return View(); } [HttpPost] public void Register(string login, string password, string fio) { if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(fio)) { throw new Exception("Введите логин, пароль и ФИО"); } ClientApp.PostRequest("api/client/register", new ClientBindingModel { ClientName = fio, ClientEmail = login, ClientPassword = password }); Response.Redirect("Enter"); return; } [HttpGet] public IActionResult Create() { ViewBag.Circles = ClientApp.GetRequest>("api/main/getcarlist"); return View(); } [HttpPost] public void Create(int circle, DateTime date, double sum) { if (ClientApp.Client == null) { throw new Exception("Вы как суда попали? Суда вход только авторизованным"); } ClientApp.PostRequest("api/main/createcircle", new CircleBindingModel { ClientId = ClientApp.Client.Id, Id = circle, DateStart = date, //TODO //Remains = Calc(sum) }); Response.Redirect("Index"); } [HttpPost] public double Calc( double sum, int circle) { //TODO //var c = //ClientApp.GetRequest($"api/main/getcircle?circleId={circle}" //); //return Remains; return 0; } } }