This commit is contained in:
bekodeg 2024-05-05 18:56:39 +04:00
parent e09c8d19c2
commit 49791fd7ff
6 changed files with 54 additions and 4 deletions

View File

@ -4,6 +4,7 @@ using SushiBarContracts.BusinessLogicsContracts;
using SushiBarContracts.SearchModels;
using SushiBarContracts.StoragesContracts;
using SushiBarContracts.ViewModels;
using SushiBarDataModels.Models;
namespace SushiBarBusinessLogic.BusinessLogics
{
@ -99,5 +100,15 @@ namespace SushiBarBusinessLogic.BusinessLogics
throw new InvalidOperationException("Магазин с таким названием уже есть");
}
}
public bool supplySushi(ShopBindingModel shopModel, SushiBindingModel sushiModel)
{
CheckModel(shopModel, false);
ShopViewModel? shop = _shopStorage.GetElement(new ShopSearchModel { Id = shopModel.Id});
if (shop == null)
{
return false;
}
ShopViewModel? shop = _shopStorage.Update(S)
}
}

View File

@ -8,5 +8,10 @@ namespace SushiBarContracts.BindingModels
public string ShopName { get; set; } = string.Empty;
public string Address { get; set; } = string.Empty;
public DateTime DateCreate { get; set; } = DateTime.Now;
public Dictionary<int, (ISushiModel, int)> ShopSushi
{
get;
set;
} = new();
}
}

View File

@ -11,5 +11,6 @@ namespace SushiBarContracts.BusinessLogicsContracts
bool Create(ShopBindingModel model);
bool Update(ShopBindingModel model);
bool Delete(ShopBindingModel model);
bool supplySushi(ShopBindingModel shopModel, SushiBindingModel sushiModel, int count);
}
}

View File

@ -5,5 +5,6 @@
string ShopName { get; }
string Address { get; }
DateTime DateCreate { get; }
Dictionary<int, (ISushiModel, int)> ShopSushi {get;}
}
}

View File

@ -2,7 +2,10 @@
using SushiBarContracts.SearchModels;
using SushiBarContracts.StoragesContracts;
using SushiBarContracts.ViewModels;
using SushiBarDataModels.Models;
using SushiBarListImplement.Models;
using System.ComponentModel.Design;
using System.Reflection;
namespace SushiBarListImplement.Implements
{
@ -98,6 +101,33 @@ namespace SushiBarListImplement.Implements
}
return null;
}
з
public ShopViewModel? supplySushi(ShopBindingModel model)
{
int id = -1;
for (int i = 0; i < _source.Shops.Count; ++i)
{
if (_source.Shops[i].Id == model.Id)
{
id = i;
break;
}
}
if (id < 0)
{
return null;
}
model.ShopName = _source.Shops[id].ShopName;
model.Address = _source.Shops[id].Address;
model.DateCreate = _source.Shops[id].DateCreate;
foreach (var key in model.ShopSushi.Keys)
{
if (_source.Shops[id].ShopSushi.ContainsKey(key)){
model.ShopSushi[key] = (model.ShopSushi[key].Item1, model.ShopSushi[key].Item2 + _source.Shops[id].ShopSushi[key].Item2);
}
}
_source.Shops[id].Update(model);
return _source.Shops[id].GetViewModel;
}
}
}

View File

@ -10,7 +10,7 @@ namespace SushiBarListImplement.Models
public string ShopName { get; private set; } = string.Empty;
public string Address { get; private set; } = string.Empty;
public DateTime DateCreate { get; private set; }
public Dictionary<int, (ISushiModel, int)> ShopShoshi
public Dictionary<int, (ISushiModel, int)> ShopSushi
{
get;
private set;
@ -26,7 +26,8 @@ namespace SushiBarListImplement.Models
Id = model.Id,
ShopName = model.ShopName,
Address = model.Address,
DateCreate = model.DateCreate
DateCreate = model.DateCreate,
ShopSushi = model.ShopSushi
};
}
public void Update(ShopBindingModel? model)
@ -38,13 +39,14 @@ namespace SushiBarListImplement.Models
ShopName = model.ShopName;
Address = model.Address;
DateCreate = model.DateCreate;
ShopSushi = model.ShopSushi;
}
public ShopViewModel GetViewModel => new()
{
Id = Id,
ShopName = ShopName,
Address = Address,
DateCreate = DateCreate
DateCreate = DateCreate,
};
}
}