diff --git a/Confectionery/Confectionery.sln b/Confectionery/Confectionery.sln index 30fc608..2c453a2 100644 --- a/Confectionery/Confectionery.sln +++ b/Confectionery/Confectionery.sln @@ -3,7 +3,15 @@ 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}") = "Confectionery", "Confectionery\Confectionery.csproj", "{7B75620D-9ECD-4175-8E35-D31CEC904A4B}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Confectionery", "Confectionery\Confectionery.csproj", "{7B75620D-9ECD-4175-8E35-D31CEC904A4B}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ConfectioneryDataModels", "ConfectioneryDataModels\ConfectioneryDataModels.csproj", "{22A053DC-3DC2-4375-9563-BF647A1092A4}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConfectioneryContracts", "ConfectioneryContracts\ConfectioneryContracts.csproj", "{6C4950D1-D788-4D5A-8C15-0A376274F2DD}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConfectioneryBusinessLogic", "ConfectioneryBusinessLogic\ConfectioneryBusinessLogic.csproj", "{30F4AE5A-2C90-4C7F-BBE9-2FA56BE26C63}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConfectioneryListImplement", "ConfectioneryListImplement\ConfectioneryListImplement.csproj", "{85992074-656D-4F79-AB23-60DE4F9ABF30}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -15,6 +23,22 @@ Global {7B75620D-9ECD-4175-8E35-D31CEC904A4B}.Debug|Any CPU.Build.0 = Debug|Any CPU {7B75620D-9ECD-4175-8E35-D31CEC904A4B}.Release|Any CPU.ActiveCfg = Release|Any CPU {7B75620D-9ECD-4175-8E35-D31CEC904A4B}.Release|Any CPU.Build.0 = Release|Any CPU + {22A053DC-3DC2-4375-9563-BF647A1092A4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {22A053DC-3DC2-4375-9563-BF647A1092A4}.Debug|Any CPU.Build.0 = Debug|Any CPU + {22A053DC-3DC2-4375-9563-BF647A1092A4}.Release|Any CPU.ActiveCfg = Release|Any CPU + {22A053DC-3DC2-4375-9563-BF647A1092A4}.Release|Any CPU.Build.0 = Release|Any CPU + {6C4950D1-D788-4D5A-8C15-0A376274F2DD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6C4950D1-D788-4D5A-8C15-0A376274F2DD}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6C4950D1-D788-4D5A-8C15-0A376274F2DD}.Release|Any CPU.ActiveCfg = Release|Any CPU + {6C4950D1-D788-4D5A-8C15-0A376274F2DD}.Release|Any CPU.Build.0 = Release|Any CPU + {30F4AE5A-2C90-4C7F-BBE9-2FA56BE26C63}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {30F4AE5A-2C90-4C7F-BBE9-2FA56BE26C63}.Debug|Any CPU.Build.0 = Debug|Any CPU + {30F4AE5A-2C90-4C7F-BBE9-2FA56BE26C63}.Release|Any CPU.ActiveCfg = Release|Any CPU + {30F4AE5A-2C90-4C7F-BBE9-2FA56BE26C63}.Release|Any CPU.Build.0 = Release|Any CPU + {85992074-656D-4F79-AB23-60DE4F9ABF30}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {85992074-656D-4F79-AB23-60DE4F9ABF30}.Debug|Any CPU.Build.0 = Debug|Any CPU + {85992074-656D-4F79-AB23-60DE4F9ABF30}.Release|Any CPU.ActiveCfg = Release|Any CPU + {85992074-656D-4F79-AB23-60DE4F9ABF30}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Confectionery/ConfectioneryBusinessLogic/BusinessLogics/IngredientLogic.cs b/Confectionery/ConfectioneryBusinessLogic/BusinessLogics/IngredientLogic.cs new file mode 100644 index 0000000..8dd820f --- /dev/null +++ b/Confectionery/ConfectioneryBusinessLogic/BusinessLogics/IngredientLogic.cs @@ -0,0 +1,118 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.BusinessLogicsContracts; +using ConfectioneryContracts.SearchModels; +using ConfectioneryContracts.StoragesContracts; +using ConfectioneryContracts.ViewModels; +using Microsoft.Extensions.Logging; + +namespace ConfectioneryBusinessLogic.BusinessLogics +{ + public class IngredientLogic : IIngredientLogic + { + private readonly ILogger _logger; + private readonly IIngredientStorage _ingredientStorage; + + public IngredientLogic(ILogger logger, IIngredientStorage ingredientStorage) + { + _logger = logger; + _ingredientStorage = ingredientStorage; + } + + public List? ReadList(IngredientSearchModel? model) + { + _logger.LogInformation("ReadList. IngredientName:{IngredientName}. Id:{Id}", model?.IngredientName, model?.Id); + var list = model == null ? _ingredientStorage.GetFullList() : _ingredientStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + + public IngredientViewModel? ReadElement(IngredientSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. IngredientName:{IngredientName}. Id:{Id}", model.IngredientName, model.Id); + var element = _ingredientStorage.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 (IngredientBindingModel model) + { + CheckModel(model); + if (_ingredientStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + public bool Update(IngredientBindingModel model) + { + CheckModel(model); + if (_ingredientStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + public bool Delete(IngredientBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_ingredientStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + + private void CheckModel(IngredientBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.IngredientName)) + { + throw new ArgumentNullException("Нет названия компонента", nameof(model.IngredientName)); + } + if (model.Cost <= 0) + { + throw new ArgumentNullException("Цена ингредиента должна быть больше 0", nameof(model.Cost)); + } + _logger.LogInformation("Ingredient. IngredietnName:{IngredientName}. Cost:{Cost}. Id:{Id}", model.IngredientName, model.Cost, model.Id); + var element = _ingredientStorage.GetElement(new IngredientSearchModel + { + IngredientName = model.IngredientName + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Ингредиент с таким названием уже есть"); + } + } + } +} diff --git a/Confectionery/ConfectioneryBusinessLogic/BusinessLogics/OrderLogic.cs b/Confectionery/ConfectioneryBusinessLogic/BusinessLogics/OrderLogic.cs new file mode 100644 index 0000000..d0316eb --- /dev/null +++ b/Confectionery/ConfectioneryBusinessLogic/BusinessLogics/OrderLogic.cs @@ -0,0 +1,143 @@ +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.BusinessLogicsContracts; +using ConfectioneryContracts.SearchModels; +using ConfectioneryContracts.StoragesContracts; +using ConfectioneryContracts.ViewModels; +using ConfectioneryDataModels.Enums; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryBusinessLogic.BusinessLogics +{ + public class OrderLogic : IOrderLogic + { + private readonly ILogger _logger; + private readonly IOrderStorage _orderStorage; + + public OrderLogic(ILogger logger, IOrderStorage orderStorage) + { + _logger = logger; + _orderStorage = orderStorage; + } + + public bool CreateOrder(OrderBindingModel model) + { + CheckModel(model); + if (_orderStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + public bool DeliveryOrder(OrderBindingModel model) + { + CheckModel(model); + var element = _orderStorage.GetElement(new OrderSearchModel + { + Id = model.Id + }); + if (element == null) + { + _logger.LogWarning("Read operation failed"); + return false; + } + if (element.Status != OrderStatus.Готов) + { + _logger.LogWarning("Status change operation failed"); + throw new InvalidOperationException("Заказ должен быть переведен в статус готовности перед выдачей!"); + } + element.Status = OrderStatus.Выдан; + return true; + } + + public bool FinishOrder(OrderBindingModel model) + { + CheckModel(model); + var element = _orderStorage.GetElement(new OrderSearchModel + { + Id = model.Id + }); + if (element == null) + { + _logger.LogWarning("Read operation failed"); + return false; + } + if (element.Status != OrderStatus.Выполняется) + { + _logger.LogWarning("Status change operation failed"); + throw new InvalidOperationException("Заказ должен быть переведен в статус выполнения перед готовностью!"); + } + element.Status = OrderStatus.Готов; + return true; + } + + public List? ReadList(OrderSearchModel? model) + { + _logger.LogInformation("ReadList. Id:{Id}", model?.Id); + var list = model == null ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + + public bool TakeOrderInWork(OrderBindingModel model) + { + CheckModel(model); + var element = _orderStorage.GetElement(new OrderSearchModel + { + Id = model.Id + }); + if (element == null) + { + _logger.LogWarning("Read operation failed"); + return false; + } + if (element.Status != OrderStatus.Принят) + { + _logger.LogWarning("Status change operation failed"); + throw new InvalidOperationException("Заказ должен быть переведен в статус принятого перед его выполнением!"); + } + element.Status = OrderStatus.Выполняется; + return true; + } + + private void CheckModel(OrderBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (model.Sum <= 0) + { + throw new ArgumentNullException("Сумма заказа должна быть больше 0", nameof(model.Sum)); + } + if (model.Count <= 0) + { + throw new ArgumentNullException("Количество изделий должно быть больше 0", nameof(model.Count)); + } + _logger.LogInformation("Order. Sum:{Sum}. Id:{Id}", model.Sum, model.Id); + var element = _orderStorage.GetElement(new OrderSearchModel + { + Id = model.Id + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Заказ с таким ID уже существует"); + } + } + } +} diff --git a/Confectionery/ConfectioneryBusinessLogic/BusinessLogics/PastryLogic.cs b/Confectionery/ConfectioneryBusinessLogic/BusinessLogics/PastryLogic.cs new file mode 100644 index 0000000..a7d1138 --- /dev/null +++ b/Confectionery/ConfectioneryBusinessLogic/BusinessLogics/PastryLogic.cs @@ -0,0 +1,122 @@ +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.BusinessLogicsContracts; +using ConfectioneryContracts.SearchModels; +using ConfectioneryContracts.StoragesContracts; +using ConfectioneryContracts.ViewModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryBusinessLogic.BusinessLogics +{ + public class PastryLogic : IPastryLogic + { + private readonly ILogger _logger; + private readonly IPastryStorage _pastryStorage; + + public PastryLogic(ILogger logger, IPastryStorage pastryStorage) + { + _logger = logger; + _pastryStorage = pastryStorage; + } + + public List? ReadList(PastrySearchModel? model) + { + _logger.LogInformation("ReadList. PastryName:{PastryName}. Id:{Id}", model?.PastryName, model?.Id); + var list = model == null ? _pastryStorage.GetFullList() : _pastryStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + + public PastryViewModel? ReadElement(PastrySearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. PastryName:{PastryName}. Id:{Id}", model.PastryName, model.Id); + var element = _pastryStorage.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(PastryBindingModel model) + { + CheckModel(model); + if (_pastryStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + public bool Update(PastryBindingModel model) + { + CheckModel(model); + if (_pastryStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + public bool Delete(PastryBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_pastryStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + + private void CheckModel(PastryBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.PastryName)) + { + throw new ArgumentNullException("Нет названия изделия", nameof(model.PastryName)); + } + if (model.Price <= 0) + { + throw new ArgumentNullException("Цена изделия должна быть больше 0", nameof(model.Price)); + } + if (model.PastryIngredients == null || model.PastryIngredients.Count == 0) + { + throw new ArgumentNullException("Нет ингредиентов изделия", nameof(model.PastryIngredients)); + } + _logger.LogInformation("Pastry. PastryName:{PastryName}. Cost:{Cost}. Id:{Id}", model.PastryName, model.Price, model.Id); + var element = _pastryStorage.GetElement(new PastrySearchModel + { + PastryName = model.PastryName + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Изделие с таким названием уже есть"); + } + } + } +} diff --git a/Confectionery/ConfectioneryBusinessLogic/ConfectioneryBusinessLogic.csproj b/Confectionery/ConfectioneryBusinessLogic/ConfectioneryBusinessLogic.csproj new file mode 100644 index 0000000..0eae306 --- /dev/null +++ b/Confectionery/ConfectioneryBusinessLogic/ConfectioneryBusinessLogic.csproj @@ -0,0 +1,17 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + diff --git a/Confectionery/ConfectioneryContracts/BindingModels/IngredientBindingModel.cs b/Confectionery/ConfectioneryContracts/BindingModels/IngredientBindingModel.cs new file mode 100644 index 0000000..d3a6e12 --- /dev/null +++ b/Confectionery/ConfectioneryContracts/BindingModels/IngredientBindingModel.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ConfectioneryDataModels.Models; + +namespace ConfectioneryContracts.BindingModels +{ + public class IngredientBindingModel : IIngredientModel + { + public int Id { get; set; } + public string IngredientName { get; set; } = string.Empty; + public double Cost { get; set; } + + } +} diff --git a/Confectionery/ConfectioneryContracts/BindingModels/OrderBindingModel.cs b/Confectionery/ConfectioneryContracts/BindingModels/OrderBindingModel.cs new file mode 100644 index 0000000..8262c80 --- /dev/null +++ b/Confectionery/ConfectioneryContracts/BindingModels/OrderBindingModel.cs @@ -0,0 +1,21 @@ +using ConfectioneryDataModels.Enums; +using ConfectioneryDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryContracts.BindingModels +{ + public class OrderBindingModel : IOrderModel + { + public int Id { get; set; } + public int PastryId { 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/Confectionery/ConfectioneryContracts/BindingModels/PastryBindingModel.cs b/Confectionery/ConfectioneryContracts/BindingModels/PastryBindingModel.cs new file mode 100644 index 0000000..845f1c6 --- /dev/null +++ b/Confectionery/ConfectioneryContracts/BindingModels/PastryBindingModel.cs @@ -0,0 +1,21 @@ +using ConfectioneryDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryContracts.BindingModels +{ + public class PastryBindingModel : IPastryModel + { + public int Id { get; set; } + public string PastryName { get; set; } = string.Empty; + public double Price { get; set; } + public Dictionary PastryIngredients + { + get; + set; + } = new(); + } +} diff --git a/Confectionery/ConfectioneryContracts/BusinessLogicsContracts/IIngredientLogic.cs b/Confectionery/ConfectioneryContracts/BusinessLogicsContracts/IIngredientLogic.cs new file mode 100644 index 0000000..2701f63 --- /dev/null +++ b/Confectionery/ConfectioneryContracts/BusinessLogicsContracts/IIngredientLogic.cs @@ -0,0 +1,20 @@ +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.SearchModels; +using ConfectioneryContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryContracts.BusinessLogicsContracts +{ + public interface IIngredientLogic + { + List? ReadList(IngredientSearchModel? model); + IngredientViewModel? ReadElement(IngredientSearchModel model); + bool Create(IngredientBindingModel model); + bool Update(IngredientBindingModel model); + bool Delete(IngredientBindingModel model); + } +} diff --git a/Confectionery/ConfectioneryContracts/BusinessLogicsContracts/IOrderLogic.cs b/Confectionery/ConfectioneryContracts/BusinessLogicsContracts/IOrderLogic.cs new file mode 100644 index 0000000..7a91377 --- /dev/null +++ b/Confectionery/ConfectioneryContracts/BusinessLogicsContracts/IOrderLogic.cs @@ -0,0 +1,21 @@ +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.SearchModels; +using ConfectioneryContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryContracts.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/Confectionery/ConfectioneryContracts/BusinessLogicsContracts/IPastryLogic.cs b/Confectionery/ConfectioneryContracts/BusinessLogicsContracts/IPastryLogic.cs new file mode 100644 index 0000000..961f022 --- /dev/null +++ b/Confectionery/ConfectioneryContracts/BusinessLogicsContracts/IPastryLogic.cs @@ -0,0 +1,20 @@ +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.SearchModels; +using ConfectioneryContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryContracts.BusinessLogicsContracts +{ + public interface IPastryLogic + { + List? ReadList(PastrySearchModel? model); + PastryViewModel? ReadElement(PastrySearchModel model); + bool Create(PastryBindingModel model); + bool Update(PastryBindingModel model); + bool Delete(PastryBindingModel model); + } +} diff --git a/Confectionery/ConfectioneryContracts/ConfectioneryContracts.csproj b/Confectionery/ConfectioneryContracts/ConfectioneryContracts.csproj new file mode 100644 index 0000000..b0b970c --- /dev/null +++ b/Confectionery/ConfectioneryContracts/ConfectioneryContracts.csproj @@ -0,0 +1,13 @@ + + + + net6.0 + enable + enable + + + + + + + diff --git a/Confectionery/ConfectioneryContracts/SearchModels/IngredientSearchModel.cs b/Confectionery/ConfectioneryContracts/SearchModels/IngredientSearchModel.cs new file mode 100644 index 0000000..e44cfca --- /dev/null +++ b/Confectionery/ConfectioneryContracts/SearchModels/IngredientSearchModel.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryContracts.SearchModels +{ + public class IngredientSearchModel + { + public int? Id { get; set; } + public string? IngredientName { get; set; } + + } +} diff --git a/Confectionery/ConfectioneryContracts/SearchModels/OrderSearchModel.cs b/Confectionery/ConfectioneryContracts/SearchModels/OrderSearchModel.cs new file mode 100644 index 0000000..99f81bc --- /dev/null +++ b/Confectionery/ConfectioneryContracts/SearchModels/OrderSearchModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryContracts.SearchModels +{ + public class OrderSearchModel + { + public int? Id { get; set; } + + } +} diff --git a/Confectionery/ConfectioneryContracts/SearchModels/PastrySearchModel.cs b/Confectionery/ConfectioneryContracts/SearchModels/PastrySearchModel.cs new file mode 100644 index 0000000..33c17c1 --- /dev/null +++ b/Confectionery/ConfectioneryContracts/SearchModels/PastrySearchModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryContracts.SearchModels +{ + public class PastrySearchModel + { + public int? Id { get; set; } + public string? PastryName { get; set; } + } +} diff --git a/Confectionery/ConfectioneryContracts/StoragesContracts/IIngredientStorage.cs b/Confectionery/ConfectioneryContracts/StoragesContracts/IIngredientStorage.cs new file mode 100644 index 0000000..574c861 --- /dev/null +++ b/Confectionery/ConfectioneryContracts/StoragesContracts/IIngredientStorage.cs @@ -0,0 +1,22 @@ +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.SearchModels; +using ConfectioneryContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryContracts.StoragesContracts +{ + public interface IIngredientStorage + { + List GetFullList(); + List GetFilteredList(IngredientSearchModel model); + IngredientViewModel? GetElement(IngredientSearchModel model); + IngredientViewModel? Insert(IngredientBindingModel model); + IngredientViewModel? Update(IngredientBindingModel model); + IngredientViewModel? Delete(IngredientBindingModel model); + + } +} diff --git a/Confectionery/ConfectioneryContracts/StoragesContracts/IOrderStorage.cs b/Confectionery/ConfectioneryContracts/StoragesContracts/IOrderStorage.cs new file mode 100644 index 0000000..cbdd94f --- /dev/null +++ b/Confectionery/ConfectioneryContracts/StoragesContracts/IOrderStorage.cs @@ -0,0 +1,21 @@ +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.SearchModels; +using ConfectioneryContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryContracts.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/Confectionery/ConfectioneryContracts/StoragesContracts/IPastryStorage.cs b/Confectionery/ConfectioneryContracts/StoragesContracts/IPastryStorage.cs new file mode 100644 index 0000000..78fc0c9 --- /dev/null +++ b/Confectionery/ConfectioneryContracts/StoragesContracts/IPastryStorage.cs @@ -0,0 +1,22 @@ +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.SearchModels; +using ConfectioneryContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryContracts.StoragesContracts +{ + public interface IPastryStorage + { + List GetFullList(); + List GetFilteredList(PastrySearchModel model); + PastryViewModel? GetElement(PastrySearchModel model); + PastryViewModel? Insert(PastryBindingModel model); + PastryViewModel? Update(PastryBindingModel model); + PastryViewModel? Delete(PastryBindingModel model); + + } +} diff --git a/Confectionery/ConfectioneryContracts/ViewModels/IngredientViewModel.cs b/Confectionery/ConfectioneryContracts/ViewModels/IngredientViewModel.cs new file mode 100644 index 0000000..81a9302 --- /dev/null +++ b/Confectionery/ConfectioneryContracts/ViewModels/IngredientViewModel.cs @@ -0,0 +1,20 @@ +using ConfectioneryDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryContracts.ViewModels +{ + public class IngredientViewModel : IIngredientModel + { + public int Id { get; set; } + [DisplayName("Название ингредиента")] + public string IngredientName { get; set; } = string.Empty; + [DisplayName("Цена")] + public double Cost { get; set; } + + } +} diff --git a/Confectionery/ConfectioneryContracts/ViewModels/OrderViewModel.cs b/Confectionery/ConfectioneryContracts/ViewModels/OrderViewModel.cs new file mode 100644 index 0000000..dadab69 --- /dev/null +++ b/Confectionery/ConfectioneryContracts/ViewModels/OrderViewModel.cs @@ -0,0 +1,30 @@ +using ConfectioneryDataModels.Enums; +using ConfectioneryDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryContracts.ViewModels +{ + public class OrderViewModel : IOrderModel + { + [DisplayName("Номер")] + public int Id { get; set; } + public int PastryId { get; set; } + [DisplayName("Кондитерское изделие")] + public string PastryName { 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/Confectionery/ConfectioneryContracts/ViewModels/PastryViewModel.cs b/Confectionery/ConfectioneryContracts/ViewModels/PastryViewModel.cs new file mode 100644 index 0000000..b96bfb9 --- /dev/null +++ b/Confectionery/ConfectioneryContracts/ViewModels/PastryViewModel.cs @@ -0,0 +1,24 @@ +using ConfectioneryDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryContracts.ViewModels +{ + public class PastryViewModel : IPastryModel + { + public int Id { get; set; } + [DisplayName("Название кондитерского изделия")] + public string PastryName { get; set; } = string.Empty; + [DisplayName("Цена")] + public double Price { get; set; } + public Dictionary PastryIngredients + { + get; + set; + } = new(); + } +} diff --git a/Confectionery/ConfectioneryDataModels/ConfectioneryDataModels.csproj b/Confectionery/ConfectioneryDataModels/ConfectioneryDataModels.csproj new file mode 100644 index 0000000..27ac386 --- /dev/null +++ b/Confectionery/ConfectioneryDataModels/ConfectioneryDataModels.csproj @@ -0,0 +1,9 @@ + + + + net6.0 + enable + enable + + + diff --git a/Confectionery/ConfectioneryDataModels/Enums/OrderStatus.cs b/Confectionery/ConfectioneryDataModels/Enums/OrderStatus.cs new file mode 100644 index 0000000..bb0ce5a --- /dev/null +++ b/Confectionery/ConfectioneryDataModels/Enums/OrderStatus.cs @@ -0,0 +1,11 @@ +namespace ConfectioneryDataModels.Enums +{ + public enum OrderStatus + { + Неизвестен = -1, + Принят = 0, + Выполняется = 1, + Готов = 2, + Выдан = 3 + } +} \ No newline at end of file diff --git a/Confectionery/ConfectioneryDataModels/IId.cs b/Confectionery/ConfectioneryDataModels/IId.cs new file mode 100644 index 0000000..fc8cada --- /dev/null +++ b/Confectionery/ConfectioneryDataModels/IId.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryDataModels +{ + public interface IId + { + int Id { get; } + } +} diff --git a/Confectionery/ConfectioneryDataModels/Models/IIngredientModel.cs b/Confectionery/ConfectioneryDataModels/Models/IIngredientModel.cs new file mode 100644 index 0000000..de483fd --- /dev/null +++ b/Confectionery/ConfectioneryDataModels/Models/IIngredientModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryDataModels.Models +{ + public interface IIngredientModel : IId + { + string IngredientName { get; } + double Cost { get; } + } +} diff --git a/Confectionery/ConfectioneryDataModels/Models/IOrderModel.cs b/Confectionery/ConfectioneryDataModels/Models/IOrderModel.cs new file mode 100644 index 0000000..2ca229e --- /dev/null +++ b/Confectionery/ConfectioneryDataModels/Models/IOrderModel.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ConfectioneryDataModels.Enums; + +namespace ConfectioneryDataModels.Models +{ + public interface IOrderModel : IId + { + int PastryId { get; } + int Count { get; } + double Sum { get; } + OrderStatus Status { get; } + DateTime DateCreate { get; } + DateTime? DateImplement { get; } + + } +} diff --git a/Confectionery/ConfectioneryDataModels/Models/IPastryModel.cs b/Confectionery/ConfectioneryDataModels/Models/IPastryModel.cs new file mode 100644 index 0000000..b6ebab9 --- /dev/null +++ b/Confectionery/ConfectioneryDataModels/Models/IPastryModel.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryDataModels.Models +{ + public interface IPastryModel : IId + { + string PastryName { get; } + double Price { get; } + Dictionary PastryIngredients { get; } + } +} diff --git a/Confectionery/ConfectioneryListImplement/ConfectioneryListImplement.csproj b/Confectionery/ConfectioneryListImplement/ConfectioneryListImplement.csproj new file mode 100644 index 0000000..2234730 --- /dev/null +++ b/Confectionery/ConfectioneryListImplement/ConfectioneryListImplement.csproj @@ -0,0 +1,18 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + + diff --git a/Confectionery/ConfectioneryListImplement/DataListSingleton.cs b/Confectionery/ConfectioneryListImplement/DataListSingleton.cs new file mode 100644 index 0000000..e468aca --- /dev/null +++ b/Confectionery/ConfectioneryListImplement/DataListSingleton.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryListImplement +{ + public class DataListSingleton + { + + } +} diff --git a/Confectionery/ConfectioneryListImplement/Models/Ingredient.cs b/Confectionery/ConfectioneryListImplement/Models/Ingredient.cs new file mode 100644 index 0000000..9d185c0 --- /dev/null +++ b/Confectionery/ConfectioneryListImplement/Models/Ingredient.cs @@ -0,0 +1,47 @@ +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.ViewModels; +using ConfectioneryDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryListImplement.Models +{ + public class Ingredient : IIngredientModel + { + public int Id { get; private set; } + public string IngredientName { get; private set; } = string.Empty; + public double Cost { get; set; } + public static Ingredient? Create(IngredientBindingModel? model) + { + if (model == null) + { + return null; + } + return new Ingredient() + { + Id = model.Id, + IngredientName = model.IngredientName, + Cost = model.Cost + }; + } + public void Update(IngredientBindingModel? model) + { + if (model == null) + { + return; + } + IngredientName = model.IngredientName; + Cost = model.Cost; + } + public IngredientViewModel GetViewModel => new() + { + Id = Id, + IngredientName = IngredientName, + Cost = Cost + }; + } +} diff --git a/Confectionery/ConfectioneryListImplement/Models/Order.cs b/Confectionery/ConfectioneryListImplement/Models/Order.cs new file mode 100644 index 0000000..6b61957 --- /dev/null +++ b/Confectionery/ConfectioneryListImplement/Models/Order.cs @@ -0,0 +1,69 @@ +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.ViewModels; +using ConfectioneryDataModels.Enums; +using ConfectioneryDataModels.Models; +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryListImplement.Models +{ + public class Order : IOrderModel + { + public int Id {get; private set;} + public int PastryId { get; private set; } + public int Count { get; private set; } + public double Sum { get; private set; } + + public OrderStatus Status { get; private set; } + + public DateTime DateCreate { get; private set; } + + public DateTime? DateImplement { get; private set; } + + public static Order? Create(OrderBindingModel? model) + { + if (model == null) + { + return null; + } + return new Order() + { + Id = model.Id, + PastryId = model.PastryId, + Count = model.Count, + Sum = model.Sum, + Status = model.Status, + DateCreate = model.DateCreate, + DateImplement = model.DateImplement + }; + } + public void Update(OrderBindingModel? model) + { + if (model == null) + { + return; + } + PastryId = model.PastryId; + Count = model.Count; + Sum = model.Sum; + Status = model.Status; + DateImplement = model.DateImplement; + } + public OrderViewModel GetViewModel => new() + { + Id = Id, + PastryId = PastryId, + Count = Count, + Sum = Sum, + Status = Status, + DateCreate = DateCreate, + DateImplement = DateImplement + }; + + } +} diff --git a/Confectionery/ConfectioneryListImplement/Models/Pastry.cs b/Confectionery/ConfectioneryListImplement/Models/Pastry.cs new file mode 100644 index 0000000..b4f45ed --- /dev/null +++ b/Confectionery/ConfectioneryListImplement/Models/Pastry.cs @@ -0,0 +1,50 @@ +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.ViewModels; +using ConfectioneryDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryListImplement.Models +{ + public class Pastry : IPastryModel + { + public int Id { get; private set; } + public string PastryName { get; private set; } = string.Empty; + public double Price { get; private set; } + public Dictionary PastryIngredients { get; private set; } = new Dictionary(); + public static Pastry? Create(PastryBindingModel? model) + { + if (model == null) + { + return null; + } + return new Pastry() + { + Id = model.Id, + PastryName = model.PastryName, + Price = model.Price, + PastryIngredients = model.PastryIngredients + }; + } + public void Update(PastryBindingModel? model) + { + if (model == null) + { + return; + } + PastryName = model.PastryName; + Price = model.Price; + PastryIngredients = model.PastryIngredients; + } + public PastryViewModel GetViewModel => new() + { + Id = Id, + PastryName = PastryName, + Price = Price, + PastryIngredients = PastryIngredients + }; + } +}