Compare commits
No commits in common. "726036b570d3293133242389a30c2d2175170907" and "d528524f2cf7a377851ceec46bb2838dd18b918e" have entirely different histories.
726036b570
...
d528524f2c
@ -1,6 +1,7 @@
|
|||||||
using SushiBarContracts.BindingModels;
|
using SushiBarContracts.BindingModels;
|
||||||
using SushiBarContracts.SearchModels;
|
using SushiBarContracts.SearchModels;
|
||||||
using SushiBarContracts.ViewModels;
|
using SushiBarContracts.ViewModels;
|
||||||
|
using SushiBarDataModels.Models;
|
||||||
|
|
||||||
namespace SushiBarContracts.StoragesContracts
|
namespace SushiBarContracts.StoragesContracts
|
||||||
{
|
{
|
||||||
@ -12,5 +13,7 @@ namespace SushiBarContracts.StoragesContracts
|
|||||||
SushiViewModel? Insert(SushiBindingModel model);
|
SushiViewModel? Insert(SushiBindingModel model);
|
||||||
SushiViewModel? Update(SushiBindingModel model);
|
SushiViewModel? Update(SushiBindingModel model);
|
||||||
SushiViewModel? Delete(SushiBindingModel model);
|
SushiViewModel? Delete(SushiBindingModel model);
|
||||||
|
bool HasSushi(ISushiModel model, int needCount);
|
||||||
|
bool SellSushi(ISushiModel model, int count);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -41,8 +41,14 @@ namespace SushiBarFileImplement.Implements
|
|||||||
private OrderViewModel GetViewModel(Order order)
|
private OrderViewModel GetViewModel(Order order)
|
||||||
{
|
{
|
||||||
var viewModel = order.GetViewModel;
|
var viewModel = order.GetViewModel;
|
||||||
var sushi = source.ListSushi.FirstOrDefault(x => x.Id == order.SushiId);
|
foreach (var sushi in source.ListSushi)
|
||||||
if (sushi != null) viewModel.SushiName = sushi.SushiName;
|
{
|
||||||
|
if (sushi.Id == order.SushiId)
|
||||||
|
{
|
||||||
|
viewModel.SushiName = sushi.SushiName;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
return viewModel;
|
return viewModel;
|
||||||
}
|
}
|
||||||
public OrderViewModel? Insert(OrderBindingModel model)
|
public OrderViewModel? Insert(OrderBindingModel model)
|
||||||
|
@ -72,5 +72,40 @@ namespace SushiBarFileImplement.Implements
|
|||||||
}
|
}
|
||||||
return null;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
using SushiBarContracts.SearchModels;
|
using SushiBarContracts.SearchModels;
|
||||||
using SushiBarContracts.StoragesContracts;
|
using SushiBarContracts.StoragesContracts;
|
||||||
using SushiBarContracts.ViewModels;
|
using SushiBarContracts.ViewModels;
|
||||||
|
using SushiBarDataModels.Models;
|
||||||
using SushiBarListImplement.Models;
|
using SushiBarListImplement.Models;
|
||||||
|
|
||||||
namespace SushiBarListImplement.Implements
|
namespace SushiBarListImplement.Implements
|
||||||
@ -98,5 +99,15 @@ namespace SushiBarListImplement.Implements
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool HasSushi(ISushiModel model, int needCount)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool SellSushi(ISushiModel model, int count)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user