diff --git a/JewelryStoreFileImplement/Implements/JewelStorage.cs b/JewelryStoreFileImplement/Implements/JewelStorage.cs index e09b4ab..2fb5632 100644 --- a/JewelryStoreFileImplement/Implements/JewelStorage.cs +++ b/JewelryStoreFileImplement/Implements/JewelStorage.cs @@ -2,111 +2,17 @@ using JewelryStoreContracts.SearchModels; using JewelryStoreContracts.StoragesContracts; using JewelryStoreContracts.ViewModels; -using JewelryStoreListImplement.Models; +using JewelryStoreFileImplement.Models; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; -namespace JewelryStoreListImplement.Implements +namespace JewelryStoreFileImplement.Implements { - public class JewelStorage : IJewelStorage // TODO реализовать интерфейс + public class JewelStorage : IJewelStorage // TODO Lab_2 { - private readonly DataListSingleton _source; - public JewelStorage() - { - _source = DataListSingleton.GetInstance(); - } - public JewelViewModel? Delete(JewelBindingModel model) - { - for (int i = 0; i < _source.Jewels.Count; ++i) - { - if (_source.Jewels[i].Id == model.Id) - { - var element = _source.Jewels[i]; - _source.Jewels.RemoveAt(i); - return element.GetViewModel; - } - } - return null; - } - - public JewelViewModel? GetElement(JewelSearchModel model) - { - if (string.IsNullOrEmpty(model.JewelName) && !model.Id.HasValue) - { - return null; - } - foreach (var jewel in _source.Jewels) - { - if ((!string.IsNullOrEmpty(model.JewelName) && - jewel.JewelName == model.JewelName) || - (model.Id.HasValue && jewel.Id == model.Id)) - { - return jewel.GetViewModel; - } - } - return null; - } - - public List GetFilteredList(JewelSearchModel model) - { - var result = new List(); - if (string.IsNullOrEmpty(model.JewelName)) - { - return result; - } - foreach (var jewel in _source.Jewels) - { - if (jewel.JewelName.Contains(model.JewelName)) - { - result.Add(jewel.GetViewModel); - } - } - return result; - } - - public List GetFullList() - { - var result = new List(); - foreach (var jewel in _source.Jewels) - { - result.Add(jewel.GetViewModel); - } - return result; - } - - public JewelViewModel? Insert(JewelBindingModel model) - { - model.Id = 1; - foreach (var jewel in _source.Jewels) - { - if (model.Id <= jewel.Id) - { - model.Id = jewel.Id + 1; - } - } - var newJewel = Jewel.Create(model); - if (newJewel == null) - { - return null; - } - _source.Jewels.Add(newJewel); - return newJewel.GetViewModel; - } - - public JewelViewModel? Update(JewelBindingModel model) - { - foreach (var jewel in _source.Jewels) - { - if (jewel.Id == model.Id) - { - jewel.Update(model); - return jewel.GetViewModel; - } - } - return null; - } + } }