Исправлена логика сущности "Магазин"

This commit is contained in:
Данияр Аглиуллов 2023-02-05 17:05:49 +04:00
parent ed54dc6fbe
commit d86f89eca4
3 changed files with 71 additions and 8 deletions

View File

@ -52,6 +52,7 @@ namespace ConfectioneryBusinessLogic
public bool Create(ShopBindingModel model) public bool Create(ShopBindingModel model)
{ {
CheckModel(model); CheckModel(model);
model.Pastries = new();
if (_shopStorage.Insert(model) == null) if (_shopStorage.Insert(model) == null)
{ {
_logger.LogWarning("Insert operation failed"); _logger.LogWarning("Insert operation failed");
@ -62,6 +63,7 @@ namespace ConfectioneryBusinessLogic
public bool Update(ShopBindingModel model) public bool Update(ShopBindingModel model)
{ {
CheckModel(model); CheckModel(model);
model.Pastries = new();
if (_shopStorage.Update(model) == null) if (_shopStorage.Update(model) == null)
{ {
_logger.LogWarning("Update operation failed"); _logger.LogWarning("Update operation failed");

View File

@ -8,13 +8,13 @@ namespace ConfectioneryListImplement
public List<Component> Components { get; set; } public List<Component> Components { get; set; }
public List<Order> Orders { get; set; } public List<Order> Orders { get; set; }
public List<Pastry> Pastry { get; set; } public List<Pastry> Pastry { get; set; }
public List<Shop> Shop { get; set; } public List<Shop> Shops { get; set; }
private DataListSingleton() private DataListSingleton()
{ {
Components = new List<Component>(); Components = new List<Component>();
Orders = new List<Order>(); Orders = new List<Order>();
Pastry = new List<Pastry>(); Pastry = new List<Pastry>();
Shop = new List<Shop>(); Shops = new List<Shop>();
} }
public static DataListSingleton GetInstance() public static DataListSingleton GetInstance()
{ {

View File

@ -15,32 +15,93 @@ namespace ConfectioneryListImplement
public ShopViewModel? Delete(ShopBindingModel model) public ShopViewModel? Delete(ShopBindingModel model)
{ {
throw new NotImplementedException(); for (int i = 0; i < _source.Shops.Count; ++i)
{
if (_source.Shops[i].Id == model.Id)
{
var element = _source.Shops[i];
_source.Shops.RemoveAt(i);
return element.GetViewModel;
}
}
return null;
} }
public ShopViewModel? GetElement(ShopSearchModel model) public ShopViewModel? GetElement(ShopSearchModel model)
{ {
throw new NotImplementedException(); if (string.IsNullOrEmpty(model.Name) && !model.Id.HasValue)
{
return null;
}
foreach (var shop in _source.Shops)
{
if ((!string.IsNullOrEmpty(model.Name) &&
shop.Name == model.Name) ||
(model.Id.HasValue && shop.Id == model.Id))
{
return shop.GetViewModel;
}
}
return null;
} }
public List<ShopViewModel> GetFilteredList(ShopSearchModel model) public List<ShopViewModel> GetFilteredList(ShopSearchModel model)
{ {
throw new NotImplementedException(); var result = new List<ShopViewModel>();
if (string.IsNullOrEmpty(model.Name))
{
return result;
}
foreach (var shop in _source.Shops)
{
if (shop.Name.Contains(model.Name ?? string.Empty))
{
result.Add(shop.GetViewModel);
}
}
return result;
} }
public List<ShopViewModel> GetFullList() public List<ShopViewModel> GetFullList()
{ {
throw new NotImplementedException(); var result = new List<ShopViewModel>();
foreach (var shop in _source.Shops)
{
result.Add(shop.GetViewModel);
}
return result;
} }
public ShopViewModel? Insert(ShopBindingModel model) public ShopViewModel? Insert(ShopBindingModel model)
{ {
throw new NotImplementedException(); model.Id = 1;
foreach (var shop in _source.Shops)
{
if (model.Id <= shop.Id)
{
model.Id = shop.Id + 1;
}
}
var newShop = Shop.Create(model);
if (newShop == null)
{
return null;
}
_source.Shops.Add(newShop);
return newShop.GetViewModel;
} }
public ShopViewModel? Update(ShopBindingModel model) public ShopViewModel? Update(ShopBindingModel model)
{ {
throw new NotImplementedException(); foreach (var shop in _source.Shops)
{
if (shop.Id == model.Id)
{
shop.Update(model);
return shop.GetViewModel;
}
}
return null;
} }
} }
} }