diff --git a/PlumbingRepair/PlumbingRepair.sln b/PlumbingRepair/PlumbingRepair.sln index 15ecd93..d074019 100644 --- a/PlumbingRepair/PlumbingRepair.sln +++ b/PlumbingRepair/PlumbingRepair.sln @@ -7,6 +7,12 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PlumbingRepair", "PlumbingR EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PlumbingRepairDataModels", "PlumbingRepairDataModels\PlumbingRepairDataModels.csproj", "{90DD7D7A-91FD-403D-8D3A-FE8842AA5848}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PlumbingRepairContracts", "PlumbingRepairContracts\PlumbingRepairContracts.csproj", "{5200A7ED-CC3F-4602-984D-1B56A43A50D2}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PlumbingRepairBusinessLogic", "PlumbingRepairBusinessLogic\PlumbingRepairBusinessLogic.csproj", "{3C711D99-7E84-4B26-8312-7C10A360BD54}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PlumbingRepairListImplement", "PlumbingRepairListImplement\PlumbingRepairListImplement.csproj", "{9B17B17E-1201-4B23-ACCD-EF7F4495E4B7}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -21,6 +27,18 @@ Global {90DD7D7A-91FD-403D-8D3A-FE8842AA5848}.Debug|Any CPU.Build.0 = Debug|Any CPU {90DD7D7A-91FD-403D-8D3A-FE8842AA5848}.Release|Any CPU.ActiveCfg = Release|Any CPU {90DD7D7A-91FD-403D-8D3A-FE8842AA5848}.Release|Any CPU.Build.0 = Release|Any CPU + {5200A7ED-CC3F-4602-984D-1B56A43A50D2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {5200A7ED-CC3F-4602-984D-1B56A43A50D2}.Debug|Any CPU.Build.0 = Debug|Any CPU + {5200A7ED-CC3F-4602-984D-1B56A43A50D2}.Release|Any CPU.ActiveCfg = Release|Any CPU + {5200A7ED-CC3F-4602-984D-1B56A43A50D2}.Release|Any CPU.Build.0 = Release|Any CPU + {3C711D99-7E84-4B26-8312-7C10A360BD54}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {3C711D99-7E84-4B26-8312-7C10A360BD54}.Debug|Any CPU.Build.0 = Debug|Any CPU + {3C711D99-7E84-4B26-8312-7C10A360BD54}.Release|Any CPU.ActiveCfg = Release|Any CPU + {3C711D99-7E84-4B26-8312-7C10A360BD54}.Release|Any CPU.Build.0 = Release|Any CPU + {9B17B17E-1201-4B23-ACCD-EF7F4495E4B7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9B17B17E-1201-4B23-ACCD-EF7F4495E4B7}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9B17B17E-1201-4B23-ACCD-EF7F4495E4B7}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9B17B17E-1201-4B23-ACCD-EF7F4495E4B7}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/PlumbingRepair/PlumbingRepairBusinessLogic/BusinessLogic/ComponentLogic.cs b/PlumbingRepair/PlumbingRepairBusinessLogic/BusinessLogic/ComponentLogic.cs new file mode 100644 index 0000000..b2a9101 --- /dev/null +++ b/PlumbingRepair/PlumbingRepairBusinessLogic/BusinessLogic/ComponentLogic.cs @@ -0,0 +1,137 @@ +using PlumbingRepairContracts.BindingModels; +using PlumbingRepairContracts.BusinessLogicsContracts; +using PlumbingRepairContracts.SearchModels; +using PlumbingRepairContracts.StoragesContracts; +using PlumbingRepairContracts.ViewModels; +using Microsoft.Extensions.Logging; + +namespace PlumbingRepairBusinessLogic.BusinessLogic +{ + public class ComponentLogic : IComponentLogic + { + private readonly ILogger _logger; + + private readonly IComponentStorage _componentStorage; + + public ComponentLogic(ILogger logger, IComponentStorage componentStorage) + { + _logger = logger; + _componentStorage = componentStorage; + } + + public bool Create(ComponentBindingModel model) + { + CheckModel(model); + + if (_componentStorage.Insert(model) == null) + { + _logger.LogWarning("Insert 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; + } + + 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 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 bool Update(ComponentBindingModel model) + { + CheckModel(model); + + if (_componentStorage.Update(model) == null) + { + _logger.LogWarning("Update 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/PlumbingRepair/PlumbingRepairBusinessLogic/BusinessLogic/OrderLogic.cs b/PlumbingRepair/PlumbingRepairBusinessLogic/BusinessLogic/OrderLogic.cs new file mode 100644 index 0000000..990c5a9 --- /dev/null +++ b/PlumbingRepair/PlumbingRepairBusinessLogic/BusinessLogic/OrderLogic.cs @@ -0,0 +1,130 @@ +using PlumbingRepairContracts.BindingModels; +using PlumbingRepairContracts.BusinessLogicsContracts; +using PlumbingRepairContracts.SearchModels; +using PlumbingRepairContracts.StoragesContracts; +using PlumbingRepairContracts.ViewModels; +using Microsoft.Extensions.Logging; +using PlumbingRepairDataModels.Enums; + +namespace PlumbingRepairBusinessLogic.BusinessLogic +{ + public class OrderLogic + { + 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 (model.Status != OrderStatus.Неизвестен) + { + _logger.LogWarning("Insert operation failed. Order status incorrect."); + return false; + } + + model.Status = OrderStatus.Принят; + + if (_orderStorage.Insert(model) == null) + { + model.Status = OrderStatus.Неизвестен; + _logger.LogWarning("Insert operation failed"); + return false; + } + + return true; + } + + public bool StatusUpdate(OrderBindingModel model, OrderStatus newStatus) + { + CheckModel(model); + + if (model.Status + 1 != newStatus) + { + _logger.LogWarning("Status update to " + newStatus.ToString() + " operation failed. Order status incorrect."); + return false; + } + + model.Status = newStatus; + + if (model.Status == OrderStatus.Выдан) + model.DateImplement = DateTime.Now; + + if (_orderStorage.Update(model) == null) + { + model.Status--; + _logger.LogWarning("Update operation failed"); + return false; + } + + return true; + } + + public bool TakeOrderInWork(OrderBindingModel model) + { + return StatusUpdate(model, OrderStatus.Выполняется); + } + + public bool DeliveryOrder(OrderBindingModel model) + { + return StatusUpdate(model, OrderStatus.Готов); + } + + public bool FinishOrder(OrderBindingModel model) + { + return StatusUpdate(model, OrderStatus.Выдан); + } + + public List? ReadList(OrderSearchModel? model) + { + _logger.LogInformation("Order. OrderId:{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; + } + + private void CheckModel(OrderBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + if (!withParams) + { + return; + } + + if (model.WorkId < 0) + { + throw new ArgumentNullException("Некорректный идентификатор изделия", nameof(model.WorkId)); + } + + if (model.Count <= 0) + { + throw new ArgumentNullException("Количество изделий в заказе должно быть больше 0", nameof(model.Count)); + } + + if (model.Sum <= 0) + { + throw new ArgumentNullException("Сумма заказа должна быть больше 0", nameof(model.Sum)); + } + + _logger.LogInformation("Order. OrderId:{Id}.Sum:{ Sum}. WorkId: { WorkId}", model.Id, model.Sum, model.WorkId); + } + } +} diff --git a/PlumbingRepair/PlumbingRepairBusinessLogic/BusinessLogic/WorkLogic.cs b/PlumbingRepair/PlumbingRepairBusinessLogic/BusinessLogic/WorkLogic.cs new file mode 100644 index 0000000..5b68c25 --- /dev/null +++ b/PlumbingRepair/PlumbingRepairBusinessLogic/BusinessLogic/WorkLogic.cs @@ -0,0 +1,137 @@ +using PlumbingRepairContracts.BindingModels; +using PlumbingRepairContracts.BusinessLogicsContracts; +using PlumbingRepairContracts.SearchModels; +using PlumbingRepairContracts.StoragesContracts; +using PlumbingRepairContracts.ViewModels; +using Microsoft.Extensions.Logging; + +namespace PlumbingRepairBusinessLogic.BusinessLogic +{ + public class WorkLogic : IWorkLogic + { + private readonly ILogger _logger; + + private readonly IWorkStorage _workStorage; + + public WorkLogic(ILogger logger, IWorkStorage workStorage) + { + _logger = logger; + _workStorage = workStorage; + } + + public bool Create(WorkBindingModel model) + { + CheckModel(model); + + if (_workStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + + return true; + } + + public bool Delete(WorkBindingModel model) + { + CheckModel(model, false); + + _logger.LogInformation("Delete. Id:{Id}", model.Id); + + if (_workStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + + return true; + } + + public WorkViewModel? ReadElement(WorkSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + _logger.LogInformation("ReadElement. WorkName:{WorkName}.Id:{ Id}", model.WorkName, model.Id); + + var element = _workStorage.GetElement(model); + + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + + return element; + } + + public List? ReadList(WorkSearchModel? model) + { + _logger.LogInformation("ReadList. WorkName:{WorkName}.Id:{ Id}", model?.WorkName, model?.Id); + + var list = model == null ? _workStorage.GetFullList() : _workStorage.GetFilteredList(model); + + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + + return list; + } + + public bool Update(WorkBindingModel model) + { + CheckModel(model); + + if (_workStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + + return true; + } + + private void CheckModel(WorkBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + if (!withParams) + { + return; + } + + if (string.IsNullOrEmpty(model.WorkName)) + { + throw new ArgumentNullException("Нет названия изделия", nameof(model.WorkName)); + } + + if (model.Price <= 0) + { + throw new ArgumentNullException("Цена изделия должна быть больше 0", nameof(model.Price)); + } + + _logger.LogInformation("Work. WorkName:{WorkName}.Price:{ Cost}. Id: { Id}", model.WorkName, model.Price, model.Id); + + var element = _workStorage.GetElement(new WorkSearchModel + { + WorkName = model.WorkName + }); + + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Изделие с таким названием уже есть"); + } + } + } +} diff --git a/PlumbingRepair/PlumbingRepairBusinessLogic/PlumbingRepairBusinessLogic.csproj b/PlumbingRepair/PlumbingRepairBusinessLogic/PlumbingRepairBusinessLogic.csproj new file mode 100644 index 0000000..9cf9a9a --- /dev/null +++ b/PlumbingRepair/PlumbingRepairBusinessLogic/PlumbingRepairBusinessLogic.csproj @@ -0,0 +1,17 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + diff --git a/PlumbingRepair/PlumbingRepairContracts/BindingModels/ComponentBindingModel.cs b/PlumbingRepair/PlumbingRepairContracts/BindingModels/ComponentBindingModel.cs new file mode 100644 index 0000000..8415b86 --- /dev/null +++ b/PlumbingRepair/PlumbingRepairContracts/BindingModels/ComponentBindingModel.cs @@ -0,0 +1,11 @@ +using PlumbingRepairDataModels.Models; + +namespace PlumbingRepairContracts.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/PlumbingRepair/PlumbingRepairContracts/BindingModels/OrderBindingModel.cs b/PlumbingRepair/PlumbingRepairContracts/BindingModels/OrderBindingModel.cs new file mode 100644 index 0000000..1a1ca0e --- /dev/null +++ b/PlumbingRepair/PlumbingRepairContracts/BindingModels/OrderBindingModel.cs @@ -0,0 +1,17 @@ +using PlumbingRepairDataModels.Enums; +using PlumbingRepairDataModels.Models; + +namespace PlumbingRepairContracts.BindingModels +{ + public class OrderBindingModel : IOrderModel + { + public int Id { get; set; } + public int WorkId { 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; } + public string WorkName { get; set; } = string.Empty; + } +} diff --git a/PlumbingRepair/PlumbingRepairContracts/BindingModels/WorkBindingModel.cs b/PlumbingRepair/PlumbingRepairContracts/BindingModels/WorkBindingModel.cs new file mode 100644 index 0000000..d1defcc --- /dev/null +++ b/PlumbingRepair/PlumbingRepairContracts/BindingModels/WorkBindingModel.cs @@ -0,0 +1,12 @@ +using PlumbingRepairDataModels.Models; + +namespace PlumbingRepairContracts.BindingModels +{ + public class WorkBindingModel : IWorkModel + { + public int Id { get; set; } + public string WorkName { get; set; } = string.Empty; + public double Price { get; set; } + public Dictionary WorkComponents { get; set; } = new(); + } +} diff --git a/PlumbingRepair/PlumbingRepairContracts/BusinessLogicsContracts/IComponentLogic.cs b/PlumbingRepair/PlumbingRepairContracts/BusinessLogicsContracts/IComponentLogic.cs new file mode 100644 index 0000000..11f855a --- /dev/null +++ b/PlumbingRepair/PlumbingRepairContracts/BusinessLogicsContracts/IComponentLogic.cs @@ -0,0 +1,15 @@ +using PlumbingRepairContracts.BindingModels; +using PlumbingRepairContracts.SearchModels; +using PlumbingRepairContracts.ViewModels; + +namespace PlumbingRepairContracts.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/PlumbingRepair/PlumbingRepairContracts/BusinessLogicsContracts/IOrderLogic.cs b/PlumbingRepair/PlumbingRepairContracts/BusinessLogicsContracts/IOrderLogic.cs new file mode 100644 index 0000000..f694d80 --- /dev/null +++ b/PlumbingRepair/PlumbingRepairContracts/BusinessLogicsContracts/IOrderLogic.cs @@ -0,0 +1,15 @@ +using PlumbingRepairContracts.BindingModels; +using PlumbingRepairContracts.SearchModels; +using PlumbingRepairContracts.ViewModels; + +namespace PlumbingRepairContracts.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/PlumbingRepair/PlumbingRepairContracts/BusinessLogicsContracts/IWorkLogic.cs b/PlumbingRepair/PlumbingRepairContracts/BusinessLogicsContracts/IWorkLogic.cs new file mode 100644 index 0000000..63405c3 --- /dev/null +++ b/PlumbingRepair/PlumbingRepairContracts/BusinessLogicsContracts/IWorkLogic.cs @@ -0,0 +1,15 @@ +using PlumbingRepairContracts.BindingModels; +using PlumbingRepairContracts.SearchModels; +using PlumbingRepairContracts.ViewModels; + +namespace PlumbingRepairContracts.BusinessLogicsContracts +{ + public interface IWorkLogic + { + List? ReadList(WorkSearchModel? model); + WorkViewModel? ReadElement(WorkSearchModel model); + bool Create(WorkBindingModel model); + bool Update(WorkBindingModel model); + bool Delete(WorkBindingModel model); + } +} diff --git a/PlumbingRepair/PlumbingRepairContracts/PlumbingRepairContracts.csproj b/PlumbingRepair/PlumbingRepairContracts/PlumbingRepairContracts.csproj new file mode 100644 index 0000000..5c96a30 --- /dev/null +++ b/PlumbingRepair/PlumbingRepairContracts/PlumbingRepairContracts.csproj @@ -0,0 +1,13 @@ + + + + net6.0 + enable + enable + + + + + + + diff --git a/PlumbingRepair/PlumbingRepairContracts/SearchModels/ComponentSearchModel.cs b/PlumbingRepair/PlumbingRepairContracts/SearchModels/ComponentSearchModel.cs new file mode 100644 index 0000000..011b3c6 --- /dev/null +++ b/PlumbingRepair/PlumbingRepairContracts/SearchModels/ComponentSearchModel.cs @@ -0,0 +1,8 @@ +namespace PlumbingRepairContracts.SearchModels +{ + public class ComponentSearchModel + { + public int? Id { get; set; } + public string? ComponentName { get; set; } + } +} diff --git a/PlumbingRepair/PlumbingRepairContracts/SearchModels/OrderSearchModel.cs b/PlumbingRepair/PlumbingRepairContracts/SearchModels/OrderSearchModel.cs new file mode 100644 index 0000000..77ad642 --- /dev/null +++ b/PlumbingRepair/PlumbingRepairContracts/SearchModels/OrderSearchModel.cs @@ -0,0 +1,7 @@ +namespace PlumbingRepairContracts.SearchModels +{ + public class OrderSearchModel + { + public int? Id { get; set; } + } +} diff --git a/PlumbingRepair/PlumbingRepairContracts/SearchModels/WorkSearchModel.cs b/PlumbingRepair/PlumbingRepairContracts/SearchModels/WorkSearchModel.cs new file mode 100644 index 0000000..34c40d5 --- /dev/null +++ b/PlumbingRepair/PlumbingRepairContracts/SearchModels/WorkSearchModel.cs @@ -0,0 +1,8 @@ +namespace PlumbingRepairContracts.SearchModels +{ + public class WorkSearchModel + { + public int? Id { get; set; } + public string? WorkName { get; set; } + } +} diff --git a/PlumbingRepair/PlumbingRepairContracts/StoragesContracts/IComponentStorage.cs b/PlumbingRepair/PlumbingRepairContracts/StoragesContracts/IComponentStorage.cs new file mode 100644 index 0000000..aabbc71 --- /dev/null +++ b/PlumbingRepair/PlumbingRepairContracts/StoragesContracts/IComponentStorage.cs @@ -0,0 +1,16 @@ +using PlumbingRepairContracts.BindingModels; +using PlumbingRepairContracts.SearchModels; +using PlumbingRepairContracts.ViewModels; + +namespace PlumbingRepairContracts.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/PlumbingRepair/PlumbingRepairContracts/StoragesContracts/IOrderStorage.cs b/PlumbingRepair/PlumbingRepairContracts/StoragesContracts/IOrderStorage.cs new file mode 100644 index 0000000..17a7c96 --- /dev/null +++ b/PlumbingRepair/PlumbingRepairContracts/StoragesContracts/IOrderStorage.cs @@ -0,0 +1,16 @@ +using PlumbingRepairContracts.BindingModels; +using PlumbingRepairContracts.SearchModels; +using PlumbingRepairContracts.ViewModels; + +namespace PlumbingRepairContracts.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/PlumbingRepair/PlumbingRepairContracts/StoragesContracts/IWorkStorage.cs b/PlumbingRepair/PlumbingRepairContracts/StoragesContracts/IWorkStorage.cs new file mode 100644 index 0000000..4ef73d3 --- /dev/null +++ b/PlumbingRepair/PlumbingRepairContracts/StoragesContracts/IWorkStorage.cs @@ -0,0 +1,16 @@ +using PlumbingRepairContracts.BindingModels; +using PlumbingRepairContracts.SearchModels; +using PlumbingRepairContracts.ViewModels; + +namespace PlumbingRepairContracts.StoragesContracts +{ + public interface IWorkStorage + { + List GetFullList(); + List GetFilteredList(WorkSearchModel model); + WorkViewModel? GetElement(WorkSearchModel model); + WorkViewModel? Insert(WorkBindingModel model); + WorkViewModel? Update(WorkBindingModel model); + WorkViewModel? Delete(WorkBindingModel model); + } +} diff --git a/PlumbingRepair/PlumbingRepairContracts/ViewModels/ComponentViewModel.cs b/PlumbingRepair/PlumbingRepairContracts/ViewModels/ComponentViewModel.cs new file mode 100644 index 0000000..611d741 --- /dev/null +++ b/PlumbingRepair/PlumbingRepairContracts/ViewModels/ComponentViewModel.cs @@ -0,0 +1,14 @@ +using PlumbingRepairDataModels.Models; +using System.ComponentModel; + +namespace PlumbingRepairContracts.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/PlumbingRepair/PlumbingRepairContracts/ViewModels/OrderViewModel.cs b/PlumbingRepair/PlumbingRepairContracts/ViewModels/OrderViewModel.cs new file mode 100644 index 0000000..801613c --- /dev/null +++ b/PlumbingRepair/PlumbingRepairContracts/ViewModels/OrderViewModel.cs @@ -0,0 +1,25 @@ +using PlumbingRepairDataModels.Enums; +using PlumbingRepairDataModels.Models; +using System.ComponentModel; + +namespace PlumbingRepairContracts.ViewModels +{ + public class OrderViewModel : IOrderModel + { + [DisplayName("Номер")] + public int Id { get; set; } + public int WorkId { get; set; } + [DisplayName("Название изделия")] + public string WorkName { 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/PlumbingRepair/PlumbingRepairContracts/ViewModels/WorkViewModel.cs b/PlumbingRepair/PlumbingRepairContracts/ViewModels/WorkViewModel.cs new file mode 100644 index 0000000..10404e2 --- /dev/null +++ b/PlumbingRepair/PlumbingRepairContracts/ViewModels/WorkViewModel.cs @@ -0,0 +1,15 @@ +using PlumbingRepairDataModels.Models; +using System.ComponentModel; + +namespace PlumbingRepairContracts.ViewModels +{ + public class WorkViewModel : IWorkModel + { + public int Id { get; set; } + [DisplayName("Название изделия")] + public string WorkName { get; set; } = string.Empty; + [DisplayName("Цена")] + public double Price { get; set; } + public Dictionary WorkComponents { get; set; } = new(); + } +} diff --git a/PlumbingRepair/PlumbingRepairListImplement/DataListSingleton.cs b/PlumbingRepair/PlumbingRepairListImplement/DataListSingleton.cs new file mode 100644 index 0000000..2a6b2e0 --- /dev/null +++ b/PlumbingRepair/PlumbingRepairListImplement/DataListSingleton.cs @@ -0,0 +1,28 @@ +using PlumbingRepairListImplement.Models; + +namespace PlumbingRepairListImplement +{ + public class DataListSingleton + { + private static DataListSingleton? _instance; + public List Components { get; set; } + public List Orders { get; set; } + public List Works { get; set; } + + private DataListSingleton() + { + Components = new List(); + Orders = new List(); + Works = new List(); + } + + public static DataListSingleton GetInstance() + { + if (_instance == null) + { + _instance = new DataListSingleton(); + } + return _instance; + } + } +} diff --git a/PlumbingRepair/PlumbingRepairListImplement/Implements/ComponentStorage.cs b/PlumbingRepair/PlumbingRepairListImplement/Implements/ComponentStorage.cs new file mode 100644 index 0000000..5d9aac4 --- /dev/null +++ b/PlumbingRepair/PlumbingRepairListImplement/Implements/ComponentStorage.cs @@ -0,0 +1,118 @@ +using PlumbingRepairContracts.StoragesContracts; +using PlumbingRepairContracts.BindingModels; +using PlumbingRepairContracts.SearchModels; +using PlumbingRepairContracts.ViewModels; +using PlumbingRepairListImplement.Models; + +namespace PlumbingRepairListImplement.Implements +{ + public class ComponentStorage : IComponentStorage + { + private readonly DataListSingleton _source; + public ComponentStorage() + { + _source = DataListSingleton.GetInstance(); + } + public List GetFullList() + { + var result = new List(); + + foreach (var component in _source.Components) + { + result.Add(component.GetViewModel); + } + + return result; + } + + public List GetFilteredList(ComponentSearchModel model) + { + var result = new List(); + + if (string.IsNullOrEmpty(model.ComponentName)) + { + return result; + } + + foreach (var component in _source.Components) + { + if (component.ComponentName.Contains(model.ComponentName)) + { + result.Add(component.GetViewModel); + } + } + + return result; + } + + public ComponentViewModel? GetElement(ComponentSearchModel model) + { + if (string.IsNullOrEmpty(model.ComponentName) && !model.Id.HasValue) + { + return null; + } + + foreach (var component in _source.Components) + { + if ((!string.IsNullOrEmpty(model.ComponentName) && component.ComponentName == model.ComponentName) || (model.Id.HasValue && component.Id == model.Id)) + { + return component.GetViewModel; + } + } + + return null; + } + + public ComponentViewModel? Insert(ComponentBindingModel model) + { + model.Id = 1; + + foreach (var component in _source.Components) + { + if (model.Id <= component.Id) + { + model.Id = component.Id + 1; + } + } + + var newComponent = Component.Create(model); + + if (newComponent == null) + { + return null; + } + + _source.Components.Add(newComponent); + + return newComponent.GetViewModel; + } + + public ComponentViewModel? Update(ComponentBindingModel model) + { + foreach (var component in _source.Components) + { + if (component.Id == model.Id) + { + component.Update(model); + return component.GetViewModel; + } + } + + return null; + } + public ComponentViewModel? Delete(ComponentBindingModel model) + { + for (int i = 0; i < _source.Components.Count; ++i) + { + if (_source.Components[i].Id == model.Id) + { + var element = _source.Components[i]; + _source.Components.RemoveAt(i); + return element.GetViewModel; + } + } + + return null; + } + } +} diff --git a/PlumbingRepair/PlumbingRepairListImplement/Implements/OrderStorage.cs b/PlumbingRepair/PlumbingRepairListImplement/Implements/OrderStorage.cs new file mode 100644 index 0000000..5ab9980 --- /dev/null +++ b/PlumbingRepair/PlumbingRepairListImplement/Implements/OrderStorage.cs @@ -0,0 +1,119 @@ +using PlumbingRepairContracts.StoragesContracts; +using PlumbingRepairContracts.BindingModels; +using PlumbingRepairContracts.SearchModels; +using PlumbingRepairContracts.ViewModels; +using PlumbingRepairListImplement.Models; + +namespace PlumbingRepairListImplement.Implements +{ + public class OrderStorage : IOrderStorage + { + private readonly DataListSingleton _source; + public OrderStorage() + { + _source = DataListSingleton.GetInstance(); + } + + public List GetFullList() + { + var result = new List(); + + foreach (var order in _source.Orders) + { + result.Add(order.GetViewModel); + } + + return result; + } + + public List GetFilteredList(OrderSearchModel model) + { + var result = new List(); + + if (!model.Id.HasValue) + { + return result; + } + + foreach (var order in _source.Orders) + { + if (model.Id.HasValue && order.Id == model.Id) + { + result.Add(order.GetViewModel); + } + } + + return result; + } + + public OrderViewModel? GetElement(OrderSearchModel model) + { + if (!model.Id.HasValue) + { + return null; + } + + foreach (var order in _source.Orders) + { + if (model.Id.HasValue && order.Id == model.Id) + { + return order.GetViewModel; + } + } + + return null; + } + + public OrderViewModel? Insert(OrderBindingModel model) + { + model.Id = 1; + + foreach (var order in _source.Orders) + { + if (model.Id <= order.Id) + { + model.Id = order.Id + 1; + } + } + + var newOrder = Order.Create(model); + + if (newOrder == null) + { + return null; + } + + _source.Orders.Add(newOrder); + + return newOrder.GetViewModel; + } + + public OrderViewModel? Update(OrderBindingModel model) + { + foreach (var order in _source.Orders) + { + if (order.Id == model.Id) + { + order.Update(model); + return order.GetViewModel; + } + } + + return null; + } + public OrderViewModel? Delete(OrderBindingModel model) + { + for (int i = 0; i < _source.Orders.Count; ++i) + { + if (_source.Orders[i].Id == model.Id) + { + var element = _source.Orders[i]; + _source.Orders.RemoveAt(i); + return element.GetViewModel; + } + } + + return null; + } + } +} diff --git a/PlumbingRepair/PlumbingRepairListImplement/Implements/WorkStorage.cs b/PlumbingRepair/PlumbingRepairListImplement/Implements/WorkStorage.cs new file mode 100644 index 0000000..e4774c6 --- /dev/null +++ b/PlumbingRepair/PlumbingRepairListImplement/Implements/WorkStorage.cs @@ -0,0 +1,121 @@ +using PlumbingRepairContracts.StoragesContracts; +using PlumbingRepairContracts.BindingModels; +using PlumbingRepairContracts.SearchModels; +using PlumbingRepairContracts.ViewModels; +using PlumbingRepairListImplement.Models; + +namespace PlumbingRepairListImplement.Implements +{ + public class WorkStorage : IWorkStorage + { + private readonly DataListSingleton _source; + + public WorkStorage() + { + _source = DataListSingleton.GetInstance(); + } + + public List GetFullList() + { + var result = new List(); + + foreach (var work in _source.Works) + { + result.Add(work.GetViewModel); + } + + return result; + } + + public List GetFilteredList(WorkSearchModel model) + { + var result = new List(); + + if (string.IsNullOrEmpty(model.WorkName)) + { + return result; + } + + foreach (var work in _source.Works) + { + if (work.WorkName.Contains(model.WorkName)) + { + result.Add(work.GetViewModel); + } + } + + return result; + } + + public WorkViewModel? GetElement(WorkSearchModel model) + { + if (string.IsNullOrEmpty(model.WorkName) && !model.Id.HasValue) + { + return null; + } + + foreach (var work in _source.Works) + { + if ((!string.IsNullOrEmpty(model.WorkName) && work.WorkName == model.WorkName) || (model.Id.HasValue && work.Id == model.Id)) + { + return work.GetViewModel; + } + } + + return null; + } + + public WorkViewModel? Insert(WorkBindingModel model) + { + model.Id = 1; + + foreach (var work in _source.Works) + { + if (model.Id <= work.Id) + { + model.Id = work.Id + 1; + } + } + + var newWork = Work.Create(model); + + if (newWork == null) + { + return null; + } + + _source.Works.Add(newWork); + + return newWork.GetViewModel; + } + + public WorkViewModel? Update(WorkBindingModel model) + { + foreach (var work in _source.Works) + { + if (work.Id == model.Id) + { + work.Update(model); + return work.GetViewModel; + } + } + + return null; + } + + public WorkViewModel? Delete(WorkBindingModel model) + { + for (int i = 0; i < _source.Works.Count; ++i) + { + if (_source.Works[i].Id == model.Id) + { + var element = _source.Works[i]; + _source.Works.RemoveAt(i); + return element.GetViewModel; + } + } + + return null; + } + } +} diff --git a/PlumbingRepair/PlumbingRepairListImplement/Models/Component.cs b/PlumbingRepair/PlumbingRepairListImplement/Models/Component.cs new file mode 100644 index 0000000..380ee30 --- /dev/null +++ b/PlumbingRepair/PlumbingRepairListImplement/Models/Component.cs @@ -0,0 +1,44 @@ +using PlumbingRepairContracts.BindingModels; +using PlumbingRepairContracts.ViewModels; +using PlumbingRepairDataModels.Models; + +namespace PlumbingRepairListImplement.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/PlumbingRepair/PlumbingRepairListImplement/Models/Order.cs b/PlumbingRepair/PlumbingRepairListImplement/Models/Order.cs new file mode 100644 index 0000000..ef3854f --- /dev/null +++ b/PlumbingRepair/PlumbingRepairListImplement/Models/Order.cs @@ -0,0 +1,65 @@ +using PlumbingRepairContracts.BindingModels; +using PlumbingRepairContracts.ViewModels; +using PlumbingRepairDataModels.Enums; +using PlumbingRepairDataModels.Models; + +namespace PlumbingRepairListImplement.Models +{ + public class Order : IOrderModel + { + public int Id { get; private set; } + public int WorkId { get; private set; } + public string WorkName { get; private set; } + public int Count { get; private set; } + public double Sum { get; private set; } + public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; + public DateTime DateCreate { get; private set; } = DateTime.Now; + public DateTime? DateImplement { get; private set; } + + public static Order? Create(OrderBindingModel? model) + { + if (model == null) + { + return null; + } + return new Order() + { + Id = model.Id, + WorkId = model.WorkId, + WorkName = model.WorkName, + Count = model.Count, + Sum = model.Sum, + Status = model.Status, + DateCreate = model.DateCreate, + DateImplement = model.DateImplement + }; + } + + public void Update(OrderBindingModel? model) + { + if (model == null) + { + return; + } + WorkId = model.WorkId; + WorkName = model.WorkName; + Count = model.Count; + Sum = model.Sum; + Status = model.Status; + DateCreate = model.DateCreate; + DateImplement = model.DateImplement; + } + + public OrderViewModel GetViewModel => new() + { + Id = Id, + WorkId = WorkId, + WorkName = WorkName, + Count = Count, + Sum = Sum, + Status = Status, + DateCreate = DateCreate, + DateImplement = DateImplement + }; + } +} diff --git a/PlumbingRepair/PlumbingRepairListImplement/Models/Work.cs b/PlumbingRepair/PlumbingRepairListImplement/Models/Work.cs new file mode 100644 index 0000000..c4bf767 --- /dev/null +++ b/PlumbingRepair/PlumbingRepairListImplement/Models/Work.cs @@ -0,0 +1,48 @@ +using PlumbingRepairContracts.BindingModels; +using PlumbingRepairContracts.ViewModels; +using PlumbingRepairDataModels.Models; + +namespace PlumbingRepairListImplement.Models +{ + public class Work : IWorkModel + { + public int Id { get; private set; } + public string WorkName { get; private set; } = string.Empty; + public double Price { get; private set; } + public Dictionary WorkComponents { get; private set; } = new Dictionary(); + + public static Work? Create(WorkBindingModel? model) + { + if (model == null) + { + return null; + } + return new Work() + { + Id = model.Id, + WorkName = model.WorkName, + Price = model.Price, + WorkComponents = model.WorkComponents + }; + } + + public void Update(WorkBindingModel? model) + { + if (model == null) + { + return; + } + WorkName = model.WorkName; + Price = model.Price; + WorkComponents = model.WorkComponents; + } + + public WorkViewModel GetViewModel => new() + { + Id = Id, + WorkName = WorkName, + Price = Price, + WorkComponents = WorkComponents + }; + } +} diff --git a/PlumbingRepair/PlumbingRepairListImplement/PlumbingRepairListImplement.csproj b/PlumbingRepair/PlumbingRepairListImplement/PlumbingRepairListImplement.csproj new file mode 100644 index 0000000..05f8377 --- /dev/null +++ b/PlumbingRepair/PlumbingRepairListImplement/PlumbingRepairListImplement.csproj @@ -0,0 +1,14 @@ + + + + net6.0 + enable + enable + + + + + + + +