Сделаны библиотеки
This commit is contained in:
parent
b855fc1d11
commit
a5e8434111
13
AbstractComputerDataModel/ComputerShopDataModels.csproj
Normal file
13
AbstractComputerDataModel/ComputerShopDataModels.csproj
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Logging" Version="7.0.0" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
11
AbstractComputerDataModel/Enums/OrderStatus.cs
Normal file
11
AbstractComputerDataModel/Enums/OrderStatus.cs
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
namespace ComputerShopDataModels.Enums
|
||||||
|
{
|
||||||
|
public enum OrderStatus
|
||||||
|
{
|
||||||
|
Неизвестен = -1,
|
||||||
|
Принят = 0,
|
||||||
|
Выполняется = 1,
|
||||||
|
Готов = 2,
|
||||||
|
Выдан = 3
|
||||||
|
}
|
||||||
|
}
|
14
AbstractComputerDataModel/Models/IComponentModel.cs
Normal file
14
AbstractComputerDataModel/Models/IComponentModel.cs
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ComputerShopDataModels.Models
|
||||||
|
{
|
||||||
|
public interface IComponentModel
|
||||||
|
{
|
||||||
|
string ComponentName { get; }
|
||||||
|
double Cost { get; }
|
||||||
|
}
|
||||||
|
}
|
15
AbstractComputerDataModel/Models/IComputerModel.cs
Normal file
15
AbstractComputerDataModel/Models/IComputerModel.cs
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ComputerShopDataModels.Models
|
||||||
|
{
|
||||||
|
public interface IComputerModel
|
||||||
|
{
|
||||||
|
string ComputerName { get; }
|
||||||
|
double Price { get; }
|
||||||
|
Dictionary<int, (IComponentModel, int)> ComputerComponents { get; }
|
||||||
|
}
|
||||||
|
}
|
13
AbstractComputerDataModel/Models/IId.cs
Normal file
13
AbstractComputerDataModel/Models/IId.cs
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ComputerShopDataModels.Models
|
||||||
|
{
|
||||||
|
public interface IId
|
||||||
|
{
|
||||||
|
string Id { get; }
|
||||||
|
}
|
||||||
|
}
|
19
AbstractComputerDataModel/Models/IOrderModel.cs
Normal file
19
AbstractComputerDataModel/Models/IOrderModel.cs
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using ComputerShopDataModels.Enums;
|
||||||
|
|
||||||
|
namespace ComputerShopDataModels.Models
|
||||||
|
{
|
||||||
|
public interface IOrderModel
|
||||||
|
{
|
||||||
|
int ComputerId { get; }
|
||||||
|
int Count { get; }
|
||||||
|
double Sum { get; }
|
||||||
|
OrderStatus Status { get; }
|
||||||
|
DateTime DateCreate { get; }
|
||||||
|
DateTime? DateImplement { get; }
|
||||||
|
}
|
||||||
|
}
|
114
ComputerShopBusinessLogic/BusinessLogics/ComponentLogic.cs
Normal file
114
ComputerShopBusinessLogic/BusinessLogics/ComponentLogic.cs
Normal file
@ -0,0 +1,114 @@
|
|||||||
|
using ComputerShopContracts.BindingModels;
|
||||||
|
using ComputerShopContracts.BusinessLogicsContracts;
|
||||||
|
using ComputerShopContracts.SearchModels;
|
||||||
|
using ComputerShopContracts.StoragesContracts;
|
||||||
|
using ComputerShopContracts.ViewModels;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
|
namespace ComputerShopBusinessLogic.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("Компонент с таким названием уже есть");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
17
ComputerShopBusinessLogic/ComputerShopBusinessLogic.csproj
Normal file
17
ComputerShopBusinessLogic/ComputerShopBusinessLogic.csproj
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Logging" Version="7.0.0" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\ComputerShopContracts\ComputerShopContracts.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
17
ComputerShopContracts/BindingModels/ComponentBindingModel.cs
Normal file
17
ComputerShopContracts/BindingModels/ComponentBindingModel.cs
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using ComputerShopDataModels.Models;
|
||||||
|
|
||||||
|
namespace ComputerShopContracts.BindingModels
|
||||||
|
{
|
||||||
|
public class ComponentBindingModel : IComponentModel
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
public string ComponentName { get; set; } = string.Empty;
|
||||||
|
public double Cost { get; set; }
|
||||||
|
}
|
||||||
|
}
|
21
ComputerShopContracts/BindingModels/ComputerBindingModel.cs
Normal file
21
ComputerShopContracts/BindingModels/ComputerBindingModel.cs
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using ComputerShopDataModels.Models;
|
||||||
|
|
||||||
|
namespace ComputerShopContracts.BindingModels
|
||||||
|
{
|
||||||
|
public class ComputerBindingModel : IComputerModel
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
public string ComputerName { get; set; } = string.Empty;
|
||||||
|
public double Price { get; set; }
|
||||||
|
public Dictionary<int, (IComponentModel, int)> ComputerComponents
|
||||||
|
{
|
||||||
|
get;
|
||||||
|
set;
|
||||||
|
} = new();
|
||||||
|
}
|
||||||
|
}
|
21
ComputerShopContracts/BindingModels/OrderBindingModel.cs
Normal file
21
ComputerShopContracts/BindingModels/OrderBindingModel.cs
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using ComputerShopDataModels.Models;
|
||||||
|
using ComputerShopDataModels.Enums;
|
||||||
|
|
||||||
|
namespace ComputerShopContracts.BindingModels
|
||||||
|
{
|
||||||
|
public class OrderBindingModel : IOrderModel
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
public int ComputerId { 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,20 @@
|
|||||||
|
using ComputerShopContracts.BindingModels;
|
||||||
|
using ComputerShopContracts.SearchModels;
|
||||||
|
using ComputerShopContracts.ViewModels;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ComputerShopContracts.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);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,20 @@
|
|||||||
|
using ComputerShopContracts.BindingModels;
|
||||||
|
using ComputerShopContracts.SearchModels;
|
||||||
|
using ComputerShopContracts.ViewModels;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ComputerShopContracts.BusinessLogicsContracts
|
||||||
|
{
|
||||||
|
public interface IComputerLogic
|
||||||
|
{
|
||||||
|
List<ComputerViewModel>? ReadList(ComputerSearchModel? model);
|
||||||
|
ComputerViewModel? ReadElement(ComputerSearchModel model);
|
||||||
|
bool Create(ComputerBindingModel model);
|
||||||
|
bool Update(ComputerBindingModel model);
|
||||||
|
bool Delete(ComputerBindingModel model);
|
||||||
|
}
|
||||||
|
}
|
20
ComputerShopContracts/BusinessLogicsContracts/IOrderLogic.cs
Normal file
20
ComputerShopContracts/BusinessLogicsContracts/IOrderLogic.cs
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
using ComputerShopContracts.BindingModels;
|
||||||
|
using ComputerShopContracts.SearchModels;
|
||||||
|
using ComputerShopContracts.ViewModels;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ComputerShopContracts.BusinessLogicsContracts
|
||||||
|
{
|
||||||
|
internal interface IOrderLogic
|
||||||
|
{
|
||||||
|
List<OrderViewModel>? ReadList(OrderSearchModel? model);
|
||||||
|
bool CreateOrder(OrderBindingModel model);
|
||||||
|
bool TakeOrderInWork(OrderBindingModel model);
|
||||||
|
bool FinishOrder(OrderBindingModel model);
|
||||||
|
bool DeliveryOrder(OrderBindingModel model);
|
||||||
|
}
|
||||||
|
}
|
17
ComputerShopContracts/ComputerShopContracts.csproj
Normal file
17
ComputerShopContracts/ComputerShopContracts.csproj
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Logging" Version="7.0.0" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\AbstractComputerDataModel\ComputerShopDataModels.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
14
ComputerShopContracts/SearchModels/ComponentSearchModel.cs
Normal file
14
ComputerShopContracts/SearchModels/ComponentSearchModel.cs
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ComputerShopContracts.SearchModels
|
||||||
|
{
|
||||||
|
public class ComponentSearchModel
|
||||||
|
{
|
||||||
|
public int? Id { get; set; }
|
||||||
|
public string? ComponentName { get; set; }
|
||||||
|
}
|
||||||
|
}
|
14
ComputerShopContracts/SearchModels/ComputerSearchModel.cs
Normal file
14
ComputerShopContracts/SearchModels/ComputerSearchModel.cs
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ComputerShopContracts.SearchModels
|
||||||
|
{
|
||||||
|
public class ComputerSearchModel
|
||||||
|
{
|
||||||
|
public int? Id { get; set; }
|
||||||
|
public string? ComputerName { get; set; }
|
||||||
|
}
|
||||||
|
}
|
13
ComputerShopContracts/SearchModels/OrderSearchModel.cs
Normal file
13
ComputerShopContracts/SearchModels/OrderSearchModel.cs
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ComputerShopContracts.SearchModels
|
||||||
|
{
|
||||||
|
public class OrderSearchModel
|
||||||
|
{
|
||||||
|
public int? Id { get; set; }
|
||||||
|
}
|
||||||
|
}
|
21
ComputerShopContracts/StoragesContracts/IComponentStorage.cs
Normal file
21
ComputerShopContracts/StoragesContracts/IComponentStorage.cs
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
using ComputerShopContracts.BindingModels;
|
||||||
|
using ComputerShopContracts.SearchModels;
|
||||||
|
using ComputerShopContracts.ViewModels;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ComputerShopContracts.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);
|
||||||
|
}
|
||||||
|
}
|
21
ComputerShopContracts/StoragesContracts/IComputerStorage.cs
Normal file
21
ComputerShopContracts/StoragesContracts/IComputerStorage.cs
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
using ComputerShopContracts.BindingModels;
|
||||||
|
using ComputerShopContracts.SearchModels;
|
||||||
|
using ComputerShopContracts.ViewModels;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ComputerShopContracts.StoragesContracts
|
||||||
|
{
|
||||||
|
public interface IComputerStorage
|
||||||
|
{
|
||||||
|
List<ComputerViewModel> GetFullList();
|
||||||
|
List<ComputerViewModel> GetFilteredList(ComputerSearchModel model);
|
||||||
|
ComputerViewModel? GetElement(ComputerSearchModel model);
|
||||||
|
ComputerViewModel? Insert(ComputerBindingModel model);
|
||||||
|
ComputerViewModel? Update(ComputerBindingModel model);
|
||||||
|
ComputerViewModel? Delete(ComputerBindingModel model);
|
||||||
|
}
|
||||||
|
}
|
21
ComputerShopContracts/StoragesContracts/IOrderStorage.cs
Normal file
21
ComputerShopContracts/StoragesContracts/IOrderStorage.cs
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
using ComputerShopContracts.BindingModels;
|
||||||
|
using ComputerShopContracts.SearchModels;
|
||||||
|
using ComputerShopContracts.ViewModels;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ComputerShopContracts.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);
|
||||||
|
}
|
||||||
|
}
|
19
ComputerShopContracts/ViewModels/ComponentViewModel.cs
Normal file
19
ComputerShopContracts/ViewModels/ComponentViewModel.cs
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
using ComputerShopDataModels.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ComputerShopContracts.ViewModels
|
||||||
|
{
|
||||||
|
public class ComponentViewModel : IComponentModel
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
[DisplayName("Название компонента")]
|
||||||
|
public string ComponentName { get; set; } = string.Empty;
|
||||||
|
[DisplayName("Цена")]
|
||||||
|
public double Cost { get; set; }
|
||||||
|
}
|
||||||
|
}
|
24
ComputerShopContracts/ViewModels/ComputerViewModel.cs
Normal file
24
ComputerShopContracts/ViewModels/ComputerViewModel.cs
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
using ComputerShopDataModels.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ComputerShopContracts.ViewModels
|
||||||
|
{
|
||||||
|
public class ComputerViewModel : IComputerModel
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
[DisplayName("Название изделия")]
|
||||||
|
public string ComputerName { get; set; } = string.Empty;
|
||||||
|
[DisplayName("Цена")]
|
||||||
|
public double Price { get; set; }
|
||||||
|
public Dictionary<int, (IComponentModel, int)> ComputerComponents
|
||||||
|
{
|
||||||
|
get;
|
||||||
|
set;
|
||||||
|
} = new();
|
||||||
|
}
|
||||||
|
}
|
30
ComputerShopContracts/ViewModels/OrderViewModel.cs
Normal file
30
ComputerShopContracts/ViewModels/OrderViewModel.cs
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
using ComputerShopDataModels.Enums;
|
||||||
|
using ComputerShopDataModels.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ComputerShopContracts.ViewModels
|
||||||
|
{
|
||||||
|
public class OrderViewModel : IOrderModel
|
||||||
|
{
|
||||||
|
[DisplayName("Номер")]
|
||||||
|
public int Id { get; set; }
|
||||||
|
public int ComputerId { get; set; }
|
||||||
|
[DisplayName("Изделие")]
|
||||||
|
public string ComputerName { 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; }
|
||||||
|
}
|
||||||
|
}
|
14
ComputerShopListImplement/ComputerShopListImplement.csproj
Normal file
14
ComputerShopListImplement/ComputerShopListImplement.csproj
Normal 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="..\AbstractComputerDataModel\ComputerShopDataModels.csproj" />
|
||||||
|
<ProjectReference Include="..\ComputerShopContracts\ComputerShopContracts.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
108
ComputerShopListImplement/Implements/ComponentStorage.cs
Normal file
108
ComputerShopListImplement/Implements/ComponentStorage.cs
Normal file
@ -0,0 +1,108 @@
|
|||||||
|
using ComputerShopContracts.BindingModels;
|
||||||
|
using ComputerShopContracts.SearchModels;
|
||||||
|
using ComputerShopContracts.StoragesContracts;
|
||||||
|
using ComputerShopContracts.ViewModels;
|
||||||
|
using ComputerShopListImplement.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ComputerShopListImplement.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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
47
ComputerShopListImplement/Models/Component.cs
Normal file
47
ComputerShopListImplement/Models/Component.cs
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
using ComputerShopContracts.BindingModels;
|
||||||
|
using ComputerShopContracts.ViewModels;
|
||||||
|
using ComputerShopDataModels.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ComputerShopListImplement.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
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
54
ComputerShopListImplement/Models/Computer.cs
Normal file
54
ComputerShopListImplement/Models/Computer.cs
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
using ComputerShopContracts.BindingModels;
|
||||||
|
using ComputerShopContracts.ViewModels;
|
||||||
|
using ComputerShopDataModels.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ComputerShopListImplement.Models
|
||||||
|
{
|
||||||
|
public class Computer : IComputerModel
|
||||||
|
{
|
||||||
|
public int Id { get; private set; }
|
||||||
|
public string ComputerName { get; private set; } = string.Empty;
|
||||||
|
public double Price { get; private set; }
|
||||||
|
public Dictionary<int, (IComponentModel, int)> ComputerComponents
|
||||||
|
{
|
||||||
|
get;
|
||||||
|
private set;
|
||||||
|
} = new Dictionary<int, (IComponentModel, int)>();
|
||||||
|
public static Computer? Create(ComputerBindingModel? model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new Computer()
|
||||||
|
{
|
||||||
|
Id = model.Id,
|
||||||
|
ComputerName = model.ComputerName,
|
||||||
|
Price = model.Price,
|
||||||
|
ComputerComponents = model.ComputerComponents
|
||||||
|
};
|
||||||
|
}
|
||||||
|
public void Update(ComputerBindingModel? model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ComputerName = model.ComputerName;
|
||||||
|
Price = model.Price;
|
||||||
|
ComputerComponents = model.ComputerComponents;
|
||||||
|
}
|
||||||
|
public ComputerViewModel GetViewModel => new()
|
||||||
|
{
|
||||||
|
Id = Id,
|
||||||
|
ComputerName = ComputerName,
|
||||||
|
Price = Price,
|
||||||
|
ComputerComponents = ComputerComponents
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
30
ComputerShopListImplement/Models/DataListSingleton.cs
Normal file
30
ComputerShopListImplement/Models/DataListSingleton.cs
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ComputerShopListImplement.Models
|
||||||
|
{
|
||||||
|
public class DataListSingleton
|
||||||
|
{
|
||||||
|
private static DataListSingleton? _instance;
|
||||||
|
public List<Component> Components { get; set; }
|
||||||
|
//public List<Order> Orders { get; set; }
|
||||||
|
public List<Computer> Computers { get; set; }
|
||||||
|
private DataListSingleton()
|
||||||
|
{
|
||||||
|
Components = new List<Component>();
|
||||||
|
//Orders = new List<Order>();
|
||||||
|
Computers = new List<Computer>();
|
||||||
|
}
|
||||||
|
public static DataListSingleton GetInstance()
|
||||||
|
{
|
||||||
|
if (_instance == null)
|
||||||
|
{
|
||||||
|
_instance = new DataListSingleton();
|
||||||
|
}
|
||||||
|
return _instance;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -8,4 +8,8 @@
|
|||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Logging" Version="7.0.0" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
@ -5,6 +5,14 @@ VisualStudioVersion = 17.3.32819.101
|
|||||||
MinimumVisualStudioVersion = 10.0.40219.1
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ComputersShop", "ComputersShop.csproj", "{7BE0F575-7A99-4161-BCD0-4F14E5AC7B95}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ComputersShop", "ComputersShop.csproj", "{7BE0F575-7A99-4161-BCD0-4F14E5AC7B95}"
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ComputerShopDataModels", "..\AbstractComputerDataModel\ComputerShopDataModels.csproj", "{07BF1453-7129-45C4-AB54-AFC38F1E579D}"
|
||||||
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ComputerShopContracts", "..\ComputerShopContracts\ComputerShopContracts.csproj", "{4684F24F-29DC-496C-803F-0877E5100939}"
|
||||||
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ComputerShopBusinessLogic", "..\ComputerShopBusinessLogic\ComputerShopBusinessLogic.csproj", "{8A6D08BB-449A-4C35-81CA-F82B6293D241}"
|
||||||
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ComputerShopListImplement", "..\ComputerShopListImplement\ComputerShopListImplement.csproj", "{D632C3A7-3E0E-4B53-B2B4-696A9F6B8D38}"
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
Debug|Any CPU = Debug|Any CPU
|
||||||
@ -15,6 +23,22 @@ Global
|
|||||||
{7BE0F575-7A99-4161-BCD0-4F14E5AC7B95}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{7BE0F575-7A99-4161-BCD0-4F14E5AC7B95}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{7BE0F575-7A99-4161-BCD0-4F14E5AC7B95}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{7BE0F575-7A99-4161-BCD0-4F14E5AC7B95}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{7BE0F575-7A99-4161-BCD0-4F14E5AC7B95}.Release|Any CPU.Build.0 = Release|Any CPU
|
{7BE0F575-7A99-4161-BCD0-4F14E5AC7B95}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{07BF1453-7129-45C4-AB54-AFC38F1E579D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{07BF1453-7129-45C4-AB54-AFC38F1E579D}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{07BF1453-7129-45C4-AB54-AFC38F1E579D}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{07BF1453-7129-45C4-AB54-AFC38F1E579D}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{4684F24F-29DC-496C-803F-0877E5100939}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{4684F24F-29DC-496C-803F-0877E5100939}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{4684F24F-29DC-496C-803F-0877E5100939}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{4684F24F-29DC-496C-803F-0877E5100939}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{8A6D08BB-449A-4C35-81CA-F82B6293D241}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{8A6D08BB-449A-4C35-81CA-F82B6293D241}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{8A6D08BB-449A-4C35-81CA-F82B6293D241}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{8A6D08BB-449A-4C35-81CA-F82B6293D241}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{D632C3A7-3E0E-4B53-B2B4-696A9F6B8D38}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{D632C3A7-3E0E-4B53-B2B4-696A9F6B8D38}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{D632C3A7-3E0E-4B53-B2B4-696A9F6B8D38}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{D632C3A7-3E0E-4B53-B2B4-696A9F6B8D38}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
Loading…
Reference in New Issue
Block a user