2023-04-06 17:55:49 +04:00
|
|
|
|
using HostrelHeadwaiterApp.Models;
|
2023-05-16 00:09:17 +04:00
|
|
|
|
using HotelContracts.BindingModels;
|
|
|
|
|
using HotelContracts.ViewModels;
|
2023-04-06 17:55:49 +04:00
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
|
|
|
|
|
namespace HostrelHeadwaiterApp.Controllers
|
|
|
|
|
{
|
|
|
|
|
public class HomeController : Controller
|
|
|
|
|
{
|
|
|
|
|
private readonly ILogger<HomeController> _logger;
|
|
|
|
|
|
|
|
|
|
public HomeController(ILogger<HomeController> logger)
|
|
|
|
|
{
|
|
|
|
|
_logger = logger;
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-16 00:09:17 +04:00
|
|
|
|
public IActionResult CreateDinner()
|
2023-04-06 17:55:49 +04:00
|
|
|
|
{
|
2023-05-16 00:09:17 +04:00
|
|
|
|
if (APIClient.Headwaiter == null)
|
|
|
|
|
{
|
|
|
|
|
return Redirect("~/Home/Enter");
|
|
|
|
|
}
|
2023-04-06 17:55:49 +04:00
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-16 00:09:17 +04:00
|
|
|
|
[HttpPost]
|
|
|
|
|
public void CreateDinner(double dinnerPrice, string dinnerName)
|
2023-04-06 17:55:49 +04:00
|
|
|
|
{
|
2023-05-16 00:09:17 +04:00
|
|
|
|
if (APIClient.Headwaiter == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Необходима авторизация");
|
|
|
|
|
}
|
|
|
|
|
if (string.IsNullOrEmpty(dinnerName))
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Введите имя");
|
|
|
|
|
}
|
|
|
|
|
APIClient.PostRequest("api/main/createdinner", new DinnerBindingModel
|
|
|
|
|
{
|
|
|
|
|
DinnerPrice = dinnerPrice,
|
|
|
|
|
DinnerName = dinnerName,
|
|
|
|
|
HeadwaiterId = APIClient.Headwaiter.Id,
|
|
|
|
|
});
|
|
|
|
|
Response.Redirect("ListDinners");
|
2023-04-06 17:55:49 +04:00
|
|
|
|
}
|
|
|
|
|
|
2023-05-16 00:09:17 +04:00
|
|
|
|
public IActionResult UpdateDinner()
|
2023-04-06 19:55:59 +04:00
|
|
|
|
{
|
2023-05-16 00:09:17 +04:00
|
|
|
|
if (APIClient.Headwaiter == null)
|
|
|
|
|
{
|
|
|
|
|
return Redirect("~/Home/Enter");
|
|
|
|
|
}
|
|
|
|
|
ViewBag.Dinners = APIClient.GetRequest<List<DinnerViewModel>>($"api/main/getdinnerlist?headwaiterId={APIClient.Headwaiter.Id}");
|
2023-04-06 19:55:59 +04:00
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-16 00:09:17 +04:00
|
|
|
|
[HttpPost]
|
|
|
|
|
public void UpdateDinner(int dinner, string dinnerName, double dinnerPrice)
|
2023-04-06 19:55:59 +04:00
|
|
|
|
{
|
2023-05-16 00:09:17 +04:00
|
|
|
|
if (APIClient.Headwaiter == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Необходима авторизация");
|
|
|
|
|
}
|
|
|
|
|
if (string.IsNullOrEmpty(dinnerName))
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("имя не может быть пустым");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
APIClient.PostRequest("api/main/updatedinner", new DinnerBindingModel
|
|
|
|
|
{
|
|
|
|
|
Id = dinner,
|
|
|
|
|
DinnerName = dinnerName,
|
|
|
|
|
DinnerPrice = dinnerPrice,
|
|
|
|
|
HeadwaiterId = APIClient.Headwaiter.Id,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Response.Redirect("ListDinners");
|
2023-04-06 19:55:59 +04:00
|
|
|
|
}
|
|
|
|
|
|
2023-05-16 00:09:17 +04:00
|
|
|
|
public IActionResult DeleteDinner()
|
2023-04-06 20:25:46 +04:00
|
|
|
|
{
|
2023-05-16 00:09:17 +04:00
|
|
|
|
if (APIClient.Headwaiter == null)
|
|
|
|
|
{
|
|
|
|
|
return Redirect("~/Home/Enter");
|
|
|
|
|
}
|
|
|
|
|
ViewBag.Dinners = APIClient.GetRequest<List<DinnerViewModel>>($"api/main/getdinnerlist?headwaiterId={APIClient.Headwaiter.Id}");
|
2023-04-06 20:25:46 +04:00
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-16 00:09:17 +04:00
|
|
|
|
[HttpPost]
|
|
|
|
|
public void DeleteDinner(int dinner)
|
2023-04-06 20:25:46 +04:00
|
|
|
|
{
|
2023-05-16 00:09:17 +04:00
|
|
|
|
if (APIClient.Headwaiter == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Необходима авторизация");
|
|
|
|
|
}
|
|
|
|
|
APIClient.PostRequest("api/main/deletedinner", new DinnerBindingModel
|
|
|
|
|
{
|
|
|
|
|
Id = dinner
|
|
|
|
|
});
|
|
|
|
|
Response.Redirect("ListDinners");
|
2023-04-06 20:25:46 +04:00
|
|
|
|
}
|
2023-04-06 22:33:29 +04:00
|
|
|
|
|
2023-05-16 00:09:17 +04:00
|
|
|
|
[HttpGet]
|
|
|
|
|
public DinnerViewModel? GetDinner(int dinnerId)
|
2023-04-06 22:33:29 +04:00
|
|
|
|
{
|
2023-05-16 00:09:17 +04:00
|
|
|
|
if (APIClient.Headwaiter == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Необходима авторизация");
|
|
|
|
|
}
|
|
|
|
|
var result = APIClient.GetRequest<DinnerViewModel>($"api/main/getdinner?dinnerid={dinnerId}");
|
|
|
|
|
if (result == null)
|
|
|
|
|
{
|
|
|
|
|
return default;
|
|
|
|
|
}
|
|
|
|
|
var dinnerPrice = result.DinnerPrice;
|
|
|
|
|
var dinnerName = result.DinnerName;
|
|
|
|
|
|
|
|
|
|
return result;
|
2023-04-06 22:33:29 +04:00
|
|
|
|
}
|
|
|
|
|
|
2023-05-16 00:09:17 +04:00
|
|
|
|
public IActionResult Index()
|
2023-04-06 23:44:20 +04:00
|
|
|
|
{
|
2023-05-16 00:09:17 +04:00
|
|
|
|
if (APIClient.Headwaiter == null)
|
|
|
|
|
{
|
|
|
|
|
return Redirect("~/Home/Enter");
|
|
|
|
|
}
|
2023-04-06 23:44:20 +04:00
|
|
|
|
return View();
|
2023-05-16 00:09:17 +04:00
|
|
|
|
}
|
2023-04-06 23:44:20 +04:00
|
|
|
|
|
2023-05-16 00:09:17 +04:00
|
|
|
|
public IActionResult ListDinners()
|
|
|
|
|
{
|
|
|
|
|
if (APIClient.Headwaiter == null)
|
|
|
|
|
{
|
|
|
|
|
return Redirect("~/Home/Enter");
|
|
|
|
|
}
|
|
|
|
|
return View(APIClient.GetRequest<List<DinnerViewModel>>($"api/main/getdinnerlist?headwaiterId={APIClient.Headwaiter.Id}"));
|
2023-04-06 23:44:20 +04:00
|
|
|
|
}
|
2023-05-16 00:09:17 +04:00
|
|
|
|
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public IActionResult Privacy()
|
2023-04-06 23:44:20 +04:00
|
|
|
|
{
|
2023-05-16 00:09:17 +04:00
|
|
|
|
if (APIClient.Headwaiter == null)
|
|
|
|
|
{
|
|
|
|
|
return Redirect("~/Home/Enter");
|
|
|
|
|
}
|
|
|
|
|
return View(APIClient.Headwaiter);
|
2023-04-06 23:44:20 +04:00
|
|
|
|
}
|
|
|
|
|
|
2023-05-16 00:09:17 +04:00
|
|
|
|
[HttpPost]
|
|
|
|
|
public void Privacy(string login, string email, string password, string fio, string telephone)
|
|
|
|
|
{
|
|
|
|
|
if (APIClient.Headwaiter == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Вы как сюда попали? Сюда вход только авторизованным");
|
|
|
|
|
}
|
|
|
|
|
if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(fio))
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Введите логин, пароль и ФИО");
|
|
|
|
|
}
|
|
|
|
|
APIClient.PostRequest("api/headwaiter/updatedata", new HeadwaiterBindingModel
|
|
|
|
|
{
|
|
|
|
|
Id = APIClient.Headwaiter.Id,
|
|
|
|
|
HeadwaiterFIO = fio,
|
|
|
|
|
HeadwaiterLogin = login,
|
|
|
|
|
HeadwaiterPassword = password,
|
|
|
|
|
HeadwaiterEmail = email,
|
|
|
|
|
HeadwaiterNumber = telephone
|
|
|
|
|
});
|
2023-04-06 20:25:46 +04:00
|
|
|
|
|
2023-05-16 00:09:17 +04:00
|
|
|
|
APIClient.Headwaiter.HeadwaiterFIO = fio;
|
|
|
|
|
APIClient.Headwaiter.HeadwaiterLogin = login;
|
|
|
|
|
APIClient.Headwaiter.HeadwaiterPassword = password;
|
|
|
|
|
APIClient.Headwaiter.HeadwaiterEmail = email;
|
|
|
|
|
APIClient.Headwaiter.HeadwaiterNumber = telephone;
|
|
|
|
|
Response.Redirect("Index");
|
|
|
|
|
}
|
2023-04-06 19:55:59 +04:00
|
|
|
|
|
2023-05-16 00:09:17 +04:00
|
|
|
|
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
2023-04-06 17:55:49 +04:00
|
|
|
|
public IActionResult Error()
|
|
|
|
|
{
|
|
|
|
|
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
|
|
|
|
|
}
|
2023-05-16 00:09:17 +04:00
|
|
|
|
|
|
|
|
|
[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.Headwaiter = APIClient.GetRequest<HeadwaiterViewModel>($"api/headwaiter/login?login={login}&password={password}");
|
|
|
|
|
if (APIClient.Headwaiter == 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/headwaiter/register", new HeadwaiterBindingModel
|
|
|
|
|
{
|
|
|
|
|
HeadwaiterFIO = fio,
|
|
|
|
|
HeadwaiterLogin = login,
|
|
|
|
|
HeadwaiterPassword = password,
|
|
|
|
|
HeadwaiterEmail = email,
|
|
|
|
|
HeadwaiterNumber = telephone
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Response.Redirect("Enter");
|
|
|
|
|
return;
|
|
|
|
|
}
|
2023-04-06 17:55:49 +04:00
|
|
|
|
}
|
|
|
|
|
}
|