2023-05-16 19:13:19 +04:00
|
|
|
|
using CanteenContracts.BindingModels;
|
|
|
|
|
using CanteenContracts.View;
|
2023-04-09 19:05:54 +04:00
|
|
|
|
using CanteenManagerApp.Models;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace CanteenManagerApp.Controllers
|
|
|
|
|
{
|
|
|
|
|
public class HomeController : Controller
|
|
|
|
|
{
|
|
|
|
|
private readonly ILogger<HomeController> _logger;
|
|
|
|
|
|
|
|
|
|
public HomeController(ILogger<HomeController> logger)
|
|
|
|
|
{
|
|
|
|
|
_logger = logger;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IActionResult Index()
|
|
|
|
|
{
|
2023-05-16 19:13:19 +04:00
|
|
|
|
if (APIClient.Manager == null)
|
|
|
|
|
{
|
|
|
|
|
return Redirect("~/Home/Enter");
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-09 19:05:54 +04:00
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IActionResult Cooks()
|
|
|
|
|
{
|
2023-05-16 19:13:19 +04:00
|
|
|
|
if (APIClient.Manager == null)
|
|
|
|
|
{
|
|
|
|
|
return Redirect("~/Home/Enter");
|
|
|
|
|
}
|
|
|
|
|
ViewBag.Cooks = APIClient.GetRequest<List<CookViewModel>>($"api/main/getcooklist?managerId={APIClient.Manager.Id}");
|
2023-04-09 19:05:54 +04:00
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public IActionResult Products()
|
|
|
|
|
{
|
|
|
|
|
ViewBag.Products = new List<ProductViewModel>();
|
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public IActionResult Dishes()
|
|
|
|
|
{
|
|
|
|
|
ViewBag.Dishes = new List<DishViewModel>();
|
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
public IActionResult Privacy()
|
|
|
|
|
{
|
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public IActionResult CreateCook()
|
|
|
|
|
{
|
|
|
|
|
return View();
|
|
|
|
|
}
|
2023-05-16 19:13:19 +04:00
|
|
|
|
[HttpPost]
|
|
|
|
|
public void CreateCook(string FIO, string position)
|
|
|
|
|
{
|
|
|
|
|
if (APIClient.Manager == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Доступ возможен только авторизованным пользователям");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(FIO))
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("ФИО не должно быть пустым");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
APIClient.PostRequest("api/main/createcook", new CookBindingModel
|
|
|
|
|
{
|
|
|
|
|
ManagerId = APIClient.Manager.Id,
|
|
|
|
|
FIO = FIO,
|
|
|
|
|
Position = position
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Response.Redirect("Cooks");
|
|
|
|
|
}
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public IActionResult DeleteCook(int CookId)
|
|
|
|
|
{
|
|
|
|
|
APIClient.PostRequest("api/main/deletecook", new CookBindingModel { Id = CookId }); ;
|
|
|
|
|
return Redirect("~/Home/Cooks");
|
|
|
|
|
}
|
2023-04-09 19:05:54 +04:00
|
|
|
|
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public IActionResult CreateProduct()
|
|
|
|
|
{
|
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public IActionResult CreateDish()
|
|
|
|
|
{
|
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2023-05-16 19:13:19 +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.Manager = APIClient.GetRequest<ManagerViewModel>($"api/manager/login?login={login}&password={password}");
|
|
|
|
|
if (APIClient.Manager == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Неверный логин/пароль");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Response.Redirect("Index");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public IActionResult Register()
|
|
|
|
|
{
|
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public void Register(string login, string password, string fio, string phoneNumber)
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(fio))
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Введите логин, пароль и ФИО");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
APIClient.PostRequest("api/manager/register", new ManagerBindingModel
|
|
|
|
|
{
|
|
|
|
|
FIO = fio,
|
|
|
|
|
Login = login,
|
|
|
|
|
Password = password,
|
|
|
|
|
PhoneNumber = phoneNumber
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Response.Redirect("Enter");
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-09 19:05:54 +04:00
|
|
|
|
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
|
|
|
|
public IActionResult Error()
|
|
|
|
|
{
|
|
|
|
|
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|