2024-05-03 21:53:27 +04:00
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2024-04-25 13:16:23 +04:00
|
|
|
|
using SushiBarClientApp.Models;
|
2024-05-01 10:50:16 +04:00
|
|
|
|
using SushiBarContracts.BindingModel;
|
2024-05-01 13:12:40 +04:00
|
|
|
|
using SushiBarContracts.BindingModels;
|
2024-04-25 13:16:23 +04:00
|
|
|
|
using SushiBarContracts.ViewModels;
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
|
|
|
|
|
namespace SushiBarClientApp.Controllers
|
|
|
|
|
{
|
|
|
|
|
public class HomeController : Controller
|
|
|
|
|
{
|
2024-05-03 21:53:27 +04:00
|
|
|
|
private readonly ILogger<HomeController> _logger;
|
|
|
|
|
public HomeController(ILogger<HomeController> logger)
|
2024-04-25 13:16:23 +04:00
|
|
|
|
{
|
2024-05-03 21:53:27 +04:00
|
|
|
|
_logger = logger;
|
2024-04-25 13:16:23 +04:00
|
|
|
|
}
|
2024-05-03 21:53:27 +04:00
|
|
|
|
public IActionResult Index()
|
2024-04-25 13:16:23 +04:00
|
|
|
|
{
|
2024-05-03 21:53:27 +04:00
|
|
|
|
if (APIClient.Client == null)
|
|
|
|
|
{
|
|
|
|
|
return Redirect("~/Home/Enter");
|
|
|
|
|
}
|
2024-05-12 19:04:40 +04:00
|
|
|
|
return
|
|
|
|
|
View(APIClient.GetRequest<List<OrderViewModel>>($"api/main/getorders?clientId={APIClient.Client.Id}"));
|
2024-04-25 13:16:23 +04:00
|
|
|
|
}
|
2024-05-03 21:53:27 +04:00
|
|
|
|
[HttpGet]
|
|
|
|
|
public IActionResult Privacy()
|
2024-04-25 13:16:23 +04:00
|
|
|
|
{
|
2024-05-03 21:53:27 +04:00
|
|
|
|
if (APIClient.Client == null)
|
|
|
|
|
{
|
|
|
|
|
return Redirect("~/Home/Enter");
|
|
|
|
|
}
|
|
|
|
|
return View(APIClient.Client);
|
2024-04-25 13:16:23 +04:00
|
|
|
|
}
|
2024-05-03 21:53:27 +04:00
|
|
|
|
[HttpPost]
|
|
|
|
|
public void Privacy(string login, string password, string fio)
|
2024-04-25 13:16:23 +04:00
|
|
|
|
{
|
2024-05-03 21:53:27 +04:00
|
|
|
|
if (APIClient.Client == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
|
|
|
|
|
}
|
|
|
|
|
if (string.IsNullOrEmpty(login) ||
|
|
|
|
|
string.IsNullOrEmpty(password) || string.IsNullOrEmpty(fio))
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Введите логин, пароль и ФИО");
|
|
|
|
|
}
|
|
|
|
|
APIClient.PostRequest("api/client/updatedata", new
|
2024-05-12 19:04:40 +04:00
|
|
|
|
ClientBindingModel
|
2024-05-03 21:53:27 +04:00
|
|
|
|
{
|
|
|
|
|
Id = APIClient.Client.Id,
|
|
|
|
|
ClientFIO = fio,
|
|
|
|
|
Email = login,
|
|
|
|
|
Password = password
|
|
|
|
|
});
|
|
|
|
|
APIClient.Client.ClientFIO = fio;
|
|
|
|
|
APIClient.Client.Email = login;
|
|
|
|
|
APIClient.Client.Password = password;
|
|
|
|
|
Response.Redirect("Index");
|
2024-04-25 13:16:23 +04:00
|
|
|
|
}
|
2024-05-03 21:53:27 +04:00
|
|
|
|
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None,
|
|
|
|
|
NoStore = true)]
|
|
|
|
|
public IActionResult Error()
|
2024-05-01 10:50:16 +04:00
|
|
|
|
{
|
2024-05-03 21:53:27 +04:00
|
|
|
|
return View(new ErrorViewModel
|
|
|
|
|
{
|
|
|
|
|
RequestId =
|
|
|
|
|
Activity.Current?.Id ?? HttpContext.TraceIdentifier
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public IActionResult Enter()
|
2024-04-25 13:16:23 +04:00
|
|
|
|
{
|
2024-05-03 21:53:27 +04:00
|
|
|
|
return View();
|
2024-04-25 13:16:23 +04:00
|
|
|
|
}
|
2024-05-03 21:53:27 +04:00
|
|
|
|
[HttpPost]
|
|
|
|
|
public void Enter(string login, string password)
|
2024-04-25 13:16:23 +04:00
|
|
|
|
{
|
2024-05-03 21:53:27 +04:00
|
|
|
|
if (string.IsNullOrEmpty(login) ||
|
|
|
|
|
string.IsNullOrEmpty(password))
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Введите логин и пароль");
|
|
|
|
|
}
|
|
|
|
|
APIClient.Client =
|
|
|
|
|
APIClient.GetRequest<ClientViewModel>($"api/client/login?login={login}&password={password}");
|
|
|
|
|
if (APIClient.Client == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Неверный логин/пароль");
|
|
|
|
|
}
|
|
|
|
|
Response.Redirect("Index");
|
2024-04-25 13:16:23 +04:00
|
|
|
|
}
|
2024-05-03 21:53:27 +04:00
|
|
|
|
[HttpGet]
|
|
|
|
|
public IActionResult Register()
|
2024-04-25 13:16:23 +04:00
|
|
|
|
{
|
2024-05-03 21:53:27 +04:00
|
|
|
|
return View();
|
2024-04-25 13:16:23 +04:00
|
|
|
|
}
|
2024-05-03 21:53:27 +04:00
|
|
|
|
[HttpPost]
|
|
|
|
|
public void Register(string login, string password, string fio)
|
2024-04-25 13:16:23 +04:00
|
|
|
|
{
|
2024-05-03 21:53:27 +04:00
|
|
|
|
if (string.IsNullOrEmpty(login) ||
|
|
|
|
|
string.IsNullOrEmpty(password) || string.IsNullOrEmpty(fio))
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Введите логин, пароль и ФИО");
|
|
|
|
|
}
|
|
|
|
|
APIClient.PostRequest("api/client/register", new
|
|
|
|
|
ClientBindingModel
|
|
|
|
|
{
|
|
|
|
|
ClientFIO = fio,
|
|
|
|
|
Email = login,
|
|
|
|
|
Password = password
|
|
|
|
|
});
|
|
|
|
|
Response.Redirect("Enter");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public IActionResult Create()
|
2024-04-25 13:16:23 +04:00
|
|
|
|
{
|
2024-05-03 21:53:27 +04:00
|
|
|
|
ViewBag.Sushis =
|
|
|
|
|
APIClient.GetRequest<List<SushiViewModel>>("api/main/getsushilist");
|
|
|
|
|
return View();
|
2024-04-25 13:16:23 +04:00
|
|
|
|
}
|
2024-05-03 21:53:27 +04:00
|
|
|
|
[HttpPost]
|
|
|
|
|
public void Create(int sushi, int count)
|
2024-04-25 13:16:23 +04:00
|
|
|
|
{
|
2024-05-03 21:53:27 +04:00
|
|
|
|
if (APIClient.Client == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
|
|
|
|
|
}
|
|
|
|
|
if (count <= 0)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Количество и сумма должны быть больше 0");
|
|
|
|
|
}
|
|
|
|
|
APIClient.PostRequest("api/main/createorder", new OrderBindingModel
|
|
|
|
|
{
|
|
|
|
|
ClientId = APIClient.Client.Id,
|
|
|
|
|
SushiId = sushi,
|
|
|
|
|
Count = count,
|
|
|
|
|
Sum = Calc(count, sushi)
|
|
|
|
|
});
|
|
|
|
|
Response.Redirect("Index");
|
2024-04-25 13:16:23 +04:00
|
|
|
|
}
|
2024-05-03 21:53:27 +04:00
|
|
|
|
[HttpPost]
|
|
|
|
|
public double Calc(int count, int sushi)
|
2024-04-25 13:16:23 +04:00
|
|
|
|
{
|
2024-05-03 21:53:27 +04:00
|
|
|
|
var prod =
|
|
|
|
|
APIClient.GetRequest<SushiViewModel>($"api/main/getsushi?sushiId={sushi}"
|
|
|
|
|
);
|
|
|
|
|
return count * (prod?.Price ?? 1);
|
|
|
|
|
}
|
2024-05-16 18:55:15 +04:00
|
|
|
|
public IActionResult Mails()
|
|
|
|
|
{
|
|
|
|
|
if (APIClient.Client == null)
|
|
|
|
|
{
|
|
|
|
|
return Redirect("~/Home/Enter");
|
|
|
|
|
}
|
|
|
|
|
return View(APIClient.GetRequest<List<MessageInfoViewModel>>($"api/client/getmessages?clientId={APIClient.Client.Id}"));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|