Переключение через header

This commit is contained in:
dasha 2023-04-02 21:00:44 +04:00
parent 3db96eaaa1
commit 88504d8bf1
12 changed files with 236 additions and 214 deletions

View File

@ -3,7 +3,6 @@ using HardwareShopContracts.BindingModels;
using HardwareShopContracts.ViewModels; using HardwareShopContracts.ViewModels;
using HardwareShopDataModels.Enums; using HardwareShopDataModels.Enums;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using System.Data;
using System.Diagnostics; using System.Diagnostics;
namespace HardwareShopClientApp.Controllers namespace HardwareShopClientApp.Controllers
@ -17,7 +16,6 @@ namespace HardwareShopClientApp.Controllers
_logger = logger; _logger = logger;
} }
[HttpGet]
public IActionResult Register() public IActionResult Register()
{ {
return View(); return View();
@ -43,10 +41,6 @@ namespace HardwareShopClientApp.Controllers
public IActionResult Index() public IActionResult Index()
{ {
if (APIClient.User == null)
{
return Redirect("~/Home/Enter");
}
return View(); return View();
} }
@ -61,15 +55,13 @@ namespace HardwareShopClientApp.Controllers
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier }); return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
} }
[HttpGet]
public IActionResult Enter() public IActionResult Enter()
{ {
return View(); return View();
} }
[HttpPost] [HttpPost]
public IActionResult Enter(string email, string password) public void Enter(string email, string password)
{ {
if (string.IsNullOrEmpty(email) || string.IsNullOrEmpty(password)) if (string.IsNullOrEmpty(email) || string.IsNullOrEmpty(password))
{ {
@ -82,21 +74,12 @@ namespace HardwareShopClientApp.Controllers
} }
if ((int)APIClient.User.Role == 1) if ((int)APIClient.User.Role == 1)
{ {
return RedirectToAction("MainWorker", "Worker"); RedirectToAction("MainWorker", "Worker");
return RedirectToAction("WorkerReport", "Worker");
} }
else else
{ {
return Redirect("Index"); RedirectToAction("Goods", "Storekeeper");
} }
}
}
[HttpGet]
public IActionResult MainWorker()
{
return View();
}
} }
} }

View File

@ -0,0 +1,35 @@
using Microsoft.AspNetCore.Mvc;
namespace HardwareShopClientApp.Controllers
{
public class StorekeeperController : Controller
{
private readonly ILogger<HomeController> _logger;
public StorekeeperController(ILogger<HomeController> logger)
{
_logger = logger;
}
public IActionResult MainStorekeeper()
{
return View();
}
public IActionResult Components()
{
return View();
}
public IActionResult Goods()
{
return View();
}
public IActionResult Orders()
{
return View();
}
}
}

View File

@ -35,7 +35,7 @@ namespace HardwareShopClientApp.Controllers
[HttpGet] [HttpGet]
public IActionResult Purchases() public IActionResult Purchases()
{ {
return View(APIClient.GetRequest<List<PurchaseViewModel>>($"api/client/getpurchases?UserId={APIClient.User.Id}")); return View();
} }
[HttpPost] [HttpPost]

View File

@ -1,7 +1,24 @@
@{ @{
ViewData["Title"] = "Enter"; ViewData["Title"] = "Enter";
} }
@section Header {} @section Header {
<header>
<nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light bg-white border-bottom box-shadow mb-3">
<div class="container-fluid">
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target=".navbar-collapse" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="navbar-collapse collapse d-sm-inline-flex justify-content-between">
<ul class="navbar-nav flex-grow-1">
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Index">Index</a>
</li>
</ul>
</div>
</div>
</nav>
</header>
}
<div class="text-center"> <div class="text-center">
<h2 class="display-4">Вход в приложение</h2> <h2 class="display-4">Вход в приложение</h2>
</div> </div>
@ -16,8 +33,6 @@
</div> </div>
<div class="col-sm-2 d-flex justify-content-evenly align-items-baseline"> <div class="col-sm-2 d-flex justify-content-evenly align-items-baseline">
<button type="submit" class="btn btn-primary mt-3 px-4">Подтвердить</button> <button type="submit" class="btn btn-primary mt-3 px-4">Подтвердить</button>
<a asp-action="Register">Регистрация</a> </div><a asp-action="Register">Регистрация</a>
</div>
</form> </form>

View File

@ -1,35 +1,26 @@
@{ @{
ViewData["Title"] = "Home Page"; ViewData["Title"] = "Enter";
} }
@using HardwareShopContracts.ViewModels
@model List<PurchaseViewModel>
@section Header { @section Header {
<header> <header>
<nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light bg-white border-bottom box-shadow mb-3"> <nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light bg-white border-bottom box-shadow mb-3">
<div class="container-fluid"> <div class="container-fluid">
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target=".navbar-collapse" aria-controls="navbarSupportedContent" <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target=".navbar-collapse" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span> <span class="navbar-toggler-icon"></span>
</button> </button>
<div class="navbar-collapse collapse d-sm-inline-flex justify-content-between"> <div class="navbar-collapse collapse d-sm-inline-flex justify-content-between">
<ul class="navbar-nav flex-grow-1"> <ul class="navbar-nav flex-grow-1">
<li class="nav-item"> <li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Worker" asp-action="Purchases">Purchases</a> <a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Enter">Enter</a>
</li> </li>
<li class="nav-item"> <li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Worker" asp-action="Builds">Builds</a> <a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Register">Register</a>
</li> </li>
<li class="nav-item"> <li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Worker" asp-action="Comments">Comments</a> <a class="nav-link text-dark" asp-area="" asp-controller="Worker" asp-action="MainWorker">MainWorker</a>
</li> </li>
<li class="nav-item"> <li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Worker" asp-action="listComponents">listComponents</a> <a class="nav-link text-dark" asp-area="" asp-controller="Storekeeper" asp-action="MainStorekeeper">MainStorekeeper</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Worker" asp-action="WorkerReport">WorkerReport</a>
</li> </li>
</ul> </ul>
</div> </div>
@ -37,63 +28,7 @@
</nav> </nav>
</header> </header>
} }
<div>
<div class="text-center"> Основная страница
<h2 class="display-4">Регистрация</h2>
</div>
<div class="text-center">
@{
if (Model == null)
{
<h3 class="display-4">Авторизируйтесь</h3>
return;
}
<table class="table">
<thead>
<tr>
<th>
Номер
</th>
<th>
Блюдо
</th>
<th>
Дата создания
</th>
<th>
Количество
</th>
<th>
Сумма
</th>
<th>
Статус
</th>
</tr>
</thead>
<tbody>
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.Id)
</td>
<td>
@Html.DisplayFor(modelItem => item.DatePurchase)
</td>
<td>
@Html.DisplayFor(modelItem => item.Sum)
</td>
<td>
@Html.DisplayFor(modelItem => item.PurchaseStatus)
</td>
<td>
@Html.DisplayFor(modelItem => item.UserLogin)
</td>
</tr>
}
</tbody>
</table>
}
</div> </div>

View File

@ -1,7 +1,24 @@
@{ @{
ViewData["Title"] = "Register"; ViewData["Title"] = "Register";
} }
@section Header {} @section Header {
<header>
<nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light bg-white border-bottom box-shadow mb-3">
<div class="container-fluid">
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target=".navbar-collapse" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="navbar-collapse collapse d-sm-inline-flex justify-content-between">
<ul class="navbar-nav flex-grow-1">
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Index">Index</a>
</li>
</ul>
</div>
</div>
</nav>
</header>
}
<div class="text-center"> <div class="text-center">
<h2 class="display-4">Регистрация</h2> <h2 class="display-4">Регистрация</h2>
</div> </div>

View File

@ -1,10 +1,32 @@
<!DOCTYPE html> @using HardwareShopContracts.ViewModels
<html> @{
<head> ViewData["Title"] = "Goods";
<meta charset="utf-8" /> }
<title></title>
</head>
<body>
</body> @model List<ComponentViewModel>
</html>
@section Header {
<header>
<nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light bg-white border-bottom box-shadow mb-3">
<div class="container-fluid">
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target=".navbar-collapse" aria-controls="navbarSupportedContent"
aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="navbar-collapse collapse d-sm-inline-flex justify-content-between">
<ul class="navbar-nav flex-grow-1">
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Storekeeper" asp-action="Goods">Goods</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Storekeeper" asp-action="Components">Components</a>
</li>
</ul>
</div>
</div>
</nav>
</header>
}
<div>
привет, мы в компонентах
</div>

View File

@ -0,0 +1,35 @@
@using HardwareShopContracts.ViewModels
@{
ViewData["Title"] = "Goods";
}
@model List<GoodViewModel>
@section Header {
<header>
<nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light bg-white border-bottom box-shadow mb-3">
<div class="container-fluid">
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target=".navbar-collapse" aria-controls="navbarSupportedContent"
aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="navbar-collapse collapse d-sm-inline-flex justify-content-between">
<ul class="navbar-nav flex-grow-1">
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Storekeeper" asp-action="Components">Components</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Storekeeper" asp-action="Goods">Goods</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Storekeeper" asp-action="Orders">Orders</a>
</li>
</ul>
</div>
</div>
</nav>
</header>
}
<div>
привет, мы в товарах
</div>

View File

@ -0,0 +1,29 @@
@{
ViewData["Title"] = "MainStorekeeper";
}
@section Header {
<header>
<nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light bg-white border-bottom box-shadow mb-3">
<div class="container-fluid">
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target=".navbar-collapse" aria-controls="navbarSupportedContent"
aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="navbar-collapse collapse d-sm-inline-flex justify-content-between">
<ul class="navbar-nav flex-grow-1">
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Storekeeper" asp-action="Components">Components</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Storekeeper" asp-action="Goods">Goods</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Storekeeper" asp-action="Orders">Orders</a>
</li>
</ul>
</div>
</div>
</nav>
</header>
}

View File

@ -0,0 +1,35 @@
@using HardwareShopContracts.ViewModels
@{
ViewData["Title"] = "Goods";
}
@model List<OrderViewModel>
@section Header {
<header>
<nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light bg-white border-bottom box-shadow mb-3">
<div class="container-fluid">
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target=".navbar-collapse" aria-controls="navbarSupportedContent"
aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="navbar-collapse collapse d-sm-inline-flex justify-content-between">
<ul class="navbar-nav flex-grow-1">
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Storekeeper" asp-action="Components">Components</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Storekeeper" asp-action="Goods">Goods</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Storekeeper" asp-action="Orders">Orders</a>
</li>
</ul>
</div>
</div>
</nav>
</header>
}
<div>
привет, мы в заказах
</div>

View File

@ -15,13 +15,10 @@ namespace HardwareShopRestApi.Controllers
private readonly IUserLogic _logic; private readonly IUserLogic _logic;
private readonly IPurchaseLogic _purchaseLogic; public ClientController(IUserLogic logic, ILogger<ClientController> logger)
public ClientController(IUserLogic logic, IPurchaseLogic purchaseLogic, ILogger<ClientController> logger)
{ {
_logger = logger; _logger = logger;
_logic = logic; _logic = logic;
_purchaseLogic = purchaseLogic;
} }
[HttpGet] [HttpGet]
@ -55,20 +52,5 @@ namespace HardwareShopRestApi.Controllers
throw; throw;
} }
} }
[HttpGet]
public List<PurchaseViewModel>? GetPurchases(int userId)
{
try
{
return _purchaseLogic.ReadList(new PurchaseSearchModel { UserId = userId });
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения списка заказов клиента id={Id}", userId);
throw;
}
}
} }
} }

View File

@ -1,66 +0,0 @@
using HardwareShopContracts.BindingModels;
using HardwareShopContracts.BusinessLogicsContracts;
using Microsoft.AspNetCore.Mvc;
namespace HardwareShopRestApi.Controllers
{
[Route("api/[controller]/[action]")]
[ApiController]
public class MainController : Controller
{
private readonly ILogger _logger;
private readonly IPurchaseLogic _purchase;
private readonly IBuildLogic _build;
public MainController(ILogger<MainController> logger, IPurchaseLogic pur, IBuildLogic build)
{
_logger = logger;
_purchase = pur;
_build = build;
}
[HttpPost]
public void CreateBuild(BuildBindingModel model)
{
try
{
_build.Create(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка создания");
throw;
}
}
[HttpPost]
public void CreatePurchase(PurchaseBindingModel model)
{
try
{
_purchase.Create(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка создания");
throw;
}
}
[HttpPut]
public void UpdateBuild(BuildBindingModel model)
{
try
{
_build.Update(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка обновления");
throw;
}
}
}
}