Merge branch 'LabWork02Hard' into LabWork03Hard

This commit is contained in:
dasha 2023-03-19 12:39:55 +04:00
commit 726036b570
4 changed files with 2 additions and 57 deletions

View File

@ -1,7 +1,6 @@
using SushiBarContracts.BindingModels;
using SushiBarContracts.SearchModels;
using SushiBarContracts.ViewModels;
using SushiBarDataModels.Models;
namespace SushiBarContracts.StoragesContracts
{
@ -13,7 +12,5 @@ namespace SushiBarContracts.StoragesContracts
SushiViewModel? Insert(SushiBindingModel model);
SushiViewModel? Update(SushiBindingModel model);
SushiViewModel? Delete(SushiBindingModel model);
bool HasSushi(ISushiModel model, int needCount);
bool SellSushi(ISushiModel model, int count);
}
}

View File

@ -41,14 +41,8 @@ namespace SushiBarFileImplement.Implements
private OrderViewModel GetViewModel(Order order)
{
var viewModel = order.GetViewModel;
foreach (var sushi in source.ListSushi)
{
if (sushi.Id == order.SushiId)
{
viewModel.SushiName = sushi.SushiName;
break;
}
}
var sushi = source.ListSushi.FirstOrDefault(x => x.Id == order.SushiId);
if (sushi != null) viewModel.SushiName = sushi.SushiName;
return viewModel;
}
public OrderViewModel? Insert(OrderBindingModel model)

View File

@ -72,40 +72,5 @@ namespace SushiBarFileImplement.Implements
}
return null;
}
public bool HasSushi(ISushiModel sushi, int needCount)
{
var temp = source.Shops
.Select(x => x.ListSushi
.FirstOrDefault(x => x.Key == sushi.Id).Value.Item2).Sum();
return temp >= needCount;
}
public bool SellSushi(ISushiModel model, int count)
{
if (!HasSushi(model, count))
{
return false;
}
foreach (var shop in source.Shops.Where(x => x.ListSushi.ContainsKey(model.Id)))
{
if (shop.ListSushi[model.Id].Item2 < count)
{
shop.ListSushi[model.Id] = (shop.ListSushi[model.Id].Item1, 0);
count -= shop.ListSushi[model.Id].Item2;
}
else
{
shop.ListSushi[model.Id] = (shop.ListSushi[model.Id].Item1,
shop.ListSushi[model.Id].Item2 - count);
count -= count;
}
if (count <= 0)
{
return true;
}
}
return true;
}
}
}

View File

@ -2,7 +2,6 @@
using SushiBarContracts.SearchModels;
using SushiBarContracts.StoragesContracts;
using SushiBarContracts.ViewModels;
using SushiBarDataModels.Models;
using SushiBarListImplement.Models;
namespace SushiBarListImplement.Implements
@ -99,15 +98,5 @@ namespace SushiBarListImplement.Implements
}
return null;
}
public bool HasSushi(ISushiModel model, int needCount)
{
throw new NotImplementedException();
}
public bool SellSushi(ISushiModel model, int count)
{
throw new NotImplementedException();
}
}
}