From d86f89eca47f3b9eadae62ec9c3248f07a2dd285 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B0=D0=BD=D0=B8=D1=8F=D1=80=20=D0=90=D0=B3=D0=BB?= =?UTF-8?q?=D0=B8=D1=83=D0=BB=D0=BB=D0=BE=D0=B2?= Date: Sun, 5 Feb 2023 17:05:49 +0400 Subject: [PATCH] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B0=20=D0=BB=D0=BE=D0=B3=D0=B8=D0=BA=D0=B0=20?= =?UTF-8?q?=D1=81=D1=83=D1=89=D0=BD=D0=BE=D1=81=D1=82=D0=B8=20"=D0=9C?= =?UTF-8?q?=D0=B0=D0=B3=D0=B0=D0=B7=D0=B8=D0=BD"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ConfectionaryBusinessLogic/ShopLogic.cs | 2 + .../DataListSingleton.cs | 4 +- ConfectionaryListImplement/ShopStorage.cs | 73 +++++++++++++++++-- 3 files changed, 71 insertions(+), 8 deletions(-) diff --git a/ConfectionaryBusinessLogic/ShopLogic.cs b/ConfectionaryBusinessLogic/ShopLogic.cs index c32a715..920f493 100644 --- a/ConfectionaryBusinessLogic/ShopLogic.cs +++ b/ConfectionaryBusinessLogic/ShopLogic.cs @@ -52,6 +52,7 @@ namespace ConfectioneryBusinessLogic public bool Create(ShopBindingModel model) { CheckModel(model); + model.Pastries = new(); if (_shopStorage.Insert(model) == null) { _logger.LogWarning("Insert operation failed"); @@ -62,6 +63,7 @@ namespace ConfectioneryBusinessLogic public bool Update(ShopBindingModel model) { CheckModel(model); + model.Pastries = new(); if (_shopStorage.Update(model) == null) { _logger.LogWarning("Update operation failed"); diff --git a/ConfectionaryListImplement/DataListSingleton.cs b/ConfectionaryListImplement/DataListSingleton.cs index dab3ef1..b34de5e 100644 --- a/ConfectionaryListImplement/DataListSingleton.cs +++ b/ConfectionaryListImplement/DataListSingleton.cs @@ -8,13 +8,13 @@ namespace ConfectioneryListImplement public List Components { get; set; } public List Orders { get; set; } public List Pastry { get; set; } - public List Shop { get; set; } + public List Shops { get; set; } private DataListSingleton() { Components = new List(); Orders = new List(); Pastry = new List(); - Shop = new List(); + Shops = new List(); } public static DataListSingleton GetInstance() { diff --git a/ConfectionaryListImplement/ShopStorage.cs b/ConfectionaryListImplement/ShopStorage.cs index d7c3547..893b6ad 100644 --- a/ConfectionaryListImplement/ShopStorage.cs +++ b/ConfectionaryListImplement/ShopStorage.cs @@ -15,32 +15,93 @@ namespace ConfectioneryListImplement 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) { - 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 GetFilteredList(ShopSearchModel model) { - throw new NotImplementedException(); + var result = new List(); + 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 GetFullList() { - throw new NotImplementedException(); + var result = new List(); + foreach (var shop in _source.Shops) + { + result.Add(shop.GetViewModel); + } + return result; } 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) { - throw new NotImplementedException(); + foreach (var shop in _source.Shops) + { + if (shop.Id == model.Id) + { + shop.Update(model); + return shop.GetViewModel; + } + } + return null; } } }