2023-05-16 19:13:19 +04:00
|
|
|
|
using CanteenContracts.BindingModels;
|
2023-05-17 17:02:26 +04:00
|
|
|
|
using CanteenContracts.SearchModel;
|
2023-05-16 19:13:19 +04:00
|
|
|
|
using CanteenContracts.View;
|
2023-05-17 17:59:48 +04:00
|
|
|
|
using CanteenContracts.ViewModels;
|
2023-05-17 17:02:26 +04:00
|
|
|
|
using CanteenDatabaseImplement.Models;
|
|
|
|
|
using CanteenDataModels.Models;
|
2023-04-09 19:05:54 +04:00
|
|
|
|
using CanteenManagerApp.Models;
|
2023-05-17 17:02:26 +04:00
|
|
|
|
using FluentNHibernate.Conventions;
|
2023-04-09 19:05:54 +04:00
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2023-05-17 17:02:26 +04:00
|
|
|
|
using System.Data;
|
2023-04-09 19:05:54 +04:00
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace CanteenManagerApp.Controllers
|
|
|
|
|
{
|
|
|
|
|
public class HomeController : Controller
|
|
|
|
|
{
|
|
|
|
|
private readonly ILogger<HomeController> _logger;
|
|
|
|
|
|
|
|
|
|
public HomeController(ILogger<HomeController> logger)
|
|
|
|
|
{
|
|
|
|
|
_logger = logger;
|
|
|
|
|
}
|
2023-05-17 17:02:26 +04:00
|
|
|
|
[HttpGet]
|
2023-04-09 19:05:54 +04:00
|
|
|
|
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();
|
|
|
|
|
}
|
2023-05-17 17:02:26 +04:00
|
|
|
|
[HttpGet]
|
|
|
|
|
public IActionResult Enter()
|
|
|
|
|
{
|
|
|
|
|
return View();
|
|
|
|
|
}
|
2023-04-09 19:05:54 +04:00
|
|
|
|
|
2023-05-17 17:02:26 +04:00
|
|
|
|
[HttpPost]
|
|
|
|
|
public void Enter(string login, string password)
|
2023-04-09 19:05:54 +04:00
|
|
|
|
{
|
2023-05-17 17:02:26 +04:00
|
|
|
|
if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password))
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Введите логин и пароль");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
APIClient.Manager = APIClient.GetRequest<ManagerViewModel>($"api/manager/login?login={login}&password={password}");
|
2023-05-16 19:13:19 +04:00
|
|
|
|
if (APIClient.Manager == null)
|
|
|
|
|
{
|
2023-05-17 17:02:26 +04:00
|
|
|
|
throw new Exception("Неверный логин/пароль");
|
2023-05-16 19:13:19 +04:00
|
|
|
|
}
|
2023-05-17 17:02:26 +04:00
|
|
|
|
|
|
|
|
|
Response.Redirect("Index");
|
2023-04-09 19:05:54 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet]
|
2023-05-17 17:02:26 +04:00
|
|
|
|
public IActionResult Register()
|
2023-04-09 19:05:54 +04:00
|
|
|
|
{
|
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-17 17:02:26 +04:00
|
|
|
|
[HttpPost]
|
|
|
|
|
public void Register(string login, string password, string fio, string phoneNumber)
|
2023-04-09 19:05:54 +04:00
|
|
|
|
{
|
2023-05-17 17:02:26 +04:00
|
|
|
|
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
|
|
|
|
}
|
2023-05-17 17:02:26 +04:00
|
|
|
|
|
|
|
|
|
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
|
|
|
|
public IActionResult Error()
|
2023-04-09 19:05:54 +04:00
|
|
|
|
{
|
2023-05-17 17:02:26 +04:00
|
|
|
|
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public IActionResult Cooks()
|
|
|
|
|
{
|
|
|
|
|
if (APIClient.Manager == null)
|
|
|
|
|
{
|
|
|
|
|
return Redirect("~/Home/Enter");
|
|
|
|
|
}
|
|
|
|
|
ViewBag.Cooks = APIClient.GetRequest<List<CookViewModel>>($"api/main/getcooklist? ={APIClient.Manager.Id}");
|
2023-04-09 19:05:54 +04:00
|
|
|
|
return View();
|
|
|
|
|
}
|
2023-05-17 17:02:26 +04:00
|
|
|
|
|
2023-04-09 19:05:54 +04:00
|
|
|
|
[HttpGet]
|
|
|
|
|
public IActionResult CreateCook()
|
|
|
|
|
{
|
2023-05-17 17:02:26 +04:00
|
|
|
|
if (APIClient.Manager == null)
|
|
|
|
|
{
|
|
|
|
|
return Redirect("~/Home/Enter");
|
|
|
|
|
}
|
2023-04-09 19:05:54 +04:00
|
|
|
|
return View();
|
|
|
|
|
}
|
2023-05-17 17:02:26 +04:00
|
|
|
|
|
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");
|
|
|
|
|
}
|
2023-05-17 17:02:26 +04:00
|
|
|
|
|
|
|
|
|
[HttpGet]
|
2023-05-16 19:13:19 +04:00
|
|
|
|
public IActionResult DeleteCook(int CookId)
|
|
|
|
|
{
|
2023-05-17 17:02:26 +04:00
|
|
|
|
if (APIClient.Manager == null)
|
|
|
|
|
{
|
|
|
|
|
return Redirect("~/Home/Enter");
|
|
|
|
|
}
|
2023-05-16 19:13:19 +04:00
|
|
|
|
APIClient.PostRequest("api/main/deletecook", new CookBindingModel { Id = CookId }); ;
|
|
|
|
|
return Redirect("~/Home/Cooks");
|
|
|
|
|
}
|
2023-04-09 19:05:54 +04:00
|
|
|
|
|
|
|
|
|
[HttpGet]
|
2023-05-17 17:02:26 +04:00
|
|
|
|
public IActionResult UpdateCook()
|
|
|
|
|
{
|
|
|
|
|
if (APIClient.Manager == null)
|
|
|
|
|
{
|
|
|
|
|
return Redirect("~/Home/Enter");
|
|
|
|
|
}
|
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public void UpdateCook(string FIO, string postition)
|
|
|
|
|
{
|
|
|
|
|
if (APIClient.Manager == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Доступ возможен только авторизованным пользователям");
|
|
|
|
|
}
|
|
|
|
|
APIClient.PostRequest("api/main/updatecook", new CookBindingModel
|
|
|
|
|
{
|
|
|
|
|
Id = APIClient.Manager.Id,
|
|
|
|
|
FIO = FIO,
|
|
|
|
|
Position = postition
|
|
|
|
|
});
|
|
|
|
|
Response.Redirect("Cooks");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public IActionResult Products()
|
2023-04-09 19:05:54 +04:00
|
|
|
|
{
|
2023-05-17 17:02:26 +04:00
|
|
|
|
if (APIClient.Manager == null)
|
|
|
|
|
{
|
|
|
|
|
return Redirect("~/Home/Enter");
|
|
|
|
|
}
|
|
|
|
|
ViewBag.Products = APIClient.GetRequest<List<ProductViewModel>>($"api/main/getproductlist?managerId={APIClient.Manager.Id}");
|
2023-04-09 19:05:54 +04:00
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet]
|
2023-05-17 17:02:26 +04:00
|
|
|
|
public IActionResult CreateProduct()
|
2023-04-09 19:05:54 +04:00
|
|
|
|
{
|
2023-05-17 17:02:26 +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();
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-17 17:02:26 +04:00
|
|
|
|
[HttpPost]
|
|
|
|
|
public void CreateProduct(string name, double price)
|
|
|
|
|
{
|
|
|
|
|
if (APIClient.Manager == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Доступ возможен только авторизованным пользователям");
|
|
|
|
|
}
|
2023-04-09 19:05:54 +04:00
|
|
|
|
|
2023-05-17 17:02:26 +04:00
|
|
|
|
if (string.IsNullOrEmpty(name))
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Наименование продукта не должно быть пустым");
|
|
|
|
|
}
|
|
|
|
|
APIClient.PostRequest("api/main/createproduct", new ProductBindingModel
|
|
|
|
|
{
|
|
|
|
|
ManagerId = APIClient.Manager.Id,
|
|
|
|
|
ProductName = name,
|
|
|
|
|
Price = price
|
|
|
|
|
});
|
2023-05-16 19:13:19 +04:00
|
|
|
|
|
2023-05-17 17:02:26 +04:00
|
|
|
|
Response.Redirect("Products");
|
|
|
|
|
}
|
2023-05-16 19:13:19 +04:00
|
|
|
|
[HttpGet]
|
2023-05-17 17:02:26 +04:00
|
|
|
|
public IActionResult AddCooksToProduct()
|
2023-05-16 19:13:19 +04:00
|
|
|
|
{
|
2023-05-17 17:02:26 +04:00
|
|
|
|
if (APIClient.Manager == null)
|
|
|
|
|
{
|
|
|
|
|
return Redirect("~/Home/Enter");
|
|
|
|
|
}
|
|
|
|
|
ViewBag.Products = APIClient.GetRequest<List<ProductViewModel>>($"api/main/getproductlist?managerId={APIClient.Manager.Id}");
|
|
|
|
|
ViewBag.Cooks = APIClient.GetRequest<List<CookViewModel>>($"api/main/getcooklist?managerId={APIClient.Manager.Id}");
|
2023-05-16 19:13:19 +04:00
|
|
|
|
return View();
|
|
|
|
|
}
|
2023-05-17 17:02:26 +04:00
|
|
|
|
|
2023-05-16 19:13:19 +04:00
|
|
|
|
[HttpPost]
|
2023-05-17 17:02:26 +04:00
|
|
|
|
public void AddCooksToProduct(int selectedProduct, int selectedCook)
|
2023-05-16 19:13:19 +04:00
|
|
|
|
{
|
2023-05-17 17:02:26 +04:00
|
|
|
|
if (APIClient.Manager == null)
|
2023-05-16 19:13:19 +04:00
|
|
|
|
{
|
2023-05-17 17:02:26 +04:00
|
|
|
|
throw new Exception("Доступ возможен только авторизованным пользователям");
|
2023-05-16 19:13:19 +04:00
|
|
|
|
}
|
|
|
|
|
|
2023-05-17 17:02:26 +04:00
|
|
|
|
if (selectedProduct <= 0)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Должен быть выбран продукт");
|
|
|
|
|
}
|
|
|
|
|
if (selectedCook <= 0)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Должен быть выбран повар");
|
|
|
|
|
}
|
|
|
|
|
APIClient.PostRequest("api/main/addcookstoproduct", Tuple.Create
|
|
|
|
|
(
|
|
|
|
|
new ProductSearchModel { Id = selectedProduct },
|
|
|
|
|
new CookViewModel { Id = selectedCook }
|
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
Response.Redirect("Products");
|
|
|
|
|
}
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public IActionResult DeleteProduct(int productId)
|
|
|
|
|
{
|
2023-05-16 19:13:19 +04:00
|
|
|
|
if (APIClient.Manager == null)
|
|
|
|
|
{
|
2023-05-17 17:02:26 +04:00
|
|
|
|
return Redirect("~/Home/Enter");
|
2023-05-16 19:13:19 +04:00
|
|
|
|
}
|
2023-05-17 17:02:26 +04:00
|
|
|
|
APIClient.PostRequest("api/main/deleteproduct", new ProductBindingModel { Id = productId });
|
|
|
|
|
return Redirect("~/Home/Products");
|
|
|
|
|
}
|
2023-05-16 19:13:19 +04:00
|
|
|
|
|
2023-05-17 17:02:26 +04:00
|
|
|
|
[HttpGet]
|
|
|
|
|
public IActionResult UpdateProduct()
|
|
|
|
|
{
|
|
|
|
|
if (APIClient.Manager == null)
|
|
|
|
|
{
|
|
|
|
|
return Redirect("~/Home/Enter");
|
|
|
|
|
}
|
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public void UpdateProduct(string productName, double price)
|
|
|
|
|
{
|
|
|
|
|
if (APIClient.Manager == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Доступ возможен только авторизованным пользователям");
|
|
|
|
|
}
|
|
|
|
|
APIClient.PostRequest("api/main/updateproduct", new ProductBindingModel
|
|
|
|
|
{
|
|
|
|
|
Id = APIClient.Manager.Id,
|
|
|
|
|
ProductName = productName,
|
|
|
|
|
Price = price
|
|
|
|
|
});
|
|
|
|
|
Response.Redirect("Products");
|
2023-05-16 19:13:19 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet]
|
2023-05-17 17:02:26 +04:00
|
|
|
|
public IActionResult Dishes()
|
2023-05-16 19:13:19 +04:00
|
|
|
|
{
|
2023-05-17 17:02:26 +04:00
|
|
|
|
if (APIClient.Manager == null)
|
|
|
|
|
{
|
|
|
|
|
return Redirect("~/Home/Enter");
|
|
|
|
|
}
|
|
|
|
|
ViewBag.Dishes = APIClient.GetRequest<List<DishViewModel>>($"api/main/getdishlist?managerId={APIClient.Manager.Id}");
|
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public IActionResult CreateDish()
|
|
|
|
|
{
|
|
|
|
|
if (APIClient.Manager == null)
|
|
|
|
|
{
|
|
|
|
|
return Redirect("~/Home/Enter");
|
|
|
|
|
}
|
2023-05-16 19:13:19 +04:00
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
2023-05-17 17:02:26 +04:00
|
|
|
|
public void CreateDish(string dishName, double price)
|
2023-05-16 19:13:19 +04:00
|
|
|
|
{
|
2023-05-17 17:02:26 +04:00
|
|
|
|
if (APIClient.Manager == null)
|
2023-05-16 19:13:19 +04:00
|
|
|
|
{
|
2023-05-17 17:02:26 +04:00
|
|
|
|
throw new Exception("Доступ возможен только авторизованным пользователям");
|
2023-05-16 19:13:19 +04:00
|
|
|
|
}
|
|
|
|
|
|
2023-05-17 17:02:26 +04:00
|
|
|
|
if (string.IsNullOrEmpty(dishName))
|
2023-05-16 19:13:19 +04:00
|
|
|
|
{
|
2023-05-17 17:02:26 +04:00
|
|
|
|
throw new Exception("Наименование блюда не должно быть пустым");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
APIClient.PostRequest("api/main/createdish", new DishBindingModel
|
|
|
|
|
{
|
|
|
|
|
ManagerId = APIClient.Manager.Id,
|
|
|
|
|
DishName = dishName,
|
|
|
|
|
Price = price
|
2023-05-16 19:13:19 +04:00
|
|
|
|
});
|
|
|
|
|
|
2023-05-17 17:02:26 +04:00
|
|
|
|
Response.Redirect("Dishes");
|
|
|
|
|
}
|
2023-05-16 19:13:19 +04:00
|
|
|
|
|
2023-05-17 17:02:26 +04:00
|
|
|
|
[HttpGet]
|
|
|
|
|
public IActionResult DeleteDish(int dishId)
|
|
|
|
|
{
|
|
|
|
|
if (APIClient.Manager == null)
|
|
|
|
|
{
|
|
|
|
|
return Redirect("~/Home/Enter");
|
|
|
|
|
}
|
|
|
|
|
APIClient.PostRequest("api/main/deletedish", new DishBindingModel { Id = dishId });
|
|
|
|
|
return Redirect("~/Home/Dishes");
|
2023-05-16 19:13:19 +04:00
|
|
|
|
}
|
|
|
|
|
|
2023-05-17 17:02:26 +04:00
|
|
|
|
[HttpGet]
|
|
|
|
|
public IActionResult UpdateDish()
|
2023-04-09 19:05:54 +04:00
|
|
|
|
{
|
2023-05-17 17:02:26 +04:00
|
|
|
|
if (APIClient.Manager == null)
|
|
|
|
|
{
|
|
|
|
|
return Redirect("~/Home/Enter");
|
|
|
|
|
}
|
|
|
|
|
return View();
|
2023-04-09 19:05:54 +04:00
|
|
|
|
}
|
2023-05-17 17:02:26 +04:00
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public void UpdateDish(string dishName, double price)
|
|
|
|
|
{
|
|
|
|
|
if (APIClient.Manager == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Доступ возможен только авторизованным пользователям");
|
|
|
|
|
}
|
|
|
|
|
APIClient.PostRequest("api/main/updatedish", new DishBindingModel
|
|
|
|
|
{
|
|
|
|
|
Id = APIClient.Manager.Id,
|
|
|
|
|
DishName = dishName,
|
|
|
|
|
Price = price
|
|
|
|
|
});
|
|
|
|
|
Response.Redirect("Dishes");
|
|
|
|
|
}
|
2023-05-17 17:59:48 +04:00
|
|
|
|
[HttpGet]
|
|
|
|
|
public IActionResult Graphic()
|
|
|
|
|
{
|
|
|
|
|
if (APIClient.Manager == null)
|
|
|
|
|
{
|
|
|
|
|
return Redirect("~/Home/Enter");
|
|
|
|
|
}
|
|
|
|
|
ViewBag.Model = APIClient.GetRequest<List<GraphicViewModel>>($"api/main/GetGraphic");
|
|
|
|
|
return View();
|
|
|
|
|
}
|
2023-04-09 19:05:54 +04:00
|
|
|
|
}
|
|
|
|
|
}
|