Add: MotorPlantBusinessLogics and MotorPlantListImplement

Rename: Product to Engine
This commit is contained in:
Efi 2024-02-14 17:20:07 +04:00
parent 85d51a0493
commit 58d7425a2e
23 changed files with 640 additions and 50 deletions

View File

@ -8,9 +8,10 @@ EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MotorPlantDataModels", "MotorPlantDataModels\MotorPlantDataModels.csproj", "{BF6606D4-C24E-4CC6-BA24-E505AB2BCC6B}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MotorPlantDataModels", "MotorPlantDataModels\MotorPlantDataModels.csproj", "{BF6606D4-C24E-4CC6-BA24-E505AB2BCC6B}"
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MotorPlantContracts", "MotorPlantContracts\MotorPlantContracts.csproj", "{29205916-9BE6-4349-9131-79573670D7DB}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MotorPlantContracts", "MotorPlantContracts\MotorPlantContracts.csproj", "{29205916-9BE6-4349-9131-79573670D7DB}"
ProjectSection(ProjectDependencies) = postProject EndProject
{BF6606D4-C24E-4CC6-BA24-E505AB2BCC6B} = {BF6606D4-C24E-4CC6-BA24-E505AB2BCC6B} Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MotorPlantBusinessLogics", "MotorPlantBusinessLogics\MotorPlantBusinessLogics.csproj", "{438B62AC-624E-4457-844C-9C4C257DD223}"
EndProjectSection EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MotorPlantListImplement", "MotorPlantListImplement\MotorPlantListImplement.csproj", "{BC88368B-CBE2-420A-BD30-164216769F80}"
EndProject EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -30,6 +31,14 @@ Global
{29205916-9BE6-4349-9131-79573670D7DB}.Debug|Any CPU.Build.0 = Debug|Any CPU {29205916-9BE6-4349-9131-79573670D7DB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{29205916-9BE6-4349-9131-79573670D7DB}.Release|Any CPU.ActiveCfg = Release|Any CPU {29205916-9BE6-4349-9131-79573670D7DB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{29205916-9BE6-4349-9131-79573670D7DB}.Release|Any CPU.Build.0 = Release|Any CPU {29205916-9BE6-4349-9131-79573670D7DB}.Release|Any CPU.Build.0 = Release|Any CPU
{438B62AC-624E-4457-844C-9C4C257DD223}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{438B62AC-624E-4457-844C-9C4C257DD223}.Debug|Any CPU.Build.0 = Debug|Any CPU
{438B62AC-624E-4457-844C-9C4C257DD223}.Release|Any CPU.ActiveCfg = Release|Any CPU
{438B62AC-624E-4457-844C-9C4C257DD223}.Release|Any CPU.Build.0 = Release|Any CPU
{BC88368B-CBE2-420A-BD30-164216769F80}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BC88368B-CBE2-420A-BD30-164216769F80}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BC88368B-CBE2-420A-BD30-164216769F80}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BC88368B-CBE2-420A-BD30-164216769F80}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE

View File

@ -0,0 +1,120 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MotorPlantContracts.BindingModels;
using MotorPlantContracts.BusinessLogicsContracts;
using MotorPlantContracts.SearchModels;
using MotorPlantContracts.ViewModels;
using MotorPlantContracts.StoragesContracts;
using Microsoft.Extensions.Logging;
namespace MotorPlantBusinessLogics.BusinessLogics
{
public class ComponentLogic : IComponentLogic
{
private readonly ILogger _logger;
private readonly IComponentStorage _componentStorage;
public ComponentLogic(ILogger<ComponentLogic> logger, IComponentStorage componentStorage)
{
_logger = logger;
_componentStorage = componentStorage;
}
public List<ComponentViewModel>? 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("Компонент с таким названием уже есть");
}
}
}
}

View File

@ -0,0 +1,40 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MotorPlantContracts.BindingModels;
using MotorPlantContracts.BusinessLogicsContracts;
using MotorPlantContracts.SearchModels;
using MotorPlantContracts.ViewModels;
namespace MotorPlantBusinessLogics.BusinessLogics
{
public class EngineLogic : IEngineLogic
{
public bool Create(EngineBindingModel model)
{
throw new NotImplementedException();
}
public bool Delete(EngineBindingModel model)
{
throw new NotImplementedException();
}
public EngineViewModel? ReadElement(EngineSearchModel model)
{
throw new NotImplementedException();
}
public List<EngineViewModel>? ReadList(EngineSearchModel? model)
{
throw new NotImplementedException();
}
public bool Update(EngineBindingModel model)
{
throw new NotImplementedException();
}
}
}

View File

@ -0,0 +1,40 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MotorPlantContracts.BindingModels;
using MotorPlantContracts.BusinessLogicsContracts;
using MotorPlantContracts.SearchModels;
using MotorPlantContracts.ViewModels;
namespace MotorPlantBusinessLogics.BusinessLogics
{
public class OrderLogic : IOrderLogic
{
public bool CreateOrder(OrderBindingModel model)
{
throw new NotImplementedException();
}
public bool DeliveryOrder(OrderBindingModel model)
{
throw new NotImplementedException();
}
public bool FinishOrder(OrderBindingModel model)
{
throw new NotImplementedException();
}
public List<OrderViewModel>? ReadList(OrderSearchModel? model)
{
throw new NotImplementedException();
}
public bool TakeOrderInWork(OrderBindingModel model)
{
throw new NotImplementedException();
}
}
}

View File

@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\MotorPlantContracts\MotorPlantContracts.csproj" />
</ItemGroup>
</Project>

View File

@ -7,14 +7,14 @@ using MotorPlantDataModels.Models;
namespace MotorPlantContracts.BindingModels namespace MotorPlantContracts.BindingModels
{ {
public class ProductBindingModel : IProductModel public class EngineBindingModel : IEngineModel
{ {
public int Id { get; set; } public int Id { get; set; }
public string ProductName { get; set; } = string.Empty; public string EngineName { get; set; } = string.Empty;
public double Price { get; set; } public double Price { get; set; }
public Dictionary<int, (IComponentModel, int)> ProductComponents { get; set; } = new(); public Dictionary<int, (IComponentModel, int)> EngineComponents { get; set; } = new();
} }
} }

View File

@ -12,7 +12,7 @@ namespace MotorPlantContracts.BindingModels
{ {
public int Id { get; set; } public int Id { get; set; }
public int ProductId { get; set; } public int EngineId { get; set; }
public int Count { get; set; } public int Count { get; set; }

View File

@ -9,16 +9,16 @@ using MotorPlantContracts.ViewModels;
namespace MotorPlantContracts.BusinessLogicsContracts namespace MotorPlantContracts.BusinessLogicsContracts
{ {
public interface IProductLogic public interface IEngineLogic
{ {
List<ProductViewModel>? ReadList(ProductSearchModel? model); List<EngineViewModel>? ReadList(EngineSearchModel? model);
ProductViewModel? ReadElement(ProductSearchModel model); EngineViewModel? ReadElement(EngineSearchModel model);
bool Create(ProductBindingModel model); bool Create(EngineBindingModel model);
bool Update(ProductBindingModel model); bool Update(EngineBindingModel model);
bool Delete(ProductBindingModel model); bool Delete(EngineBindingModel model);
} }
} }

View File

@ -6,4 +6,8 @@
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\MotorPlantDataModels\MotorPlantDataModels.csproj" />
</ItemGroup>
</Project> </Project>

View File

@ -6,10 +6,10 @@ using System.Threading.Tasks;
namespace MotorPlantContracts.SearchModels namespace MotorPlantContracts.SearchModels
{ {
public class ProductSearchModel public class EngineSearchModel
{ {
public int? Id { get; set; } public int? Id { get; set; }
public string? ProductName { get; set; } public string? EngineName { get; set; }
} }
} }

View File

@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MotorPlantContracts.BindingModels;
using MotorPlantContracts.SearchModels;
using MotorPlantContracts.ViewModels;
namespace MotorPlantContracts.StoragesContracts
{
public interface IEngineStorage
{
List<EngineViewModel> GetFullList();
List<EngineViewModel> GetFilteredList(EngineSearchModel model);
EngineViewModel? GetElement(EngineSearchModel model);
EngineViewModel? Insert(EngineBindingModel model);
EngineViewModel? Update(EngineBindingModel model);
EngineViewModel? Delete(EngineBindingModel model);
}
}

View File

@ -1,26 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MotorPlantContracts.BindingModels;
using MotorPlantContracts.SearchModels;
using MotorPlantContracts.ViewModels;
namespace MotorPlantContracts.StoragesContracts
{
public interface IProductStorage
{
List<ProductViewModel> GetFullList();
List<ProductViewModel> GetFilteredList(ProductSearchModel model);
ProductViewModel? GetElement(ProductSearchModel model);
ProductViewModel? Insert(ProductBindingModel model);
ProductViewModel? Update(ProductBindingModel model);
ProductViewModel? Delete(ProductBindingModel model);
}
}

View File

@ -8,16 +8,16 @@ using System.ComponentModel;
namespace MotorPlantContracts.ViewModels namespace MotorPlantContracts.ViewModels
{ {
public class ProductViewModel : IProductModel public class EngineViewModel : IEngineModel
{ {
public int Id { get; set; } public int Id { get; set; }
[DisplayName("Название изделия")] [DisplayName("Название изделия")]
public string ProductName { get; set; } = string.Empty; public string EngineName { get; set; } = string.Empty;
[DisplayName("Цена")] [DisplayName("Цена")]
public double Price { get; set; } public double Price { get; set; }
public Dictionary<int, (IComponentModel, int)> ProductComponents { get; set; } = new(); public Dictionary<int, (IComponentModel, int)> EngineComponents { get; set; } = new();
} }
} }

View File

@ -14,10 +14,10 @@ namespace MotorPlantContracts.ViewModels
[DisplayName("Номер")] [DisplayName("Номер")]
public int Id { get; set; } public int Id { get; set; }
public int ProductId { get; set; } public int EngineId { get; set; }
[DisplayName("Изделие")] [DisplayName("Изделие")]
public string ProductName { get; set; } = string.Empty; public string EngineName { get; set; } = string.Empty;
[DisplayName("Количество")] [DisplayName("Количество")]
public int Count { get; set; } public int Count { get; set; }

View File

@ -6,13 +6,13 @@ using System.Threading.Tasks;
namespace MotorPlantDataModels.Models namespace MotorPlantDataModels.Models
{ {
public interface IProductModel : IId public interface IEngineModel : IId
{ {
string ProductName { get; } string EngineName { get; }
double Price { get; } double Price { get; }
Dictionary<int, (IComponentModel, int)> ProductComponents { get; } Dictionary<int, (IComponentModel, int)> EngineComponents { get; }
} }
} }

View File

@ -9,7 +9,7 @@ namespace MotorPlantDataModels.Models
{ {
public interface IOrderModel : IId public interface IOrderModel : IId
{ {
int ProductId { get; } int EngineId { get; }
int Count { get; } int Count { get; }

View File

@ -0,0 +1,114 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MotorPlantContracts.BindingModels;
using MotorPlantContracts.BusinessLogicsContracts;
using MotorPlantContracts.SearchModels;
using MotorPlantContracts.ViewModels;
using MotorPlantListImplement.Models;
namespace MotorPlantListImplement.Implements
{
public class ComponentStorage : IComponentStorage
{
private readonly DataListSingleton _source;
public ComponentStorage()
{
_source = DataListSingleton.GetInstance();
}
public List<ComponentViewModel> GetFullList()
{
var result = new List<ComponentViewModel>();
foreach (var component in _source.Components)
{
result.Add(component.GetViewModel);
}
return result;
}
public List<ComponentViewModel> GetFilteredList(ComponentSearchModel model)
{
var result = new List<ComponentViewModel>();
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;
}
}
}

View File

@ -0,0 +1,40 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MotorPlantContracts.BindingModels;
using MotorPlantContracts.BusinessLogicsContracts;
using MotorPlantContracts.SearchModels;
using MotorPlantContracts.ViewModels;
namespace MotorPlantListImplement.Implements
{
public class EngineLogic : IEngineLogic
{
public bool Create(EngineBindingModel model)
{
throw new NotImplementedException();
}
public bool Delete(EngineBindingModel model)
{
throw new NotImplementedException();
}
public EngineViewModel? ReadElement(EngineSearchModel model)
{
throw new NotImplementedException();
}
public List<EngineViewModel>? ReadList(EngineSearchModel? model)
{
throw new NotImplementedException();
}
public bool Update(EngineBindingModel model)
{
throw new NotImplementedException();
}
}
}

View File

@ -0,0 +1,45 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MotorPlantContracts.BindingModels;
using MotorPlantContracts.BusinessLogicsContracts;
using MotorPlantContracts.SearchModels;
using MotorPlantContracts.ViewModels;
namespace MotorPlantListImplement.Implements
{
public class OrderStorage : IOrderStorage
{
public OrderViewModel? Delete(OrderBindingModel model)
{
throw new NotImplementedException();
}
public OrderViewModel? GetElement(OrderSearchModel model)
{
throw new NotImplementedException();
}
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
{
throw new NotImplementedException();
}
public List<OrderViewModel> GetFullList()
{
throw new NotImplementedException();
}
public OrderViewModel? Insert(OrderBindingModel model)
{
throw new NotImplementedException();
}
public OrderViewModel? Update(OrderBindingModel model)
{
throw new NotImplementedException();
}
}
}

View File

@ -0,0 +1,51 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MotorPlantContracts.BindingModels;
using AMotorPlantContracts.ViewModels;
using MotorPlantDataModels.Models;
namespace MotorPlantListImplement.Models
{
internal 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
};
}
}

View File

@ -0,0 +1,57 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MotorPlantContracts.BindingModels;
using MotorPlantContracts.ViewModels;
using MotorPlantDataModels.Models;
namespace MotorPlantListImplement.Models
{
internal class Engine : IEngineModel
{
public int Id { get; private set; }
public string EngineName { get; private set; } = string.Empty;
public double Price { get; private set; }
public Dictionary<int, (IComponentModel, int)> EngineComponents { get; private set; } = new Dictionary<int, (IComponentModel, int)>();
public static Engine? Create(EngineBindingModel? model)
{
if (model == null)
{
return null;
}
return new Engine()
{
Id = model.Id,
EngineName = model.EngineName,
Price = model.Price,
EngineComponents = model.EngineComponents
};
}
public void Update(EngineBindingModel? model)
{
if (model == null)
{
return;
}
EngineName = model.EngineName;
Price = model.Price;
EngineComponents = model.EngineComponents;
}
public EngineViewModel GetViewModel => new()
{
Id = Id,
EngineName = EngineName,
Price = Price,
EngineComponents = EngineComponents
};
}
}

View File

@ -0,0 +1,43 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MotorPlantContracts.BindingModels;
using AMotorPlantContracts.ViewModels;
using MotorPlantDataModels.Models;
using MotorPlantDataModels.Enums;
namespace MotorPlantListImplement.Models
{
internal class Order : IOrderModel
{
public int ProductId => throw new NotImplementedException();
public int Count => throw new NotImplementedException();
public double Sum => throw new NotImplementedException();
public OrderStatus Status => throw new NotImplementedException();
public DateTime DateCreate => throw new NotImplementedException();
public DateTime? DateImplement => throw new NotImplementedException();
public int Id => throw new NotImplementedException();
public static Order? Create(OrderBindingModel? model)
{
return new Order();
}
public void Update(OrderBindingModel? model)
{
}
public OrderViewModel GetViewModel => new()
{
};
}
}

View File

@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\MotorPlantContracts\MotorPlantContracts.csproj" />
<ProjectReference Include="..\MotorPlantDataModels\MotorPlantDataModels.csproj" />
</ItemGroup>
</Project>