diff --git a/SushiBar/SushiBar.sln b/SushiBar/SushiBar.sln index e1006df..747c7e6 100644 --- a/SushiBar/SushiBar.sln +++ b/SushiBar/SushiBar.sln @@ -3,18 +3,100 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.3.32825.248 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SushiBar", "SushiBar\SushiBar.csproj", "{1DBEFDAC-8E94-49DB-9C92-576BF0A2B862}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SushiBar", "SushiBar\SushiBar.csproj", "{1DBEFDAC-8E94-49DB-9C92-576BF0A2B862}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SushiBarDataModels", "SushiBarDataModels\SushiBarDataModels.csproj", "{76043DE7-71BC-41E8-B4C0-ECFADDFBF55F}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SushiBarContracts", "SushiBarContracts\SushiBarContracts.csproj", "{993E0787-3AD5-4743-8997-C828CD0CDC10}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SushiBarBusinessLogic", "SushiBarBusinessLogic\SushiBarBusinessLogic.csproj", "{E9064087-924C-4E00-A9EA-8E922CF49D11}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SushiBarListImplement", "SushiBarListImplement\SushiBarListImplement.csproj", "{1BBC3A4B-BF06-4EBF-AA20-863B369E234E}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SushiBarView", "SushiBarView\SushiBarView.csproj", "{55A792F4-5723-476F-A420-0F863B7C7F99}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 Release|Any CPU = Release|Any CPU + Release|x64 = Release|x64 + Release|x86 = Release|x86 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {1DBEFDAC-8E94-49DB-9C92-576BF0A2B862}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {1DBEFDAC-8E94-49DB-9C92-576BF0A2B862}.Debug|Any CPU.Build.0 = Debug|Any CPU + {1DBEFDAC-8E94-49DB-9C92-576BF0A2B862}.Debug|x64.ActiveCfg = Debug|Any CPU + {1DBEFDAC-8E94-49DB-9C92-576BF0A2B862}.Debug|x64.Build.0 = Debug|Any CPU + {1DBEFDAC-8E94-49DB-9C92-576BF0A2B862}.Debug|x86.ActiveCfg = Debug|Any CPU + {1DBEFDAC-8E94-49DB-9C92-576BF0A2B862}.Debug|x86.Build.0 = Debug|Any CPU {1DBEFDAC-8E94-49DB-9C92-576BF0A2B862}.Release|Any CPU.ActiveCfg = Release|Any CPU {1DBEFDAC-8E94-49DB-9C92-576BF0A2B862}.Release|Any CPU.Build.0 = Release|Any CPU + {1DBEFDAC-8E94-49DB-9C92-576BF0A2B862}.Release|x64.ActiveCfg = Release|Any CPU + {1DBEFDAC-8E94-49DB-9C92-576BF0A2B862}.Release|x64.Build.0 = Release|Any CPU + {1DBEFDAC-8E94-49DB-9C92-576BF0A2B862}.Release|x86.ActiveCfg = Release|Any CPU + {1DBEFDAC-8E94-49DB-9C92-576BF0A2B862}.Release|x86.Build.0 = Release|Any CPU + {76043DE7-71BC-41E8-B4C0-ECFADDFBF55F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {76043DE7-71BC-41E8-B4C0-ECFADDFBF55F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {76043DE7-71BC-41E8-B4C0-ECFADDFBF55F}.Debug|x64.ActiveCfg = Debug|Any CPU + {76043DE7-71BC-41E8-B4C0-ECFADDFBF55F}.Debug|x64.Build.0 = Debug|Any CPU + {76043DE7-71BC-41E8-B4C0-ECFADDFBF55F}.Debug|x86.ActiveCfg = Debug|Any CPU + {76043DE7-71BC-41E8-B4C0-ECFADDFBF55F}.Debug|x86.Build.0 = Debug|Any CPU + {76043DE7-71BC-41E8-B4C0-ECFADDFBF55F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {76043DE7-71BC-41E8-B4C0-ECFADDFBF55F}.Release|Any CPU.Build.0 = Release|Any CPU + {76043DE7-71BC-41E8-B4C0-ECFADDFBF55F}.Release|x64.ActiveCfg = Release|Any CPU + {76043DE7-71BC-41E8-B4C0-ECFADDFBF55F}.Release|x64.Build.0 = Release|Any CPU + {76043DE7-71BC-41E8-B4C0-ECFADDFBF55F}.Release|x86.ActiveCfg = Release|Any CPU + {76043DE7-71BC-41E8-B4C0-ECFADDFBF55F}.Release|x86.Build.0 = Release|Any CPU + {993E0787-3AD5-4743-8997-C828CD0CDC10}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {993E0787-3AD5-4743-8997-C828CD0CDC10}.Debug|Any CPU.Build.0 = Debug|Any CPU + {993E0787-3AD5-4743-8997-C828CD0CDC10}.Debug|x64.ActiveCfg = Debug|Any CPU + {993E0787-3AD5-4743-8997-C828CD0CDC10}.Debug|x64.Build.0 = Debug|Any CPU + {993E0787-3AD5-4743-8997-C828CD0CDC10}.Debug|x86.ActiveCfg = Debug|Any CPU + {993E0787-3AD5-4743-8997-C828CD0CDC10}.Debug|x86.Build.0 = Debug|Any CPU + {993E0787-3AD5-4743-8997-C828CD0CDC10}.Release|Any CPU.ActiveCfg = Release|Any CPU + {993E0787-3AD5-4743-8997-C828CD0CDC10}.Release|Any CPU.Build.0 = Release|Any CPU + {993E0787-3AD5-4743-8997-C828CD0CDC10}.Release|x64.ActiveCfg = Release|Any CPU + {993E0787-3AD5-4743-8997-C828CD0CDC10}.Release|x64.Build.0 = Release|Any CPU + {993E0787-3AD5-4743-8997-C828CD0CDC10}.Release|x86.ActiveCfg = Release|Any CPU + {993E0787-3AD5-4743-8997-C828CD0CDC10}.Release|x86.Build.0 = Release|Any CPU + {E9064087-924C-4E00-A9EA-8E922CF49D11}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E9064087-924C-4E00-A9EA-8E922CF49D11}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E9064087-924C-4E00-A9EA-8E922CF49D11}.Debug|x64.ActiveCfg = Debug|Any CPU + {E9064087-924C-4E00-A9EA-8E922CF49D11}.Debug|x64.Build.0 = Debug|Any CPU + {E9064087-924C-4E00-A9EA-8E922CF49D11}.Debug|x86.ActiveCfg = Debug|Any CPU + {E9064087-924C-4E00-A9EA-8E922CF49D11}.Debug|x86.Build.0 = Debug|Any CPU + {E9064087-924C-4E00-A9EA-8E922CF49D11}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E9064087-924C-4E00-A9EA-8E922CF49D11}.Release|Any CPU.Build.0 = Release|Any CPU + {E9064087-924C-4E00-A9EA-8E922CF49D11}.Release|x64.ActiveCfg = Release|Any CPU + {E9064087-924C-4E00-A9EA-8E922CF49D11}.Release|x64.Build.0 = Release|Any CPU + {E9064087-924C-4E00-A9EA-8E922CF49D11}.Release|x86.ActiveCfg = Release|Any CPU + {E9064087-924C-4E00-A9EA-8E922CF49D11}.Release|x86.Build.0 = Release|Any CPU + {1BBC3A4B-BF06-4EBF-AA20-863B369E234E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {1BBC3A4B-BF06-4EBF-AA20-863B369E234E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {1BBC3A4B-BF06-4EBF-AA20-863B369E234E}.Debug|x64.ActiveCfg = Debug|Any CPU + {1BBC3A4B-BF06-4EBF-AA20-863B369E234E}.Debug|x64.Build.0 = Debug|Any CPU + {1BBC3A4B-BF06-4EBF-AA20-863B369E234E}.Debug|x86.ActiveCfg = Debug|Any CPU + {1BBC3A4B-BF06-4EBF-AA20-863B369E234E}.Debug|x86.Build.0 = Debug|Any CPU + {1BBC3A4B-BF06-4EBF-AA20-863B369E234E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {1BBC3A4B-BF06-4EBF-AA20-863B369E234E}.Release|Any CPU.Build.0 = Release|Any CPU + {1BBC3A4B-BF06-4EBF-AA20-863B369E234E}.Release|x64.ActiveCfg = Release|Any CPU + {1BBC3A4B-BF06-4EBF-AA20-863B369E234E}.Release|x64.Build.0 = Release|Any CPU + {1BBC3A4B-BF06-4EBF-AA20-863B369E234E}.Release|x86.ActiveCfg = Release|Any CPU + {1BBC3A4B-BF06-4EBF-AA20-863B369E234E}.Release|x86.Build.0 = Release|Any CPU + {55A792F4-5723-476F-A420-0F863B7C7F99}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {55A792F4-5723-476F-A420-0F863B7C7F99}.Debug|Any CPU.Build.0 = Debug|Any CPU + {55A792F4-5723-476F-A420-0F863B7C7F99}.Debug|x64.ActiveCfg = Debug|Any CPU + {55A792F4-5723-476F-A420-0F863B7C7F99}.Debug|x64.Build.0 = Debug|Any CPU + {55A792F4-5723-476F-A420-0F863B7C7F99}.Debug|x86.ActiveCfg = Debug|Any CPU + {55A792F4-5723-476F-A420-0F863B7C7F99}.Debug|x86.Build.0 = Debug|Any CPU + {55A792F4-5723-476F-A420-0F863B7C7F99}.Release|Any CPU.ActiveCfg = Release|Any CPU + {55A792F4-5723-476F-A420-0F863B7C7F99}.Release|Any CPU.Build.0 = Release|Any CPU + {55A792F4-5723-476F-A420-0F863B7C7F99}.Release|x64.ActiveCfg = Release|Any CPU + {55A792F4-5723-476F-A420-0F863B7C7F99}.Release|x64.Build.0 = Release|Any CPU + {55A792F4-5723-476F-A420-0F863B7C7F99}.Release|x86.ActiveCfg = Release|Any CPU + {55A792F4-5723-476F-A420-0F863B7C7F99}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/SushiBar/SushiBarBusinessLogic/App.config b/SushiBar/SushiBarBusinessLogic/App.config new file mode 100644 index 0000000..56efbc7 --- /dev/null +++ b/SushiBar/SushiBarBusinessLogic/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/SushiBar/SushiBarBusinessLogic/ComponentLogic.cs b/SushiBar/SushiBarBusinessLogic/ComponentLogic.cs new file mode 100644 index 0000000..98d9d85 --- /dev/null +++ b/SushiBar/SushiBarBusinessLogic/ComponentLogic.cs @@ -0,0 +1,112 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SushiBarBusinessLogic.BusinessLogics +{ + public class ComponentLogic + private readonly ILogger _logger; + private readonly IComponentStorage _componentStorage; + public ComponentLogic(ILogger logger, IComponentStorage + componentStorage) + { + _logger = logger; + _componentStorage = componentStorage; + } + public List? ReadList(ComponentSearchModel? model) + { + _logger.LogInformation("ReadList. ComponentName:{ComponentName}. Id:{ Id}", model?.ComponentName, model?.Id); + var list = model == null ? _componentStorage.GetFullList() : _componentStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + public ComponentViewModel? ReadElement(ComponentSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. ComponentName:{ComponentName}. Id:{ Id} ", model.ComponentName, model.Id); + var element = _componentStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + return element; + } + public bool Create(ComponentBindingModel model) + { + CheckModel(model); + if (_componentStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + 18 + } + public bool Update(ComponentBindingModel model) + { + CheckModel(model); + if (_componentStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + public bool Delete(ComponentBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_componentStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + private void CheckModel(ComponentBindingModel model, bool withParams = + true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.ComponentName)) + { + throw new ArgumentNullException("Нет названия компонента", + nameof(model.ComponentName)); + } + if (model.Cost <= 0) + { + throw new ArgumentNullException("Цена компонента должна быть + больше 0", nameof(model.Cost)); + } + _logger.LogInformation("Component. ComponentName:{ComponentName}. + Cost:{ Cost}. Id: { Id} + ", model.ComponentName, model.Cost, model.Id); + var element = _componentStorage.GetElement(new ComponentSearchModel + { + ComponentName = model.ComponentName + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Компонент с таким названием + уже есть"); + } + } +} diff --git a/SushiBar/SushiBarBusinessLogic/SushiBarBusinessLogic.csproj b/SushiBar/SushiBarBusinessLogic/SushiBarBusinessLogic.csproj new file mode 100644 index 0000000..166199b --- /dev/null +++ b/SushiBar/SushiBarBusinessLogic/SushiBarBusinessLogic.csproj @@ -0,0 +1,48 @@ + + + + + Debug + AnyCPU + {E9064087-924C-4E00-A9EA-8E922CF49D11} + Exe + SushiBarBusinessLogic + SushiBarBusinessLogic + v4.7.2 + 512 + true + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + {993e0787-3ad5-4743-8997-c828cd0cdc10} + SushiBarContracts + + + + + + + \ No newline at end of file diff --git a/SushiBar/SushiBarContracts/BindingModels/ComponentBindingModel.cs b/SushiBar/SushiBarContracts/BindingModels/ComponentBindingModel.cs new file mode 100644 index 0000000..206930c --- /dev/null +++ b/SushiBar/SushiBarContracts/BindingModels/ComponentBindingModel.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using SushiBarDataModels.Models; + +namespace SushiBarContracts.BindingModels +{ + public class ComponentBindingModel : IComponentModel + { + public int Id { get; set; } + public string ComponentName { get; set; } = string.Empty; + public double Cost { get; set; } + } +} diff --git a/SushiBar/SushiBarContracts/BindingModels/OrderBindingModel.cs b/SushiBar/SushiBarContracts/BindingModels/OrderBindingModel.cs new file mode 100644 index 0000000..ee30e84 --- /dev/null +++ b/SushiBar/SushiBarContracts/BindingModels/OrderBindingModel.cs @@ -0,0 +1,21 @@ +using SushiBarDataModels.Enums; +using SushiBarDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SushiBarContracts.BindingModels +{ + public class OrderBindingModel : IOrderModel + { + public int Id { get; set; } + public int SushiId { get; set; } + public int Count { get; set; } + public double Sum { get; set; } + public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; + public DateTime DateCreate { get; set; } = DateTime.Now; + public DateTime? DateImplement { get; set; } + } +} diff --git a/SushiBar/SushiBarContracts/BindingModels/SushiBindingModel.cs b/SushiBar/SushiBarContracts/BindingModels/SushiBindingModel.cs new file mode 100644 index 0000000..ce67161 --- /dev/null +++ b/SushiBar/SushiBarContracts/BindingModels/SushiBindingModel.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using SushiBarDataModels.Models; + +namespace SushiBarContracts.BindingModels +{ + public class SushiBindingModel : ISushiModel + { + public int Id { get; set; } + public string SushiName { get; set; } = string.Empty; + public double Price { get; set; } + public Dictionary SushiComponents + { + get; + set; + } = new(); + + } +} diff --git a/SushiBar/SushiBarContracts/BusinessLogicsContracts/IComponentLogic.cs b/SushiBar/SushiBarContracts/BusinessLogicsContracts/IComponentLogic.cs new file mode 100644 index 0000000..5c2b515 --- /dev/null +++ b/SushiBar/SushiBarContracts/BusinessLogicsContracts/IComponentLogic.cs @@ -0,0 +1,20 @@ +using SushiBarContracts.BindingModels; +using SushiBarContracts.SearchModels; +using SushiBarContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SushiBarContracts.BusinessLogicsContracts +{ + public interface IComponentLogic + { + List? ReadList(ComponentSearchModel? model); + ComponentViewModel? ReadElement(ComponentSearchModel model); + bool Create(ComponentBindingModel model); + bool Update(ComponentBindingModel model); + bool Delete(ComponentBindingModel model); + } +} diff --git a/SushiBar/SushiBarContracts/BusinessLogicsContracts/IOrderLogic.cs b/SushiBar/SushiBarContracts/BusinessLogicsContracts/IOrderLogic.cs new file mode 100644 index 0000000..b90fb79 --- /dev/null +++ b/SushiBar/SushiBarContracts/BusinessLogicsContracts/IOrderLogic.cs @@ -0,0 +1,20 @@ +using SushiBarContracts.BindingModels; +using SushiBarContracts.SearchModels; +using SushiBarContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SushiBarContracts.BusinessLogicsContracts +{ + public interface IOrderLogic + { + List? ReadList(OrderSearchModel? model); + bool CreateOrder(OrderBindingModel model); + bool TakeOrderInWork(OrderBindingModel model); + bool FinishOrder(OrderBindingModel model); + bool DeliveryOrder(OrderBindingModel model); + } +} diff --git a/SushiBar/SushiBarContracts/BusinessLogicsContracts/ISushiLogic.cs b/SushiBar/SushiBarContracts/BusinessLogicsContracts/ISushiLogic.cs new file mode 100644 index 0000000..32c732b --- /dev/null +++ b/SushiBar/SushiBarContracts/BusinessLogicsContracts/ISushiLogic.cs @@ -0,0 +1,21 @@ +using SushiBarContracts.BindingModels; +using SushiBarContracts.SearchModels; +using SushiBarContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SushiBarContracts.BusinessLogicsContracts +{ + public interface ISushiLogic + { + List? ReadList(SushiSearchModel? model); + SushiViewModel? ReadElement(SushiSearchModel model); + bool Create(SushiBindingModel model); + bool Update(SushiBindingModel model); + bool Delete(SushiBindingModel model); + } + +} diff --git a/SushiBar/SushiBarContracts/SearchModels/ComponentSearchModel.cs b/SushiBar/SushiBarContracts/SearchModels/ComponentSearchModel.cs new file mode 100644 index 0000000..a69687d --- /dev/null +++ b/SushiBar/SushiBarContracts/SearchModels/ComponentSearchModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SushiBarContracts.SearchModels +{ + public class ComponentSearchModel + { + public int? Id { get; set; } + public string? ComponentName { get; set; } + } +} diff --git a/SushiBar/SushiBarContracts/SearchModels/OrderSearchModel.cs b/SushiBar/SushiBarContracts/SearchModels/OrderSearchModel.cs new file mode 100644 index 0000000..98630db --- /dev/null +++ b/SushiBar/SushiBarContracts/SearchModels/OrderSearchModel.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SushiBarContracts.SearchModels +{ + public class OrderSearchModel + { + public int? Id { get; set; } + } +} diff --git a/SushiBar/SushiBarContracts/SearchModels/SushiSearchModel.cs b/SushiBar/SushiBarContracts/SearchModels/SushiSearchModel.cs new file mode 100644 index 0000000..95d2732 --- /dev/null +++ b/SushiBar/SushiBarContracts/SearchModels/SushiSearchModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SushiBarContracts.SearchModels +{ + public class SushiSearchModel + { + public int? Id { get; set; } + public string? SushiName { get; set; } + } +} diff --git a/SushiBar/SushiBarContracts/StoragesContracts/IComponentStorage.cs b/SushiBar/SushiBarContracts/StoragesContracts/IComponentStorage.cs new file mode 100644 index 0000000..a58deb5 --- /dev/null +++ b/SushiBar/SushiBarContracts/StoragesContracts/IComponentStorage.cs @@ -0,0 +1,21 @@ +using SushiBarContracts.BindingModels; +using SushiBarContracts.SearchModels; +using SushiBarContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SushiBarContracts.StoragesContracts +{ + public interface IComponentStorage + { + List GetFullList(); + List GetFilteredList(ComponentSearchModel model); + ComponentViewModel? GetElement(ComponentSearchModel model); + ComponentViewModel? Insert(ComponentBindingModel model); + ComponentViewModel? Update(ComponentBindingModel model); + ComponentViewModel? Delete(ComponentBindingModel model); + } +} diff --git a/SushiBar/SushiBarContracts/StoragesContracts/IOrderStorage.cs b/SushiBar/SushiBarContracts/StoragesContracts/IOrderStorage.cs new file mode 100644 index 0000000..5d310e8 --- /dev/null +++ b/SushiBar/SushiBarContracts/StoragesContracts/IOrderStorage.cs @@ -0,0 +1,22 @@ +using SushiBarContracts.BindingModels; +using SushiBarContracts.SearchModels; +using SushiBarContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SushiBarContracts.StoragesContracts +{ + public interface IOrderStorage + { + List GetFullList(); + List GetFilteredList(OrderSearchModel model); + OrderViewModel? GetElement(OrderSearchModel model); + OrderViewModel? Insert(OrderBindingModel model); + OrderViewModel? Update(OrderBindingModel model); + OrderViewModel? Delete(OrderBindingModel model); + } + +} diff --git a/SushiBar/SushiBarContracts/StoragesContracts/ISushiStorage.cs b/SushiBar/SushiBarContracts/StoragesContracts/ISushiStorage.cs new file mode 100644 index 0000000..3682ff7 --- /dev/null +++ b/SushiBar/SushiBarContracts/StoragesContracts/ISushiStorage.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using SushiBarContracts.BindingModels; +using SushiBarContracts.SearchModels; +using SushiBarContracts.ViewModels; + +namespace SushiBarContracts.StoragesContracts +{ + public interface ISushiStorage + { + List GetFullList(); + List GetFilteredList(SushiSearchModel model); + SushiViewModel? GetElement(SushiSearchModel model); + SushiViewModel? Insert(SushiBindingModel model); + SushiViewModel? Update(SushiBindingModel model); + SushiViewModel? Delete(SushiBindingModel model); + } + +} diff --git a/SushiBar/SushiBarContracts/SushiBarContracts.csproj b/SushiBar/SushiBarContracts/SushiBarContracts.csproj new file mode 100644 index 0000000..a25f2c8 --- /dev/null +++ b/SushiBar/SushiBarContracts/SushiBarContracts.csproj @@ -0,0 +1,13 @@ + + + + net6.0 + enable + enable + + + + + + + diff --git a/SushiBar/SushiBarContracts/ViewModels/ComponentViewModel.cs b/SushiBar/SushiBarContracts/ViewModels/ComponentViewModel.cs new file mode 100644 index 0000000..5b924c1 --- /dev/null +++ b/SushiBar/SushiBarContracts/ViewModels/ComponentViewModel.cs @@ -0,0 +1,21 @@ +using SushiBarDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SushiBarContracts.ViewModels +{ + public class ComponentViewModel : IComponentModel + { + public int Id { get; set; } + + [DisplayName("Название компонента")] + public string ComponentName { get; set; } = string.Empty; + + [DisplayName("Цена")] + public double Cost { get; set; } + } +} diff --git a/SushiBar/SushiBarContracts/ViewModels/OrderViewModel.cs b/SushiBar/SushiBarContracts/ViewModels/OrderViewModel.cs new file mode 100644 index 0000000..36203b3 --- /dev/null +++ b/SushiBar/SushiBarContracts/ViewModels/OrderViewModel.cs @@ -0,0 +1,37 @@ +using SushiBarDataModels.Enums; +using SushiBarDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SushiBarContracts.ViewModels +{ + public class OrderViewModel : IOrderModel + { + [DisplayName("Номер")] + public int Id { get; set; } + + public int SushiId { get; set; } + + [DisplayName("Изделие")] + public string SushiName { get; set; } = string.Empty; + + [DisplayName("Количество")] + public int Count { get; set; } + + [DisplayName("Сумма")] + public double Sum { get; set; } + + [DisplayName("Статус")] + public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; + + [DisplayName("Дата создания")] + public DateTime DateCreate { get; set; } = DateTime.Now; + + [DisplayName("Дата выполнения")] + public DateTime? DateImplement { get; set; } + } +} diff --git a/SushiBar/SushiBarContracts/ViewModels/SushiViewModel.cs b/SushiBar/SushiBarContracts/ViewModels/SushiViewModel.cs new file mode 100644 index 0000000..8f9608c --- /dev/null +++ b/SushiBar/SushiBarContracts/ViewModels/SushiViewModel.cs @@ -0,0 +1,25 @@ +using SushiBarDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SushiBarContracts.ViewModels +{ + public class SushiViewModel : ISushiModel + { + public int Id { get; set; } + [DisplayName("Название изделия")] + public string SushiName { get; set; } = string.Empty; + [DisplayName("Цена")] + public double Price { get; set; } + public Dictionary SushiComponents + { + get; + set; + } = new(); + + } +} diff --git a/SushiBar/SushiBarDataModels/Class1.cs b/SushiBar/SushiBarDataModels/Class1.cs new file mode 100644 index 0000000..08ec173 --- /dev/null +++ b/SushiBar/SushiBarDataModels/Class1.cs @@ -0,0 +1,7 @@ +namespace SushiBarDataModels +{ + public class Class1 + { + + } +} \ No newline at end of file diff --git a/SushiBar/SushiBarDataModels/Enums/OrderStatus.cs b/SushiBar/SushiBarDataModels/Enums/OrderStatus.cs new file mode 100644 index 0000000..c1b6d91 --- /dev/null +++ b/SushiBar/SushiBarDataModels/Enums/OrderStatus.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SushiBarDataModels.Enums +{ + public enum OrderStatus + { + Неизвестен = -1, + Принят = 0, + Выполняется = 1, + Готов = 2, + Выдан = 3 + } +} diff --git a/SushiBar/SushiBarDataModels/IId.cs b/SushiBar/SushiBarDataModels/IId.cs new file mode 100644 index 0000000..91a1366 --- /dev/null +++ b/SushiBar/SushiBarDataModels/IId.cs @@ -0,0 +1,7 @@ +namespace SushiBarDataModels +{ + public interface IId + { + int Id { get; } + } +} \ No newline at end of file diff --git a/SushiBar/SushiBarDataModels/Models/IComponentModel.cs b/SushiBar/SushiBarDataModels/Models/IComponentModel.cs new file mode 100644 index 0000000..b82c233 --- /dev/null +++ b/SushiBar/SushiBarDataModels/Models/IComponentModel.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SushiBarDataModels.Models +{ + public interface IComponentModel : IId + { + string ComponentName { get; } + double Cost { get; } + + } +} diff --git a/SushiBar/SushiBarDataModels/Models/IOrderModel.cs b/SushiBar/SushiBarDataModels/Models/IOrderModel.cs new file mode 100644 index 0000000..02ca513 --- /dev/null +++ b/SushiBar/SushiBarDataModels/Models/IOrderModel.cs @@ -0,0 +1,19 @@ +using SushiBarDataModels.Enums; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SushiBarDataModels.Models +{ + public interface IOrderModel : IId + { + int SushiId { get; } + int Count { get; } + double Sum { get; } + OrderStatus Status { get; } + DateTime DateCreate { get; } + DateTime? DateImplement { get; } + } +} diff --git a/SushiBar/SushiBarDataModels/Models/ISushiModel.cs b/SushiBar/SushiBarDataModels/Models/ISushiModel.cs new file mode 100644 index 0000000..a6c7e0c --- /dev/null +++ b/SushiBar/SushiBarDataModels/Models/ISushiModel.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SushiBarDataModels.Models +{ + public interface ISushiModel : IId + { + string SushiName { get; } + double Price { get; } + Dictionary SushiComponents { get; } + } +} diff --git a/SushiBar/SushiBarDataModels/SushiBarDataModels.csproj b/SushiBar/SushiBarDataModels/SushiBarDataModels.csproj new file mode 100644 index 0000000..132c02c --- /dev/null +++ b/SushiBar/SushiBarDataModels/SushiBarDataModels.csproj @@ -0,0 +1,9 @@ + + + + net6.0 + enable + enable + + + diff --git a/SushiBar/SushiBarListImplement/App.config b/SushiBar/SushiBarListImplement/App.config new file mode 100644 index 0000000..56efbc7 --- /dev/null +++ b/SushiBar/SushiBarListImplement/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/SushiBar/SushiBarListImplement/Component.cs b/SushiBar/SushiBarListImplement/Component.cs new file mode 100644 index 0000000..453d89c --- /dev/null +++ b/SushiBar/SushiBarListImplement/Component.cs @@ -0,0 +1,43 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SushiBarListImplement.Models +{ + 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/SushiBar/SushiBarListImplement/ComponentStorage.cs b/SushiBar/SushiBarListImplement/ComponentStorage.cs new file mode 100644 index 0000000..463d75c --- /dev/null +++ b/SushiBar/SushiBarListImplement/ComponentStorage.cs @@ -0,0 +1,111 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using SushiBarContracts.BindingModels; +using SushiBarContracts.SearchModels; +using SushiBarContracts.StoragesContracts; +using SushiBarContracts.ViewModels; +using SushiBarListImplement.Models; + +namespace SushiBarListImplement.Implements +{ + internal 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; + } + 23 + 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/SushiBar/SushiBarListImplement/DataListSingleton.cs b/SushiBar/SushiBarListImplement/DataListSingleton.cs new file mode 100644 index 0000000..f0f9a1b --- /dev/null +++ b/SushiBar/SushiBarListImplement/DataListSingleton.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using SushiBarListImplement.Models; + +namespace SushiBarListImplement +{ + public class DataListSingleton + { + private static DataListSingleton? _instance; + public List Components { get; set; } + public List Orders { get; set; } + public List Products { get; set; } + private DataListSingleton() + { + Components = new List(); + Orders = new List(); + Products = new List(); + } + public static DataListSingleton GetInstance() + { + if (_instance == null) + { + _instance = new DataListSingleton(); + } + return _instance; + } + } +} diff --git a/SushiBar/SushiBarListImplement/Sushi.cs b/SushiBar/SushiBarListImplement/Sushi.cs new file mode 100644 index 0000000..133090b --- /dev/null +++ b/SushiBar/SushiBarListImplement/Sushi.cs @@ -0,0 +1,52 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SushiBarListImplement.Models +{ + internal class Sushi : IProductModel + { + public int Id { get; private set; } + public string ProductName { get; private set; } = string.Empty; + public double Price { get; private set; } + public Dictionary ProductComponents + { + get; + private set; + } = new Dictionary(); + public static Product? Create(ProductBindingModel? model) + { + if (model == null) + { + return null; + } + return new Product() + { + Id = model.Id, + ProductName = model.ProductName, + Price = model.Price, + ProductComponents = model.ProductComponents + }; + } + public void Update(ProductBindingModel? model) + { + if (model == null) + { + return; + } + ProductName = model.ProductName; + Price = model.Price; + ProductComponents = model.ProductComponents; + } + public ProductViewModel GetViewModel => new() + { + Id = Id, + ProductName = ProductName, + Price = Price, + ProductComponents = ProductComponents + }; + + } +} diff --git a/SushiBar/SushiBarListImplement/SushiBarListImplement.csproj b/SushiBar/SushiBarListImplement/SushiBarListImplement.csproj new file mode 100644 index 0000000..bbf9d38 --- /dev/null +++ b/SushiBar/SushiBarListImplement/SushiBarListImplement.csproj @@ -0,0 +1,55 @@ + + + + + Debug + AnyCPU + {1BBC3A4B-BF06-4EBF-AA20-863B369E234E} + Exe + SushiBarListImplement + SushiBarListImplement + v4.7.2 + 512 + true + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + {993e0787-3ad5-4743-8997-c828cd0cdc10} + SushiBarContracts + + + {76043de7-71bc-41e8-b4c0-ecfaddfbf55f} + SushiBarDataModels + + + + + + + + + + \ No newline at end of file diff --git a/SushiBar/SushiBarView/FormComponent.Designer.cs b/SushiBar/SushiBarView/FormComponent.Designer.cs new file mode 100644 index 0000000..f8da578 --- /dev/null +++ b/SushiBar/SushiBarView/FormComponent.Designer.cs @@ -0,0 +1,117 @@ +namespace SushiBarView +{ + partial class FormComponent + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.ButtonSave = new System.Windows.Forms.Button(); + this.ButtonCancel = new System.Windows.Forms.Button(); + this.labelName = new System.Windows.Forms.Label(); + this.labelCost = new System.Windows.Forms.Label(); + this.textBoxName = new System.Windows.Forms.TextBox(); + this.textBoxCost = new System.Windows.Forms.TextBox(); + this.SuspendLayout(); + // + // ButtonSave + // + this.ButtonSave.Location = new System.Drawing.Point(174, 99); + this.ButtonSave.Name = "ButtonSave"; + this.ButtonSave.Size = new System.Drawing.Size(87, 26); + this.ButtonSave.TabIndex = 0; + this.ButtonSave.Text = "Сохранить"; + this.ButtonSave.UseVisualStyleBackColor = true; + this.ButtonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // ButtonCancel + // + this.ButtonCancel.Location = new System.Drawing.Point(267, 99); + this.ButtonCancel.Name = "ButtonCancel"; + this.ButtonCancel.Size = new System.Drawing.Size(87, 26); + this.ButtonCancel.TabIndex = 1; + this.ButtonCancel.Text = "Отмена"; + this.ButtonCancel.UseVisualStyleBackColor = true; + // + // labelName + // + this.labelName.AutoSize = true; + this.labelName.Location = new System.Drawing.Point(12, 24); + this.labelName.Name = "labelName"; + this.labelName.Size = new System.Drawing.Size(59, 15); + this.labelName.TabIndex = 2; + this.labelName.Text = "Название"; + // + // labelCost + // + this.labelCost.AutoSize = true; + this.labelCost.Location = new System.Drawing.Point(12, 65); + this.labelCost.Name = "labelCost"; + this.labelCost.Size = new System.Drawing.Size(35, 15); + this.labelCost.TabIndex = 3; + this.labelCost.Text = "Цена"; + // + // textBoxName + // + this.textBoxName.Location = new System.Drawing.Point(83, 21); + this.textBoxName.Name = "textBoxName"; + this.textBoxName.Size = new System.Drawing.Size(133, 23); + this.textBoxName.TabIndex = 4; + // + // textBoxCost + // + this.textBoxCost.Location = new System.Drawing.Point(83, 57); + this.textBoxCost.Name = "textBoxCost"; + this.textBoxCost.Size = new System.Drawing.Size(133, 23); + this.textBoxCost.TabIndex = 5; + // + // FormComponent + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(357, 137); + this.Controls.Add(this.textBoxCost); + this.Controls.Add(this.textBoxName); + this.Controls.Add(this.labelCost); + this.Controls.Add(this.labelName); + this.Controls.Add(this.ButtonCancel); + this.Controls.Add(this.ButtonSave); + this.Name = "FormComponent"; + this.Text = "Компонент"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Button ButtonSave; + private Button ButtonCancel; + private Label labelName; + private Label labelCost; + private TextBox textBoxName; + private TextBox textBoxCost; + } +} \ No newline at end of file diff --git a/SushiBar/SushiBarView/FormComponent.cs b/SushiBar/SushiBarView/FormComponent.cs new file mode 100644 index 0000000..2b7fce4 --- /dev/null +++ b/SushiBar/SushiBarView/FormComponent.cs @@ -0,0 +1,89 @@ +using Microsoft.Extensions.Logging; +using SushiBarContracts.BindingModels; +using SushiBarContracts.BusinessLogicsContracts; +using SushiBarContracts.SearchModels; + + +namespace SushiBarView +{ + public partial class FormComponent : Form + { + private readonly ILogger _logger; + private readonly IComponentLogic _logic; + private int? _id; + public int Id { set { _id = value; } } + public FormComponent(ILogger logger, IComponentLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxName.Text)) + { + MessageBox.Show(" ", "", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation(" "); + try + { + var model = new ComponentBindingModel + { + Id = _id ?? 0, + ComponentName = textBoxName.Text, + Cost = Convert.ToDouble(textBoxCost.Text) + }; + var operationResult = _id.HasValue ? _logic.Update(model) : + _logic.Create(model); + if (!operationResult) + { + throw new Exception(" . ."); + } + MessageBox.Show(" ", "", + MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, " "); + MessageBox.Show(ex.Message, "", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + + } + + private void FormComponent_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + try + { + _logger.LogInformation(" "); + var view = _logic.ReadElement(new ComponentSearchModel + { + Id = + _id.Value + }); + if (view != null) + { + textBoxName.Text = view.ComponentName; + textBoxCost.Text = view.Cost.ToString(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, " "); + MessageBox.Show(ex.Message, "", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } + + + } +} \ No newline at end of file diff --git a/SushiBar/SushiBarView/FormComponent.resx b/SushiBar/SushiBarView/FormComponent.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/SushiBar/SushiBarView/FormComponent.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/SushiBar/SushiBarView/Program.cs b/SushiBar/SushiBarView/Program.cs new file mode 100644 index 0000000..34ba1ed --- /dev/null +++ b/SushiBar/SushiBarView/Program.cs @@ -0,0 +1,17 @@ +namespace SushiBarView +{ + internal static class Program + { + /// + /// The main entry point for the application. + /// + [STAThread] + static void Main() + { + // To customize application configuration such as set high DPI settings or default font, + // see https://aka.ms/applicationconfiguration. + ApplicationConfiguration.Initialize(); + Application.Run(new FormComponent()); + } + } +} \ No newline at end of file diff --git a/SushiBar/SushiBarView/SushiBarView.csproj b/SushiBar/SushiBarView/SushiBarView.csproj new file mode 100644 index 0000000..cf6300c --- /dev/null +++ b/SushiBar/SushiBarView/SushiBarView.csproj @@ -0,0 +1,21 @@ + + + + WinExe + net6.0-windows + enable + true + enable + + + + + + + + + + + + + \ No newline at end of file