fix in controllers
This commit is contained in:
parent
68e542bce8
commit
ae16a70b32
@ -32,51 +32,20 @@ namespace FlowerShopRestApi.Controllers
|
||||
throw;
|
||||
}
|
||||
}
|
||||
[HttpGet]
|
||||
public Tuple<ShopViewModel, List<FlowerViewModel>, List<int>>? GetShopFlowers(int shopId)
|
||||
{
|
||||
try
|
||||
{
|
||||
var shop = _logic.ReadElement(new() { Id = shopId });
|
||||
if (shop == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
var tuple = Tuple.Create(shop,
|
||||
shop.ShopFlowers.Select(x => new FlowerViewModel()
|
||||
{
|
||||
Id = x.Value.Item1.Id,
|
||||
Price = x.Value.Item1.Price,
|
||||
FlowerName = x.Value.Item1.FlowerName,
|
||||
}).ToList(),
|
||||
shop.ShopFlowers.Select(x => x.Value.Item2).ToList());
|
||||
return tuple;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка получения магазина с цветами");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
[HttpGet]
|
||||
public Dictionary<int, (IFlowerModel, int)>? GetListFlower(int shopId)
|
||||
{
|
||||
try
|
||||
{
|
||||
var shop = _logic.ReadElement(new() { Id = shopId });
|
||||
if (shop == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return shop.ShopFlowers;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка получения цветов магазина");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
[HttpPost]
|
||||
[HttpGet]
|
||||
public ShopViewModel? GetShop(int shopId)
|
||||
{
|
||||
try
|
||||
{
|
||||
return _logic.ReadElement(new ShopSearchModel { Id = shopId });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка получения списка магазинов");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
[HttpPost]
|
||||
public void CreateShop(ShopBindingModel model)
|
||||
{
|
||||
try
|
||||
|
@ -92,36 +92,13 @@ namespace FlowerShopShopApp.Controllers
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public Tuple<ShopViewModel, string>? GetShopFlowers(int shopId)
|
||||
{
|
||||
var result = APIClient.GetRequest<Tuple<ShopViewModel, List<FlowerViewModel>, List<int>>>
|
||||
($"api/shop/getshopflowers?shopId={shopId}");
|
||||
if (result == null)
|
||||
{
|
||||
return default;
|
||||
}
|
||||
string flowerTable = "";
|
||||
for (int i = 0; i < result.Item2.Count; i++)
|
||||
{
|
||||
var flower = result.Item2[i];
|
||||
var count = result.Item3[i];
|
||||
flowerTable += "<tr>";
|
||||
flowerTable += $"<td>{flower.FlowerName}</td>";
|
||||
flowerTable += $"<td>{flower.Price}</td>";
|
||||
flowerTable += $"<td>{count}</td>";
|
||||
flowerTable += "</tr>";
|
||||
}
|
||||
return Tuple.Create(result.Item1, flowerTable);
|
||||
}
|
||||
[HttpGet]
|
||||
public IActionResult Update()
|
||||
public IActionResult Update(int Id)
|
||||
{
|
||||
if (!APIClient.AuthenticationDone)
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
ViewBag.Shops = APIClient.GetRequest<List<ShopViewModel>>($"api/shop/getshoplist");
|
||||
return View("Shop");
|
||||
return View("Shop", APIClient.GetRequest<ShopViewModel>($"api/shop/getshop?shopId={Id}"));
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
@ -187,7 +164,7 @@ namespace FlowerShopShopApp.Controllers
|
||||
{
|
||||
throw new Exception("Количество должно быть больше 0");
|
||||
}
|
||||
APIClient.PostRequest("api/shop/storereplenishment", Tuple.Create(
|
||||
APIClient.PostRequest("api/shop/makesupply", Tuple.Create(
|
||||
new ShopSearchModel() { Id = shop },
|
||||
new FlowerViewModel() { Id = flower },
|
||||
count
|
||||
|
@ -64,8 +64,8 @@
|
||||
@foreach (var item in Model.ShopFlowers)
|
||||
{
|
||||
<tr>
|
||||
<td>@Html.DisplayFor(modelItem => item.Value.Item1.FlowerName)</td>
|
||||
<td>@Html.DisplayFor(modelItem => item.Value.Item2)</td>
|
||||
<td>@Html.DisplayFor(ShopItem => item.Value.Item1.FlowerName)</td>
|
||||
<td>@Html.DisplayFor(ShopItem => item.Value.Item2)</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
|
@ -10,8 +10,8 @@
|
||||
<select class="form-select form-select-lg" id="shop" name="shop" asp-items="@(new SelectList(@ViewBag.Shops,"Id", "ShopName"))"></select>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Ремонт</label>
|
||||
<select class="form-select form-select-lg" id="repair" name="repair" asp-items="@(new SelectList(@ViewBag.Repairs,"Id", "RepairName"))"></select>
|
||||
<label class="form-label">Цветок</label>
|
||||
<select class="form-select form-select-lg" id="flower" name="flower" asp-items="@(new SelectList(@ViewBag.Flowers,"Id", "FlowerName"))"></select>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Количество</label>
|
||||
|
@ -11,8 +11,8 @@
|
||||
<body>
|
||||
<header>
|
||||
<nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light bg-white border-bottom box-shadow mb-3">
|
||||
<div class="container">
|
||||
<a class="navbar-brand" asp-area="" asp-page="/Index">FlowerShopShopApp</a>
|
||||
<div class="container-fluid">
|
||||
<a class="navbar-brand" asp-area="" asp-controller="Home" asp-action="Index">FlowerShopShopApp</a>
|
||||
<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>
|
||||
@ -20,10 +20,10 @@
|
||||
<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-page="/Index">Home</a>
|
||||
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Index">Главная</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-dark" asp-area="" asp-page="/Privacy">Privacy</a>
|
||||
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Supply">Пополнение</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
@ -38,14 +38,12 @@
|
||||
|
||||
<footer class="border-top footer text-muted">
|
||||
<div class="container">
|
||||
© 2024 - FlowerShopShopApp - <a asp-area="" asp-page="/Privacy">Privacy</a>
|
||||
© 2024 - FlowerShopShopApp - <a asp-area="" asp-controller="Home" asp-action="Index">Главная</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