Не работает AddReinforced
This commit is contained in:
parent
0de788dba4
commit
e28b8f2172
@ -48,3 +48,4 @@ namespace PrecastConcretePlantShopApp
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,32 +1,199 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using PrecastConcretePlantContracts.BindingModels;
|
||||
using PrecastConcretePlantContracts.SearchModels;
|
||||
using PrecastConcretePlantContracts.ViewModels;
|
||||
using PrecastConcretePlantShopApp.Models;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace PrecastConcretePlantShopApp.Controllers
|
||||
{
|
||||
public class HomeController : Controller
|
||||
{
|
||||
private readonly ILogger<HomeController> _logger;
|
||||
public class HomeController : Controller
|
||||
{
|
||||
private readonly ILogger<HomeController> _logger;
|
||||
|
||||
public HomeController(ILogger<HomeController> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
public HomeController(ILogger<HomeController> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public IActionResult Index()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
public IActionResult Index()
|
||||
{
|
||||
if (APIClient.IsAccessAllowed is false)
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
return View(APIClient.GetRequest<List<ShopViewModel>>($"api/shop/getshops"));
|
||||
}
|
||||
|
||||
public IActionResult Privacy()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
[HttpGet]
|
||||
public IActionResult Privacy()
|
||||
{
|
||||
if (APIClient.IsAccessAllowed is false)
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
return View();
|
||||
}
|
||||
|
||||
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
||||
public IActionResult Error()
|
||||
{
|
||||
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
|
||||
}
|
||||
}
|
||||
[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 password)
|
||||
{
|
||||
if (string.IsNullOrEmpty(password))
|
||||
{
|
||||
throw new Exception("Введите пароль");
|
||||
}
|
||||
APIClient.IsAccessAllowed = password.Equals(APIClient.AccessPassword);
|
||||
if (APIClient.IsAccessAllowed is false)
|
||||
{
|
||||
throw new Exception("Неверный пароль");
|
||||
}
|
||||
Response.Redirect("Index");
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult Create()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void Create(string name, string address, int maxCount)
|
||||
{
|
||||
if (APIClient.IsAccessAllowed is false)
|
||||
{
|
||||
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
|
||||
}
|
||||
if (maxCount <= 0)
|
||||
{
|
||||
throw new Exception("Количество и сумма должны быть больше 0");
|
||||
}
|
||||
if (string.IsNullOrEmpty(name))
|
||||
{
|
||||
throw new Exception($"Имя магазина не должно быть пустым");
|
||||
}
|
||||
if (string.IsNullOrEmpty(address))
|
||||
{
|
||||
throw new Exception($"Адрес магазина не должен быть пустым");
|
||||
}
|
||||
APIClient.PostRequest("api/shop/createshop", new ShopBindingModel
|
||||
{
|
||||
Name = name,
|
||||
Address = address,
|
||||
ReinforcedMaxCount = maxCount,
|
||||
});
|
||||
Response.Redirect("Index");
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public Tuple<string, ShopViewModel>? GetTableReinforcediesFromShop(int shop)
|
||||
{
|
||||
var result = APIClient.GetRequest<Tuple<ShopViewModel, IEnumerable<ReinforcedViewModel>, IEnumerable<int>>?>($"api/shop/getshopwithreinforcedies?id={shop}");
|
||||
if (result == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
var shopModel = result.Item1;
|
||||
var resultHtml = "";
|
||||
foreach (var (item, count) in result.Item2.Zip(result.Item3))
|
||||
{
|
||||
resultHtml += "<tr>";
|
||||
resultHtml += $"<td>{item?.ReinforcedName ?? string.Empty}</td>";
|
||||
resultHtml += $"<td>{item?.Price ?? 0}</td>";
|
||||
resultHtml += $"<td>{count}</td>";
|
||||
resultHtml += "</tr>";
|
||||
}
|
||||
return Tuple.Create(resultHtml, shopModel);
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult Update()
|
||||
{
|
||||
ViewBag.Shops = APIClient.GetRequest<List<ShopViewModel>>("api/shop/getshops");
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void Update(int shop, string name, string address)
|
||||
{
|
||||
if (APIClient.IsAccessAllowed is false)
|
||||
{
|
||||
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
|
||||
}
|
||||
if (string.IsNullOrEmpty(name))
|
||||
{
|
||||
throw new Exception($"Имя магазина не должно быть пустым");
|
||||
}
|
||||
if (string.IsNullOrEmpty(address))
|
||||
{
|
||||
throw new Exception($"Адрес магазина не должен быть пустым");
|
||||
}
|
||||
APIClient.PostRequest("api/shop/updateshop", new ShopBindingModel
|
||||
{
|
||||
Id = shop,
|
||||
Name = name,
|
||||
Address = address,
|
||||
});
|
||||
Response.Redirect("Index");
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult Delete()
|
||||
{
|
||||
ViewBag.Shops = APIClient.GetRequest<List<ShopViewModel>>("api/shop/getshops");
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void Delete(int shop)
|
||||
{
|
||||
if (APIClient.IsAccessAllowed is false)
|
||||
{
|
||||
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
|
||||
}
|
||||
APIClient.PostRequest("api/shop/deleteshop", new ShopBindingModel
|
||||
{
|
||||
Id = shop,
|
||||
});
|
||||
Response.Redirect("Index");
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult AddReinforced()
|
||||
{
|
||||
ViewBag.Shops = APIClient.GetRequest<List<ShopViewModel>>("api/shop/getshops");
|
||||
ViewBag.Reinforcedies = APIClient.GetRequest<List<ReinforcedViewModel>>("api/main/getreinforcedlist");
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void AddReinforced(int shop, int reinforced, int count)
|
||||
{
|
||||
if (APIClient.IsAccessAllowed is false)
|
||||
{
|
||||
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
|
||||
}
|
||||
if (count <= 0)
|
||||
{
|
||||
throw new Exception("Количество должно быть больше 0");
|
||||
}
|
||||
APIClient.PostRequest("api/shop/addreinforcedinshop", Tuple.Create(
|
||||
new ShopSearchModel() { Id = shop },
|
||||
new ReinforcedViewModel() { Id = reinforced },
|
||||
count
|
||||
));
|
||||
Response.Redirect("Index");
|
||||
}
|
||||
}
|
||||
}
|
@ -10,4 +10,8 @@
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\PrecastConcretePlantContracts\PrecastConcretePlantContracts.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
@ -1,3 +1,5 @@
|
||||
using PrecastConcretePlantShopApp;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
// Add services to the container.
|
||||
|
@ -0,0 +1,33 @@
|
||||
@using PrecastConcretePlantDataModels.Models
|
||||
@using PrecastConcretePlantContracts.ViewModels;
|
||||
|
||||
@model Dictionary<int, (IReinforcedModel, int)>
|
||||
|
||||
@{
|
||||
ViewData["Title"] = "AddReinforced";
|
||||
}
|
||||
<div class="text-center">
|
||||
<h2 class="display-4">Пополнения магазина изделием</h2>
|
||||
</div>
|
||||
<form method="post">
|
||||
<div class="row">
|
||||
<div class="col-4">Выбранный магазин:</div>
|
||||
<div class="col-8">
|
||||
<select id="shop" name="shop" class="form-control" asp-items="@(new SelectList(@ViewBag.Shops, "Id", "Name"))"></select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-4">Выбранное изделие:</div>
|
||||
<div class="col-8">
|
||||
<select id="reinforced" name="reinforced" class="form-control" asp-items="@(new SelectList(@ViewBag.Pastries, "Id", "PastryName"))"></select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-4">Количество:</div>
|
||||
<div class="col-8"><input type="text" id="count" name="count"/></div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-8"></div>
|
||||
<div class="col-4"><input type="submit" value="Добавить" class="btn btn-primary" /></div>
|
||||
</div>
|
||||
</form>
|
@ -0,0 +1,24 @@
|
||||
@{
|
||||
ViewData["Title"] = "Create";
|
||||
}
|
||||
<div class="text-center">
|
||||
<h2 class="display-4">Создание магазина</h2>
|
||||
</div>
|
||||
<form method="post">
|
||||
<div class="row">
|
||||
<div class="col-4">Название магазина:</div>
|
||||
<div class="col-8"><input type="text" name="name" id="name" /></div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-4">Адрес магазина:</div>
|
||||
<div class="col-8"><input type="text" id="address" name="address"/></div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-4">Максимальное кол-во изделий:</div>
|
||||
<div class="col-8"><input type="text" id="maxCount" name="maxCount"/></div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-8"></div>
|
||||
<div class="col-4"><input type="submit" value="Создать" class="btn btn-primary" /></div>
|
||||
</div>
|
||||
</form>
|
@ -0,0 +1,18 @@
|
||||
@{
|
||||
ViewData["Title"] = "Update";
|
||||
}
|
||||
<div class="text-center">
|
||||
<h2 class="display-4">Редактирование магазина</h2>
|
||||
</div>
|
||||
<form method="post">
|
||||
<div class="row">
|
||||
<div class="col-4">Выбранный магазин:</div>
|
||||
<div class="col-8">
|
||||
<select id="shop" name="shop" class="form-control" asp-items="@(new SelectList(@ViewBag.Shops, "Id", "Name"))"></select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-8"></div>
|
||||
<div class="col-4"><input type="submit" value="Удалить" class="btn btn-primary" /></div>
|
||||
</div>
|
||||
</form>
|
@ -0,0 +1,15 @@
|
||||
@{
|
||||
ViewData["Title"] = "Enter";
|
||||
}
|
||||
|
||||
<div class="text-center">
|
||||
<h2 class="display-4">Вход в приложение</h2>
|
||||
</div>
|
||||
<form method="post">
|
||||
<div class="row">
|
||||
<div class="col-4">Пароль:</div>
|
||||
<div class="col-8"><input type="password" name="password" /></div>
|
||||
<div class="col-8"></div>
|
||||
<div class="col-4"><input type="submit" value="Вход" class="btn btn-primary" /></div>
|
||||
</div>
|
||||
</form>
|
@ -1,8 +1,66 @@
|
||||
@{
|
||||
ViewData["Title"] = "Home Page";
|
||||
@using PrecastConcretePlantContracts.ViewModels
|
||||
|
||||
@model List<ShopViewModel>
|
||||
|
||||
@{
|
||||
ViewData["Title"] = "Home Page";
|
||||
}
|
||||
|
||||
<div class="text-center">
|
||||
<h1 class="display-4">Welcome</h1>
|
||||
<p>Learn about <a href="https://docs.microsoft.com/aspnet/core">building Web apps with ASP.NET Core</a>.</p>
|
||||
<h1 class="display-4">Магазины</h1>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="text-center">
|
||||
@{
|
||||
if (Model == null)
|
||||
{
|
||||
<h3 class="display-4">Введите пароль</h3>
|
||||
return;
|
||||
}
|
||||
|
||||
<p>
|
||||
<a asp-action="Create">Создать магазин</a>
|
||||
<a asp-action="Update">Редактировать магазин</a>
|
||||
<a asp-action="Delete">Удалить магазин</a>
|
||||
<a asp-action="AddReinforced">Добавить изделие в магазин</a>
|
||||
</p>
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>
|
||||
Название магазина
|
||||
</th>
|
||||
<th>
|
||||
Адрес
|
||||
</th>
|
||||
<th>
|
||||
Дата открытия
|
||||
</th>
|
||||
<th>
|
||||
Максимальное количество изделий
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (var item in Model)
|
||||
{
|
||||
<tr>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.Name)
|
||||
</td>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.Address)
|
||||
</td>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.DateOpening)
|
||||
</td>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.ReinforcedMaxCount)
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
}
|
||||
</div>
|
||||
|
@ -0,0 +1,71 @@
|
||||
@using PrecastConcretePlantContracts.ViewModels;
|
||||
@using PrecastConcretePlantDataModels.Models;
|
||||
|
||||
@{
|
||||
ViewData["Title"] = "Update";
|
||||
}
|
||||
<div class="text-center">
|
||||
<h2 class="display-4">Редактирование магазина</h2>
|
||||
</div>
|
||||
<form method="post">
|
||||
<div class="row">
|
||||
<div class="col-4">Выбранный магазин:</div>
|
||||
<div class="col-8">
|
||||
<select id="shop" name="shop" class="form-control" asp-items="@(new SelectList(@ViewBag.Shops, "Id", "Name"))"></select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-4">Новое название магазина:</div>
|
||||
<div class="col-8"><input type="text" name="name" id="name" /></div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-4">Адрес магазина:</div>
|
||||
<div class="col-8"><input type="text" id="address" name="address"/></div>
|
||||
</div>
|
||||
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>
|
||||
Название изделия
|
||||
</th>
|
||||
<th>
|
||||
Цена
|
||||
</th>
|
||||
<th>
|
||||
Количество
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="table-reinforcedies">
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-8"></div>
|
||||
<div class="col-4"><input type="submit" value="Изменить" class="btn btn-primary" /></div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<script>
|
||||
function check() {
|
||||
var shop = $('#shop').val();
|
||||
if (shop) {
|
||||
$.ajax({
|
||||
method: "GET",
|
||||
url: "/Home/GetTableReinforcediesFromShop",
|
||||
data: { shop: shop },
|
||||
success: function (result) {
|
||||
if (result != null)
|
||||
{
|
||||
$('#name').val(result.item2.name);
|
||||
$('#address').val(result.item2.address);
|
||||
$('#table-reinforcedies').html(result.item1);
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
check();
|
||||
$('#shop').on('change', (e) => check());
|
||||
</script>
|
@ -7,23 +7,23 @@
|
||||
<link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css" />
|
||||
<link rel="stylesheet" href="~/css/site.css" asp-append-version="true" />
|
||||
<link rel="stylesheet" href="~/PrecastConcretePlantShopApp.styles.css" asp-append-version="true" />
|
||||
<script src="~/lib/jquery/dist/jquery.min.js"></script>
|
||||
<script src="~/lib/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
|
||||
<script src="~/js/site.js" asp-append-version="true"></script>
|
||||
</head>
|
||||
<body>
|
||||
<header>
|
||||
<nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light bg-white border-bottom box-shadow mb-3">
|
||||
<div class="container-fluid">
|
||||
<a class="navbar-brand" asp-area="" asp-controller="Home" asp-action="Index">PrecastConcretePlantShopApp</a>
|
||||
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target=".navbar-collapse" aria-controls="navbarSupportedContent"
|
||||
<a class="navbar-brand" asp-area="" asp-controller="Home" asp-action="Index">Завод</a>
|
||||
<button class="navbar-toggler" type="button" data-toggle="collapse" data-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">
|
||||
<div class="navbar-collapse collapse d-sm-inline-flex flex-sm-row-reverse">
|
||||
<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">Home</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Privacy">Privacy</a>
|
||||
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Index">Магазины</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
@ -41,9 +41,6 @@
|
||||
© 2023 - PrecastConcretePlantShopApp - <a asp-area="" asp-controller="Home" asp-action="Privacy">Privacy</a>
|
||||
</div>
|
||||
</footer>
|
||||
<script src="~/lib/jquery/dist/jquery.min.js"></script>
|
||||
<script src="~/lib/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
|
||||
<script src="~/js/site.js" asp-append-version="true"></script>
|
||||
@await RenderSectionAsync("Scripts", required: false)
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue
Block a user