Прописание бизнес-логики
This commit is contained in:
parent
44f046f7e0
commit
ca80eab8a6
@ -3,7 +3,15 @@ Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.8.34316.72
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Aparyan.ISE_22.MotorPlant", "Aparyan.ISE_22.MotorPlant.csproj", "{F1A04B81-A34D-4C40-BC03-FD0B410AF68E}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Aparyan.ISE_22.MotorPlant", "Aparyan.ISE_22.MotorPlant.csproj", "{F1A04B81-A34D-4C40-BC03-FD0B410AF68E}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MotorPlantDataModels", "..\MotorPlantDataModels\MotorPlantDataModels.csproj", "{1D2D7C4C-A127-4BCB-965C-E55D4BA1BBB4}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MotorPlantContracts", "..\MotorPlantContracts\MotorPlantContracts.csproj", "{2D2B3484-09AE-4DF5-A293-35A8BEDA6E1C}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MotorPlantListImplement", "..\MoorPlantListImplement\MotorPlantListImplement.csproj", "{F0D12A96-D511-4277-B576-6ED1F85F4A08}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MotorPlantBusinessLogic", "..\MotorPlantBusinessLogic\MotorPlantBusinessLogic.csproj", "{BE9E33C8-F7AD-4952-80B8-68FAE35E0BDC}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
@ -15,6 +23,22 @@ Global
|
||||
{F1A04B81-A34D-4C40-BC03-FD0B410AF68E}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{F1A04B81-A34D-4C40-BC03-FD0B410AF68E}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{F1A04B81-A34D-4C40-BC03-FD0B410AF68E}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{1D2D7C4C-A127-4BCB-965C-E55D4BA1BBB4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{1D2D7C4C-A127-4BCB-965C-E55D4BA1BBB4}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{1D2D7C4C-A127-4BCB-965C-E55D4BA1BBB4}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{1D2D7C4C-A127-4BCB-965C-E55D4BA1BBB4}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{2D2B3484-09AE-4DF5-A293-35A8BEDA6E1C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{2D2B3484-09AE-4DF5-A293-35A8BEDA6E1C}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{2D2B3484-09AE-4DF5-A293-35A8BEDA6E1C}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{2D2B3484-09AE-4DF5-A293-35A8BEDA6E1C}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{F0D12A96-D511-4277-B576-6ED1F85F4A08}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{F0D12A96-D511-4277-B576-6ED1F85F4A08}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{F0D12A96-D511-4277-B576-6ED1F85F4A08}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{F0D12A96-D511-4277-B576-6ED1F85F4A08}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{BE9E33C8-F7AD-4952-80B8-68FAE35E0BDC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{BE9E33C8-F7AD-4952-80B8-68FAE35E0BDC}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{BE9E33C8-F7AD-4952-80B8-68FAE35E0BDC}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{BE9E33C8-F7AD-4952-80B8-68FAE35E0BDC}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
27
MoorPlantListImplement/DataListSingleton.cs
Normal file
27
MoorPlantListImplement/DataListSingleton.cs
Normal file
@ -0,0 +1,27 @@
|
||||
using MotorPlantListImplement.Models;
|
||||
|
||||
namespace MotorPlantListImplement
|
||||
{
|
||||
public class DataListSingleton
|
||||
{
|
||||
private static DataListSingleton? _instance;
|
||||
public List<Component> Components { get; set; }
|
||||
public List<Order> Orders { get; set; }
|
||||
public List<Motor> Motor { get; set; }
|
||||
private DataListSingleton()
|
||||
{
|
||||
Components = new List<Component>();
|
||||
Orders = new List<Order>();
|
||||
Motor = new List<Motor>();
|
||||
}
|
||||
|
||||
public static DataListSingleton GetInstance()
|
||||
{
|
||||
if (_instance == null)
|
||||
{
|
||||
_instance = new DataListSingleton();
|
||||
}
|
||||
return _instance;
|
||||
}
|
||||
}
|
||||
}
|
110
MoorPlantListImplement/Implements/ComponentStorage.cs
Normal file
110
MoorPlantListImplement/Implements/ComponentStorage.cs
Normal file
@ -0,0 +1,110 @@
|
||||
using MotorPlantContracts.BindingModels;
|
||||
using MotorPlantContracts.SearchModels;
|
||||
using MotorPlantContracts.StoragesContracts;
|
||||
using MotorPlantContracts.VeiwModels;
|
||||
using MotorPlantListImplement.Models;
|
||||
using System.ComponentModel;
|
||||
|
||||
|
||||
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 = Models.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;
|
||||
}
|
||||
}
|
||||
}
|
109
MoorPlantListImplement/Implements/MotorStorage.cs
Normal file
109
MoorPlantListImplement/Implements/MotorStorage.cs
Normal file
@ -0,0 +1,109 @@
|
||||
using MotorPlantContracts.BindingModels;
|
||||
using MotorPlantContracts.SearchModels;
|
||||
using MotorPlantContracts.StoragesContracts;
|
||||
using MotorPlantContracts.VeiwModels;
|
||||
using MotorPlantListImplement.Models;
|
||||
|
||||
|
||||
namespace MotorPlantListImplement
|
||||
{
|
||||
public class Motortorage : IMotorStorage
|
||||
{
|
||||
private readonly DataListSingleton _source;
|
||||
|
||||
public Motortorage()
|
||||
{
|
||||
_source = DataListSingleton.GetInstance();
|
||||
}
|
||||
|
||||
public List<MotorViewModel> GetFullList()
|
||||
{
|
||||
var result = new List<MotorViewModel>();
|
||||
foreach (var Motor in _source.Motor)
|
||||
{
|
||||
result.Add(Motor.GetViewModel);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public List<MotorViewModel> GetFilteredList(MotorSearchModel model)
|
||||
{
|
||||
var result = new List<MotorViewModel>();
|
||||
if (string.IsNullOrEmpty(model.MotorName))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
foreach (var Motor in _source.Motor)
|
||||
{
|
||||
if (Motor.MotorName.Contains(model.MotorName))
|
||||
{
|
||||
result.Add(Motor.GetViewModel);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public MotorViewModel? GetElement(MotorSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.MotorName) && !model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
foreach (var Motor in _source.Motor)
|
||||
{
|
||||
if ((!string.IsNullOrEmpty(model.MotorName) && Motor.MotorName == model.MotorName) ||
|
||||
(model.Id.HasValue && Motor.Id == model.Id))
|
||||
{
|
||||
return Motor.GetViewModel;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public MotorViewModel? Insert(MotorBindingModel model)
|
||||
{
|
||||
model.Id = 1;
|
||||
foreach (var Motor in _source.Motor)
|
||||
{
|
||||
if (model.Id <= Motor.Id)
|
||||
{
|
||||
model.Id = Motor.Id + 1;
|
||||
}
|
||||
}
|
||||
var newMotor = Motor.Create(model);
|
||||
if (newMotor == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
_source.Motor.Add(newMotor);
|
||||
return newMotor.GetViewModel;
|
||||
}
|
||||
|
||||
public MotorViewModel? Update(MotorBindingModel model)
|
||||
{
|
||||
foreach (var Motor in _source.Motor)
|
||||
{
|
||||
if (Motor.Id == model.Id)
|
||||
{
|
||||
Motor.Update(model);
|
||||
return Motor.GetViewModel;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public MotorViewModel? Delete(MotorBindingModel model)
|
||||
{
|
||||
for (int i = 0; i < _source.Motor.Count; ++i)
|
||||
{
|
||||
if (_source.Motor[i].Id == model.Id)
|
||||
{
|
||||
var element = _source.Motor[i];
|
||||
_source.Motor.RemoveAt(i);
|
||||
return element.GetViewModel;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
121
MoorPlantListImplement/Implements/OrderStorage.cs
Normal file
121
MoorPlantListImplement/Implements/OrderStorage.cs
Normal file
@ -0,0 +1,121 @@
|
||||
using MotorPlantContracts.BindingModels;
|
||||
using MotorPlantContracts.SearchModels;
|
||||
using MotorPlantContracts.StoragesContracts;
|
||||
using MotorPlantContracts.VeiwModels;
|
||||
using MotorPlantListImplement.Models;
|
||||
|
||||
|
||||
namespace MotorPlantListImplement
|
||||
{
|
||||
public class OrderStorage : IOrderStorage
|
||||
{
|
||||
private readonly DataListSingleton _source;
|
||||
|
||||
public OrderStorage()
|
||||
{
|
||||
_source = DataListSingleton.GetInstance();
|
||||
}
|
||||
|
||||
public List<OrderViewModel> GetFullList()
|
||||
{
|
||||
var result = new List<OrderViewModel>();
|
||||
foreach (var order in _source.Orders)
|
||||
{
|
||||
result.Add(AttachMotorName(order.GetViewModel));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
|
||||
{
|
||||
var result = new List<OrderViewModel>();
|
||||
if (model == null || !model.Id.HasValue)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
foreach (var order in _source.Orders)
|
||||
{
|
||||
if (order.Id == model.Id)
|
||||
{
|
||||
result.Add(AttachMotorName(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 AttachMotorName(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 AttachMotorName(newOrder.GetViewModel);
|
||||
}
|
||||
|
||||
public OrderViewModel? Update(OrderBindingModel model)
|
||||
{
|
||||
foreach (var order in _source.Orders)
|
||||
{
|
||||
if (order.Id == model.Id)
|
||||
{
|
||||
order.Update(model);
|
||||
return AttachMotorName(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 AttachMotorName(element.GetViewModel);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private OrderViewModel AttachMotorName(OrderViewModel model)
|
||||
{
|
||||
foreach (var motor in _source.Motor)
|
||||
{
|
||||
if (motor.Id == model.MotorId)
|
||||
{
|
||||
model.MotorName = motor.MotorName;
|
||||
return model;
|
||||
}
|
||||
}
|
||||
return model;
|
||||
}
|
||||
}
|
||||
}
|
45
MoorPlantListImplement/Models/Component.cs
Normal file
45
MoorPlantListImplement/Models/Component.cs
Normal file
@ -0,0 +1,45 @@
|
||||
using MotorPlantContracts.BindingModels;
|
||||
using MotorPlantContracts.VeiwModels;
|
||||
using MotorPlantDataModels.Models;
|
||||
namespace MotorPlantListImplement.Models
|
||||
{
|
||||
public class Component : IComponentModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
public string ComponentName { get; 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
|
||||
};
|
||||
}
|
||||
}
|
51
MoorPlantListImplement/Models/Motor.cs
Normal file
51
MoorPlantListImplement/Models/Motor.cs
Normal file
@ -0,0 +1,51 @@
|
||||
using MotorPlantContracts.BindingModels;
|
||||
using MotorPlantContracts.VeiwModels;
|
||||
using MotorPlantDataModels.Models;
|
||||
|
||||
namespace MotorPlantListImplement.Models
|
||||
{
|
||||
public class Motor: IMotorModel
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
public string MotorName { get; private set; } = string.Empty;
|
||||
public double Price { get; private set; }
|
||||
public Dictionary<int, (IComponentModel, int)> MotorComponents { get; private set; } = new Dictionary<int, (IComponentModel, int)> { };
|
||||
|
||||
public static Motor? Create(MotorBindingModel? model)
|
||||
{
|
||||
if(model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Motor()
|
||||
{
|
||||
Id = model.Id,
|
||||
MotorName = model.MotorName,
|
||||
Price = model.Price,
|
||||
MotorComponents = model.MotorComponents
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(MotorBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
MotorName = model.MotorName;
|
||||
Price = model.Price;
|
||||
MotorComponents = model.MotorComponents;
|
||||
}
|
||||
|
||||
public MotorViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
MotorName = MotorName,
|
||||
Price = Price,
|
||||
MotorComponents = MotorComponents
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
63
MoorPlantListImplement/Models/Order.cs
Normal file
63
MoorPlantListImplement/Models/Order.cs
Normal file
@ -0,0 +1,63 @@
|
||||
using MotorPlantContracts.BindingModels;
|
||||
using MotorPlantContracts.VeiwModels;
|
||||
using MotorPlantDataModels.Enums;
|
||||
using MotorPlantDataModels.Models;
|
||||
|
||||
namespace MotorPlantListImplement.Models
|
||||
{
|
||||
public class Order : IOrderModel
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
|
||||
public int MotorId { 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,
|
||||
MotorId = model.MotorId,
|
||||
Count = model.Count,
|
||||
Sum = model.Sum,
|
||||
Status = model.Status,
|
||||
DateCreate = model.DateCreate,
|
||||
DateImplement = model.DateImplement,
|
||||
};
|
||||
}
|
||||
public void Update(OrderBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Status = model.Status;
|
||||
if (model.Status == OrderStatus.Выдан) DateImplement = model.DateImplement;
|
||||
}
|
||||
|
||||
public OrderViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
MotorId = MotorId,
|
||||
Count = Count,
|
||||
Sum = Sum,
|
||||
Status = Status,
|
||||
DateCreate = DateCreate,
|
||||
DateImplement = DateImplement,
|
||||
};
|
||||
}
|
||||
}
|
14
MoorPlantListImplement/MotorPlantListImplement.csproj
Normal file
14
MoorPlantListImplement/MotorPlantListImplement.csproj
Normal file
@ -0,0 +1,14 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\MotorPlantContracts\MotorPlantContracts.csproj" />
|
||||
<ProjectReference Include="..\MotorPlantDataModels\MotorPlantDataModels.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
114
MotorPlantBusinessLogic/BusinessLogics/ComponentLogic.cs
Normal file
114
MotorPlantBusinessLogic/BusinessLogics/ComponentLogic.cs
Normal file
@ -0,0 +1,114 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using MotorPlantContracts.BindingModels;
|
||||
using MotorPlantContracts.BusinessLogicsContracts;
|
||||
using MotorPlantContracts.SearchModels;
|
||||
using MotorPlantContracts.StoragesContracts;
|
||||
using MotorPlantContracts.VeiwModels;
|
||||
|
||||
namespace MotorPlantBusinessLogic.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("Ингредиент с таким названием уже есть");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
111
MotorPlantBusinessLogic/BusinessLogics/MotorLogic.cs
Normal file
111
MotorPlantBusinessLogic/BusinessLogics/MotorLogic.cs
Normal file
@ -0,0 +1,111 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using MotorPlantContracts.BindingModels;
|
||||
using MotorPlantContracts.BusinessLogicsContracts;
|
||||
using MotorPlantContracts.SearchModels;
|
||||
using MotorPlantContracts.StoragesContracts;
|
||||
using MotorPlantContracts.VeiwModels;
|
||||
|
||||
namespace MotorPlantBusinessLogic.BusinessLogics
|
||||
{
|
||||
public class MotorLogic : IMotorLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IMotorStorage _MotorStorage;
|
||||
public MotorLogic(ILogger<MotorLogic> logger, IMotorStorage MotorStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_MotorStorage = MotorStorage;
|
||||
}
|
||||
public List<MotorViewModel>? ReadList(MotorSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. MotorName:{MotorName}.Id:{ Id}", model?.MotorName, model?.Id);
|
||||
var list = model == null ? _MotorStorage.GetFullList() : _MotorStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList return null list");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||
return list;
|
||||
}
|
||||
public MotorViewModel? ReadElement(MotorSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
_logger.LogInformation("ReadElement. MotorName:{MotorName}.Id:{ Id}", model.MotorName, model.Id);
|
||||
var element = _MotorStorage.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(MotorBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_MotorStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public bool Update(MotorBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_MotorStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public bool Delete(MotorBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
_logger.LogInformation("Delete. Id:{Id}", model.Id);
|
||||
if (_MotorStorage.Delete(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Delete operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
private void CheckModel(MotorBindingModel model, bool withParams = true)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
if (!withParams)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.MotorName))
|
||||
{
|
||||
throw new ArgumentNullException("Нет названия мотора", nameof(model.MotorName));
|
||||
}
|
||||
if (model.Price <= 0)
|
||||
{
|
||||
throw new ArgumentNullException("Цена мотора должна быть больше 0", nameof(model.Price));
|
||||
}
|
||||
if (model.MotorComponents == null || model.MotorComponents.Count == 0)
|
||||
{
|
||||
throw new ArgumentNullException("Перечень деталей не может быть пустым", nameof(model.MotorComponents));
|
||||
}
|
||||
_logger.LogInformation("Motor. MotorName:{MotorName}.Price:{Price}.Id: { Id}", model.MotorName, model.Price, model.Id);
|
||||
var element = _MotorStorage.GetElement(new MotorSearchModel
|
||||
{
|
||||
MotorName = model.MotorName
|
||||
});
|
||||
if (element != null && element.Id != model.Id)
|
||||
{
|
||||
throw new InvalidOperationException("Мотор с таким названием уже есть");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
120
MotorPlantBusinessLogic/BusinessLogics/OrderLogic.cs
Normal file
120
MotorPlantBusinessLogic/BusinessLogics/OrderLogic.cs
Normal file
@ -0,0 +1,120 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using MotorPlantContracts.BindingModels;
|
||||
using MotorPlantContracts.BusinessLogicsContracts;
|
||||
using MotorPlantContracts.SearchModels;
|
||||
using MotorPlantContracts.StoragesContracts;
|
||||
using MotorPlantContracts.VeiwModels;
|
||||
using MotorPlantDataModels.Enums;
|
||||
|
||||
namespace MotorPlantBusinessLogic.BusinessLogics
|
||||
{
|
||||
public class OrderLogic : IOrderLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IOrderStorage _orderStorage;
|
||||
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_orderStorage = orderStorage;
|
||||
}
|
||||
public List<OrderViewModel>? ReadList(OrderSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. 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;
|
||||
}
|
||||
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 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.Count <= 0)
|
||||
{
|
||||
throw new ArgumentException("Колличество моторов в заказе не может быть меньше 1", nameof(model.Count));
|
||||
}
|
||||
if (model.Sum <= 0)
|
||||
{
|
||||
throw new ArgumentException("Стоимость заказа на может быть меньше 1", nameof(model.Sum));
|
||||
}
|
||||
if (model.DateImplement.HasValue && model.DateImplement < model.DateCreate)
|
||||
{
|
||||
throw new ArithmeticException($"Дата выдачи заказа {model.DateImplement} не может быть раньше даты его создания {model.DateCreate}");
|
||||
}
|
||||
_logger.LogInformation("Motor. MotorId:{MotorId}.Count:{Count}.Sum:{Sum}Id:{Id}",
|
||||
model.MotorId, model.Count, model.Sum, model.Id);
|
||||
}
|
||||
|
||||
private bool ChangeStatus(OrderBindingModel model, OrderStatus requiredStatus)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
var element = _orderStorage.GetElement(new OrderSearchModel()
|
||||
{
|
||||
Id = model.Id
|
||||
});
|
||||
if (element == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(element));
|
||||
}
|
||||
model.DateCreate = element.DateCreate;
|
||||
model.MotorId = element.MotorId;
|
||||
model.DateImplement = element.DateImplement;
|
||||
model.Status = element.Status;
|
||||
model.Count = element.Count;
|
||||
model.Sum = element.Sum;
|
||||
if (requiredStatus - model.Status == 1)
|
||||
{
|
||||
model.Status = requiredStatus;
|
||||
if (model.Status == OrderStatus.Выдан)
|
||||
model.DateImplement = DateTime.Now;
|
||||
if (_orderStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
_logger.LogWarning("Changing status operation faled: Current-{Status}:required-{requiredStatus}.", model.Status, requiredStatus);
|
||||
throw new ArgumentException($"Невозможно присвоить статус {requiredStatus} заказу с текущим статусом {model.Status}");
|
||||
}
|
||||
}
|
||||
}
|
17
MotorPlantBusinessLogic/MotorPlantBusinessLogic.csproj
Normal file
17
MotorPlantBusinessLogic/MotorPlantBusinessLogic.csproj
Normal file
@ -0,0 +1,17 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\MotorPlantContracts\MotorPlantContracts.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
12
MotorPlantContracts/BindingModels/ComponentBindingModel.cs
Normal file
12
MotorPlantContracts/BindingModels/ComponentBindingModel.cs
Normal file
@ -0,0 +1,12 @@
|
||||
using MotorPlantDataModels.Models;
|
||||
|
||||
namespace MotorPlantContracts.BindingModels
|
||||
{
|
||||
public class ComponentBindingModel : IComponentModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string ComponentName { get; set; } = string.Empty;
|
||||
public double Cost { get; set; }
|
||||
|
||||
}
|
||||
}
|
16
MotorPlantContracts/BindingModels/MotorBindingModel.cs
Normal file
16
MotorPlantContracts/BindingModels/MotorBindingModel.cs
Normal file
@ -0,0 +1,16 @@
|
||||
using MotorPlantDataModels.Models;
|
||||
|
||||
namespace MotorPlantContracts.BindingModels
|
||||
{
|
||||
public class MotorBindingModel : IMotorModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string MotorName { get; set; } = string.Empty;
|
||||
public double Price { get; set; }
|
||||
public Dictionary<int, (IComponentModel, int)> MotorComponents { get; set; } = new();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
16
MotorPlantContracts/BindingModels/OrderBindingModel.cs
Normal file
16
MotorPlantContracts/BindingModels/OrderBindingModel.cs
Normal file
@ -0,0 +1,16 @@
|
||||
using MotorPlantDataModels.Enums;
|
||||
using MotorPlantDataModels.Models;
|
||||
|
||||
namespace MotorPlantContracts.BindingModels
|
||||
{
|
||||
public class OrderBindingModel: IOrderModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public int MotorId { 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; }
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
using MotorPlantContracts.BindingModels;
|
||||
using MotorPlantContracts.SearchModels;
|
||||
using MotorPlantContracts.VeiwModels;
|
||||
namespace MotorPlantContracts.BusinessLogicsContracts
|
||||
{
|
||||
public interface IComponentLogic
|
||||
{
|
||||
List<ComponentViewModel>? ReadList(ComponentSearchModel? model);
|
||||
|
||||
ComponentViewModel? ReadElement(ComponentSearchModel model);
|
||||
bool Create(ComponentBindingModel model);
|
||||
bool Update(ComponentBindingModel model);
|
||||
bool Delete(ComponentBindingModel model);
|
||||
}
|
||||
}
|
16
MotorPlantContracts/BusinessLogicsContracts/IMotorLogic.cs
Normal file
16
MotorPlantContracts/BusinessLogicsContracts/IMotorLogic.cs
Normal file
@ -0,0 +1,16 @@
|
||||
using MotorPlantContracts.BindingModels;
|
||||
using MotorPlantContracts.SearchModels;
|
||||
using MotorPlantContracts.VeiwModels;
|
||||
|
||||
namespace MotorPlantContracts.BusinessLogicsContracts
|
||||
{
|
||||
public interface IMotorLogic
|
||||
{
|
||||
List<MotorViewModel>? ReadList(MotorSearchModel? model);
|
||||
|
||||
MotorViewModel? ReadElement(MotorSearchModel model);
|
||||
bool Create(MotorBindingModel model);
|
||||
bool Update(MotorBindingModel model);
|
||||
bool Delete(MotorBindingModel model);
|
||||
}
|
||||
}
|
16
MotorPlantContracts/BusinessLogicsContracts/IOrderLogic.cs
Normal file
16
MotorPlantContracts/BusinessLogicsContracts/IOrderLogic.cs
Normal file
@ -0,0 +1,16 @@
|
||||
using MotorPlantContracts.BindingModels;
|
||||
using MotorPlantContracts.SearchModels;
|
||||
using MotorPlantContracts.VeiwModels;
|
||||
|
||||
namespace MotorPlantContracts.BusinessLogicsContracts
|
||||
{
|
||||
public interface IOrderLogic
|
||||
{
|
||||
List<OrderViewModel>? ReadList(OrderSearchModel? model);
|
||||
bool CreateOrder(OrderBindingModel model);
|
||||
bool TakeOrderInWork(OrderBindingModel model);
|
||||
bool FinishOrder(OrderBindingModel model);
|
||||
bool DeliveryOrder(OrderBindingModel model);
|
||||
|
||||
}
|
||||
}
|
7
MotorPlantContracts/Class1.cs
Normal file
7
MotorPlantContracts/Class1.cs
Normal file
@ -0,0 +1,7 @@
|
||||
namespace MotorPlantContracts
|
||||
{
|
||||
public class Class1
|
||||
{
|
||||
|
||||
}
|
||||
}
|
13
MotorPlantContracts/MotorPlantContracts.csproj
Normal file
13
MotorPlantContracts/MotorPlantContracts.csproj
Normal file
@ -0,0 +1,13 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\MotorPlantDataModels\MotorPlantDataModels.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
8
MotorPlantContracts/SearchModels/ComponentSearchModel.cs
Normal file
8
MotorPlantContracts/SearchModels/ComponentSearchModel.cs
Normal file
@ -0,0 +1,8 @@
|
||||
namespace MotorPlantContracts.SearchModels
|
||||
{
|
||||
public class ComponentSearchModel
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
public string? ComponentName { get; set; }
|
||||
}
|
||||
}
|
14
MotorPlantContracts/SearchModels/MotorSearchModel.cs
Normal file
14
MotorPlantContracts/SearchModels/MotorSearchModel.cs
Normal file
@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MotorPlantContracts.SearchModels
|
||||
{
|
||||
public class MotorSearchModel
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
public string? MotorName { get; set; }
|
||||
}
|
||||
}
|
7
MotorPlantContracts/SearchModels/OrderSearchModel.cs
Normal file
7
MotorPlantContracts/SearchModels/OrderSearchModel.cs
Normal file
@ -0,0 +1,7 @@
|
||||
namespace MotorPlantContracts.SearchModels
|
||||
{
|
||||
public class OrderSearchModel
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
}
|
||||
}
|
16
MotorPlantContracts/StoragesContracts/IComponentStorage.cs
Normal file
16
MotorPlantContracts/StoragesContracts/IComponentStorage.cs
Normal file
@ -0,0 +1,16 @@
|
||||
using MotorPlantContracts.BindingModels;
|
||||
using MotorPlantContracts.SearchModels;
|
||||
using MotorPlantContracts.VeiwModels;
|
||||
|
||||
namespace MotorPlantContracts.StoragesContracts
|
||||
{
|
||||
public interface IComponentStorage
|
||||
{
|
||||
List<ComponentViewModel> GetFullList();
|
||||
List<ComponentViewModel> GetFilteredList(ComponentSearchModel model);
|
||||
ComponentViewModel? GetElement(ComponentSearchModel model);
|
||||
ComponentViewModel? Insert(ComponentBindingModel model);
|
||||
ComponentViewModel? Update(ComponentBindingModel model);
|
||||
ComponentViewModel? Delete(ComponentBindingModel model);
|
||||
}
|
||||
}
|
16
MotorPlantContracts/StoragesContracts/IMotorStorage.cs
Normal file
16
MotorPlantContracts/StoragesContracts/IMotorStorage.cs
Normal file
@ -0,0 +1,16 @@
|
||||
using MotorPlantContracts.BindingModels;
|
||||
using MotorPlantContracts.SearchModels;
|
||||
using MotorPlantContracts.VeiwModels;
|
||||
|
||||
namespace MotorPlantContracts.StoragesContracts
|
||||
{
|
||||
public interface IMotorStorage
|
||||
{
|
||||
List<MotorViewModel> GetFullList();
|
||||
List<MotorViewModel> GetFilteredList(MotorSearchModel model);
|
||||
MotorViewModel? GetElement(MotorSearchModel model);
|
||||
MotorViewModel? Insert(MotorBindingModel model);
|
||||
MotorViewModel? Update(MotorBindingModel model);
|
||||
MotorViewModel? Delete(MotorBindingModel model);
|
||||
}
|
||||
}
|
17
MotorPlantContracts/StoragesContracts/IOrderStorage.cs
Normal file
17
MotorPlantContracts/StoragesContracts/IOrderStorage.cs
Normal file
@ -0,0 +1,17 @@
|
||||
using MotorPlantContracts.BindingModels;
|
||||
using MotorPlantContracts.SearchModels;
|
||||
using MotorPlantContracts.VeiwModels;
|
||||
|
||||
|
||||
namespace MotorPlantContracts.StoragesContracts
|
||||
{
|
||||
public interface IOrderStorage
|
||||
{
|
||||
List<OrderViewModel> GetFullList();
|
||||
List<OrderViewModel> GetFilteredList(OrderSearchModel model);
|
||||
OrderViewModel? GetElement(OrderSearchModel model);
|
||||
OrderViewModel? Insert(OrderBindingModel model);
|
||||
OrderViewModel? Update(OrderBindingModel model);
|
||||
OrderViewModel? Delete(OrderBindingModel model);
|
||||
}
|
||||
}
|
14
MotorPlantContracts/ViewModels/ComponentViewModel.cs
Normal file
14
MotorPlantContracts/ViewModels/ComponentViewModel.cs
Normal file
@ -0,0 +1,14 @@
|
||||
using MotorPlantDataModels.Models;
|
||||
using System.ComponentModel;
|
||||
namespace MotorPlantContracts.VeiwModels
|
||||
{
|
||||
public class ComponentViewModel: IComponentModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[DisplayName("Название компонента")]
|
||||
public string ComponentName { get; set; } = string.Empty;
|
||||
|
||||
[DisplayName("Цена")]
|
||||
public double Cost { get; set; }
|
||||
}
|
||||
}
|
17
MotorPlantContracts/ViewModels/MotorViewModel.cs
Normal file
17
MotorPlantContracts/ViewModels/MotorViewModel.cs
Normal file
@ -0,0 +1,17 @@
|
||||
using MotorPlantDataModels.Models;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace MotorPlantContracts.VeiwModels
|
||||
{
|
||||
public class MotorViewModel : IMotorModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[DisplayName("Название мотора")]
|
||||
public string MotorName { get; set; } = string.Empty;
|
||||
|
||||
[DisplayName("Цена")]
|
||||
public double Price { get; set; }
|
||||
public Dictionary<int, (IComponentModel, int)> MotorComponents { get; set; } = new();
|
||||
|
||||
}
|
||||
}
|
33
MotorPlantContracts/ViewModels/OrderViewModel.cs
Normal file
33
MotorPlantContracts/ViewModels/OrderViewModel.cs
Normal file
@ -0,0 +1,33 @@
|
||||
using MotorPlantDataModels.Enums;
|
||||
using MotorPlantDataModels.Models;
|
||||
using System.ComponentModel;
|
||||
namespace MotorPlantContracts.VeiwModels
|
||||
{
|
||||
public class OrderViewModel : IOrderModel
|
||||
{
|
||||
[DisplayName("Номер")]
|
||||
public int Id { get; set; }
|
||||
|
||||
public int MotorId { get; set; }
|
||||
|
||||
[DisplayName("Мотор")]
|
||||
public string MotorName { 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; }
|
||||
}
|
||||
}
|
||||
|
||||
|
21
MotorPlantDataModels/Enums/OrderStatus.cs
Normal file
21
MotorPlantDataModels/Enums/OrderStatus.cs
Normal file
@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MotorPlantDataModels.Enums
|
||||
{
|
||||
public enum OrderStatus
|
||||
{
|
||||
Неизвестен = -1,
|
||||
|
||||
Принят = 0,
|
||||
|
||||
Выполняется = 1,
|
||||
|
||||
Готов = 2,
|
||||
|
||||
Выдан = 3
|
||||
}
|
||||
}
|
7
MotorPlantDataModels/IId.cs
Normal file
7
MotorPlantDataModels/IId.cs
Normal file
@ -0,0 +1,7 @@
|
||||
namespace MotorPlantDataModels
|
||||
{
|
||||
public interface IId
|
||||
{
|
||||
int Id { get; }
|
||||
}
|
||||
}
|
8
MotorPlantDataModels/Models/IComponentModel.cs
Normal file
8
MotorPlantDataModels/Models/IComponentModel.cs
Normal file
@ -0,0 +1,8 @@
|
||||
namespace MotorPlantDataModels.Models
|
||||
{
|
||||
public interface IComponentModel : IId
|
||||
{
|
||||
string ComponentName { get; }
|
||||
double Cost { get; }
|
||||
}
|
||||
}
|
9
MotorPlantDataModels/Models/IMotorModel.cs
Normal file
9
MotorPlantDataModels/Models/IMotorModel.cs
Normal file
@ -0,0 +1,9 @@
|
||||
namespace MotorPlantDataModels.Models
|
||||
{
|
||||
public interface IMotorModel : IId
|
||||
{
|
||||
string MotorName { get; }
|
||||
double Price { get; }
|
||||
Dictionary <int , (IComponentModel, int)> MotorComponents { get; }
|
||||
}
|
||||
}
|
13
MotorPlantDataModels/Models/IOrderModel.cs
Normal file
13
MotorPlantDataModels/Models/IOrderModel.cs
Normal file
@ -0,0 +1,13 @@
|
||||
using MotorPlantDataModels.Enums;
|
||||
namespace MotorPlantDataModels.Models
|
||||
{
|
||||
public interface IOrderModel : IId
|
||||
{
|
||||
int MotorId { get; }
|
||||
int Count { get; }
|
||||
double Sum { get; }
|
||||
OrderStatus Status { get; }
|
||||
DateTime DateCreate { get; }
|
||||
DateTime? DateImplement { get; }
|
||||
}
|
||||
}
|
9
MotorPlantDataModels/MotorPlantDataModels.csproj
Normal file
9
MotorPlantDataModels/MotorPlantDataModels.csproj
Normal file
@ -0,0 +1,9 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
Loading…
x
Reference in New Issue
Block a user