2024-05-02 09:33:43 +04:00
|
|
|
|
using ComputerHardwareStoreContracts.ViewModels;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
using StoreKeeperClient.Models;
|
2024-05-28 20:21:49 +04:00
|
|
|
|
using ComputerHardwareStoreContracts.BindingModels;
|
2024-05-02 09:33:43 +04:00
|
|
|
|
|
|
|
|
|
namespace StoreKeeperClient.Controllers
|
|
|
|
|
{
|
2024-05-28 22:41:22 +04:00
|
|
|
|
public class HomeController : Controller
|
2024-05-02 09:33:43 +04:00
|
|
|
|
{
|
|
|
|
|
private readonly ILogger<HomeController> _logger;
|
|
|
|
|
|
|
|
|
|
public HomeController(ILogger<HomeController> logger)
|
|
|
|
|
{
|
|
|
|
|
_logger = logger;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public IActionResult Index()
|
|
|
|
|
{
|
2024-05-29 18:48:47 +04:00
|
|
|
|
return View();
|
|
|
|
|
}
|
2024-05-28 20:21:49 +04:00
|
|
|
|
|
|
|
|
|
[HttpGet]
|
2024-05-02 09:33:43 +04:00
|
|
|
|
public IActionResult Enter()
|
|
|
|
|
{
|
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-29 17:25:32 +04:00
|
|
|
|
[HttpPost]
|
|
|
|
|
public void Enter(string login, string password)
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password))
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Введите почту и пароль");
|
|
|
|
|
}
|
|
|
|
|
APIClient.Client = APIClient.GetRequest<StoreKeeperViewModel>($"api/storekeeper/login?login={login}&password={password}");
|
|
|
|
|
if (APIClient.Client == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Неверные почта и/или пароль");
|
|
|
|
|
}
|
2024-05-29 18:48:47 +04:00
|
|
|
|
Response.Redirect("Home/Index");
|
2024-05-29 17:25:32 +04:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-02 09:33:43 +04:00
|
|
|
|
[HttpGet]
|
|
|
|
|
public IActionResult Register()
|
|
|
|
|
{
|
2024-05-28 20:21:49 +04:00
|
|
|
|
|
2024-05-02 09:33:43 +04:00
|
|
|
|
return View();
|
|
|
|
|
}
|
2024-05-29 17:25:32 +04:00
|
|
|
|
[HttpPost]
|
|
|
|
|
public void Register(string name, string login, string password)
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(name) || string.IsNullOrEmpty(password))
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Введите логин, name, пароль");
|
|
|
|
|
}
|
|
|
|
|
APIClient.PostRequest("api/storekeeper/register", new StoreKeeperBindingModel
|
|
|
|
|
{
|
|
|
|
|
Name = name,
|
|
|
|
|
Login = login,
|
|
|
|
|
Password = password,
|
|
|
|
|
});
|
|
|
|
|
Response.Redirect("Enter");
|
|
|
|
|
return;
|
|
|
|
|
}
|
2024-05-29 18:48:47 +04:00
|
|
|
|
|
2024-05-02 09:33:43 +04:00
|
|
|
|
[HttpGet]
|
|
|
|
|
public IActionResult AddBuildToPurchase()
|
|
|
|
|
{
|
2024-05-28 20:21:49 +04:00
|
|
|
|
if (APIClient.Client == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
|
|
|
|
|
}
|
|
|
|
|
return View();
|
2024-05-02 09:33:43 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public IActionResult Builds()
|
|
|
|
|
{
|
2024-05-28 20:21:49 +04:00
|
|
|
|
if (APIClient.Client == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
|
|
|
|
|
}
|
|
|
|
|
return View(new List<BuildViewModel>());
|
2024-05-02 09:33:43 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public IActionResult BuildCreate()
|
|
|
|
|
{
|
2024-05-28 20:21:49 +04:00
|
|
|
|
if (APIClient.Client == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
|
|
|
|
|
}
|
|
|
|
|
return View();
|
2024-05-02 09:33:43 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public IActionResult BuildDelete()
|
|
|
|
|
{
|
2024-05-28 20:21:49 +04:00
|
|
|
|
if (APIClient.Client == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
|
|
|
|
|
}
|
|
|
|
|
return View();
|
2024-05-02 09:33:43 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public IActionResult BuildUpdate()
|
|
|
|
|
{
|
2024-05-28 20:21:49 +04:00
|
|
|
|
if (APIClient.Client == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
|
|
|
|
|
}
|
|
|
|
|
return View();
|
2024-05-02 09:33:43 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public IActionResult CommentCreate()
|
|
|
|
|
{
|
2024-05-28 20:21:49 +04:00
|
|
|
|
if (APIClient.Client == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
|
|
|
|
|
}
|
|
|
|
|
return View();
|
2024-05-02 09:33:43 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public IActionResult CommentDelete()
|
|
|
|
|
{
|
2024-05-28 20:21:49 +04:00
|
|
|
|
if (APIClient.Client == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
|
|
|
|
|
}
|
|
|
|
|
return View();
|
2024-05-02 09:33:43 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public IActionResult CommentUpdate()
|
|
|
|
|
{
|
2024-05-28 20:21:49 +04:00
|
|
|
|
if (APIClient.Client == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
|
|
|
|
|
}
|
|
|
|
|
return View();
|
2024-05-02 09:33:43 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public IActionResult Comments()
|
|
|
|
|
{
|
2024-05-28 20:21:49 +04:00
|
|
|
|
if (APIClient.Client == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
|
|
|
|
|
}
|
|
|
|
|
return View(new List<CommentViewModel>());
|
2024-05-02 09:33:43 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet]
|
2024-05-29 18:48:47 +04:00
|
|
|
|
public IActionResult Products()
|
2024-05-02 09:33:43 +04:00
|
|
|
|
{
|
2024-05-28 20:21:49 +04:00
|
|
|
|
if (APIClient.Client == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
|
|
|
|
|
}
|
2024-05-29 18:48:47 +04:00
|
|
|
|
return View(new List<ProductViewModel>());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IActionResult CreateProduct()
|
|
|
|
|
{
|
|
|
|
|
if (APIClient.Client == null)
|
|
|
|
|
{
|
|
|
|
|
return Redirect("~/Home/Enter");
|
|
|
|
|
}
|
|
|
|
|
ViewBag.Components = APIClient.GetRequest<List<ComponentViewModel>>($"api/component/getcomponents?userId={APIClient.Client.Id}");
|
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public void CreateProduct([FromBody] ProductBindingModel productModel)
|
|
|
|
|
{
|
|
|
|
|
if (APIClient.Client == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Вы как сюда попали? Сюда вход только авторизованным");
|
|
|
|
|
}
|
|
|
|
|
if (string.IsNullOrEmpty(productModel.Name))
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Название не должно быть пустым");
|
|
|
|
|
}
|
|
|
|
|
if (productModel.Price <= 0)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Цена должна быть больше 0");
|
|
|
|
|
}
|
|
|
|
|
productModel.StoreKeeperId = APIClient.Client.Id;
|
|
|
|
|
APIClient.PostRequest("api/product/createproduct", productModel);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IActionResult UpdateProduct(int productid)
|
|
|
|
|
{
|
|
|
|
|
if (APIClient.Client == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Вы как сюда попали? Сюда вход только авторизованным");
|
|
|
|
|
}
|
|
|
|
|
ViewBag.Components = APIClient.GetRequest<List<ComponentViewModel>>($"api/component/getcomponents?userId={APIClient.Client.Id}");
|
|
|
|
|
return View(productid);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public void UpdateProduct([FromBody] ProductBindingModel productModel)
|
|
|
|
|
{
|
|
|
|
|
if (APIClient.Client == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Вы как сюда попали? Сюда вход только авторизованным");
|
|
|
|
|
}
|
|
|
|
|
if (string.IsNullOrEmpty(productModel.Name))
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Название не должно быть пустым");
|
|
|
|
|
}
|
|
|
|
|
if (productModel.Price <= 0)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Цена должна быть больше 0");
|
|
|
|
|
}
|
|
|
|
|
productModel.StoreKeeperId = APIClient.Client.Id;
|
|
|
|
|
APIClient.PostRequest("api/product/updatedata", productModel);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public void DeleteGood(int model)
|
|
|
|
|
{
|
|
|
|
|
if (APIClient.Client == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Вы как сюда попали? Сюда вход только авторизованным");
|
|
|
|
|
}
|
|
|
|
|
if (model <= 0)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception($"Идентификатор товара не может быть меньше или равен 0");
|
|
|
|
|
}
|
|
|
|
|
APIClient.PostRequest("api/product/deleteproduct", new ProductBindingModel
|
|
|
|
|
{
|
|
|
|
|
Id = model
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public ProductViewModel? GetProduct(int Id)
|
|
|
|
|
{
|
|
|
|
|
if (APIClient.Client == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Вы как сюда попали? Сюда вход только авторизованным");
|
|
|
|
|
}
|
|
|
|
|
if (Id <= 0)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception($"Идентификатор товара не может быть меньше или равен 0");
|
|
|
|
|
}
|
|
|
|
|
var result = APIClient.GetRequest<ProductViewModel>($"api/product/getproduct?id={Id}");
|
|
|
|
|
return result;
|
2024-05-02 09:33:43 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public IActionResult PurchaseCreate()
|
|
|
|
|
{
|
2024-05-28 20:21:49 +04:00
|
|
|
|
if (APIClient.Client == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
|
|
|
|
|
}
|
|
|
|
|
return View();
|
2024-05-02 09:33:43 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public IActionResult PurchaseDelete()
|
|
|
|
|
{
|
2024-05-28 20:21:49 +04:00
|
|
|
|
if (APIClient.Client == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
|
|
|
|
|
}
|
|
|
|
|
return View();
|
2024-05-02 09:33:43 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public IActionResult Purchases()
|
|
|
|
|
{
|
2024-05-28 20:21:49 +04:00
|
|
|
|
if (APIClient.Client == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
|
|
|
|
|
}
|
|
|
|
|
return View(new List<PurchaseViewModel>());
|
2024-05-02 09:33:43 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public IActionResult Report()
|
|
|
|
|
{
|
2024-05-28 20:21:49 +04:00
|
|
|
|
if (APIClient.Client == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
|
|
|
|
|
}
|
|
|
|
|
return View(new List<PurchaseViewModel>());
|
2024-05-02 09:33:43 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public void Report(string password)
|
|
|
|
|
{
|
2024-05-28 20:21:49 +04:00
|
|
|
|
if (APIClient.Client == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
|
|
|
|
|
}
|
|
|
|
|
Response.Redirect("ReportOnly");
|
2024-05-02 09:33:43 +04:00
|
|
|
|
}
|
|
|
|
|
|
2024-05-28 15:27:44 +04:00
|
|
|
|
public IActionResult Mails()
|
|
|
|
|
{
|
|
|
|
|
if (APIClient.Client == null)
|
|
|
|
|
{
|
|
|
|
|
return Redirect("~/Home/Enter");
|
|
|
|
|
}
|
2024-05-29 17:25:32 +04:00
|
|
|
|
return View(APIClient.GetRequest<List<MessageInfoViewModel>>($"api/storekeeper/getmessages?storekeeperId={APIClient.Client.Id}"));
|
2024-05-28 15:27:44 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
2024-05-02 09:33:43 +04:00
|
|
|
|
public IActionResult Error()
|
|
|
|
|
{
|
|
|
|
|
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|