Настоящая свобода начинается по ту сторону отчаяния.

This commit is contained in:
Игорь Гордеев 2024-05-03 21:53:27 +04:00
parent 939cba359a
commit 44b11867c9

View File

@ -1,4 +1,4 @@
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using SushiBarClientApp.Models; using SushiBarClientApp.Models;
using SushiBarContracts.BindingModel; using SushiBarContracts.BindingModel;
using SushiBarContracts.BindingModels; using SushiBarContracts.BindingModels;
@ -9,133 +9,144 @@ namespace SushiBarClientApp.Controllers
{ {
public class HomeController : Controller public class HomeController : Controller
{ {
private readonly ILogger<HomeController> _logger; private readonly ILogger<HomeController> _logger;
public HomeController(ILogger<HomeController> logger) public HomeController(ILogger<HomeController> logger)
{
_logger = logger;
}
public IActionResult Index()
{
if (APIClient.Client == null)
{ {
return Redirect("~/Home/Enter"); _logger = logger;
} }
return public IActionResult Index()
View(APIClient.GetRequest<List<OrderViewModel>>($"api/main/getorders?clientId={APIClient.Client.Id}"));
}
[HttpGet]
public IActionResult Privacy()
{
if (APIClient.Client == null)
{ {
return Redirect("~/Home/Enter"); if (APIClient.Client == null)
{
return Redirect("~/Home/Enter");
}
return
View(APIClient.GetRequest<List<OrderViewModel>>($"api/main/getorders?clientId={APIClient.Client.Id}"));
} }
return View(APIClient.Client); [HttpGet]
} public IActionResult Privacy()
[HttpPost]
public void Privacy(string login, string password, string fio)
{
if (APIClient.Client == null)
{ {
throw new Exception("Âû êàê ñóäà ïîïàëè? Ñóäà âõîä òîëüêî àâòîðèçîâàííûì"); if (APIClient.Client == null)
{
return Redirect("~/Home/Enter");
}
return View(APIClient.Client);
} }
if (string.IsNullOrEmpty(login) || [HttpPost]
string.IsNullOrEmpty(password) || string.IsNullOrEmpty(fio)) public void Privacy(string login, string password, string fio)
{ {
throw new Exception("Ââåäèòå ëîãèí, ïàðîëü è ÔÈÎ"); 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
ClientBindingModel
{
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");
} }
APIClient.PostRequest("api/client/updatedata", new ClientBindingModel [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None,
NoStore = true)]
public IActionResult Error()
{ {
Id = APIClient.Client.Id, return View(new ErrorViewModel
ClientFIO = fio, {
Email = login, RequestId =
Password = password Activity.Current?.Id ?? HttpContext.TraceIdentifier
}); });
APIClient.Client.ClientFIO = fio;
APIClient.Client.Email = login;
APIClient.Client.Password = password;
Response.Redirect("Index");
}
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public IActionResult Error()
{
return View(new ErrorViewModel
{
RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier
});
}
[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.Client = APIClient.GetRequest<ClientViewModel>($"api/client/login?login={login}&password={password}"); [HttpGet]
if (APIClient.Client == null) public IActionResult Enter()
{ {
throw new Exception("Íåâåðíûé ëîãèí/ïàðîëü"); return View();
} }
Response.Redirect("Index"); [HttpPost]
} public void Enter(string login, string password)
[HttpGet]
public IActionResult Register()
{
return View();
}
[HttpPost]
public void Register(string login, string password, string fio)
{
if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(fio))
{ {
throw new Exception("Ââåäèòå ëîãèí, ïàðîëü è ÔÈÎ"); 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");
} }
APIClient.PostRequest("api/client/register", new ClientBindingModel [HttpGet]
public IActionResult Register()
{ {
ClientFIO = fio, return View();
Email = login,
Password = password
});
Response.Redirect("Enter");
return;
}
[HttpGet]
public IActionResult Create()
{
ViewBag.Sushis = APIClient.GetRequest<List<SushiViewModel>>("api/main/getsushilist");
return View();
}
[HttpPost]
public void Create(int sushi, int count)
{
if (APIClient.Client == null)
{
throw new Exception("Âû êàê ñóäà ïîïàëè? Ñóäà âõîä òîëüêî àâòîðèçîâàííûì");
} }
if (count <= 0) [HttpPost]
public void Register(string login, string password, string fio)
{ {
throw new Exception("Êîëè÷åñòâî è ñóììà äîëæíû áûòü áîëüøå 0"); 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;
} }
APIClient.PostRequest("api/main/createorder", new OrderBindingModel [HttpGet]
public IActionResult Create()
{ {
ClientId = APIClient.Client.Id, ViewBag.Sushis =
SushiId = sushi, APIClient.GetRequest<List<SushiViewModel>>("api/main/getsushilist");
Count = count, return View();
Sum = Calc(count, sushi) }
}); [HttpPost]
Response.Redirect("Index"); public void Create(int sushi, int count)
} {
[HttpPost] if (APIClient.Client == null)
public double Calc(int count, int sushi) {
{ throw new Exception("Вы как суда попали? Суда вход только авторизованным");
var prod = APIClient.GetRequest<SushiViewModel>($"api/main/getsushi?sushiId={sushi}" }
); if (count <= 0)
return count * (prod?.Price ?? 1); {
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");
}
[HttpPost]
public double Calc(int count, int sushi)
{
var prod =
APIClient.GetRequest<SushiViewModel>($"api/main/getsushi?sushiId={sushi}"
);
return count * (prod?.Price ?? 1);
}
} }
} }
}