121 lines
3.9 KiB
C#
121 lines
3.9 KiB
C#
using HotelContracts.BindingModels;
|
|
using HotelContracts.ViewModels;
|
|
using HotelOrganiserApp.Models;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using System.Diagnostics;
|
|
using System.Text;
|
|
|
|
namespace HotelOrganiserApp.Controllers
|
|
{
|
|
public class HomeController : Controller
|
|
{
|
|
private readonly ILogger<HomeController> _logger;
|
|
|
|
public HomeController(ILogger<HomeController> logger)
|
|
{
|
|
_logger = logger;
|
|
}
|
|
|
|
public IActionResult Index()
|
|
{
|
|
if (APIClient.Organiser == null)
|
|
{
|
|
return Redirect("~/Home/Enter");
|
|
}
|
|
return View();
|
|
}
|
|
|
|
[HttpGet]
|
|
public IActionResult Privacy()
|
|
{
|
|
if (APIClient.Organiser == null)
|
|
{
|
|
return Redirect("~/Home/Enter");
|
|
}
|
|
return View(APIClient.Organiser);
|
|
}
|
|
|
|
[HttpPost]
|
|
public void Privacy(string login, string email, string password, string fio, string telephone)
|
|
{
|
|
if (APIClient.Organiser == null)
|
|
{
|
|
throw new Exception("Вы как сюда попали? Сюда вход только авторизованным");
|
|
}
|
|
if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(fio))
|
|
{
|
|
throw new Exception("Введите логин, пароль и ФИО");
|
|
}
|
|
APIClient.PostRequest("api/organiser/updatedata", new OrganiserBindingModel
|
|
{
|
|
Id = APIClient.Organiser.Id,
|
|
OrganiserFIO = fio,
|
|
OrganiserLogin = login,
|
|
OrganiserPassword = password,
|
|
OrganiserEmail= email,
|
|
OrganiserNumber= telephone
|
|
});
|
|
|
|
APIClient.Organiser.OrganiserFIO = fio;
|
|
APIClient.Organiser.OrganiserLogin = login;
|
|
APIClient.Organiser.OrganiserPassword = password;
|
|
APIClient.Organiser.OrganiserEmail = email;
|
|
APIClient.Organiser.OrganiserNumber = telephone;
|
|
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("Введите логин и пароль");
|
|
}
|
|
APIClient.Organiser = APIClient.GetRequest<OrganiserViewModel>($"api/organiser/login?login={login}&password={password}");
|
|
if (APIClient.Organiser == null)
|
|
{
|
|
throw new Exception("Неверный логин/пароль");
|
|
}
|
|
Response.Redirect("Index");
|
|
}
|
|
|
|
[HttpGet]
|
|
public IActionResult Register()
|
|
{
|
|
return View();
|
|
}
|
|
|
|
[HttpPost]
|
|
public void Register(string login, string email, string password, string fio, string telephone)
|
|
{
|
|
if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(fio))
|
|
{
|
|
throw new Exception("Введите логин, пароль и ФИО");
|
|
}
|
|
APIClient.PostRequest("api/organiser/register", new OrganiserBindingModel
|
|
{
|
|
OrganiserFIO = fio,
|
|
OrganiserLogin = login,
|
|
OrganiserPassword = password,
|
|
OrganiserEmail = email,
|
|
OrganiserNumber = telephone
|
|
});
|
|
|
|
Response.Redirect("Enter");
|
|
return;
|
|
}
|
|
|
|
}
|
|
} |