2023-05-16 20:05:59 +04:00
|
|
|
|
|
|
|
|
|
using BankYouBankruptClientApp.Models;
|
|
|
|
|
using BankYouBankruptContracts.BindingModels;
|
|
|
|
|
using BankYouBankruptContracts.ViewModels;
|
|
|
|
|
using BankYouBankruptСlientApp;
|
2023-03-31 20:13:22 +04:00
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using System.Diagnostics;
|
2023-05-16 20:05:59 +04:00
|
|
|
|
using System.Xml.Linq;
|
2023-03-31 20:13:22 +04:00
|
|
|
|
|
|
|
|
|
namespace BankYouBankruptClientApp.Controllers
|
|
|
|
|
{
|
2023-05-16 20:05:59 +04:00
|
|
|
|
public class HomeController : Controller
|
|
|
|
|
{
|
2023-04-02 01:17:44 +04:00
|
|
|
|
private readonly ILogger<HomeController> _logger;
|
2023-03-31 20:13:22 +04:00
|
|
|
|
|
2023-04-02 01:17:44 +04:00
|
|
|
|
public HomeController(ILogger<HomeController> logger)
|
|
|
|
|
{
|
|
|
|
|
_logger = logger;
|
|
|
|
|
}
|
2023-03-31 20:13:22 +04:00
|
|
|
|
|
2023-05-16 20:05:59 +04:00
|
|
|
|
//вытаскивает через API клиента Get-запросом список его собственных заказов
|
|
|
|
|
[HttpGet]
|
2023-04-02 01:17:44 +04:00
|
|
|
|
public IActionResult Index()
|
2023-05-16 20:05:59 +04:00
|
|
|
|
{
|
|
|
|
|
if (APIClient.Client == null)
|
|
|
|
|
{
|
|
|
|
|
return Redirect("~/Home/Enter");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return View(APIClient.GetRequest<ClientViewModel>($"api/Client/GetClient?clientId={APIClient.Client.Id}"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[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()
|
2023-04-02 01:17:44 +04:00
|
|
|
|
{
|
|
|
|
|
return View();
|
|
|
|
|
}
|
2023-03-31 20:13:22 +04:00
|
|
|
|
|
2023-05-16 20:05:59 +04:00
|
|
|
|
//отсылаем указанные данные на проверку
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public void Enter(string login, string password)
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password))
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Введите логин и пароль");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
APIClient.Client = APIClient.GetRequest<ClientViewModel>($"api/Client/Login?login={login}&password={password}");
|
|
|
|
|
|
|
|
|
|
if (APIClient.Client == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Неверный логин/пароль");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Response.Redirect("Index");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//просто открытие вьюхи
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public IActionResult Register()
|
2023-04-02 01:17:44 +04:00
|
|
|
|
{
|
|
|
|
|
return View();
|
|
|
|
|
}
|
2023-03-31 20:13:22 +04:00
|
|
|
|
|
2023-05-16 20:05:59 +04:00
|
|
|
|
//Post-запрос по созданию нового пользователя
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public void Register(string login, string password, string name, string surname, string patronymic, string telephone)
|
2023-04-02 01:17:44 +04:00
|
|
|
|
{
|
2023-05-16 20:05:59 +04:00
|
|
|
|
if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(name)
|
|
|
|
|
|| string.IsNullOrEmpty(surname) || string.IsNullOrEmpty(patronymic) || string.IsNullOrEmpty(telephone))
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Введите логин, пароль, ФИО и телефон");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
APIClient.PostRequest("api/Client/Register", new ClientBindingModel
|
|
|
|
|
{
|
|
|
|
|
Name = name,
|
|
|
|
|
Surname = surname,
|
|
|
|
|
Patronymic = patronymic,
|
|
|
|
|
Email = login,
|
|
|
|
|
Password = password,
|
|
|
|
|
Telephone = telephone
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
//переход на вкладку "Enter", чтобы пользователь сразу смог зайти
|
|
|
|
|
Response.Redirect("Enter");
|
|
|
|
|
|
|
|
|
|
return;
|
2023-04-02 01:17:44 +04:00
|
|
|
|
}
|
2023-05-16 20:05:59 +04:00
|
|
|
|
}
|
2023-03-31 20:13:22 +04:00
|
|
|
|
}
|