Реализованы все библиотеки классов для лаб. работы 1

This commit is contained in:
Никита Потапов 2024-02-25 22:08:12 +04:00
parent 385252ecd2
commit 53192ffd12
9 changed files with 528 additions and 0 deletions

View File

@ -11,6 +11,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SecuritySystemContracts", "
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SecuritySystemBusinessLogic", "SecuritySystemBusinessLogic\SecuritySystemBusinessLogic.csproj", "{38C8A0AB-9363-4914-B967-02586827588D}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SecuritySystemBusinessLogic", "SecuritySystemBusinessLogic\SecuritySystemBusinessLogic.csproj", "{38C8A0AB-9363-4914-B967-02586827588D}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SecuritySystemListImplement", "SecuritySystemListImplement\SecuritySystemListImplement.csproj", "{6A104362-3398-4D4E-A3D0-2F4B32858569}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU
@ -33,6 +35,10 @@ Global
{38C8A0AB-9363-4914-B967-02586827588D}.Debug|Any CPU.Build.0 = Debug|Any CPU {38C8A0AB-9363-4914-B967-02586827588D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{38C8A0AB-9363-4914-B967-02586827588D}.Release|Any CPU.ActiveCfg = Release|Any CPU {38C8A0AB-9363-4914-B967-02586827588D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{38C8A0AB-9363-4914-B967-02586827588D}.Release|Any CPU.Build.0 = Release|Any CPU {38C8A0AB-9363-4914-B967-02586827588D}.Release|Any CPU.Build.0 = Release|Any CPU
{6A104362-3398-4D4E-A3D0-2F4B32858569}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6A104362-3398-4D4E-A3D0-2F4B32858569}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6A104362-3398-4D4E-A3D0-2F4B32858569}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6A104362-3398-4D4E-A3D0-2F4B32858569}.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,28 @@
using SecuritySystemListImplement.Models;
namespace SecuritySystemListImplement
{
public class DataListSingleton
{
private static DataListSingleton? _instance;
public List<Component> Components { get; set; }
public List<Order> Orders { get; set; }
public List<Secure> Secures { get; set; }
private DataListSingleton()
{
Components = new List<Component>();
Orders = new List<Order>();
Secures = new List<Secure>();
}
public static DataListSingleton GetInstance()
{
if (_instance == null)
{
_instance = new DataListSingleton();
}
return _instance;
}
22
}
}

View File

@ -0,0 +1,104 @@
using SecuritySystemContracts.BindingModels;
using SecuritySystemContracts.SearchModels;
using SecuritySystemContracts.StoragesContracts;
using SecuritySystemContracts.ViewModels;
using SecuritySystemListImplement.Models;
namespace SecuritySystemListImplement.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,115 @@
using SecuritySystemContracts.BindingModels;
using SecuritySystemContracts.SearchModels;
using SecuritySystemContracts.StoragesContracts;
using SecuritySystemContracts.ViewModels;
using SecuritySystemListImplement.Models;
namespace SecuritySystemListImplement.Implements
{
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(GetViewModel(order));
}
return result;
}
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
{
var result = new List<OrderViewModel>();
if (!model.Id.HasValue)
{
return result;
}
foreach (var order in _source.Orders)
{
if (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;
}
private OrderViewModel GetViewModel(Order order)
{
var viewModel = order.GetViewModel;
foreach (var secure in _source.Secures)
{
if (secure.Id == order.SecureId)
{
viewModel.SecureName = secure.SecureName;
break;
}
}
return viewModel;
}
}
}

View File

@ -0,0 +1,108 @@
using SecuritySystemContracts.BindingModels;
using SecuritySystemContracts.SearchModels;
using SecuritySystemContracts.StoragesContracts;
using SecuritySystemContracts.ViewModels;
namespace SecuritySystemListImplement.Implements
{
public class SecureStorage : ISecureStorage
{
private readonly DataListSingleton _source;
public SecureStorage()
{
_source = DataListSingleton.GetInstance();
}
public List<SecureViewModel> GetFullList()
{
var result = new List<SecureViewModel>();
foreach (var secure in _source.Secures)
{
result.Add(secure.GetViewModel);
}
return result;
}
public List<SecureViewModel> GetFilteredList(SecureSearchModel model)
{
var result = new List<SecureViewModel>();
if (string.IsNullOrEmpty(model.SecureName))
{
return result;
}
foreach (var secure in _source.Secures)
{
if (secure.SecureName.Contains(model.SecureName))
{
result.Add(secure.GetViewModel);
}
}
return result;
}
public SecureViewModel? GetElement(SecureSearchModel model)
{
if (string.IsNullOrEmpty(model.SecureName) && !model.Id.HasValue)
{
return null;
}
foreach (var secure in _source.Secures)
{
if (
(!string.IsNullOrEmpty(model.SecureName) &&
secure.SecureName == model.SecureName) ||
(model.Id.HasValue && secure.Id == model.Id)
)
{
return secure.GetViewModel;
}
}
return null;
}
public SecureViewModel? Insert(SecureBindingModel model)
{
model.Id = 1;
foreach (var secure in _source.Secures)
{
if (model.Id <= secure.Id)
{
model.Id = secure.Id + 1;
}
}
var newSecure = Secure.Create(model);
if (newSecure == null)
{
return null;
}
_source.Secures.Add(newSecure);
return newSecure.GetViewModel;
}
public SecureViewModel? Update(SecureBindingModel model)
{
foreach (var secure in _source.Secures)
{
if (secure.Id == model.Id)
{
secure.Update(model);
return secure.GetViewModel;
}
}
return null;
}
public SecureViewModel? Delete(SecureBindingModel model)
{
for (int i = 0; i < _source.Secures.Count; ++i)
{
if (_source.Secures[i].Id == model.Id)
{
var element = _source.Secures[i];
_source.Secures.RemoveAt(i);
return element.GetViewModel;
}
}
return null;
}
}
}

View File

@ -0,0 +1,41 @@
using SecuritySystemContracts.BindingModels;
using SecuritySystemContracts.ViewModels;
using SecuritySystemDataModels.Models;
namespace SecuritySystemListImplement.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
};
}
}

View File

@ -0,0 +1,62 @@
using SecuritySystemContracts.BindingModels;
using SecuritySystemContracts.ViewModels;
using SecuritySystemDataModels.Enums;
namespace SecuritySystemListImplement.Models
{
public class Order
{
public int SecureId { 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 int Id { get; private set; }
public static Order? Create(OrderBindingModel? model)
{
if (model == null)
{
return null;
}
return new Order
{
Id = model.Id,
SecureId = model.SecureId,
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;
DateImplement = model.DateImplement;
}
public OrderViewModel GetViewModel => new()
{
SecureId = SecureId,
Count = Count,
Sum = Sum,
DateCreate = DateCreate,
DateImplement = DateImplement,
Id = Id,
Status = Status,
};
}
}

View File

@ -0,0 +1,50 @@
using SecuritySystemContracts.BindingModels;
using SecuritySystemContracts.ViewModels;
using SecuritySystemDataModels.Models;
namespace SecuritySystemListImplement.Models
{
public class Secure : ISecureModel
{
public int Id { get; private set; }
public string SecureName { get; private set; } = string.Empty;
public double Price { get; private set; }
public Dictionary<int, (IComponentModel, int)> SecureComponents
{
get;
private set;
} = new Dictionary<int, (IComponentModel, int)>();
public static Secure? Create(SecureBindingModel? model)
{
if (model == null)
{
return null;
}
return new Secure()
{
Id = model.Id,
SecureName = model.SecureName,
Price = model.Price,
SecureComponents = model.SecureComponents
};
}
public void Update(SecureBindingModel? model)
{
if (model == null)
{
return;
}
SecureName = model.SecureName;
Price = model.Price;
SecureComponents = model.SecureComponents;
}
public SecureViewModel GetViewModel => new()
{
Id = Id,
SecureName = SecureName,
Price = Price,
SecureComponents = SecureComponents
};
}
}

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="..\SecuritySystemContracts\SecuritySystemContracts.csproj" />
<ProjectReference Include="..\SecuritySystemDataModels\SecuritySystemDataModels.csproj" />
</ItemGroup>
</Project>