full hard_lab5
This commit is contained in:
parent
5398571593
commit
2726b6e623
@ -0,0 +1,8 @@
|
||||
namespace FlowerShopContracts.ViewModels
|
||||
{
|
||||
public class ShopFlowerViewModel
|
||||
{
|
||||
public string FlowerName { get; set; }
|
||||
public int Count { get; set; }
|
||||
}
|
||||
}
|
@ -19,5 +19,6 @@ namespace FlowerShopContracts.ViewModels
|
||||
} = new();
|
||||
[DisplayName("Максимальное количество цветков")]
|
||||
public int MaximumFlowers { get; set; }
|
||||
public Dictionary<int, ShopFlowerViewModel> ViewFlowers { get; set; } = new();
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -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>
|
||||
|
Loading…
Reference in New Issue
Block a user