full hard_lab5

This commit is contained in:
DavidMakarov 2024-05-17 02:35:47 +04:00
parent 5398571593
commit 2726b6e623
4 changed files with 31 additions and 6 deletions

View File

@ -0,0 +1,8 @@
namespace FlowerShopContracts.ViewModels
{
public class ShopFlowerViewModel
{
public string FlowerName { get; set; }
public int Count { get; set; }
}
}

View File

@ -19,5 +19,6 @@ namespace FlowerShopContracts.ViewModels
} = new();
[DisplayName("Максимальное количество цветков")]
public int MaximumFlowers { get; set; }
public Dictionary<int, ShopFlowerViewModel> ViewFlowers { get; set; } = new();
}
}

View File

@ -2,7 +2,6 @@
using FlowerShopContracts.BusinessLogicsContracts;
using FlowerShopContracts.SearchModels;
using FlowerShopContracts.ViewModels;
using FlowerShopDataModels.Models;
using Microsoft.AspNetCore.Mvc;
namespace FlowerShopRestApi.Controllers
@ -37,7 +36,21 @@ namespace FlowerShopRestApi.Controllers
{
try
{
return _logic.ReadElement(new ShopSearchModel { Id = shopId });
var element = _logic.ReadElement(new ShopSearchModel { Id = shopId });
var newDict = new Dictionary<int, ShopFlowerViewModel>();
if (element != null)
{
foreach (var item in element.ShopFlowers)
{
newDict.Add(item.Key, new ShopFlowerViewModel
{
FlowerName = item.Value.Item1.FlowerName,
Count = item.Value.Item2,
});
}
element.ViewFlowers = newDict;
}
return element;
}
catch (Exception ex)
{
@ -89,7 +102,10 @@ namespace FlowerShopRestApi.Controllers
{
try
{
_logic.MakeSupply(shopFlowers.Item1, shopFlowers.Item2, shopFlowers.Item3);
if (!_logic.MakeSupply(shopFlowers.Item1, shopFlowers.Item2, shopFlowers.Item3))
{
throw new Exception("Попытка добавить в магазин число элементов, большее чем максимум");
}
}
catch (Exception ex)
{

View File

@ -61,11 +61,11 @@
</tr>
</thead>
<tbody>
@foreach (var item in Model.ShopFlowers)
@foreach (var item in Model.ViewFlowers)
{
<tr>
<td>@Html.DisplayFor(ShopItem => item.Value.Item1.FlowerName)</td>
<td>@Html.DisplayFor(ShopItem => item.Value.Item2)</td>
<td>@Html.DisplayFor(shopItem => item.Value.FlowerName)</td>
<td>@Html.DisplayFor(shopItem => item.Value.Count)</td>
</tr>
}
</tbody>