From d3d8f5d7e7dbd242c8b9b832e0f3e6e666da2864 Mon Sep 17 00:00:00 2001 From: VictoriaPresnyakova Date: Sun, 5 Feb 2023 19:55:48 +0400 Subject: [PATCH] ListImplements --- .../Implements/ComponentStorage .cs | 100 +++++++++++++++++- .../Implements/JewelStorage.cs | 37 ++++++- .../Implements/OrderStorage.cs | 37 ++++++- JewelryStoreListImplement/Models/Component.cs | 39 ++++++- JewelryStoreListImplement/Models/Jewel.cs | 2 + JewelryStoreListImplement/Models/Order.cs | 19 +++- 6 files changed, 224 insertions(+), 10 deletions(-) diff --git a/JewelryStoreListImplement/Implements/ComponentStorage .cs b/JewelryStoreListImplement/Implements/ComponentStorage .cs index aaffee8..b6270b0 100644 --- a/JewelryStoreListImplement/Implements/ComponentStorage .cs +++ b/JewelryStoreListImplement/Implements/ComponentStorage .cs @@ -1,4 +1,9 @@ -using System; +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.SearchModels; +using JewelryStoreContracts.StoragesContracts; +using JewelryStoreContracts.ViewModels; +using JewelryStoreListImplement.Models; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -6,7 +11,98 @@ using System.Threading.Tasks; namespace JewelryStoreListImplement.Implements { - internal class ComponentStorage + public class ComponentStorage : IComponentStorage { + private readonly DataListSingleton _source; + public ComponentStorage() + { + _source = DataListSingleton.GetInstance(); + } + public List GetFullList() + { + var result = new List(); + foreach (var component in _source.Components) + { + result.Add(component.GetViewModel); + } + return result; + } + public List GetFilteredList(ComponentSearchModel + model) + { + var result = new List(); + if (string.IsNullOrEmpty(model.ComponentName)) + { + return result; + } + foreach (var component in _source.Components) + { + if (component.ComponentName.Contains(model.ComponentName)) + { + result.Add(component.GetViewModel); + } + } + return result; + } + public ComponentViewModel? GetElement(ComponentSearchModel model) + { + if (string.IsNullOrEmpty(model.ComponentName) && !model.Id.HasValue) + { + return null; + } + foreach (var component in _source.Components) + { + if ((!string.IsNullOrEmpty(model.ComponentName) && + component.ComponentName == model.ComponentName) || + (model.Id.HasValue && component.Id == model.Id)) + { + return component.GetViewModel; + } + } + return null; + } + public ComponentViewModel? Insert(ComponentBindingModel model) + { + model.Id = 1; + foreach (var component in _source.Components) + { + if (model.Id <= component.Id) + { + model.Id = component.Id + 1; + } + } + var newComponent = Component.Create(model); + if (newComponent == null) + { + return null; + } + _source.Components.Add(newComponent); + return newComponent.GetViewModel; + } + public ComponentViewModel? Update(ComponentBindingModel model) + { + foreach (var component in _source.Components) + { + if (component.Id == model.Id) + { + component.Update(model); + return component.GetViewModel; + } + } + return null; + } + public ComponentViewModel? Delete(ComponentBindingModel model) + { + for (int i = 0; i < _source.Components.Count; ++i) + { + if (_source.Components[i].Id == model.Id) + { + var element = _source.Components[i]; + _source.Components.RemoveAt(i); + return element.GetViewModel; + } + } + return null; + } } } diff --git a/JewelryStoreListImplement/Implements/JewelStorage.cs b/JewelryStoreListImplement/Implements/JewelStorage.cs index 57e8b90..8b2fd87 100644 --- a/JewelryStoreListImplement/Implements/JewelStorage.cs +++ b/JewelryStoreListImplement/Implements/JewelStorage.cs @@ -1,4 +1,8 @@ -using System; +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.SearchModels; +using JewelryStoreContracts.StoragesContracts; +using JewelryStoreContracts.ViewModels; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -6,7 +10,36 @@ using System.Threading.Tasks; namespace JewelryStoreListImplement.Implements { - internal class JewelStorage + internal class JewelStorage : IJewelStorage // TODO реализовать интерфейс { + public JewelViewModel? Delete(JewelBindingModel model) + { + throw new NotImplementedException(); + } + + public JewelViewModel? GetElement(JewelSearchModel model) + { + throw new NotImplementedException(); + } + + public List GetFilteredList(JewelSearchModel model) + { + throw new NotImplementedException(); + } + + public List GetFullList() + { + throw new NotImplementedException(); + } + + public JewelViewModel? Insert(JewelBindingModel model) + { + throw new NotImplementedException(); + } + + public JewelViewModel? Update(JewelBindingModel model) + { + throw new NotImplementedException(); + } } } diff --git a/JewelryStoreListImplement/Implements/OrderStorage.cs b/JewelryStoreListImplement/Implements/OrderStorage.cs index d13c73f..abcb051 100644 --- a/JewelryStoreListImplement/Implements/OrderStorage.cs +++ b/JewelryStoreListImplement/Implements/OrderStorage.cs @@ -1,4 +1,8 @@ -using System; +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.SearchModels; +using JewelryStoreContracts.StoragesContracts; +using JewelryStoreContracts.ViewModels; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -6,7 +10,36 @@ using System.Threading.Tasks; namespace JewelryStoreListImplement.Implements { - internal class OrderStorage + internal class OrderStorage : IOrderStorage // TODO реализовать интерфейс { + public OrderViewModel? Delete(OrderBindingModel model) + { + throw new NotImplementedException(); + } + + public OrderViewModel? GetElement(OrderSearchModel model) + { + throw new NotImplementedException(); + } + + public List GetFilteredList(OrderSearchModel model) + { + throw new NotImplementedException(); + } + + public List GetFullList() + { + throw new NotImplementedException(); + } + + public OrderViewModel? Insert(OrderBindingModel model) + { + throw new NotImplementedException(); + } + + public OrderViewModel? Update(OrderBindingModel model) + { + throw new NotImplementedException(); + } } } diff --git a/JewelryStoreListImplement/Models/Component.cs b/JewelryStoreListImplement/Models/Component.cs index 6ad51d8..be9adee 100644 --- a/JewelryStoreListImplement/Models/Component.cs +++ b/JewelryStoreListImplement/Models/Component.cs @@ -1,4 +1,7 @@ -using System; +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.ViewModels; +using JewelryStoreDataModels.Models; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -6,7 +9,39 @@ using System.Threading.Tasks; namespace JewelryStoreListImplement.Models { - internal class Component + public class Component : IComponentModel { + public int Id { get; private set; } + public string ComponentName { get; private set; } = string.Empty; + public double Cost { get; set; } + public static Component? Create(ComponentBindingModel? model) + { + if (model == null) + { + return null; + } + return new Component() + { + Id = model.Id, + ComponentName = model.ComponentName, + Cost = model.Cost + }; + } + public void Update(ComponentBindingModel? model) + { + if (model == null) + { + return; + } + ComponentName = model.ComponentName; + Cost = model.Cost; + } + public ComponentViewModel GetViewModel => new() + { + Id = Id, + ComponentName = ComponentName, + Cost = Cost + }; } + } diff --git a/JewelryStoreListImplement/Models/Jewel.cs b/JewelryStoreListImplement/Models/Jewel.cs index 11d77df..2ba83ef 100644 --- a/JewelryStoreListImplement/Models/Jewel.cs +++ b/JewelryStoreListImplement/Models/Jewel.cs @@ -1,9 +1,11 @@ using JewelryStoreDataModels.Models; +using JewelryStoreContracts.ViewModels; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using JewelryStoreContracts.BindingModels; namespace JewelryStoreListImplement.Models { diff --git a/JewelryStoreListImplement/Models/Order.cs b/JewelryStoreListImplement/Models/Order.cs index d982fe3..dc1ef36 100644 --- a/JewelryStoreListImplement/Models/Order.cs +++ b/JewelryStoreListImplement/Models/Order.cs @@ -1,4 +1,6 @@ -using System; +using JewelryStoreDataModels.Enums; +using JewelryStoreDataModels.Models; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -6,7 +8,20 @@ using System.Threading.Tasks; namespace JewelryStoreListImplement.Models { - internal class Order + public class Order : IOrderModel // TODO Класс для модели сущности «Заказ» разработать самостоятельно { + public int JewelId => throw new NotImplementedException(); + + public int Count => throw new NotImplementedException(); + + public double Sum => throw new NotImplementedException(); + + public OrderStatus Status => throw new NotImplementedException(); + + public DateTime DateCreate => throw new NotImplementedException(); + + public DateTime? DateImplement => throw new NotImplementedException(); + + public int Id => throw new NotImplementedException(); } }