101 lines
3.7 KiB
C#
101 lines
3.7 KiB
C#
using HostrelHeadwaiterApp;
|
|
using HotelContracts.BindingModels;
|
|
using HotelHeadwaiterApp.Models;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using System.Diagnostics;
|
|
|
|
namespace HotelHeadwaiterApp.Controllers
|
|
{
|
|
public class HomeController : Controller
|
|
{
|
|
private readonly ILogger<HomeController> _logger;
|
|
|
|
public HomeController(ILogger<HomeController> logger)
|
|
{
|
|
_logger = logger;
|
|
}
|
|
|
|
public IActionResult Index()
|
|
{
|
|
return View();
|
|
}
|
|
|
|
[HttpGet]
|
|
public IActionResult Privacy()
|
|
{
|
|
if (APIClient.Headwaiter == null)
|
|
{
|
|
return Redirect("~/Home/Enter");
|
|
}
|
|
return View(APIClient.Headwaiter);
|
|
}
|
|
|
|
[HttpPost]
|
|
public void Privacy(string login, string email, string password, string surname, string name, string patronymic, string number)
|
|
{
|
|
if (APIClient.Headwaiter == null)
|
|
{
|
|
throw new Exception("Вы как сюда попали? Сюда вход только авторизованным");
|
|
}
|
|
if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(surname) || string.IsNullOrEmpty(name) || string.IsNullOrEmpty(patronymic))
|
|
{
|
|
throw new Exception("Введите логин, пароль, фамилию, имя и отчество");
|
|
}
|
|
APIClient.PostRequest("api/headwaiter/updatedata", new HeadwaiterBindingModel
|
|
{
|
|
Id = APIClient.Headwaiter.Id,
|
|
HeadwaiterSurname = surname,
|
|
HeadwaiterName = name,
|
|
HeadwaiterPatronymic = patronymic,
|
|
HeadwaiterLogin = login,
|
|
HeadwaiterPassword = password,
|
|
HeadwaiterEmail = email,
|
|
HeadwaiterPhoneNumber = number
|
|
});
|
|
|
|
APIClient.Headwaiter.HeadwaiterSurname = surname;
|
|
APIClient.Headwaiter.HeadwaiterName = name;
|
|
APIClient.Headwaiter.HeadwaiterPatronymic = patronymic;
|
|
APIClient.Headwaiter.HeadwaiterLogin = login;
|
|
APIClient.Headwaiter.HeadwaiterPassword = password;
|
|
APIClient.Headwaiter.HeadwaiterEmail = email;
|
|
APIClient.Headwaiter.HeadwaiterPhoneNumber = number;
|
|
Response.Redirect("Index");
|
|
}
|
|
|
|
[HttpGet]
|
|
public IActionResult Register()
|
|
{
|
|
return View();
|
|
}
|
|
|
|
[HttpPost]
|
|
public void Register(string login, string email, string password, string surname, string name, string patronymic, string telephone)
|
|
{
|
|
if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(surname) || string.IsNullOrEmpty(name) || string.IsNullOrEmpty(patronymic))
|
|
{
|
|
throw new Exception("Введите логин, пароль, фамилию, имя и отчество");
|
|
}
|
|
APIClient.PostRequest("api/headwaiter/register", new HeadwaiterBindingModel
|
|
{
|
|
HeadwaiterSurname = surname,
|
|
HeadwaiterName = name,
|
|
HeadwaiterPatronymic = patronymic,
|
|
HeadwaiterLogin = login,
|
|
HeadwaiterPassword = password,
|
|
HeadwaiterEmail = email,
|
|
HeadwaiterPhoneNumber = telephone
|
|
});
|
|
|
|
Response.Redirect("Enter");
|
|
return;
|
|
}
|
|
|
|
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
|
public IActionResult Error()
|
|
{
|
|
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
|
|
}
|
|
}
|
|
}
|