Compare commits

..

No commits in common. "726036b570d3293133242389a30c2d2175170907" and "d528524f2cf7a377851ceec46bb2838dd18b918e" have entirely different histories.

4 changed files with 57 additions and 2 deletions

View File

@ -1,6 +1,7 @@
using SushiBarContracts.BindingModels;
using SushiBarContracts.SearchModels;
using SushiBarContracts.ViewModels;
using SushiBarDataModels.Models;
namespace SushiBarContracts.StoragesContracts
{
@ -12,5 +13,7 @@ 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,8 +41,14 @@ namespace SushiBarFileImplement.Implements
private OrderViewModel GetViewModel(Order order)
{
var viewModel = order.GetViewModel;
var sushi = source.ListSushi.FirstOrDefault(x => x.Id == order.SushiId);
if (sushi != null) viewModel.SushiName = sushi.SushiName;
foreach (var sushi in source.ListSushi)
{
if (sushi.Id == order.SushiId)
{
viewModel.SushiName = sushi.SushiName;
break;
}
}
return viewModel;
}
public OrderViewModel? Insert(OrderBindingModel model)

View File

@ -72,5 +72,40 @@ 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,6 +2,7 @@
using SushiBarContracts.SearchModels;
using SushiBarContracts.StoragesContracts;
using SushiBarContracts.ViewModels;
using SushiBarDataModels.Models;
using SushiBarListImplement.Models;
namespace SushiBarListImplement.Implements
@ -98,5 +99,15 @@ 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();
}
}
}