105 lines
2.7 KiB
C#
Raw Normal View History

2024-05-29 12:38:52 +04:00
using ComputerHardwareStoreContracts.BindingModels;
using ComputerHardwareStoreContracts.ViewModels;
2024-05-01 19:39:07 +04:00
using Microsoft.AspNetCore.Mvc;
using System.Diagnostics;
using VendorClient.Models;
namespace VendorClient.Controllers
{
2024-05-29 15:26:54 +04:00
[Route("Home/[action]")]
2024-05-01 19:39:07 +04:00
public class HomeController : Controller
{
private readonly ILogger<HomeController> _logger;
public HomeController(ILogger<HomeController> logger)
{
_logger = logger;
}
[HttpGet]
public IActionResult Index()
{
2024-05-29 12:38:52 +04:00
if (APIClient.Vendor == null)
{
return Redirect("~/Home/Enter");
}
2024-05-01 19:39:07 +04:00
return View();
}
[HttpGet]
public IActionResult Privacy()
{
2024-05-29 12:38:52 +04:00
if (APIClient.Vendor == null)
{
return Redirect("~/Home/Enter");
}
return View(APIClient.Vendor);
2024-05-01 19:39:07 +04:00
}
[HttpGet]
2024-05-29 12:38:52 +04:00
public void Enter(string email, string password)
2024-05-01 19:39:07 +04:00
{
2024-05-29 12:38:52 +04:00
if (string.IsNullOrEmpty(email) || string.IsNullOrEmpty(password))
{
throw new Exception("Введите почту и пароль");
}
APIClient.Vendor = APIClient.GetRequest<VendorViewModel>($"api/vendor/login?email={email}&password={password}");
if (APIClient.Vendor == null)
{
throw new Exception("Неверные почта и/или пароль");
}
Response.Redirect("MainWorker");
2024-05-01 19:39:07 +04:00
}
[HttpGet]
2024-05-29 12:38:52 +04:00
public void Register(string email, string password, string fio)
2024-05-01 19:39:07 +04:00
{
2024-05-29 12:38:52 +04:00
if (string.IsNullOrEmpty(email) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(fio))
{
throw new Exception("Введите логин, пароль и ФИО");
}
APIClient.PostRequest("api/pharmacist/register", new VendorBindingModel
{
Name = fio,
Login = email,
Password = password
});
2024-05-29 15:26:54 +04:00
Response.Redirect("~/Home/Enter");
2024-05-29 12:38:52 +04:00
return;
}
2024-05-01 19:39:07 +04:00
2024-05-29 12:38:52 +04:00
2024-05-01 19:39:07 +04:00
[HttpGet]
public IActionResult CommentCreate()
{
return View();
}
[HttpGet]
public IActionResult CommentDelete()
{
return View();
}
[HttpGet]
public IActionResult CommentUpdate()
{
return View();
}
[HttpGet]
public IActionResult Comments()
{
return View(new List<CommentViewModel>());
}
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public IActionResult Error()
{
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
}
}
}