diff --git a/FlowerShopBusinessLogic/ComponentLogic.cs b/FlowerShopBusinessLogic/ComponentLogic.cs new file mode 100644 index 0000000..ed0ddc3 --- /dev/null +++ b/FlowerShopBusinessLogic/ComponentLogic.cs @@ -0,0 +1,113 @@ +using FlowerShopContracts.BindingModels; +using FlowerShopContracts.BusinessLogicsContracts; +using FlowerShopContracts.SearchModels; +using FlowerShopContracts.StoragesContracts; +using FlowerShopContracts.ViewModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FlowerShopBusinessLogic.BusinessLogic +{ + public class ComponentLogic : IFlowerLogic + { + 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; + } + 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/FlowerShopBusinessLogic/FlowerLogic.cs b/FlowerShopBusinessLogic/FlowerLogic.cs new file mode 100644 index 0000000..76007ba --- /dev/null +++ b/FlowerShopBusinessLogic/FlowerLogic.cs @@ -0,0 +1,112 @@ +using FlowerShopContracts.BindingModels; +using FlowerShopContracts.BusinessLogicsContracts; +using FlowerShopContracts.SearchModels; +using FlowerShopContracts.StoragesContracts; +using FlowerShopContracts.ViewModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FlowerShopBusinessLogic.BusinessLogic +{ + public class FlowerLogic : IFlowerLogic + { + private readonly ILogger _logger; + private readonly IFlowerStorage _flowerStorage; + public FlowerLogic(ILogger logger, IFlowerStorage flowerStorage) + { + _logger = logger; + _flowerStorage = flowerStorage; + } + public List? ReadList(FlowerSearchModel? model) + { + _logger.LogInformation("ReadList. FlowerName:{FlowerName}.Id:{ Id}", model?.FlowerName, model?.Id); + var list = model == null ? _flowerStorage.GetFullList() : _flowerStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + public FlowerViewModel? ReadElement(FlowerSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. FlowerName:{FlowerName}.Id:{ Id}", model.FlowerName, model.Id); + var element = _flowerStorage.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(FlowerBindingModel model) + { + CheckModel(model); + if (_flowerStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + public bool Update(FlowerBindingModel model) + { + CheckModel(model); + if (_flowerStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + public bool Delete(FlowerBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_flowerStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + private void CheckModel(FlowerBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.FlowerName)) + { + throw new ArgumentNullException("Нет названия цветка", nameof(model.FlowerName)); + } + if (model.Price <= 0) + { + throw new ArgumentNullException("Цена цветка должна быть больше 0", nameof(model.Price)); + } + _logger.LogInformation("Flower. FlowerName:{FlowerName}.Cost:{ Cost}. Id: { Id}", model.FlowerName, model.Price, model.Id); + var element = _flowerStorage.GetElement(new FlowerSearchModel + { + FlowerName = model.FlowerName + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Компонент с таким названием уже есть"); + } + } + } +} diff --git a/FlowerShopBusinessLogic/FlowerShopBusinessLogic.csproj b/FlowerShopBusinessLogic/FlowerShopBusinessLogic.csproj new file mode 100644 index 0000000..e3db8e7 --- /dev/null +++ b/FlowerShopBusinessLogic/FlowerShopBusinessLogic.csproj @@ -0,0 +1,17 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + diff --git a/FlowerShopBusinessLogic/OrderLogic.cs b/FlowerShopBusinessLogic/OrderLogic.cs new file mode 100644 index 0000000..c19d04d --- /dev/null +++ b/FlowerShopBusinessLogic/OrderLogic.cs @@ -0,0 +1,110 @@ +using FlowerShopContracts.BindingModels; +using FlowerShopContracts.BusinessLogicsContracts; +using FlowerShopContracts.SearchModels; +using FlowerShopContracts.StoragesContracts; +using FlowerShopContracts.ViewModels; +using FlowerShopDataModels.Enums; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FlowerShopBusinessLogic.BusinessLogic +{ + public class OrderLogic : IOrderLogic + { + private readonly ILogger _logger; + private readonly IOrderStorage _orderStorage; + + public OrderLogic(ILogger logger, IOrderStorage orderStorage) + { + _logger = logger; + _orderStorage = orderStorage; + } + + 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 CreateOrder(OrderBindingModel model) + { + CheckModel(model); + if (model.Status != OrderStatus.Неизвестен) return false; + model.Status = OrderStatus.Принят; + if (_orderStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + public bool ChangeStatus(OrderBindingModel model, OrderStatus status) + { + CheckModel(model); + var element = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id }); + if (element == null) + { + _logger.LogWarning("Read operation failed"); + return false; + } + if (element.Status != status - 1) + { + _logger.LogWarning("Status change operation failed"); + throw new InvalidOperationException("Текущий статус заказа не может быть переведен в выбранный"); + } + model.Status = status; + if (model.Status == OrderStatus.Выдан) model.DateImplement = DateTime.Now; + _orderStorage.Update(model); + return true; + } + + public bool TakeOrderInWork(OrderBindingModel model) + { + return ChangeStatus(model, OrderStatus.Выполняется); + } + + public bool FinishOrder(OrderBindingModel model) + { + return ChangeStatus(model, OrderStatus.Готов); + } + + public bool DeliveryOrder(OrderBindingModel model) + { + return ChangeStatus(model, OrderStatus.Выдан); + } + + 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:{ Cost}. Id: { Id}", model.Sum, model.Id); + } + } +} diff --git a/FlowerShopContracts/BindingModels/ComponentBindingModel.cs b/FlowerShopContracts/BindingModels/ComponentBindingModel.cs new file mode 100644 index 0000000..3b3ae89 --- /dev/null +++ b/FlowerShopContracts/BindingModels/ComponentBindingModel.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using FlowerShopDataModels.Models; + +namespace FlowerShopContracts.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/FlowerShopContracts/BindingModels/FlowerBindingModel.cs b/FlowerShopContracts/BindingModels/FlowerBindingModel.cs new file mode 100644 index 0000000..b484875 --- /dev/null +++ b/FlowerShopContracts/BindingModels/FlowerBindingModel.cs @@ -0,0 +1,21 @@ +using FlowerShopDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FlowerShopContracts.BindingModels +{ + public class FlowerBindingModel : IFlowerModel + { + public int Id { get; set; } + public string FlowerName { get; set; } = string.Empty; + public double Price { get; set; } + public Dictionary FlowerComponents + { + get; + set; + } = new(); + } +} diff --git a/FlowerShopContracts/BindingModels/OrderBindingModel.cs b/FlowerShopContracts/BindingModels/OrderBindingModel.cs new file mode 100644 index 0000000..9da12da --- /dev/null +++ b/FlowerShopContracts/BindingModels/OrderBindingModel.cs @@ -0,0 +1,21 @@ +using FlowerShopDataModels.Enums; +using FlowerShopDataModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FlowerShopContracts.BindingModels +{ + public class OrderBindingModel : IOrderModel + { + public int Id { get; set; } + public int ProductId { 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/FlowerShopContracts/BusinessLogicsContracts/IComponentLogic.cs b/FlowerShopContracts/BusinessLogicsContracts/IComponentLogic.cs new file mode 100644 index 0000000..487a2c0 --- /dev/null +++ b/FlowerShopContracts/BusinessLogicsContracts/IComponentLogic.cs @@ -0,0 +1,20 @@ +using FlowerShopContracts.BindingModels; +using FlowerShopContracts.SearchModels; +using FlowerShopContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FlowerShopContracts.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/FlowerShopContracts/BusinessLogicsContracts/IFlowerLogic.cs b/FlowerShopContracts/BusinessLogicsContracts/IFlowerLogic.cs new file mode 100644 index 0000000..46390ec --- /dev/null +++ b/FlowerShopContracts/BusinessLogicsContracts/IFlowerLogic.cs @@ -0,0 +1,20 @@ +using FlowerShopContracts.BindingModels; +using FlowerShopContracts.SearchModels; +using FlowerShopContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FlowerShopContracts.BusinessLogicsContracts +{ + public interface IFlowerLogic + { + List? ReadList(FlowerSearchModel? model); + FlowerViewModel? ReadElement(FlowerSearchModel model); + bool Create(FlowerBindingModel model); + bool Update(FlowerBindingModel model); + bool Delete(FlowerBindingModel model); + } +} \ No newline at end of file diff --git a/FlowerShopContracts/BusinessLogicsContracts/IOrderLogic.cs b/FlowerShopContracts/BusinessLogicsContracts/IOrderLogic.cs new file mode 100644 index 0000000..298066a --- /dev/null +++ b/FlowerShopContracts/BusinessLogicsContracts/IOrderLogic.cs @@ -0,0 +1,20 @@ +using FlowerShopContracts.BindingModels; +using FlowerShopContracts.SearchModels; +using FlowerShopContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FlowerShopContracts.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/FlowerShopContracts/FlowerShopContracts.csproj b/FlowerShopContracts/FlowerShopContracts.csproj new file mode 100644 index 0000000..901b7f6 --- /dev/null +++ b/FlowerShopContracts/FlowerShopContracts.csproj @@ -0,0 +1,17 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + diff --git a/FlowerShopContracts/SearchModels/ComponentSearchModel.cs b/FlowerShopContracts/SearchModels/ComponentSearchModel.cs new file mode 100644 index 0000000..610914a --- /dev/null +++ b/FlowerShopContracts/SearchModels/ComponentSearchModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FlowerShopContracts.SearchModels +{ + public class ComponentSearchModel + { + public int? Id { get; set; } + public string? ComponentName { get; set; } + } +} diff --git a/FlowerShopContracts/SearchModels/FlowerSearchModel.cs b/FlowerShopContracts/SearchModels/FlowerSearchModel.cs new file mode 100644 index 0000000..362a865 --- /dev/null +++ b/FlowerShopContracts/SearchModels/FlowerSearchModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FlowerShopContracts.SearchModels +{ + public class FlowerSearchModel + { + public int? Id { get; set; } + public string? FlowerName { get; set; } + } +} diff --git a/FlowerShopContracts/SearchModels/OrderSearchModel.cs b/FlowerShopContracts/SearchModels/OrderSearchModel.cs new file mode 100644 index 0000000..5b569de --- /dev/null +++ b/FlowerShopContracts/SearchModels/OrderSearchModel.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FlowerShopContracts.SearchModels +{ + public class OrderSearchModel + { + public int? Id { get; set; } + } +} diff --git a/FlowerShopContracts/StoragesContracts/IComponentStorage.cs b/FlowerShopContracts/StoragesContracts/IComponentStorage.cs new file mode 100644 index 0000000..32ddbc4 --- /dev/null +++ b/FlowerShopContracts/StoragesContracts/IComponentStorage.cs @@ -0,0 +1,21 @@ +using FlowerShopContracts.BindingModels; +using FlowerShopContracts.SearchModels; +using FlowerShopContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FlowerShopContracts.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/FlowerShopContracts/StoragesContracts/IFlowerStorage.cs b/FlowerShopContracts/StoragesContracts/IFlowerStorage.cs new file mode 100644 index 0000000..6733ad4 --- /dev/null +++ b/FlowerShopContracts/StoragesContracts/IFlowerStorage.cs @@ -0,0 +1,21 @@ +using FlowerShopContracts.BindingModels; +using FlowerShopContracts.SearchModels; +using FlowerShopContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FlowerShopContracts.StoragesContracts +{ + public interface IFlowerStorage + { + List GetFullList(); + List GetFilteredList(FlowerSearchModel model); + FlowerViewModel? GetElement(FlowerSearchModel model); + FlowerViewModel? Insert(FlowerBindingModel model); + FlowerViewModel? Update(FlowerBindingModel model); + FlowerViewModel? Delete(FlowerBindingModel model); + } +} diff --git a/FlowerShopContracts/StoragesContracts/IOrderStorage.cs b/FlowerShopContracts/StoragesContracts/IOrderStorage.cs new file mode 100644 index 0000000..c108c9d --- /dev/null +++ b/FlowerShopContracts/StoragesContracts/IOrderStorage.cs @@ -0,0 +1,21 @@ +using FlowerShopContracts.BindingModels; +using FlowerShopContracts.SearchModels; +using FlowerShopContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FlowerShopContracts.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/FlowerShopContracts/ViewModels/ComponentViewModel.cs b/FlowerShopContracts/ViewModels/ComponentViewModel.cs new file mode 100644 index 0000000..667f0bb --- /dev/null +++ b/FlowerShopContracts/ViewModels/ComponentViewModel.cs @@ -0,0 +1,19 @@ +using FlowerShopDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FlowerShopContracts.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/FlowerShopContracts/ViewModels/FlowerViewModel.cs b/FlowerShopContracts/ViewModels/FlowerViewModel.cs new file mode 100644 index 0000000..0010c97 --- /dev/null +++ b/FlowerShopContracts/ViewModels/FlowerViewModel.cs @@ -0,0 +1,24 @@ +using FlowerShopDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FlowerShopContracts.ViewModels +{ + public class FlowerViewModel : IFlowerModel + { + public int Id { get; set; } + [DisplayName("Название изделия")] + public string FlowerName { get; set; } = string.Empty; + [DisplayName("Цена")] + public double Price { get; set; } + public Dictionary FlowerComponents + { + get; + set; + } = new(); + } +} diff --git a/FlowerShopContracts/ViewModels/OrderViewModel.cs b/FlowerShopContracts/ViewModels/OrderViewModel.cs new file mode 100644 index 0000000..78dfe46 --- /dev/null +++ b/FlowerShopContracts/ViewModels/OrderViewModel.cs @@ -0,0 +1,30 @@ +using FlowerShopDataModels.Enums; +using FlowerShopDataModels; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FlowerShopContracts.ViewModels +{ + public class OrderViewModel : IOrderModel + { + [DisplayName("Номер")] + public int Id { get; set; } + public int ProductId { get; set; } + [DisplayName("Изделие")] + public string ProductName { 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/FlowerShopDataModels/FlowerShopDataModels.csproj b/FlowerShopDataModels/FlowerShopDataModels.csproj index 132c02c..dce9680 100644 --- a/FlowerShopDataModels/FlowerShopDataModels.csproj +++ b/FlowerShopDataModels/FlowerShopDataModels.csproj @@ -6,4 +6,8 @@ enable + + + + diff --git a/FlowerShopDataModels/IComponentModel.cs b/FlowerShopDataModels/IComponentModel.cs new file mode 100644 index 0000000..52c8afd --- /dev/null +++ b/FlowerShopDataModels/IComponentModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FlowerShopDataModels.Models +{ + public interface IComponentModel : IId + { + string ComponentName { get; } + double Cost { get; } + } +} diff --git a/FlowerShopDataModels/IFlowerModel.cs b/FlowerShopDataModels/IFlowerModel.cs new file mode 100644 index 0000000..e785287 --- /dev/null +++ b/FlowerShopDataModels/IFlowerModel.cs @@ -0,0 +1,16 @@ +using FlowerShopDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FlowerShopDataModels.Models +{ + public interface IFlowerModel : IId + { + string FlowerName { get; } + double Price { get; } + Dictionary FlowerComponents { get; } + } +} diff --git a/FlowerShopDataModels/IId.cs b/FlowerShopDataModels/IId.cs index a8a1916..3d893b7 100644 --- a/FlowerShopDataModels/IId.cs +++ b/FlowerShopDataModels/IId.cs @@ -6,7 +6,8 @@ using System.Threading.Tasks; namespace FlowerShopDataModels { - internal interface IId + public interface IId { + int Id { get; } } } diff --git a/FlowerShopDataModels/IOrderModel.cs b/FlowerShopDataModels/IOrderModel.cs new file mode 100644 index 0000000..486a29f --- /dev/null +++ b/FlowerShopDataModels/IOrderModel.cs @@ -0,0 +1,20 @@ +using FlowerShopDataModels.Enums; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FlowerShopDataModels +{ + public interface IOrderModel : IId + { + int ProductId { get; } + int Count { get; } + double Sum { get; } + OrderStatus Status { get; } + DateTime DateCreate { get; } + DateTime? DateImplement { get; } + } + +} diff --git a/FlowerShopListImplement/Component.cs b/FlowerShopListImplement/Component.cs new file mode 100644 index 0000000..7648aa5 --- /dev/null +++ b/FlowerShopListImplement/Component.cs @@ -0,0 +1,41 @@ +using FlowerShopContracts.BindingModels; +using FlowerShopContracts.ViewModels; +using FlowerShopDataModels.Models; + +namespace FlowerShopListImplement.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 + }; + } +} \ No newline at end of file diff --git a/FlowerShopListImplement/Flower.cs b/FlowerShopListImplement/Flower.cs new file mode 100644 index 0000000..7b95dc5 --- /dev/null +++ b/FlowerShopListImplement/Flower.cs @@ -0,0 +1,54 @@ +using FlowerShopDataModels.Models; +using FlowerShopContracts.BindingModels; +using FlowerShopContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FlowerShopListImplement.Models +{ + public class Flower : IFlowerModel + { + public int Id { get; private set; } + public string FlowerName { get; private set; } = string.Empty; + public double Price { get; private set; } + public Dictionary FlowerComponents + { + get; + private set; + } = new Dictionary(); + public static Flower? Create(FlowerBindingModel? model) + { + if (model == null) + { + return null; + } + return new Flower() + { + Id = model.Id, + FlowerName = model.FlowerName, + Price = model.Price, + FlowerComponents = model.FlowerComponents + }; + } + public void Update(FlowerBindingModel? model) + { + if (model == null) + { + return; + } + FlowerName = model.FlowerName; + Price = model.Price; + FlowerName = model.FlowerName; + } + public FlowerViewModel GetViewModel => new() + { + Id = Id, + FlowerName = FlowerName, + Price = Price, + FlowerComponents = FlowerComponents + }; + } +} diff --git a/FlowerShopListImplement/FlowerShopListImplement.csproj b/FlowerShopListImplement/FlowerShopListImplement.csproj new file mode 100644 index 0000000..ca6fa62 --- /dev/null +++ b/FlowerShopListImplement/FlowerShopListImplement.csproj @@ -0,0 +1,14 @@ + + + + net6.0 + enable + enable + + + + + + + + diff --git a/ProjectFlowerShop.sln b/ProjectFlowerShop.sln index ee95802..075c8e0 100644 --- a/ProjectFlowerShop.sln +++ b/ProjectFlowerShop.sln @@ -5,7 +5,13 @@ VisualStudioVersion = 17.7.34031.279 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ProjectFlowerShop", "ProjectFlowerShop\ProjectFlowerShop.csproj", "{AB184B22-49FC-45E0-A5C0-D68310452DF3}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FlowerShopDataModels", "FlowerShopDataModels\FlowerShopDataModels.csproj", "{9E7C9D26-3932-4020-893D-1757DB2048B6}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FlowerShopDataModels", "FlowerShopDataModels\FlowerShopDataModels.csproj", "{9E7C9D26-3932-4020-893D-1757DB2048B6}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FlowerShopContracts", "FlowerShopContracts\FlowerShopContracts.csproj", "{843D517F-A9AE-4AF9-90C5-DB3E11D576E7}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FlowerShopBusinessLogic", "FlowerShopBusinessLogic\FlowerShopBusinessLogic.csproj", "{EA8DFC63-7280-4160-8EF8-DDBAF3B64F31}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FlowerShopListImplement", "FlowerShopListImplement\FlowerShopListImplement.csproj", "{62DAA9A0-9A71-4117-8D06-8825E1678D9D}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -21,6 +27,18 @@ Global {9E7C9D26-3932-4020-893D-1757DB2048B6}.Debug|Any CPU.Build.0 = Debug|Any CPU {9E7C9D26-3932-4020-893D-1757DB2048B6}.Release|Any CPU.ActiveCfg = Release|Any CPU {9E7C9D26-3932-4020-893D-1757DB2048B6}.Release|Any CPU.Build.0 = Release|Any CPU + {843D517F-A9AE-4AF9-90C5-DB3E11D576E7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {843D517F-A9AE-4AF9-90C5-DB3E11D576E7}.Debug|Any CPU.Build.0 = Debug|Any CPU + {843D517F-A9AE-4AF9-90C5-DB3E11D576E7}.Release|Any CPU.ActiveCfg = Release|Any CPU + {843D517F-A9AE-4AF9-90C5-DB3E11D576E7}.Release|Any CPU.Build.0 = Release|Any CPU + {EA8DFC63-7280-4160-8EF8-DDBAF3B64F31}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {EA8DFC63-7280-4160-8EF8-DDBAF3B64F31}.Debug|Any CPU.Build.0 = Debug|Any CPU + {EA8DFC63-7280-4160-8EF8-DDBAF3B64F31}.Release|Any CPU.ActiveCfg = Release|Any CPU + {EA8DFC63-7280-4160-8EF8-DDBAF3B64F31}.Release|Any CPU.Build.0 = Release|Any CPU + {62DAA9A0-9A71-4117-8D06-8825E1678D9D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {62DAA9A0-9A71-4117-8D06-8825E1678D9D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {62DAA9A0-9A71-4117-8D06-8825E1678D9D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {62DAA9A0-9A71-4117-8D06-8825E1678D9D}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/ProjectFlowerShop/ProjectFlowerShop.csproj b/ProjectFlowerShop/ProjectFlowerShop.csproj index b57c89e..d47a4bd 100644 --- a/ProjectFlowerShop/ProjectFlowerShop.csproj +++ b/ProjectFlowerShop/ProjectFlowerShop.csproj @@ -8,4 +8,8 @@ enable + + + + \ No newline at end of file