Compare commits
105 Commits
main
...
BACKDEV-41
Author | SHA1 | Date | |
---|---|---|---|
b8753069d7 | |||
|
dadaf9c744 | ||
|
311b70d3be | ||
|
0cf11372a7 | ||
|
0ac9228a41 | ||
|
79fcf7e9a9 | ||
|
63e1480d3d | ||
|
3d8f25f4b0 | ||
d04752b2ba | |||
c229b58d9d | |||
80f5b2fde7 | |||
|
6ca4695641 | ||
|
de8a64c509 | ||
|
c2c4759c68 | ||
|
7f6c134c57 | ||
fa4c708e1c | |||
|
fa4bf3e8d4 | ||
|
2ff2aeb812 | ||
|
765b68f754 | ||
|
2f7003d3b7 | ||
|
0a6730a722 | ||
|
7bcfa7e0e0 | ||
060c5dc37f | |||
|
3e68f069ce | ||
|
9df5c5d358 | ||
|
0fd8a7fd8f | ||
ca6035d7a1 | |||
|
ed846686ce | ||
|
7f429638b5 | ||
4733811487 | |||
9688e5eb1c | |||
34ada3ab98 | |||
|
95b2759a12 | ||
|
070473b0d6 | ||
|
affb89bb59 | ||
|
56b6290c71 | ||
|
96c186a590 | ||
|
326b2b2b87 | ||
|
09dcc021c8 | ||
e249402043 | |||
|
1ae74a6fdb | ||
|
5337beeb65 | ||
|
db1fdee078 | ||
|
19d3158342 | ||
|
fb7db4b90b | ||
|
26a687363e | ||
|
4fe042017b | ||
|
af397abdac | ||
2a30f03682 | |||
|
a30de13f4e | ||
|
c72e7a4a7a | ||
|
cc389d7922 | ||
c01e3c916d | |||
|
733c40a85a | ||
4391a40a78 | |||
2643f53e0b | |||
|
54afeb2906 | ||
|
d49014d810 | ||
|
55eade5399 | ||
41fa66267d | |||
4719cf6c0f | |||
|
1ba401c454 | ||
|
493886c45a | ||
|
210d90bb69 | ||
|
ce72b6d6b0 | ||
|
4b1d26dfb5 | ||
10ac29df01 | |||
06ec3952d3 | |||
fe14f02d22 | |||
7f35ac9210 | |||
|
3e2d8d74a5 | ||
|
b1438de286 | ||
|
e1c6fd8286 | ||
|
816fdcb208 | ||
25d027fe30 | |||
|
1f922905b0 | ||
03da9f0eda | |||
81907df9cf | |||
9945ff4bb2 | |||
9573c340ba | |||
|
2023ac13c7 | ||
b2c7cd9858 | |||
72ebbc11f9 | |||
930e4ed316 | |||
b48619623e | |||
bff0214329 | |||
8e96befcd6 | |||
14b3bbd20e | |||
6b8a7a5d1b | |||
40f96fe6c1 | |||
65599c80a2 | |||
c70fddda2c | |||
d48b7ac0de | |||
176b3bfc9d | |||
eee043483a | |||
8b9ee21fb9 | |||
1a9edefdb9 | |||
|
f952809b0e | ||
|
09f64c788f | ||
|
552c06f55e | ||
|
d7c2bc8e24 | ||
|
a328d413fa | ||
|
f6c69273df | ||
5bde6633c4 | |||
|
8049b51388 |
@ -5,6 +5,18 @@ VisualStudioVersion = 17.7.34031.279
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ComputerHardwareStore", "ComputerHardwareStore\ComputerHardwareStore.csproj", "{D5DDEE2B-A0C4-430B-B00E-452BA1AB3DDA}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ComputerHardwareStoreDataModels", "ComputerHardwareStoreDataModels\ComputerHardwareStoreDataModels.csproj", "{48126915-C6D4-451C-BC88-39E3C50332B8}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ComputerHardwareStoreContracts", "ComputerHardwareStoreContracts\ComputerHardwareStoreContracts.csproj", "{5F394E21-2597-432B-AE73-BBAFD8D9F50E}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ComputerHardwareStoreBusinessLogic", "ComputerHardwareStoreBusinessLogic\ComputerHardwareStoreBusinessLogic.csproj", "{D32DEB60-AF40-46AF-8914-DC6A19BD66CD}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ComputerHardwareStoreDatabaseImplement", "ComputerHardwareStoreDatabaseImplement\ComputerHardwareStoreDatabaseImplement.csproj", "{93BD4E28-48D8-4D3A-87FB-FB96F00DA64B}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ComputerHardwareStoreREST", "ComputerHardwareStoreREST\ComputerHardwareStoreREST.csproj", "{20E4D287-C0F4-4DAB-B338-349F8B6EA22B}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StoreKeeperClient", "ComputerHardwareStoreStoreKeeperApp\StoreKeeperClient.csproj", "{0FF8FE3D-A38E-40AF-9286-4D7B11ADA785}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@ -15,6 +27,30 @@ Global
|
||||
{D5DDEE2B-A0C4-430B-B00E-452BA1AB3DDA}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{D5DDEE2B-A0C4-430B-B00E-452BA1AB3DDA}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{D5DDEE2B-A0C4-430B-B00E-452BA1AB3DDA}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{48126915-C6D4-451C-BC88-39E3C50332B8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{48126915-C6D4-451C-BC88-39E3C50332B8}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{48126915-C6D4-451C-BC88-39E3C50332B8}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{48126915-C6D4-451C-BC88-39E3C50332B8}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{5F394E21-2597-432B-AE73-BBAFD8D9F50E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{5F394E21-2597-432B-AE73-BBAFD8D9F50E}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{5F394E21-2597-432B-AE73-BBAFD8D9F50E}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{5F394E21-2597-432B-AE73-BBAFD8D9F50E}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{D32DEB60-AF40-46AF-8914-DC6A19BD66CD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{D32DEB60-AF40-46AF-8914-DC6A19BD66CD}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{D32DEB60-AF40-46AF-8914-DC6A19BD66CD}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{D32DEB60-AF40-46AF-8914-DC6A19BD66CD}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{93BD4E28-48D8-4D3A-87FB-FB96F00DA64B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{93BD4E28-48D8-4D3A-87FB-FB96F00DA64B}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{93BD4E28-48D8-4D3A-87FB-FB96F00DA64B}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{93BD4E28-48D8-4D3A-87FB-FB96F00DA64B}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{20E4D287-C0F4-4DAB-B338-349F8B6EA22B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{20E4D287-C0F4-4DAB-B338-349F8B6EA22B}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{20E4D287-C0F4-4DAB-B338-349F8B6EA22B}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{20E4D287-C0F4-4DAB-B338-349F8B6EA22B}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{0FF8FE3D-A38E-40AF-9286-4D7B11ADA785}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{0FF8FE3D-A38E-40AF-9286-4D7B11ADA785}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{0FF8FE3D-A38E-40AF-9286-4D7B11ADA785}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{0FF8FE3D-A38E-40AF-9286-4D7B11ADA785}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
@ -34,6 +34,27 @@
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<None Include="App.config" />
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Program.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Microsoft.Bcl.AsyncInterfaces, Version=8.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.Bcl.AsyncInterfaces.8.0.0\lib\net462\Microsoft.Bcl.AsyncInterfaces.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Extensions.DependencyInjection, Version=8.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.Extensions.DependencyInjection.8.0.0\lib\net462\Microsoft.Extensions.DependencyInjection.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Extensions.DependencyInjection.Abstractions, Version=8.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.Extensions.DependencyInjection.Abstractions.8.0.0\lib\net462\Microsoft.Extensions.DependencyInjection.Abstractions.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Runtime.CompilerServices.Unsafe, Version=4.0.4.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Runtime.CompilerServices.Unsafe.4.5.3\lib\net461\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Threading.Tasks.Extensions, Version=4.2.0.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Threading.Tasks.Extensions.4.5.4\lib\net461\System.Threading.Tasks.Extensions.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
9
ComputerHardwareStore/ComputerHardwareStore/Program.cs
Normal file
9
ComputerHardwareStore/ComputerHardwareStore/Program.cs
Normal file
@ -0,0 +1,9 @@
|
||||
namespace ComputerHardwareStore
|
||||
{
|
||||
internal static class Program
|
||||
{
|
||||
static void Main()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="Microsoft.Bcl.AsyncInterfaces" version="8.0.0" targetFramework="net48" />
|
||||
<package id="Microsoft.Extensions.DependencyInjection" version="8.0.0" targetFramework="net48" />
|
||||
<package id="Microsoft.Extensions.DependencyInjection.Abstractions" version="8.0.0" targetFramework="net48" />
|
||||
<package id="System.Runtime.CompilerServices.Unsafe" version="4.5.3" targetFramework="net48" />
|
||||
<package id="System.Threading.Tasks.Extensions" version="4.5.4" targetFramework="net48" />
|
||||
</packages>
|
@ -0,0 +1,113 @@
|
||||
using ComputerHardwareStoreContracts.BindingModels;
|
||||
using ComputerHardwareStoreContracts.BusinessLogicsContracts;
|
||||
using ComputerHardwareStoreContracts.SearchModels;
|
||||
using ComputerHardwareStoreContracts.StorageContracts;
|
||||
using ComputerHardwareStoreContracts.ViewModels;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace ComputerHardwareStoreBusinessLogic.BusinessLogic
|
||||
{
|
||||
public class BuildLogic : IBuildLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IBuildStorage _buildStorage;
|
||||
|
||||
public BuildLogic(ILogger<BuildLogic> logger, IBuildStorage buildStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_buildStorage = buildStorage;
|
||||
}
|
||||
|
||||
public List<BuildViewModel>? ReadList(BuildSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList Build. Name:{Name}. Id:{ Id}", model?.Name, model?.Id);
|
||||
var list = model == null ? _buildStorage.GetFullList() :
|
||||
_buildStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList Build return null list");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadList Build. Count:{Count}", list.Count);
|
||||
return list;
|
||||
}
|
||||
|
||||
public BuildViewModel? ReadElement(BuildSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
_logger.LogInformation("ReadElement Build. Name:{Name}. Id:{ Id}", model.Name, model.Id);
|
||||
var element = _buildStorage.GetElement(model);
|
||||
if (element == null)
|
||||
{
|
||||
_logger.LogWarning("ReadElement Build element not found");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadElement Build find. Id:{Id}", element.Id);
|
||||
return element;
|
||||
}
|
||||
|
||||
public bool Create(BuildBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_buildStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert Build operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Update(BuildBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_buildStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update Build operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Delete(BuildBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
_logger.LogInformation("Delete. Id:{Id}", model.Id);
|
||||
if (_buildStorage.Delete(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Delete Build operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
private void CheckModel(BuildBindingModel model, bool withParams = true)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
if (!withParams)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.Name))
|
||||
{
|
||||
throw new ArgumentNullException("Нет названия сборки", nameof(model.Name));
|
||||
}
|
||||
if (model.Price <= 0)
|
||||
{
|
||||
throw new ArgumentNullException("Цена сборки должна быть больше 0", nameof(model.Price));
|
||||
}
|
||||
var element = _buildStorage.GetElement(new BuildSearchModel
|
||||
{
|
||||
Name = model.Name
|
||||
});
|
||||
if (element != null)
|
||||
{
|
||||
throw new InvalidOperationException("Сборка с таким названием уже есть");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,101 @@
|
||||
using ComputerHardwareStoreContracts.BindingModels;
|
||||
using ComputerHardwareStoreContracts.BusinessLogicsContracts;
|
||||
using ComputerHardwareStoreContracts.SearchModels;
|
||||
using ComputerHardwareStoreContracts.StorageContracts;
|
||||
using ComputerHardwareStoreContracts.ViewModels;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace ComputerHardwareStoreBusinessLogic.BusinessLogic
|
||||
{
|
||||
public class CommentLogic : ICommentLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly ICommentStorage _commentStorage;
|
||||
|
||||
public CommentLogic(ILogger<CommentLogic> logger, ICommentStorage commentStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_commentStorage = commentStorage;
|
||||
}
|
||||
|
||||
public List<CommentViewModel>? ReadList(CommentSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList Comment. Date:{Date}. Id:{Id}", model?.Date, model?.Id);
|
||||
var list = model == null ? _commentStorage.GetFullList() :
|
||||
_commentStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList Comment return null list");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadList Comment. Count:{Count}", list.Count);
|
||||
return list;
|
||||
}
|
||||
|
||||
public CommentViewModel? ReadElement(CommentSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
_logger.LogInformation("ReadElement Comment. Date:{Date}. Id:{ Id}", model.Date, model.Id);
|
||||
var element = _commentStorage.GetElement(model);
|
||||
if (element == null)
|
||||
{
|
||||
_logger.LogWarning("ReadElement Comment element not found");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadElement Comment find. Id:{Id}", element.Id);
|
||||
return element;
|
||||
}
|
||||
|
||||
public bool Create(CommentBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_commentStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert Comment operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Update(CommentBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_commentStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update Comment operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Delete(CommentBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
_logger.LogInformation("Delete. Id:{Id}", model.Id);
|
||||
if (_commentStorage.Delete(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Delete Comment operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
private void CheckModel(CommentBindingModel model, bool withParams = true)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
if (!withParams)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.Text))
|
||||
{
|
||||
throw new ArgumentNullException("Нет текста комментария", nameof(model.Text));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,113 @@
|
||||
using ComputerHardwareStoreContracts.BindingModels;
|
||||
using ComputerHardwareStoreContracts.BusinessLogicsContracts;
|
||||
using ComputerHardwareStoreContracts.SearchModels;
|
||||
using ComputerHardwareStoreContracts.StorageContracts;
|
||||
using ComputerHardwareStoreContracts.ViewModels;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace ComputerHardwareStoreBusinessLogic.BusinessLogic
|
||||
{
|
||||
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 Component. Name:{Name}. Id:{ Id}", model?.Name, model?.Id);
|
||||
var list = model == null ? _componentStorage.GetFullList() :
|
||||
_componentStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList Component return null list");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadList Component. Count:{Count}", list.Count);
|
||||
return list;
|
||||
}
|
||||
|
||||
public ComponentViewModel? ReadElement(ComponentSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
_logger.LogInformation("ReadElement Component. Name:{Name}. Id:{ Id}", model.Name, model.Id);
|
||||
var element = _componentStorage.GetElement(model);
|
||||
if (element == null)
|
||||
{
|
||||
_logger.LogWarning("ReadElement Component element not found");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadElement Component find. Id:{Id}", element.Id);
|
||||
return element;
|
||||
}
|
||||
|
||||
public bool Create(ComponentBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_componentStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert Component operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Update(ComponentBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_componentStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update Component 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 Component 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.Name))
|
||||
{
|
||||
throw new ArgumentNullException("Нет названия компонента", nameof(model.Name));
|
||||
}
|
||||
if (model.Cost <= 0)
|
||||
{
|
||||
throw new ArgumentNullException("Цена компонента должна быть больше 0", nameof(model.Cost));
|
||||
}
|
||||
var element = _componentStorage.GetElement(new ComponentSearchModel
|
||||
{
|
||||
Name = model.Name
|
||||
});
|
||||
if (element != null)
|
||||
{
|
||||
throw new InvalidOperationException("Компонент с таким названием уже есть");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,115 @@
|
||||
using ComputerHardwareStoreContracts.BindingModels;
|
||||
using ComputerHardwareStoreContracts.BusinessLogicsContracts;
|
||||
using ComputerHardwareStoreContracts.SearchModels;
|
||||
using ComputerHardwareStoreContracts.StorageContracts;
|
||||
using ComputerHardwareStoreContracts.ViewModels;
|
||||
using ComputerHardwareStoreDataModels.Enums;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace ComputerHardwareStoreBusinessLogic.BusinessLogic
|
||||
{
|
||||
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)
|
||||
{
|
||||
model.Status = OrderStatus.Неизвестен;
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool TakeOrderInWork(OrderBindingModel model)
|
||||
{
|
||||
return ToNextStatus(model, OrderStatus.Выполняется);
|
||||
}
|
||||
|
||||
public bool FinishOrder(OrderBindingModel model)
|
||||
{
|
||||
return ToNextStatus(model, OrderStatus.Готов);
|
||||
}
|
||||
|
||||
public bool DeliveryOrder(OrderBindingModel model)
|
||||
{
|
||||
return ToNextStatus(model, OrderStatus.Выдан);
|
||||
}
|
||||
|
||||
public bool ToNextStatus(OrderBindingModel model, OrderStatus orderStatus)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
var element = _orderStorage.GetElement(new OrderSearchModel()
|
||||
{
|
||||
Id = model.Id
|
||||
});
|
||||
if (element == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(element));
|
||||
}
|
||||
|
||||
model.OrderProduct = element.OrderProduct;
|
||||
model.DateCreate = element.DateCreate;
|
||||
model.Status = element.Status;
|
||||
|
||||
if (model.Status != orderStatus - 1)
|
||||
{
|
||||
_logger.LogWarning("Status update to " + orderStatus + " operation failed");
|
||||
return false;
|
||||
}
|
||||
model.Status = orderStatus;
|
||||
|
||||
if (_orderStorage.Update(model) == null)
|
||||
{
|
||||
model.Status--;
|
||||
_logger.LogWarning("Changing status operation faled");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void CheckModel(OrderBindingModel model, bool withParams = true)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
if (!withParams)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (model.Sum <= 0)
|
||||
{
|
||||
throw new ArgumentNullException("Цена заказа должна быть больше 0", nameof(model.Sum));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,115 @@
|
||||
using ComputerHardwareStoreContracts.BindingModels;
|
||||
using ComputerHardwareStoreContracts.BusinessLogicsContracts;
|
||||
using ComputerHardwareStoreContracts.SearchModels;
|
||||
using ComputerHardwareStoreContracts.StorageContracts;
|
||||
using ComputerHardwareStoreContracts.ViewModels;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace ComputerHardwareStoreBusinessLogic.BusinessLogic
|
||||
{
|
||||
public class ProductLogic : IProductLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IProductStorage _productStorage;
|
||||
|
||||
public ProductLogic(ILogger logger, IProductStorage productStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_productStorage = productStorage;
|
||||
}
|
||||
|
||||
public List<ProductViewModel>? ReadList(ProductSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList Product. Name:{Name}. Id:{ Id}", model?.Name, model?.Id);
|
||||
var list = model == null ?
|
||||
_productStorage.GetFullList() :
|
||||
_productStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList Product return null list");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadList Product. Count:{Count}", list.Count);
|
||||
return list;
|
||||
}
|
||||
|
||||
public ProductViewModel? ReadElement(ProductSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
_logger.LogInformation("ReadElement Product. Name:{Name}. Id:{ Id}", model.Name, model.Id);
|
||||
var element = _productStorage.GetElement(model);
|
||||
if (element == null)
|
||||
{
|
||||
_logger.LogWarning("ReadElement Product element not found");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadElement Product find. Id:{Id}", element.Id);
|
||||
return element;
|
||||
}
|
||||
|
||||
public bool Create(ProductBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_productStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert Product operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Update(ProductBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_productStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update Product Component operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Delete(ProductBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
_logger.LogInformation("Delete. Id:{Id}", model.Id);
|
||||
if (_productStorage.Delete(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Delete Product operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void CheckModel(ProductBindingModel model, bool withParams = true)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
if (!withParams)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.Name))
|
||||
{
|
||||
throw new ArgumentException("Нет названия продукта", nameof(model.Name));
|
||||
}
|
||||
if (model.Price <= 0)
|
||||
{
|
||||
throw new ArgumentNullException("Цена продукта должна быть больше 0", nameof(model.Price));
|
||||
}
|
||||
var element = _productStorage.GetElement(new ProductSearchModel
|
||||
{
|
||||
Name = model.Name
|
||||
});
|
||||
if (element != null)
|
||||
{
|
||||
throw new InvalidOperationException("Продукт с таким названием уже есть");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,101 @@
|
||||
using ComputerHardwareStoreContracts.BindingModels;
|
||||
using ComputerHardwareStoreContracts.BusinessLogicsContracts;
|
||||
using ComputerHardwareStoreContracts.SearchModels;
|
||||
using ComputerHardwareStoreContracts.StorageContracts;
|
||||
using ComputerHardwareStoreContracts.ViewModels;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace ComputerHardwareStoreBusinessLogic.BusinessLogic
|
||||
{
|
||||
public class PurchaseLogic : IPurchaseLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IPurchaseStorage _purchaseStorage;
|
||||
|
||||
public PurchaseLogic(ILogger<PurchaseLogic> logger, IPurchaseStorage purchaseStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_purchaseStorage = purchaseStorage;
|
||||
}
|
||||
|
||||
public List<PurchaseViewModel>? ReadList(PurchaseSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList Purchase. Id:{ Id}", model?.Id);
|
||||
var list = model == null ? _purchaseStorage.GetFullList() :
|
||||
_purchaseStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList Purchase return null list");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadList Purchase. Count:{Count}", list.Count);
|
||||
return list;
|
||||
}
|
||||
|
||||
public PurchaseViewModel? ReadElement(PurchaseSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
_logger.LogInformation("ReadElement Purchase. Id:{ Id}", model.Id);
|
||||
var element = _purchaseStorage.GetElement(model);
|
||||
if (element == null)
|
||||
{
|
||||
_logger.LogWarning("ReadElement Purchase element not found");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadElement Purchase find. Id:{Id}", element.Id);
|
||||
return element;
|
||||
}
|
||||
|
||||
public bool Create(PurchaseBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_purchaseStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert Purchase operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Update(PurchaseBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_purchaseStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update Purchase operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Delete(PurchaseBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
_logger.LogInformation("Delete. Id:{Id}", model.Id);
|
||||
if (_purchaseStorage.Delete(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Delete Purchase operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
private void CheckModel(PurchaseBindingModel model, bool withParams = true)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
if (!withParams)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (model.Cost <= 0)
|
||||
{
|
||||
throw new ArgumentNullException("Стоимость покупки должна быть больше 0", nameof(model.Cost));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,107 @@
|
||||
using ComputerHardwareStoreContracts.BindingModels;
|
||||
using ComputerHardwareStoreContracts.BusinessLogicsContracts;
|
||||
using ComputerHardwareStoreContracts.SearchModels;
|
||||
using ComputerHardwareStoreContracts.StorageContracts;
|
||||
using ComputerHardwareStoreContracts.ViewModels;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace ComputerHardwareStoreBusinessLogic.BusinessLogic
|
||||
{
|
||||
public class StoreKeeperLogic : IStoreKeeperLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IStoreKeeperStorage _storeKeeperStorage;
|
||||
public StoreKeeperLogic(ILogger<StoreKeeperLogic> logger, IStoreKeeperStorage storeKeeperStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_storeKeeperStorage = storeKeeperStorage;
|
||||
}
|
||||
public List<StoreKeeperViewModel>? ReadList(StoreKeeperSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. Login:{Login}.Id:{Id}", model?.Login, model?.Id);
|
||||
var list = model == null ? _storeKeeperStorage.GetFullList() : _storeKeeperStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList return null list");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||
return list;
|
||||
}
|
||||
|
||||
public StoreKeeperViewModel? ReadElement(StoreKeeperSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
_logger.LogInformation("ReadElement. Login:{Login}.Id:{Id}", model.Login, model.Id);
|
||||
var element = _storeKeeperStorage.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(StoreKeeperBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_storeKeeperStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Update(StoreKeeperBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_storeKeeperStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Delete(StoreKeeperBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
_logger.LogInformation("Delete. Id:{Id}", model.Id);
|
||||
if (_storeKeeperStorage.Delete(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Delete operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void CheckModel(StoreKeeperBindingModel model, bool withParams = true)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
if (!withParams)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.Login))
|
||||
{
|
||||
throw new ArgumentNullException("Нет логина кладовщика", nameof(model.Login));
|
||||
}
|
||||
var element = _storeKeeperStorage.GetElement(new StoreKeeperSearchModel
|
||||
{
|
||||
Login = model.Login
|
||||
});
|
||||
if (element != null && element.Id != model.Id)
|
||||
{
|
||||
throw new InvalidOperationException("Кладовщик с таким логином уже есть");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,107 @@
|
||||
using ComputerHardwareStoreContracts.BindingModels;
|
||||
using ComputerHardwareStoreContracts.BusinessLogicsContracts;
|
||||
using ComputerHardwareStoreContracts.SearchModels;
|
||||
using ComputerHardwareStoreContracts.StorageContracts;
|
||||
using ComputerHardwareStoreContracts.ViewModels;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace ComputerHardwareStoreBusinessLogic.BusinessLogic
|
||||
{
|
||||
public class VendorLogic : IVendorLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IVendorStorage _vendorStorage;
|
||||
public VendorLogic(ILogger<VendorLogic> logger, IVendorStorage vendorStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_vendorStorage = vendorStorage;
|
||||
}
|
||||
public List<VendorViewModel>? ReadList(VendorSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. Login:{Login}.Id:{Id}", model?.Login, model?.Id);
|
||||
var list = model == null ? _vendorStorage.GetFullList() : _vendorStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList return null list");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||
return list;
|
||||
}
|
||||
|
||||
public VendorViewModel? ReadElement(VendorSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
_logger.LogInformation("ReadElement. Login:{Login}.Id:{Id}", model.Login, model.Id);
|
||||
var element = _vendorStorage.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(VendorBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_vendorStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Update(VendorBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_vendorStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Delete(VendorBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
_logger.LogInformation("Delete. Id:{Id}", model.Id);
|
||||
if (_vendorStorage.Delete(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Delete operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void CheckModel(VendorBindingModel model, bool withParams = true)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
if (!withParams)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.Login))
|
||||
{
|
||||
throw new ArgumentNullException("Нет логина работника", nameof(model.Login));
|
||||
}
|
||||
var element = _vendorStorage.GetElement(new VendorSearchModel
|
||||
{
|
||||
Login = model.Login
|
||||
});
|
||||
if (element != null && element.Id != model.Id)
|
||||
{
|
||||
throw new InvalidOperationException("Работник с таким логином уже есть");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Remove="BusinessLogic\**" />
|
||||
<EmbeddedResource Remove="BusinessLogic\**" />
|
||||
<None Remove="BusinessLogic\**" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.1" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\ComputerHardwareStoreContracts\ComputerHardwareStoreContracts.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
@ -0,0 +1,14 @@
|
||||
using ComputerHardwareStoreDataModels.Models;
|
||||
|
||||
namespace ComputerHardwareStoreContracts.BindingModels
|
||||
{
|
||||
public class BuildBindingModel : IBuildModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; } = string.Empty;
|
||||
public double Price { get; set; }
|
||||
public IVendorModel Vendor { get; set; }
|
||||
public Dictionary<int, (IComponentModel, int)> BuildComponents { get; set; } = new();
|
||||
public List<ICommentModel> Comments { get; set; } = new();
|
||||
}
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
using ComputerHardwareStoreDataModels.Models;
|
||||
|
||||
namespace ComputerHardwareStoreContracts.BindingModels
|
||||
{
|
||||
public class CommentBindingModel : ICommentModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public DateTime Date { get; set; } = DateTime.Now;
|
||||
public string Text { get; set; } = string.Empty;
|
||||
public int BuildId { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
using ComputerHardwareStoreDataModels.Models;
|
||||
|
||||
namespace ComputerHardwareStoreContracts.BindingModels
|
||||
{
|
||||
public class ComponentBindingModel : IComponentModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; } = string.Empty;
|
||||
public double Cost { get; set; }
|
||||
public IStoreKeeperModel StoreKeeper { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
using ComputerHardwareStoreDataModels.Enums;
|
||||
using ComputerHardwareStoreDataModels.Models;
|
||||
|
||||
namespace ComputerHardwareStoreContracts.BindingModels
|
||||
{
|
||||
public class OrderBindingModel : IOrderModel
|
||||
{
|
||||
public int Id { 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; } = null;
|
||||
public Dictionary<int, (IProductModel, int)> OrderProducts { get; set; } = new();
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
using ComputerHardwareStoreDataModels.Models;
|
||||
|
||||
namespace ComputerHardwareStoreContracts.BindingModels
|
||||
{
|
||||
public class ProductBindingModel : IProductModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; } = string.Empty;
|
||||
public double Price { get; set; }
|
||||
public Dictionary<int, (IComponentModel, int)> ProductComponents { get; set; } = new();
|
||||
public IStoreKeeperModel StoreKeeper { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
using ComputerHardwareStoreDataModels.Models;
|
||||
|
||||
namespace ComputerHardwareStoreContracts.BindingModels
|
||||
{
|
||||
public class PurchaseBindingModel : IPurchaseModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public int VendorId { get; set; }
|
||||
public double Cost { get; set; }
|
||||
public DateTime DateCreate { get; set; }
|
||||
public DateTime? DateImplement { get; set; }
|
||||
public Dictionary<int, (IBuildModel, int)> PurchaseBuilds { get; set; } = new();
|
||||
public Dictionary<int, (IProductModel, int)> PurchaseProducts { get; set; } = new();
|
||||
}
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
using ComputerHardwareStoreDataModels.Models;
|
||||
|
||||
namespace ComputerHardwareStoreContracts.BindingModels
|
||||
{
|
||||
public class StoreKeeperBindingModel : IStoreKeeperModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; } = string.Empty;
|
||||
public string Login { get; set; } = string.Empty;
|
||||
public string Password { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
using ComputerHardwareStoreDataModels.Models;
|
||||
|
||||
namespace ComputerHardwareStoreContracts.BindingModels
|
||||
{
|
||||
public class VendorBindingModel : IVendorModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; } = string.Empty;
|
||||
public string Login { get; set; } = string.Empty;
|
||||
public string Password { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
using ComputerHardwareStoreContracts.BindingModels;
|
||||
using ComputerHardwareStoreContracts.SearchModels;
|
||||
using ComputerHardwareStoreContracts.ViewModels;
|
||||
|
||||
namespace ComputerHardwareStoreContracts.BusinessLogicsContracts
|
||||
{
|
||||
public interface IBuildLogic
|
||||
{
|
||||
List<BuildViewModel>? ReadList(BuildSearchModel? model);
|
||||
BuildViewModel? ReadElement(BuildSearchModel model);
|
||||
bool Create(BuildBindingModel model);
|
||||
bool Update(BuildBindingModel model);
|
||||
bool Delete(BuildBindingModel model);
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
using ComputerHardwareStoreContracts.BindingModels;
|
||||
using ComputerHardwareStoreContracts.SearchModels;
|
||||
using ComputerHardwareStoreContracts.ViewModels;
|
||||
|
||||
namespace ComputerHardwareStoreContracts.BusinessLogicsContracts
|
||||
{
|
||||
public interface ICommentLogic
|
||||
{
|
||||
List<CommentViewModel>? ReadList(CommentSearchModel? model);
|
||||
CommentViewModel? ReadElement(CommentSearchModel model);
|
||||
bool Create(CommentBindingModel model);
|
||||
bool Update(CommentBindingModel model);
|
||||
bool Delete(CommentBindingModel model);
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
using ComputerHardwareStoreContracts.BindingModels;
|
||||
using ComputerHardwareStoreContracts.SearchModels;
|
||||
using ComputerHardwareStoreContracts.ViewModels;
|
||||
|
||||
namespace ComputerHardwareStoreContracts.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,15 @@
|
||||
using ComputerHardwareStoreContracts.BindingModels;
|
||||
using ComputerHardwareStoreContracts.SearchModels;
|
||||
using ComputerHardwareStoreContracts.ViewModels;
|
||||
|
||||
namespace ComputerHardwareStoreContracts.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);
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
using ComputerHardwareStoreContracts.BindingModels;
|
||||
using ComputerHardwareStoreContracts.SearchModels;
|
||||
using ComputerHardwareStoreContracts.ViewModels;
|
||||
|
||||
namespace ComputerHardwareStoreContracts.BusinessLogicsContracts
|
||||
{
|
||||
public interface IProductLogic
|
||||
{
|
||||
List<ProductViewModel>? ReadList(ProductSearchModel? model);
|
||||
ProductViewModel? ReadElement(ProductSearchModel model);
|
||||
bool Create(ProductBindingModel model);
|
||||
bool Update(ProductBindingModel model);
|
||||
bool Delete(ProductBindingModel model);
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
using ComputerHardwareStoreContracts.BindingModels;
|
||||
using ComputerHardwareStoreContracts.SearchModels;
|
||||
using ComputerHardwareStoreContracts.ViewModels;
|
||||
|
||||
namespace ComputerHardwareStoreContracts.BusinessLogicsContracts
|
||||
{
|
||||
public interface IPurchaseLogic
|
||||
{
|
||||
List<PurchaseViewModel>? ReadList(PurchaseSearchModel? model);
|
||||
PurchaseViewModel? ReadElement(PurchaseSearchModel model);
|
||||
bool Create(PurchaseBindingModel model);
|
||||
bool Update(PurchaseBindingModel model);
|
||||
bool Delete(PurchaseBindingModel model);
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
using ComputerHardwareStoreContracts.BindingModels;
|
||||
using ComputerHardwareStoreContracts.SearchModels;
|
||||
using ComputerHardwareStoreContracts.ViewModels;
|
||||
|
||||
namespace ComputerHardwareStoreContracts.BusinessLogicsContracts
|
||||
{
|
||||
public interface IStoreKeeperLogic
|
||||
{
|
||||
List<StoreKeeperViewModel>? ReadList(StoreKeeperSearchModel? model);
|
||||
StoreKeeperViewModel? ReadElement(StoreKeeperSearchModel model);
|
||||
bool Create(StoreKeeperBindingModel model);
|
||||
bool Update(StoreKeeperBindingModel model);
|
||||
bool Delete(StoreKeeperBindingModel model);
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
using ComputerHardwareStoreContracts.BindingModels;
|
||||
using ComputerHardwareStoreContracts.SearchModels;
|
||||
using ComputerHardwareStoreContracts.ViewModels;
|
||||
|
||||
namespace ComputerHardwareStoreContracts.BusinessLogicsContracts
|
||||
{
|
||||
public interface IVendorLogic
|
||||
{
|
||||
List<VendorViewModel>? ReadList(VendorSearchModel? model);
|
||||
VendorViewModel? ReadElement(VendorSearchModel model);
|
||||
bool Create(VendorBindingModel model);
|
||||
bool Update(VendorBindingModel model);
|
||||
bool Delete(VendorBindingModel model);
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\ComputerHardwareStoreDataModels\ComputerHardwareStoreDataModels.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
@ -0,0 +1,10 @@
|
||||
namespace ComputerHardwareStoreContracts.SearchModels
|
||||
{
|
||||
public class BuildSearchModel
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
public int VendorId { get; set; }
|
||||
public int? ProductId { get; set; }
|
||||
public string? Name { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
namespace ComputerHardwareStoreContracts.SearchModels
|
||||
{
|
||||
public class CommentSearchModel
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
namespace ComputerHardwareStoreContracts.SearchModels
|
||||
{
|
||||
public class ComponentSearchModel
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
public string? Name { get; set; }
|
||||
public int? StoreKeeperId { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
namespace ComputerHardwareStoreContracts.SearchModels
|
||||
{
|
||||
public class OrderSearchModel
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
public DateTime? DateFrom { get; set; }
|
||||
public DateTime? DateTo { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
namespace ComputerHardwareStoreContracts.SearchModels
|
||||
{
|
||||
public class ProductSearchModel
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
public string? Name { get; set; }
|
||||
public int StoreKeeperId { get; set; }
|
||||
public int? BuildId { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
namespace ComputerHardwareStoreContracts.SearchModels
|
||||
{
|
||||
public class PurchaseSearchModel
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
public int? VendorId { get; set; }
|
||||
public DateTime? DateFrom { get; set; }
|
||||
public DateTime? DateTo { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
namespace ComputerHardwareStoreContracts.SearchModels
|
||||
{
|
||||
public class StoreKeeperSearchModel
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
public string? Login { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
namespace ComputerHardwareStoreContracts.SearchModels
|
||||
{
|
||||
public class VendorSearchModel
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
public string? Login { get; set; }
|
||||
public string? Password { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
using ComputerHardwareStoreContracts.BindingModels;
|
||||
using ComputerHardwareStoreContracts.SearchModels;
|
||||
using ComputerHardwareStoreContracts.ViewModels;
|
||||
|
||||
namespace ComputerHardwareStoreContracts.StorageContracts
|
||||
{
|
||||
public interface IBuildStorage
|
||||
{
|
||||
List<BuildViewModel> GetFullList();
|
||||
List<BuildViewModel> GetFilteredList(BuildSearchModel model);
|
||||
BuildViewModel? GetElement(BuildSearchModel model);
|
||||
BuildViewModel? Insert(BuildBindingModel model);
|
||||
BuildViewModel? Update(BuildBindingModel model);
|
||||
BuildViewModel? Delete(BuildBindingModel model);
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
using ComputerHardwareStoreContracts.BindingModels;
|
||||
using ComputerHardwareStoreContracts.SearchModels;
|
||||
using ComputerHardwareStoreContracts.ViewModels;
|
||||
|
||||
namespace ComputerHardwareStoreContracts.StorageContracts
|
||||
{
|
||||
public interface ICommentStorage
|
||||
{
|
||||
List<CommentViewModel> GetFullList();
|
||||
List<CommentViewModel> GetFilteredList(CommentSearchModel model);
|
||||
CommentViewModel? GetElement(CommentSearchModel model);
|
||||
CommentViewModel? Insert(CommentBindingModel model);
|
||||
CommentViewModel? Update(CommentBindingModel model);
|
||||
CommentViewModel? Delete(CommentBindingModel model);
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
using ComputerHardwareStoreContracts.BindingModels;
|
||||
using ComputerHardwareStoreContracts.SearchModels;
|
||||
using ComputerHardwareStoreContracts.ViewModels;
|
||||
|
||||
namespace ComputerHardwareStoreContracts.StorageContracts
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
using ComputerHardwareStoreContracts.BindingModels;
|
||||
using ComputerHardwareStoreContracts.SearchModels;
|
||||
using ComputerHardwareStoreContracts.ViewModels;
|
||||
|
||||
namespace ComputerHardwareStoreContracts.StorageContracts
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
using ComputerHardwareStoreContracts.BindingModels;
|
||||
using ComputerHardwareStoreContracts.SearchModels;
|
||||
using ComputerHardwareStoreContracts.ViewModels;
|
||||
|
||||
namespace ComputerHardwareStoreContracts.StorageContracts
|
||||
{
|
||||
public interface IProductStorage
|
||||
{
|
||||
List<ProductViewModel> GetFullList();
|
||||
List<ProductViewModel> GetFilteredList(ProductSearchModel model);
|
||||
ProductViewModel? GetElement(ProductSearchModel model);
|
||||
ProductViewModel? Insert(ProductBindingModel model);
|
||||
ProductViewModel? Update(ProductBindingModel model);
|
||||
ProductViewModel? Delete(ProductBindingModel model);
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
using ComputerHardwareStoreContracts.BindingModels;
|
||||
using ComputerHardwareStoreContracts.SearchModels;
|
||||
using ComputerHardwareStoreContracts.ViewModels;
|
||||
|
||||
namespace ComputerHardwareStoreContracts.StorageContracts
|
||||
{
|
||||
public interface IPurchaseStorage
|
||||
{
|
||||
List<PurchaseViewModel> GetFullList();
|
||||
List<PurchaseViewModel> GetFilteredList(PurchaseSearchModel model);
|
||||
PurchaseViewModel? GetElement(PurchaseSearchModel model);
|
||||
PurchaseViewModel? Insert(PurchaseBindingModel model);
|
||||
PurchaseViewModel? Update(PurchaseBindingModel model);
|
||||
PurchaseViewModel? Delete(PurchaseBindingModel model);
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
using ComputerHardwareStoreContracts.BindingModels;
|
||||
using ComputerHardwareStoreContracts.SearchModels;
|
||||
using ComputerHardwareStoreContracts.ViewModels;
|
||||
|
||||
namespace ComputerHardwareStoreContracts.StorageContracts
|
||||
{
|
||||
public interface IStoreKeeperStorage
|
||||
{
|
||||
List<StoreKeeperViewModel> GetFullList();
|
||||
List<StoreKeeperViewModel> GetFilteredList(StoreKeeperSearchModel model);
|
||||
StoreKeeperViewModel? GetElement(StoreKeeperSearchModel model);
|
||||
StoreKeeperViewModel? Insert(StoreKeeperBindingModel model);
|
||||
StoreKeeperViewModel? Update(StoreKeeperBindingModel model);
|
||||
StoreKeeperViewModel? Delete(StoreKeeperBindingModel model);
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
using ComputerHardwareStoreContracts.BindingModels;
|
||||
using ComputerHardwareStoreContracts.SearchModels;
|
||||
using ComputerHardwareStoreContracts.ViewModels;
|
||||
|
||||
namespace ComputerHardwareStoreContracts.StorageContracts
|
||||
{
|
||||
public interface IVendorStorage
|
||||
{
|
||||
List<VendorViewModel> GetFullList();
|
||||
List<VendorViewModel> GetFilteredList(VendorSearchModel model);
|
||||
VendorViewModel? GetElement(VendorSearchModel model);
|
||||
VendorViewModel? Insert(VendorBindingModel model);
|
||||
VendorViewModel? Update(VendorBindingModel model);
|
||||
VendorViewModel? Delete(VendorBindingModel model);
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
using ComputerHardwareStoreDataModels.Models;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace ComputerHardwareStoreContracts.ViewModels
|
||||
{
|
||||
public class BuildViewModel : IBuildModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[DisplayName("Название сборки")]
|
||||
public string Name { get; set; } = string.Empty;
|
||||
[DisplayName("Стоимость")]
|
||||
public double Price { get; set; }
|
||||
public IVendorModel Vendor { get; set; }
|
||||
public Dictionary<int, (IComponentModel, int)> BuildComponents { get; set; } = new();
|
||||
public List<ICommentModel> Comments { get; set; } = new();
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
using ComputerHardwareStoreDataModels.Models;
|
||||
|
||||
namespace ComputerHardwareStoreContracts.ViewModels
|
||||
{
|
||||
public class CommentViewModel : ICommentModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public DateTime Date { get; set; }
|
||||
public string Text { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
using ComputerHardwareStoreDataModels.Models;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace ComputerHardwareStoreContracts.ViewModels
|
||||
{
|
||||
public class ComponentViewModel : IComponentModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[DisplayName("Название компонента")]
|
||||
public string Name { get; set; } = string.Empty;
|
||||
[DisplayName("Цена")]
|
||||
public double Cost { get; set; }
|
||||
public IStoreKeeperModel StoreKeeper { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
using ComputerHardwareStoreDataModels.Enums;
|
||||
using ComputerHardwareStoreDataModels.Models;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace ComputerHardwareStoreContracts.ViewModels
|
||||
{
|
||||
public class OrderViewModel : IOrderModel
|
||||
{
|
||||
[DisplayName("Номер")]
|
||||
public int Id { get; set; }
|
||||
[DisplayName("Сумма")]
|
||||
public double Sum { get; set; }
|
||||
[DisplayName("Статус")]
|
||||
public OrderStatus Status { get; set; }
|
||||
[DisplayName("Дата создания")]
|
||||
public DateTime DateCreate { get; set; }
|
||||
[DisplayName("Дата выполнения")]
|
||||
public DateTime? DateImplement { get; set; }
|
||||
public Dictionary<int, (IProductModel, int)> OrderProducts { get; set; } = new();
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
using ComputerHardwareStoreDataModels.Models;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace ComputerHardwareStoreContracts.ViewModels
|
||||
{
|
||||
public class ProductViewModel : IProductModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[DisplayName("Название изделия")]
|
||||
public string Name { get; set; } = string.Empty;
|
||||
[DisplayName("Цена")]
|
||||
public double Price { get; set; }
|
||||
public Dictionary<int, (IComponentModel, int)> ProductComponents { get; set; } = new();
|
||||
public IStoreKeeperModel StoreKeeper { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
using ComputerHardwareStoreDataModels.Models;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace ComputerHardwareStoreContracts.ViewModels
|
||||
{
|
||||
public class PurchaseViewModel : IPurchaseModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[DisplayName("Стоимость")]
|
||||
public double Cost { get; set; }
|
||||
[DisplayName("Дата создания")]
|
||||
public DateTime DateCreate { get; set; }
|
||||
public DateTime? DateImplement { get; set; }
|
||||
public int VendorId { get; set; }
|
||||
[DisplayName("Сумма")]
|
||||
public double Sum { get; set; }
|
||||
public Dictionary<int, (IBuildModel, int)> PurchaseBuilds { get; set; } = new();
|
||||
|
||||
public Dictionary<int, (IProductModel, int)> PurchaseProducts { get; set; } = new();
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
using ComputerHardwareStoreDataModels.Models;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace ComputerHardwareStoreContracts.ViewModels
|
||||
{
|
||||
public class StoreKeeperViewModel : IStoreKeeperModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[DisplayName("Имя кладовщика")]
|
||||
public string Name { get; set; } = string.Empty;
|
||||
[DisplayName("Логин")]
|
||||
public string Login { get; set; } = string.Empty;
|
||||
[DisplayName("Пароль")]
|
||||
public string Password { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
using ComputerHardwareStoreDataModels.Models;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace ComputerHardwareStoreContracts.ViewModels
|
||||
{
|
||||
public class VendorViewModel : IVendorModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[DisplayName("Имя продавца")]
|
||||
public string Name { get; set; } = string.Empty;
|
||||
[DisplayName("Логин")]
|
||||
public string Login { get; set; } = string.Empty;
|
||||
[DisplayName("Пароль")]
|
||||
public string Password { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
@ -0,0 +1,11 @@
|
||||
namespace ComputerHardwareStoreDataModels.Enums
|
||||
{
|
||||
public enum OrderStatus
|
||||
{
|
||||
Неизвестен = -1,
|
||||
Принят = 0,
|
||||
Выполняется = 1,
|
||||
Готов = 2,
|
||||
Выдан = 3,
|
||||
}
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
namespace ComputerHardwareStoreDataModels
|
||||
{
|
||||
public interface IId
|
||||
{
|
||||
int Id { get; }
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
namespace ComputerHardwareStoreDataModels.Models
|
||||
{
|
||||
public interface IBuildModel : IId
|
||||
{
|
||||
string Name { get; }
|
||||
double Price { get; }
|
||||
IVendorModel Vendor { get; }
|
||||
public Dictionary<int, (IComponentModel, int)> BuildComponents { get; }
|
||||
public List<ICommentModel> Comments { get; }
|
||||
}
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
namespace ComputerHardwareStoreDataModels.Models
|
||||
{
|
||||
public interface ICommentModel : IId
|
||||
{
|
||||
DateTime Date { get; }
|
||||
string Text { get; }
|
||||
}
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
namespace ComputerHardwareStoreDataModels.Models
|
||||
{
|
||||
public interface IComponentModel : IId
|
||||
{
|
||||
string Name { get; }
|
||||
double Cost { get; }
|
||||
IStoreKeeperModel StoreKeeper { get; }
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
using ComputerHardwareStoreDataModels.Enums;
|
||||
|
||||
namespace ComputerHardwareStoreDataModels.Models
|
||||
{
|
||||
public interface IOrderModel : IId
|
||||
{
|
||||
double Sum { get; }
|
||||
OrderStatus Status { get; }
|
||||
DateTime DateCreate { get; }
|
||||
DateTime? DateImplement { get; }
|
||||
public Dictionary<int, (IProductModel, int)> OrderProducts { get; }
|
||||
}
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
namespace ComputerHardwareStoreDataModels.Models
|
||||
{
|
||||
public interface IProductModel : IId
|
||||
{
|
||||
string Name { get; }
|
||||
double Price { get; }
|
||||
public IStoreKeeperModel StoreKeeper { get; }
|
||||
public Dictionary<int, (IComponentModel, int)> ProductComponents { get; }
|
||||
}
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
namespace ComputerHardwareStoreDataModels.Models
|
||||
{
|
||||
public interface IPurchaseModel : IId
|
||||
{
|
||||
int VendorId { get; }
|
||||
double Cost { get; }
|
||||
DateTime DateCreate { get; }
|
||||
DateTime? DateImplement { get; }
|
||||
public Dictionary<int, (IBuildModel, int)> PurchaseBuilds { get; }
|
||||
public Dictionary<int, (IProductModel, int)> PurchaseProducts { get; }
|
||||
}
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
namespace ComputerHardwareStoreDataModels.Models
|
||||
{
|
||||
public interface IStoreKeeperModel : IId
|
||||
{
|
||||
string Name { get; }
|
||||
string Login { get; }
|
||||
string Password { get; }
|
||||
}
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
namespace ComputerHardwareStoreDataModels.Models
|
||||
{
|
||||
public interface IVendorModel : IId
|
||||
{
|
||||
string Name { get; }
|
||||
string Login { get; }
|
||||
string Password { get; }
|
||||
}
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
using ComputerHardwareStoreDatabaseImplement.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace ComputerHardwareStoreDatabaseImplement
|
||||
{
|
||||
public class ComputerHardwareStoreDBContext : DbContext
|
||||
{
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||
{
|
||||
optionsBuilder.UseNpgsql("Host=192.168.1.61:5432;Database=computerhardwarestore;Username=compstore;Password=compstore");
|
||||
|
||||
base.OnConfiguring(optionsBuilder);
|
||||
AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true);
|
||||
AppContext.SetSwitch("Npgsql.DisableDateTimeInfinityConversions", true);
|
||||
}
|
||||
public virtual DbSet<Component> Components { set; get; }
|
||||
public virtual DbSet<Product> Products { set; get; }
|
||||
public virtual DbSet<ProductComponent> ProductComponents { set; get; }
|
||||
|
||||
public virtual DbSet<StoreKeeper> StoreKeepers { set; get; }
|
||||
public virtual DbSet<Build> Builds { set; get; }
|
||||
public virtual DbSet<Order> Orders { set; get; }
|
||||
public virtual DbSet<OrderProduct> OrderProducts { set; get; }
|
||||
public virtual DbSet<BuildComponent> BuildComponents { set; get; }
|
||||
public virtual DbSet<Comment> Comments { set; get; }
|
||||
public virtual DbSet<Vendor> Vendors { set; get; }
|
||||
public virtual DbSet<Purchase> Purchases { set; get; }
|
||||
public virtual DbSet<PurchaseBuild> PurchaseBuilds { set; get; }
|
||||
public virtual DbSet<PurchaseProduct> PurchaseProducts { set; get; }
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.4" />
|
||||
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.2" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\ComputerHardwareStoreContracts\ComputerHardwareStoreContracts.csproj" />
|
||||
<ProjectReference Include="..\ComputerHardwareStoreDataModels\ComputerHardwareStoreDataModels.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
@ -0,0 +1,125 @@
|
||||
using ComputerHardwareStoreContracts.BindingModels;
|
||||
using ComputerHardwareStoreContracts.SearchModels;
|
||||
using ComputerHardwareStoreContracts.StorageContracts;
|
||||
using ComputerHardwareStoreContracts.ViewModels;
|
||||
using ComputerHardwareStoreDatabaseImplement.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace ComputerHardwareStoreDatabaseImplement.Implements
|
||||
{
|
||||
public class BuildStorage : IBuildStorage
|
||||
{
|
||||
public List<BuildViewModel> GetFullList()
|
||||
{
|
||||
using var context = new ComputerHardwareStoreDBContext();
|
||||
return context.Builds
|
||||
.Include(b => b.Comments)
|
||||
.Include(b => b.Components)
|
||||
.ThenInclude(b => b.Component)
|
||||
.Include(b => b.Vendor)
|
||||
.Select(b => b.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public List<BuildViewModel> GetFilteredList(BuildSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.Name))
|
||||
{
|
||||
return new();
|
||||
}
|
||||
using var context = new ComputerHardwareStoreDBContext();
|
||||
return context.Builds
|
||||
// только те, что созданы пользователем
|
||||
.Include(b => b.Vendor)
|
||||
.Where(b => b.Vendor.Id == model.VendorId
|
||||
// если есть хотя бы 1 общий компонент с товарами
|
||||
&& !model.ProductId.HasValue || b.Components.FirstOrDefault(
|
||||
c => c.Component.ProductComponents.FirstOrDefault(
|
||||
p => p.ProductId == model.ProductId)
|
||||
!= null)
|
||||
!= null)
|
||||
// вместе с комментами
|
||||
.Include(b => b.Comments)
|
||||
// вместе с компонентами
|
||||
.Include(b => b.Components)
|
||||
.ThenInclude(b => b.Component)
|
||||
.Select(b => b.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public BuildViewModel? GetElement(BuildSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.Name) && !model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new ComputerHardwareStoreDBContext();
|
||||
return context.Builds
|
||||
.Include(b => b.Vendor)
|
||||
.Where(b => b.Vendor.Id == model.VendorId)
|
||||
.Include(b => b.Comments)
|
||||
.Include(b => b.Components)
|
||||
.ThenInclude(b => b.Component)
|
||||
.FirstOrDefault(b =>
|
||||
(!string.IsNullOrEmpty(model.Name) && b.Name == model.Name) ||
|
||||
(model.Id.HasValue && b.Id == model.Id))?
|
||||
.GetViewModel;
|
||||
}
|
||||
|
||||
public BuildViewModel? Insert(BuildBindingModel model)
|
||||
{
|
||||
using var context = new ComputerHardwareStoreDBContext();
|
||||
var newBuild = Build.Create(context, model);
|
||||
if (newBuild == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
context.Builds.Add(newBuild);
|
||||
context.SaveChanges();
|
||||
return context.Builds
|
||||
.Include(b => b.Vendor)
|
||||
.Include(b => b.Comments)
|
||||
.Include(b => b.Components)
|
||||
.ThenInclude(b => b.Component)
|
||||
.FirstOrDefault(p => p.Id == newBuild.Id)?
|
||||
.GetViewModel;
|
||||
}
|
||||
|
||||
public BuildViewModel? Update(BuildBindingModel model)
|
||||
{
|
||||
using var context = new ComputerHardwareStoreDBContext();
|
||||
var build = context.Builds
|
||||
.Include(b => b.Comments)
|
||||
.Include(b => b.Components)
|
||||
.ThenInclude(b => b.Component)
|
||||
.Include(b => b.Vendor)
|
||||
.Where(b => b.Vendor.Id == model.Vendor.Id)
|
||||
.FirstOrDefault(p => p.Id == model.Id);
|
||||
if (build == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
context.Update(model);
|
||||
context.SaveChanges();
|
||||
return build.GetViewModel;
|
||||
}
|
||||
public BuildViewModel? Delete(BuildBindingModel model)
|
||||
{
|
||||
using var context = new ComputerHardwareStoreDBContext();
|
||||
var build = context.Builds
|
||||
.Include(b => b.Comments)
|
||||
.Include(b => b.Components)
|
||||
.ThenInclude(b => b.Component)
|
||||
.Include(b => b.Vendor)
|
||||
.Where(b => b.Vendor.Id == model.Vendor.Id)
|
||||
.FirstOrDefault(p => p.Id == model.Id);
|
||||
if (build == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
context.Builds.Remove(build);
|
||||
context.SaveChanges();
|
||||
return build.GetViewModel;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,77 @@
|
||||
using ComputerHardwareStoreContracts.BindingModels;
|
||||
using ComputerHardwareStoreContracts.SearchModels;
|
||||
using ComputerHardwareStoreContracts.StorageContracts;
|
||||
using ComputerHardwareStoreContracts.ViewModels;
|
||||
using ComputerHardwareStoreDatabaseImplement.Models;
|
||||
|
||||
namespace ComputerHardwareStoreDatabaseImplement.Implements
|
||||
{
|
||||
public class CommentStorage : ICommentStorage
|
||||
{
|
||||
public List<CommentViewModel> GetFullList()
|
||||
{
|
||||
using var context = new ComputerHardwareStoreDBContext();
|
||||
return context.Comments
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public List<CommentViewModel> GetFilteredList(CommentSearchModel model)
|
||||
{
|
||||
using var context = new ComputerHardwareStoreDBContext();
|
||||
return context.Comments
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public CommentViewModel? GetElement(CommentSearchModel model)
|
||||
{
|
||||
if (!model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new ComputerHardwareStoreDBContext();
|
||||
return context.Comments
|
||||
.FirstOrDefault(x => x.Id == model.Id)
|
||||
?.GetViewModel;
|
||||
}
|
||||
|
||||
public CommentViewModel? Insert(CommentBindingModel model)
|
||||
{
|
||||
using var context = new ComputerHardwareStoreDBContext();
|
||||
var newComment = Comment.Create(model);
|
||||
if (newComment == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
context.Comments.Add(newComment);
|
||||
context.SaveChanges();
|
||||
return newComment.GetViewModel;
|
||||
}
|
||||
public CommentViewModel? Update(CommentBindingModel model)
|
||||
{
|
||||
using var context = new ComputerHardwareStoreDBContext();
|
||||
var element = context.Comments.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (element == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
element.Update(model);
|
||||
context.SaveChanges();
|
||||
return element.GetViewModel;
|
||||
}
|
||||
|
||||
public CommentViewModel? Delete(CommentBindingModel model)
|
||||
{
|
||||
using var context = new ComputerHardwareStoreDBContext();
|
||||
var element = context.Comments.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
if (element != null)
|
||||
{
|
||||
context.Comments.Remove(element);
|
||||
context.SaveChanges();
|
||||
return element.GetViewModel;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,84 @@
|
||||
using ComputerHardwareStoreContracts.BindingModels;
|
||||
using ComputerHardwareStoreContracts.SearchModels;
|
||||
using ComputerHardwareStoreContracts.StorageContracts;
|
||||
using ComputerHardwareStoreContracts.ViewModels;
|
||||
using ComputerHardwareStoreDatabaseImplement.Models;
|
||||
|
||||
namespace ComputerHardwareStoreDatabaseImplement.Implements
|
||||
{
|
||||
public class ComponentStorage : IComponentStorage
|
||||
{
|
||||
public List<ComponentViewModel> GetFullList()
|
||||
{
|
||||
using var context = new ComputerHardwareStoreDBContext();
|
||||
return context.Components
|
||||
.Select(c => c.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public List<ComponentViewModel> GetFilteredList(ComponentSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.Name))
|
||||
{
|
||||
return new();
|
||||
}
|
||||
using var context = new ComputerHardwareStoreDBContext();
|
||||
return context.Components
|
||||
.Where(c => c.Name.Contains(model.Name))
|
||||
.Select(c => c.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public ComponentViewModel? GetElement(ComponentSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.Name) && !model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new ComputerHardwareStoreDBContext();
|
||||
return context.Components
|
||||
.FirstOrDefault(c =>
|
||||
(!string.IsNullOrEmpty(model.Name) && c .Name == model.Name) ||
|
||||
(model.Id.HasValue && c.Id == model.Id))
|
||||
?.GetViewModel;
|
||||
}
|
||||
|
||||
public ComponentViewModel? Insert(ComponentBindingModel model)
|
||||
{
|
||||
using var context = new ComputerHardwareStoreDBContext();
|
||||
var newComponent = Component.Create(model);
|
||||
if (newComponent == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
context.Components.Add(newComponent);
|
||||
context.SaveChanges();
|
||||
return newComponent.GetViewModel;
|
||||
}
|
||||
public ComponentViewModel? Update(ComponentBindingModel model)
|
||||
{
|
||||
using var context = new ComputerHardwareStoreDBContext();
|
||||
var element = context.Components.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (element == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
element.Update(model);
|
||||
context.SaveChanges();
|
||||
return element.GetViewModel;
|
||||
}
|
||||
|
||||
public ComponentViewModel? Delete(ComponentBindingModel model)
|
||||
{
|
||||
using var context = new ComputerHardwareStoreDBContext();
|
||||
var element = context.Components.FirstOrDefault(c => c.Id == model.Id);
|
||||
if (element == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
context.Components.Remove(element);
|
||||
context.SaveChanges();
|
||||
return element.GetViewModel;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,108 @@
|
||||
using ComputerHardwareStoreContracts.BindingModels;
|
||||
using ComputerHardwareStoreContracts.SearchModels;
|
||||
using ComputerHardwareStoreContracts.StorageContracts;
|
||||
using ComputerHardwareStoreContracts.ViewModels;
|
||||
using ComputerHardwareStoreDatabaseImplement.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace ComputerHardwareStoreDatabaseImplement.Implements
|
||||
{
|
||||
public class OrderStorage : IOrderStorage
|
||||
{
|
||||
public List<OrderViewModel> GetFullList()
|
||||
{
|
||||
using var context = new ComputerHardwareStoreDBContext();
|
||||
return context.Orders
|
||||
.Include(o => o.Products)
|
||||
.ThenInclude(o => o.Product)
|
||||
.Select(o => o.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
|
||||
{
|
||||
using var context = new ComputerHardwareStoreDBContext();
|
||||
return context.Orders
|
||||
.Include(o => o.Products)
|
||||
.ThenInclude(o => o.Product)
|
||||
.Where(o =>
|
||||
(model.Id.HasValue && o.Id == model.Id) ||
|
||||
((model.DateFrom.HasValue && model.DateTo.HasValue) &&
|
||||
((model.DateFrom <= o.DateCreate && o.DateCreate <= model.DateTo) ||
|
||||
(o.DateImplement.HasValue && o.DateCreate < model.DateFrom && model.DateFrom < o.DateImplement)))
|
||||
)
|
||||
.Select(o => o.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public OrderViewModel? GetElement(OrderSearchModel model)
|
||||
{
|
||||
if (!model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new ComputerHardwareStoreDBContext();
|
||||
return context.Orders
|
||||
.Include(o => o.Products)
|
||||
.ThenInclude(o => o.Product)
|
||||
.FirstOrDefault(o => o.Id == model.Id)?
|
||||
.GetViewModel;
|
||||
|
||||
}
|
||||
|
||||
public OrderViewModel? Insert(OrderBindingModel model)
|
||||
{
|
||||
using var context = new ComputerHardwareStoreDBContext();
|
||||
var newOrder = Order.Create(context, model);
|
||||
if (newOrder == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
context.Orders.Add(newOrder);
|
||||
context.SaveChanges();
|
||||
return newOrder.GetViewModel;
|
||||
}
|
||||
|
||||
public OrderViewModel? Update(OrderBindingModel model)
|
||||
{
|
||||
using var context = new ComputerHardwareStoreDBContext();
|
||||
using var transaction = context.Database.BeginTransaction();
|
||||
try
|
||||
{
|
||||
var order = context.Orders
|
||||
.Include(o => o.Products)
|
||||
.ThenInclude(o => o.Product)
|
||||
.FirstOrDefault(o => o.Id == model.Id);
|
||||
if (order == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
order.Update(model);
|
||||
context.SaveChanges();
|
||||
transaction.Commit();
|
||||
return order.GetViewModel;
|
||||
}
|
||||
catch
|
||||
{
|
||||
transaction.Rollback();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public OrderViewModel? Delete(OrderBindingModel model)
|
||||
{
|
||||
using var context = new ComputerHardwareStoreDBContext();
|
||||
var element = context.Orders
|
||||
.Include(o => o.Products)
|
||||
.ThenInclude(o => o.Product)
|
||||
.FirstOrDefault(o => o.Id == model.Id);
|
||||
if (element != null)
|
||||
{
|
||||
context.Orders.Remove(element);
|
||||
context.SaveChanges();
|
||||
return element.GetViewModel;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,108 @@
|
||||
using ComputerHardwareStoreContracts.BindingModels;
|
||||
using ComputerHardwareStoreContracts.SearchModels;
|
||||
using ComputerHardwareStoreContracts.StorageContracts;
|
||||
using ComputerHardwareStoreContracts.ViewModels;
|
||||
using ComputerHardwareStoreDatabaseImplement.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace ComputerHardwareStoreDatabaseImplement.Implements
|
||||
{
|
||||
public class ProductStorage : IProductStorage
|
||||
{
|
||||
public List<ProductViewModel> GetFullList()
|
||||
{
|
||||
using var context = new ComputerHardwareStoreDBContext();
|
||||
return context.Products
|
||||
.Include(p => p.Components)
|
||||
.ThenInclude(p => p.Component)
|
||||
.Select(p => p.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public List<ProductViewModel> GetFilteredList(ProductSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.Name))
|
||||
{
|
||||
return new();
|
||||
}
|
||||
using var context = new ComputerHardwareStoreDBContext();
|
||||
return context.Products
|
||||
.Where(p => (p.StoreKeeper.Id == model.StoreKeeperId)
|
||||
// есть хотя бы 1 общий со сборкой компонент
|
||||
&& (!model.BuildId.HasValue || p.Components.FirstOrDefault
|
||||
(c => c.Component.BuldComponents.FirstOrDefault(
|
||||
b => b.BuildId == model.BuildId)
|
||||
!= null)
|
||||
!= null))
|
||||
.Include(p => p.Components)
|
||||
.ThenInclude(p => p.Component)
|
||||
.Select(p => p.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public ProductViewModel? GetElement(ProductSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.Name) && !model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new ComputerHardwareStoreDBContext();
|
||||
return context.Products
|
||||
.Include(p => p.Components)
|
||||
.ThenInclude(p => p.Component)
|
||||
.FirstOrDefault(p =>
|
||||
(!string.IsNullOrEmpty(model.Name) && p.Name == model.Name) ||
|
||||
(model.Id.HasValue && p.Id == model.Id))?
|
||||
.GetViewModel;
|
||||
}
|
||||
|
||||
public ProductViewModel? Insert(ProductBindingModel model)
|
||||
{
|
||||
using var context = new ComputerHardwareStoreDBContext();
|
||||
var newProduct = Product.Create(context, model);
|
||||
if (newProduct == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
context.Products.Add(newProduct);
|
||||
context.SaveChanges();
|
||||
return context.Products
|
||||
.Include(p => p.Components)
|
||||
.ThenInclude(p => p.Component)
|
||||
.FirstOrDefault(p => p.Id == newProduct.Id)?
|
||||
.GetViewModel;
|
||||
}
|
||||
|
||||
public ProductViewModel? Update(ProductBindingModel model)
|
||||
{
|
||||
using var context = new ComputerHardwareStoreDBContext();
|
||||
var product = context.Products
|
||||
.Include(p => p.Components)
|
||||
.ThenInclude(p => p.Component)
|
||||
.FirstOrDefault(p => p.Id == model.Id);
|
||||
if (product == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
context.Update(model);
|
||||
context.SaveChanges();
|
||||
return product.GetViewModel;
|
||||
}
|
||||
|
||||
public ProductViewModel? Delete(ProductBindingModel model)
|
||||
{
|
||||
using var context = new ComputerHardwareStoreDBContext();
|
||||
var product = context.Products
|
||||
.Include(p => p.Components)
|
||||
.ThenInclude(p => p.Component)
|
||||
.FirstOrDefault(p => p.Id == model.Id);
|
||||
if (product == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
context.Products.Remove(product);
|
||||
context.SaveChanges();
|
||||
return product.GetViewModel;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,117 @@
|
||||
using ComputerHardwareStoreContracts.BindingModels;
|
||||
using ComputerHardwareStoreContracts.SearchModels;
|
||||
using ComputerHardwareStoreContracts.StorageContracts;
|
||||
using ComputerHardwareStoreContracts.ViewModels;
|
||||
using ComputerHardwareStoreDatabaseImplement.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace ComputerHardwareStoreDatabaseImplement.Implements
|
||||
{
|
||||
public class PurchaseStorage : IPurchaseStorage
|
||||
{
|
||||
public List<PurchaseViewModel> GetFullList()
|
||||
{
|
||||
using var context = new ComputerHardwareStoreDBContext();
|
||||
return context.Purchases
|
||||
.Include(p => p.Builds)
|
||||
.ThenInclude(p => p.Build)
|
||||
.Include(p => p.Products)
|
||||
.ThenInclude(p => p.Product)
|
||||
.Select(p => p.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public List<PurchaseViewModel> GetFilteredList(PurchaseSearchModel model)
|
||||
{
|
||||
using var context = new ComputerHardwareStoreDBContext();
|
||||
return context.Purchases
|
||||
.Include(p => p.Builds)
|
||||
.ThenInclude(p => p.Build)
|
||||
.Include(p => p.Products)
|
||||
.ThenInclude(p => p.Product)
|
||||
.Where(p =>
|
||||
(model.Id.HasValue && p.Id == model.Id) ||
|
||||
((model.DateFrom.HasValue && model.DateTo.HasValue) &&
|
||||
((model.DateFrom <= p.DateCreate && p.DateCreate <= model.DateTo) ||
|
||||
(p.DateImplement.HasValue && p.DateCreate < model.DateFrom && model.DateFrom < p.DateImplement)))
|
||||
)
|
||||
.Select(p => p.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public PurchaseViewModel? GetElement(PurchaseSearchModel model)
|
||||
{
|
||||
if (!model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new ComputerHardwareStoreDBContext();
|
||||
return context.Purchases
|
||||
.Include(p => p.Builds)
|
||||
.ThenInclude(p => p.Build)
|
||||
.Include(p => p.Products)
|
||||
.ThenInclude(p => p.Product)
|
||||
.FirstOrDefault(p => p.Id == model.Id)?
|
||||
.GetViewModel;
|
||||
}
|
||||
|
||||
public PurchaseViewModel? Insert(PurchaseBindingModel model)
|
||||
{
|
||||
using var context = new ComputerHardwareStoreDBContext();
|
||||
var newPurchase = Purchase.Create(context, model);
|
||||
if (newPurchase == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
context.Purchases.Add(newPurchase);
|
||||
context.SaveChanges();
|
||||
return newPurchase.GetViewModel;
|
||||
}
|
||||
|
||||
public PurchaseViewModel? Update(PurchaseBindingModel model)
|
||||
{
|
||||
using var context = new ComputerHardwareStoreDBContext();
|
||||
using var transaction = context.Database.BeginTransaction();
|
||||
try
|
||||
{
|
||||
var purchase = context.Purchases
|
||||
.Include(p => p.Builds)
|
||||
.ThenInclude(p => p.Build)
|
||||
.Include(p => p.Products)
|
||||
.ThenInclude(p => p.Product)
|
||||
.FirstOrDefault(p => p.Id == model.Id);
|
||||
if (purchase == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
purchase.Update(model);
|
||||
context.SaveChanges();
|
||||
transaction.Commit();
|
||||
return purchase.GetViewModel;
|
||||
}
|
||||
catch
|
||||
{
|
||||
transaction.Rollback();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public PurchaseViewModel? Delete(PurchaseBindingModel model)
|
||||
{
|
||||
using var context = new ComputerHardwareStoreDBContext();
|
||||
var element = context.Purchases
|
||||
.Include(p => p.Builds)
|
||||
.ThenInclude(p => p.Build)
|
||||
.Include(p => p.Products)
|
||||
.ThenInclude(p => p.Product)
|
||||
.FirstOrDefault(o => o.Id == model.Id);
|
||||
if (element != null)
|
||||
{
|
||||
context.Purchases.Remove(element);
|
||||
context.SaveChanges();
|
||||
return element.GetViewModel;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,86 @@
|
||||
using ComputerHardwareStoreContracts.BindingModels;
|
||||
using ComputerHardwareStoreContracts.SearchModels;
|
||||
using ComputerHardwareStoreContracts.StorageContracts;
|
||||
using ComputerHardwareStoreContracts.ViewModels;
|
||||
using ComputerHardwareStoreDatabaseImplement.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace ComputerHardwareStoreDatabaseImplement.Implements
|
||||
{
|
||||
public class StoreKeeperStorage : IStoreKeeperStorage
|
||||
{
|
||||
public StoreKeeperViewModel? GetElement(StoreKeeperSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.Login) && !model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new ComputerHardwareStoreDBContext();
|
||||
return context.StoreKeepers
|
||||
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.Login)
|
||||
&& x.Login == model.Login)
|
||||
|| (model.Id.HasValue && x.Id == model.Id))
|
||||
?.GetViewModel;
|
||||
}
|
||||
|
||||
public List<StoreKeeperViewModel> GetFilteredList(StoreKeeperSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.Login))
|
||||
{
|
||||
return new();
|
||||
}
|
||||
using var context = new ComputerHardwareStoreDBContext();
|
||||
return context.StoreKeepers
|
||||
.Where(x => x.Login.Contains(model.Login))
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public List<StoreKeeperViewModel> GetFullList()
|
||||
{
|
||||
using var context = new ComputerHardwareStoreDBContext();
|
||||
return context.StoreKeepers
|
||||
.Include(x => x.Components)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public StoreKeeperViewModel? Insert(StoreKeeperBindingModel model)
|
||||
{
|
||||
using var context = new ComputerHardwareStoreDBContext();
|
||||
var newStoreKeeper = StoreKeeper.Create(context, model);
|
||||
if (newStoreKeeper == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
context.StoreKeepers.Add(newStoreKeeper);
|
||||
context.SaveChanges();
|
||||
return newStoreKeeper.GetViewModel;
|
||||
}
|
||||
|
||||
public StoreKeeperViewModel? Update(StoreKeeperBindingModel model)
|
||||
{
|
||||
using var context = new ComputerHardwareStoreDBContext();
|
||||
var element = context.StoreKeepers.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (element == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
element.Update(model);
|
||||
context.SaveChanges();
|
||||
return element.GetViewModel;
|
||||
}
|
||||
public StoreKeeperViewModel? Delete(StoreKeeperBindingModel model)
|
||||
{
|
||||
using var context = new ComputerHardwareStoreDBContext();
|
||||
var element = context.StoreKeepers.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
if (element != null)
|
||||
{
|
||||
context.StoreKeepers.Remove(element);
|
||||
context.SaveChanges();
|
||||
return element.GetViewModel;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,84 @@
|
||||
using ComputerHardwareStoreContracts.BindingModels;
|
||||
using ComputerHardwareStoreContracts.SearchModels;
|
||||
using ComputerHardwareStoreContracts.StorageContracts;
|
||||
using ComputerHardwareStoreContracts.ViewModels;
|
||||
using ComputerHardwareStoreDatabaseImplement.Models;
|
||||
|
||||
namespace ComputerHardwareStoreDatabaseImplement.Implements
|
||||
{
|
||||
public class VendorStorage : IVendorStorage
|
||||
{
|
||||
public VendorViewModel? GetElement(VendorSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.Login) && !model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new ComputerHardwareStoreDBContext();
|
||||
return context.Vendors
|
||||
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.Login)
|
||||
&& x.Login == model.Login)
|
||||
|| (model.Id.HasValue && x.Id == model.Id))
|
||||
?.GetViewModel;
|
||||
}
|
||||
|
||||
public List<VendorViewModel> GetFilteredList(VendorSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.Login))
|
||||
{
|
||||
return new();
|
||||
}
|
||||
using var context = new ComputerHardwareStoreDBContext();
|
||||
return context.Vendors
|
||||
.Where(x => x.Login.Contains(model.Login))
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public List<VendorViewModel> GetFullList()
|
||||
{
|
||||
using var context = new ComputerHardwareStoreDBContext();
|
||||
return context.Vendors
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public VendorViewModel? Insert(VendorBindingModel model)
|
||||
{
|
||||
using var context = new ComputerHardwareStoreDBContext();
|
||||
var newVendor = Vendor.Create(context, model);
|
||||
if (newVendor == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
context.Vendors.Add(newVendor);
|
||||
context.SaveChanges();
|
||||
return newVendor.GetViewModel;
|
||||
}
|
||||
|
||||
public VendorViewModel? Update(VendorBindingModel model)
|
||||
{
|
||||
using var context = new ComputerHardwareStoreDBContext();
|
||||
var element = context.Vendors.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (element == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
element.Update(model);
|
||||
context.SaveChanges();
|
||||
return element.GetViewModel;
|
||||
}
|
||||
public VendorViewModel? Delete(VendorBindingModel model)
|
||||
{
|
||||
using var context = new ComputerHardwareStoreDBContext();
|
||||
var element = context.Vendors.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
if (element != null)
|
||||
{
|
||||
context.Vendors.Remove(element);
|
||||
context.SaveChanges();
|
||||
return element.GetViewModel;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
547
ComputerHardwareStore/ComputerHardwareStoreDatabaseImplement/Migrations/20240501130816_fix.Designer.cs
generated
Normal file
547
ComputerHardwareStore/ComputerHardwareStoreDatabaseImplement/Migrations/20240501130816_fix.Designer.cs
generated
Normal file
@ -0,0 +1,547 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using ComputerHardwareStoreDatabaseImplement;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace ComputerHardwareStoreDatabaseImplement.Migrations
|
||||
{
|
||||
[DbContext(typeof(ComputerHardwareStoreDBContext))]
|
||||
[Migration("20240501130816_fix")]
|
||||
partial class fix
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "8.0.4")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||
|
||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.Build", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<double>("Price")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.Property<int>("VendorId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("VendorId");
|
||||
|
||||
b.ToTable("Builds");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.BuildComponent", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("BuildId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("ComponentId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("BuildId");
|
||||
|
||||
b.HasIndex("ComponentId");
|
||||
|
||||
b.ToTable("BuildComponents");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.Comment", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("BuildId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<DateTime>("Date")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.Property<string>("Text")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("BuildId");
|
||||
|
||||
b.ToTable("Comments");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.Component", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<double>("Cost")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int>("StoreKeeperId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("StoreKeeperId");
|
||||
|
||||
b.ToTable("Components");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.Order", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<DateTime>("DateCreate")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.Property<DateTime?>("DateImplement")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.Property<int>("Status")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<double>("Sum")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Orders");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.OrderProduct", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("OrderId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("ProductId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("OrderId");
|
||||
|
||||
b.HasIndex("ProductId");
|
||||
|
||||
b.ToTable("OrderProducts");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.Product", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<double>("Price")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.Property<int?>("StoreKeeperId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("StoreKeeperId");
|
||||
|
||||
b.ToTable("Products");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.ProductComponent", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("ComponentId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("ProductId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ComponentId");
|
||||
|
||||
b.HasIndex("ProductId");
|
||||
|
||||
b.ToTable("ProductComponents");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.Purchase", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<double>("Cost")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.Property<DateTime>("DateCreate")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.Property<DateTime?>("DateImplement")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.Property<int>("VendorId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("VendorId");
|
||||
|
||||
b.ToTable("Purchases");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.PurchaseBuild", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("BuildId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("PurchaseId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("BuildId");
|
||||
|
||||
b.HasIndex("PurchaseId");
|
||||
|
||||
b.ToTable("PurchaseBuilds");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.PurchaseProduct", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("ProductId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("PurchaseId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ProductId");
|
||||
|
||||
b.HasIndex("PurchaseId");
|
||||
|
||||
b.ToTable("PurchaseProducts");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.StoreKeeper", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Login")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("Password")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("StoreKeepers");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.Vendor", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Login")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("Password")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Vendors");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.Build", b =>
|
||||
{
|
||||
b.HasOne("ComputerHardwareStoreDatabaseImplement.Models.Vendor", "Vendor")
|
||||
.WithMany("Builds")
|
||||
.HasForeignKey("VendorId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Vendor");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.BuildComponent", b =>
|
||||
{
|
||||
b.HasOne("ComputerHardwareStoreDatabaseImplement.Models.Build", "Build")
|
||||
.WithMany("Components")
|
||||
.HasForeignKey("BuildId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("ComputerHardwareStoreDatabaseImplement.Models.Component", "Component")
|
||||
.WithMany()
|
||||
.HasForeignKey("ComponentId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Build");
|
||||
|
||||
b.Navigation("Component");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.Comment", b =>
|
||||
{
|
||||
b.HasOne("ComputerHardwareStoreDatabaseImplement.Models.Build", "Build")
|
||||
.WithMany()
|
||||
.HasForeignKey("BuildId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Build");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.Component", b =>
|
||||
{
|
||||
b.HasOne("ComputerHardwareStoreDatabaseImplement.Models.StoreKeeper", "StoreKeeperЗЛ")
|
||||
.WithMany("Components")
|
||||
.HasForeignKey("StoreKeeperId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("StoreKeeperЗЛ");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.OrderProduct", b =>
|
||||
{
|
||||
b.HasOne("ComputerHardwareStoreDatabaseImplement.Models.Order", "Order")
|
||||
.WithMany("Products")
|
||||
.HasForeignKey("OrderId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("ComputerHardwareStoreDatabaseImplement.Models.Product", "Product")
|
||||
.WithMany()
|
||||
.HasForeignKey("ProductId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Order");
|
||||
|
||||
b.Navigation("Product");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.Product", b =>
|
||||
{
|
||||
b.HasOne("ComputerHardwareStoreDatabaseImplement.Models.StoreKeeper", null)
|
||||
.WithMany("Products")
|
||||
.HasForeignKey("StoreKeeperId");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.ProductComponent", b =>
|
||||
{
|
||||
b.HasOne("ComputerHardwareStoreDatabaseImplement.Models.Component", "Component")
|
||||
.WithMany("ProductComponents")
|
||||
.HasForeignKey("ComponentId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("ComputerHardwareStoreDatabaseImplement.Models.Product", "Product")
|
||||
.WithMany("Components")
|
||||
.HasForeignKey("ProductId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Component");
|
||||
|
||||
b.Navigation("Product");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.Purchase", b =>
|
||||
{
|
||||
b.HasOne("ComputerHardwareStoreDatabaseImplement.Models.Vendor", null)
|
||||
.WithMany("Purchases")
|
||||
.HasForeignKey("VendorId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.PurchaseBuild", b =>
|
||||
{
|
||||
b.HasOne("ComputerHardwareStoreDatabaseImplement.Models.Build", "Build")
|
||||
.WithMany()
|
||||
.HasForeignKey("BuildId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("ComputerHardwareStoreDatabaseImplement.Models.Purchase", "Purchase")
|
||||
.WithMany("Builds")
|
||||
.HasForeignKey("PurchaseId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Build");
|
||||
|
||||
b.Navigation("Purchase");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.PurchaseProduct", b =>
|
||||
{
|
||||
b.HasOne("ComputerHardwareStoreDatabaseImplement.Models.Product", "Product")
|
||||
.WithMany()
|
||||
.HasForeignKey("ProductId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("ComputerHardwareStoreDatabaseImplement.Models.Purchase", "Purchase")
|
||||
.WithMany("Products")
|
||||
.HasForeignKey("PurchaseId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Product");
|
||||
|
||||
b.Navigation("Purchase");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.Build", b =>
|
||||
{
|
||||
b.Navigation("Components");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.Component", b =>
|
||||
{
|
||||
b.Navigation("ProductComponents");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.Order", b =>
|
||||
{
|
||||
b.Navigation("Products");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.Product", b =>
|
||||
{
|
||||
b.Navigation("Components");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.Purchase", b =>
|
||||
{
|
||||
b.Navigation("Builds");
|
||||
|
||||
b.Navigation("Products");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.StoreKeeper", b =>
|
||||
{
|
||||
b.Navigation("Components");
|
||||
|
||||
b.Navigation("Products");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.Vendor", b =>
|
||||
{
|
||||
b.Navigation("Builds");
|
||||
|
||||
b.Navigation("Purchases");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,80 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace ComputerHardwareStoreDatabaseImplement.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class fix : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "FK_Orders_Products_ProductId",
|
||||
table: "Orders");
|
||||
|
||||
migrationBuilder.DropIndex(
|
||||
name: "IX_Orders_ProductId",
|
||||
table: "Orders");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "Count",
|
||||
table: "Orders");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "ProductId",
|
||||
table: "Orders");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Comments_BuildId",
|
||||
table: "Comments",
|
||||
column: "BuildId");
|
||||
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "FK_Comments_Builds_BuildId",
|
||||
table: "Comments",
|
||||
column: "BuildId",
|
||||
principalTable: "Builds",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "FK_Comments_Builds_BuildId",
|
||||
table: "Comments");
|
||||
|
||||
migrationBuilder.DropIndex(
|
||||
name: "IX_Comments_BuildId",
|
||||
table: "Comments");
|
||||
|
||||
migrationBuilder.AddColumn<int>(
|
||||
name: "Count",
|
||||
table: "Orders",
|
||||
type: "integer",
|
||||
nullable: false,
|
||||
defaultValue: 0);
|
||||
|
||||
migrationBuilder.AddColumn<int>(
|
||||
name: "ProductId",
|
||||
table: "Orders",
|
||||
type: "integer",
|
||||
nullable: true);
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Orders_ProductId",
|
||||
table: "Orders",
|
||||
column: "ProductId");
|
||||
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "FK_Orders_Products_ProductId",
|
||||
table: "Orders",
|
||||
column: "ProductId",
|
||||
principalTable: "Products",
|
||||
principalColumn: "Id");
|
||||
}
|
||||
}
|
||||
}
|
566
ComputerHardwareStore/ComputerHardwareStoreDatabaseImplement/Migrations/20240501142223_cs2.Designer.cs
generated
Normal file
566
ComputerHardwareStore/ComputerHardwareStoreDatabaseImplement/Migrations/20240501142223_cs2.Designer.cs
generated
Normal file
@ -0,0 +1,566 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using ComputerHardwareStoreDatabaseImplement;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace ComputerHardwareStoreDatabaseImplement.Migrations
|
||||
{
|
||||
[DbContext(typeof(ComputerHardwareStoreDBContext))]
|
||||
[Migration("20240501142223_cs2")]
|
||||
partial class cs2
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "8.0.4")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||
|
||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.Build", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<double>("Price")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.Property<int>("VendorId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("VendorId");
|
||||
|
||||
b.ToTable("Builds");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.BuildComponent", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("BuildId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("ComponentId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("BuildId");
|
||||
|
||||
b.HasIndex("ComponentId");
|
||||
|
||||
b.ToTable("BuildComponents");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.Comment", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("BuildId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<DateTime>("Date")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.Property<string>("Text")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("BuildId");
|
||||
|
||||
b.ToTable("Comments");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.Component", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<double>("Cost")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int>("StoreKeeperId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("StoreKeeperId");
|
||||
|
||||
b.ToTable("Components");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.Order", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<DateTime>("DateCreate")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.Property<DateTime?>("DateImplement")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.Property<int?>("ProductId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("Status")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<double>("Sum")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ProductId");
|
||||
|
||||
b.ToTable("Orders");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.OrderProduct", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("OrderId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("ProductId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("OrderId");
|
||||
|
||||
b.HasIndex("ProductId");
|
||||
|
||||
b.ToTable("OrderProducts");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.Product", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<double>("Price")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.Property<int?>("StoreKeeperId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("StoreKeeperId");
|
||||
|
||||
b.ToTable("Products");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.ProductComponent", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("ComponentId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("ProductId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ComponentId");
|
||||
|
||||
b.HasIndex("ProductId");
|
||||
|
||||
b.ToTable("ProductComponents");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.Purchase", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<double>("Cost")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.Property<DateTime>("DateCreate")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.Property<DateTime?>("DateImplement")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.Property<int>("VendorId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("VendorId");
|
||||
|
||||
b.ToTable("Purchases");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.PurchaseBuild", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("BuildId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("PurchaseId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("BuildId");
|
||||
|
||||
b.HasIndex("PurchaseId");
|
||||
|
||||
b.ToTable("PurchaseBuilds");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.PurchaseProduct", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("ProductId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("PurchaseId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ProductId");
|
||||
|
||||
b.HasIndex("PurchaseId");
|
||||
|
||||
b.ToTable("PurchaseProducts");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.StoreKeeper", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Login")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("Password")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("StoreKeepers");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.Vendor", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Login")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("Password")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Vendors");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.Build", b =>
|
||||
{
|
||||
b.HasOne("ComputerHardwareStoreDatabaseImplement.Models.Vendor", "Vendor")
|
||||
.WithMany("Builds")
|
||||
.HasForeignKey("VendorId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Vendor");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.BuildComponent", b =>
|
||||
{
|
||||
b.HasOne("ComputerHardwareStoreDatabaseImplement.Models.Build", "Build")
|
||||
.WithMany("Components")
|
||||
.HasForeignKey("BuildId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("ComputerHardwareStoreDatabaseImplement.Models.Component", "Component")
|
||||
.WithMany("BuldComponents")
|
||||
.HasForeignKey("ComponentId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Build");
|
||||
|
||||
b.Navigation("Component");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.Comment", b =>
|
||||
{
|
||||
b.HasOne("ComputerHardwareStoreDatabaseImplement.Models.Build", "Build")
|
||||
.WithMany()
|
||||
.HasForeignKey("BuildId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Build");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.Component", b =>
|
||||
{
|
||||
b.HasOne("ComputerHardwareStoreDatabaseImplement.Models.StoreKeeper", "StoreKeeperЗЛ")
|
||||
.WithMany("Components")
|
||||
.HasForeignKey("StoreKeeperId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("StoreKeeperЗЛ");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.Order", b =>
|
||||
{
|
||||
b.HasOne("ComputerHardwareStoreDatabaseImplement.Models.Product", null)
|
||||
.WithMany("Orders")
|
||||
.HasForeignKey("ProductId");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.OrderProduct", b =>
|
||||
{
|
||||
b.HasOne("ComputerHardwareStoreDatabaseImplement.Models.Order", "Order")
|
||||
.WithMany("Products")
|
||||
.HasForeignKey("OrderId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("ComputerHardwareStoreDatabaseImplement.Models.Product", "Product")
|
||||
.WithMany()
|
||||
.HasForeignKey("ProductId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Order");
|
||||
|
||||
b.Navigation("Product");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.Product", b =>
|
||||
{
|
||||
b.HasOne("ComputerHardwareStoreDatabaseImplement.Models.StoreKeeper", null)
|
||||
.WithMany("Products")
|
||||
.HasForeignKey("StoreKeeperId");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.ProductComponent", b =>
|
||||
{
|
||||
b.HasOne("ComputerHardwareStoreDatabaseImplement.Models.Component", "Component")
|
||||
.WithMany("ProductComponents")
|
||||
.HasForeignKey("ComponentId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("ComputerHardwareStoreDatabaseImplement.Models.Product", "Product")
|
||||
.WithMany("Components")
|
||||
.HasForeignKey("ProductId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Component");
|
||||
|
||||
b.Navigation("Product");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.Purchase", b =>
|
||||
{
|
||||
b.HasOne("ComputerHardwareStoreDatabaseImplement.Models.Vendor", null)
|
||||
.WithMany("Purchases")
|
||||
.HasForeignKey("VendorId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.PurchaseBuild", b =>
|
||||
{
|
||||
b.HasOne("ComputerHardwareStoreDatabaseImplement.Models.Build", "Build")
|
||||
.WithMany()
|
||||
.HasForeignKey("BuildId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("ComputerHardwareStoreDatabaseImplement.Models.Purchase", "Purchase")
|
||||
.WithMany("Builds")
|
||||
.HasForeignKey("PurchaseId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Build");
|
||||
|
||||
b.Navigation("Purchase");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.PurchaseProduct", b =>
|
||||
{
|
||||
b.HasOne("ComputerHardwareStoreDatabaseImplement.Models.Product", "Product")
|
||||
.WithMany()
|
||||
.HasForeignKey("ProductId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("ComputerHardwareStoreDatabaseImplement.Models.Purchase", "Purchase")
|
||||
.WithMany("Products")
|
||||
.HasForeignKey("PurchaseId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Product");
|
||||
|
||||
b.Navigation("Purchase");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.Build", b =>
|
||||
{
|
||||
b.Navigation("Components");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.Component", b =>
|
||||
{
|
||||
b.Navigation("BuldComponents");
|
||||
|
||||
b.Navigation("ProductComponents");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.Order", b =>
|
||||
{
|
||||
b.Navigation("Products");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.Product", b =>
|
||||
{
|
||||
b.Navigation("Components");
|
||||
|
||||
b.Navigation("Orders");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.Purchase", b =>
|
||||
{
|
||||
b.Navigation("Builds");
|
||||
|
||||
b.Navigation("Products");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.StoreKeeper", b =>
|
||||
{
|
||||
b.Navigation("Components");
|
||||
|
||||
b.Navigation("Products");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.Vendor", b =>
|
||||
{
|
||||
b.Navigation("Builds");
|
||||
|
||||
b.Navigation("Purchases");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,59 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace ComputerHardwareStoreDatabaseImplement.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class cs2 : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AddColumn<int>(
|
||||
name: "Count",
|
||||
table: "Orders",
|
||||
type: "integer",
|
||||
nullable: false,
|
||||
defaultValue: 0);
|
||||
|
||||
migrationBuilder.AddColumn<int>(
|
||||
name: "ProductId",
|
||||
table: "Orders",
|
||||
type: "integer",
|
||||
nullable: true);
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Orders_ProductId",
|
||||
table: "Orders",
|
||||
column: "ProductId");
|
||||
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "FK_Orders_Products_ProductId",
|
||||
table: "Orders",
|
||||
column: "ProductId",
|
||||
principalTable: "Products",
|
||||
principalColumn: "Id");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "FK_Orders_Products_ProductId",
|
||||
table: "Orders");
|
||||
|
||||
migrationBuilder.DropIndex(
|
||||
name: "IX_Orders_ProductId",
|
||||
table: "Orders");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "Count",
|
||||
table: "Orders");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "ProductId",
|
||||
table: "Orders");
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,563 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using ComputerHardwareStoreDatabaseImplement;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace ComputerHardwareStoreDatabaseImplement.Migrations
|
||||
{
|
||||
[DbContext(typeof(ComputerHardwareStoreDBContext))]
|
||||
partial class ComputerHardwareStoreDBContextModelSnapshot : ModelSnapshot
|
||||
{
|
||||
protected override void BuildModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "8.0.4")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||
|
||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.Build", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<double>("Price")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.Property<int>("VendorId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("VendorId");
|
||||
|
||||
b.ToTable("Builds");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.BuildComponent", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("BuildId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("ComponentId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("BuildId");
|
||||
|
||||
b.HasIndex("ComponentId");
|
||||
|
||||
b.ToTable("BuildComponents");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.Comment", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("BuildId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<DateTime>("Date")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.Property<string>("Text")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("BuildId");
|
||||
|
||||
b.ToTable("Comments");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.Component", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<double>("Cost")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int>("StoreKeeperId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("StoreKeeperId");
|
||||
|
||||
b.ToTable("Components");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.Order", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<DateTime>("DateCreate")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.Property<DateTime?>("DateImplement")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.Property<int?>("ProductId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("Status")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<double>("Sum")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ProductId");
|
||||
|
||||
b.ToTable("Orders");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.OrderProduct", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("OrderId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("ProductId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("OrderId");
|
||||
|
||||
b.HasIndex("ProductId");
|
||||
|
||||
b.ToTable("OrderProducts");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.Product", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<double>("Price")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.Property<int?>("StoreKeeperId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("StoreKeeperId");
|
||||
|
||||
b.ToTable("Products");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.ProductComponent", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("ComponentId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("ProductId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ComponentId");
|
||||
|
||||
b.HasIndex("ProductId");
|
||||
|
||||
b.ToTable("ProductComponents");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.Purchase", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<double>("Cost")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.Property<DateTime>("DateCreate")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.Property<DateTime?>("DateImplement")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.Property<int>("VendorId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("VendorId");
|
||||
|
||||
b.ToTable("Purchases");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.PurchaseBuild", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("BuildId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("PurchaseId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("BuildId");
|
||||
|
||||
b.HasIndex("PurchaseId");
|
||||
|
||||
b.ToTable("PurchaseBuilds");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.PurchaseProduct", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("ProductId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("PurchaseId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ProductId");
|
||||
|
||||
b.HasIndex("PurchaseId");
|
||||
|
||||
b.ToTable("PurchaseProducts");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.StoreKeeper", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Login")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("Password")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("StoreKeepers");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.Vendor", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Login")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("Password")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Vendors");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.Build", b =>
|
||||
{
|
||||
b.HasOne("ComputerHardwareStoreDatabaseImplement.Models.Vendor", "Vendor")
|
||||
.WithMany("Builds")
|
||||
.HasForeignKey("VendorId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Vendor");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.BuildComponent", b =>
|
||||
{
|
||||
b.HasOne("ComputerHardwareStoreDatabaseImplement.Models.Build", "Build")
|
||||
.WithMany("Components")
|
||||
.HasForeignKey("BuildId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("ComputerHardwareStoreDatabaseImplement.Models.Component", "Component")
|
||||
.WithMany("BuldComponents")
|
||||
.HasForeignKey("ComponentId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Build");
|
||||
|
||||
b.Navigation("Component");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.Comment", b =>
|
||||
{
|
||||
b.HasOne("ComputerHardwareStoreDatabaseImplement.Models.Build", "Build")
|
||||
.WithMany()
|
||||
.HasForeignKey("BuildId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Build");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.Component", b =>
|
||||
{
|
||||
b.HasOne("ComputerHardwareStoreDatabaseImplement.Models.StoreKeeper", "StoreKeeperЗЛ")
|
||||
.WithMany("Components")
|
||||
.HasForeignKey("StoreKeeperId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("StoreKeeperЗЛ");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.Order", b =>
|
||||
{
|
||||
b.HasOne("ComputerHardwareStoreDatabaseImplement.Models.Product", null)
|
||||
.WithMany("Orders")
|
||||
.HasForeignKey("ProductId");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.OrderProduct", b =>
|
||||
{
|
||||
b.HasOne("ComputerHardwareStoreDatabaseImplement.Models.Order", "Order")
|
||||
.WithMany("Products")
|
||||
.HasForeignKey("OrderId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("ComputerHardwareStoreDatabaseImplement.Models.Product", "Product")
|
||||
.WithMany()
|
||||
.HasForeignKey("ProductId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Order");
|
||||
|
||||
b.Navigation("Product");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.Product", b =>
|
||||
{
|
||||
b.HasOne("ComputerHardwareStoreDatabaseImplement.Models.StoreKeeper", null)
|
||||
.WithMany("Products")
|
||||
.HasForeignKey("StoreKeeperId");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.ProductComponent", b =>
|
||||
{
|
||||
b.HasOne("ComputerHardwareStoreDatabaseImplement.Models.Component", "Component")
|
||||
.WithMany("ProductComponents")
|
||||
.HasForeignKey("ComponentId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("ComputerHardwareStoreDatabaseImplement.Models.Product", "Product")
|
||||
.WithMany("Components")
|
||||
.HasForeignKey("ProductId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Component");
|
||||
|
||||
b.Navigation("Product");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.Purchase", b =>
|
||||
{
|
||||
b.HasOne("ComputerHardwareStoreDatabaseImplement.Models.Vendor", null)
|
||||
.WithMany("Purchases")
|
||||
.HasForeignKey("VendorId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.PurchaseBuild", b =>
|
||||
{
|
||||
b.HasOne("ComputerHardwareStoreDatabaseImplement.Models.Build", "Build")
|
||||
.WithMany()
|
||||
.HasForeignKey("BuildId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("ComputerHardwareStoreDatabaseImplement.Models.Purchase", "Purchase")
|
||||
.WithMany("Builds")
|
||||
.HasForeignKey("PurchaseId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Build");
|
||||
|
||||
b.Navigation("Purchase");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.PurchaseProduct", b =>
|
||||
{
|
||||
b.HasOne("ComputerHardwareStoreDatabaseImplement.Models.Product", "Product")
|
||||
.WithMany()
|
||||
.HasForeignKey("ProductId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("ComputerHardwareStoreDatabaseImplement.Models.Purchase", "Purchase")
|
||||
.WithMany("Products")
|
||||
.HasForeignKey("PurchaseId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Product");
|
||||
|
||||
b.Navigation("Purchase");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.Build", b =>
|
||||
{
|
||||
b.Navigation("Components");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.Component", b =>
|
||||
{
|
||||
b.Navigation("BuldComponents");
|
||||
|
||||
b.Navigation("ProductComponents");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.Order", b =>
|
||||
{
|
||||
b.Navigation("Products");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.Product", b =>
|
||||
{
|
||||
b.Navigation("Components");
|
||||
|
||||
b.Navigation("Orders");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.Purchase", b =>
|
||||
{
|
||||
b.Navigation("Builds");
|
||||
|
||||
b.Navigation("Products");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.StoreKeeper", b =>
|
||||
{
|
||||
b.Navigation("Components");
|
||||
|
||||
b.Navigation("Products");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.Vendor", b =>
|
||||
{
|
||||
b.Navigation("Builds");
|
||||
|
||||
b.Navigation("Purchases");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,88 @@
|
||||
using ComputerHardwareStoreContracts.BindingModels;
|
||||
using ComputerHardwareStoreContracts.ViewModels;
|
||||
using ComputerHardwareStoreDataModels.Models;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Internal;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace ComputerHardwareStoreDatabaseImplement.Models
|
||||
{
|
||||
public class Build : IBuildModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[Required]
|
||||
public string Name { get; set; } = string.Empty;
|
||||
[Required]
|
||||
public double Price { get; set; }
|
||||
[NotMapped]
|
||||
private Dictionary<int, (IComponentModel, int)>? _buildComponents = null;
|
||||
[NotMapped]
|
||||
public Dictionary<int, (IComponentModel, int)> BuildComponents
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_buildComponents == null)
|
||||
{
|
||||
_buildComponents = Components
|
||||
.ToDictionary(bc => bc.ComponentId, bc =>
|
||||
(bc.Component as IComponentModel, bc.Count));
|
||||
}
|
||||
return _buildComponents;
|
||||
}
|
||||
}
|
||||
[ForeignKey("BuildId")]
|
||||
public virtual List<BuildComponent> Components { get; set; } = new();
|
||||
[ForeignKey("BuildId")]
|
||||
|
||||
public virtual List<Comment> Comments { get; set; } = new();
|
||||
[NotMapped]
|
||||
List<ICommentModel> IBuildModel.Comments => Comments.Select(c => c as ICommentModel).ToList();
|
||||
|
||||
public virtual Vendor Vendor { get; private set; } = new();
|
||||
IVendorModel IBuildModel.Vendor => Vendor as IVendorModel;
|
||||
|
||||
public static Build? Create(ComputerHardwareStoreDBContext context, BuildBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new()
|
||||
{
|
||||
Id = model.Id,
|
||||
Name = model.Name,
|
||||
Price = model.Price,
|
||||
Vendor = context.Vendors.First(v => v.Id == model.Vendor.Id),
|
||||
Components = context.Components
|
||||
.Where(c => model.BuildComponents.ContainsKey(c.Id))
|
||||
.Select(c => new BuildComponent()
|
||||
{
|
||||
BuildId = model.Id,
|
||||
ComponentId = c.Id,
|
||||
Component = c,
|
||||
Count = model.BuildComponents[c.Id].Item2
|
||||
}).ToList()
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(BuildBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Name = string.IsNullOrEmpty(model.Name) ? Name : model.Name;
|
||||
Price = model.Price;
|
||||
}
|
||||
|
||||
public BuildViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
Name = Name,
|
||||
Price = Price,
|
||||
Vendor = Vendor,
|
||||
Comments = Comments.Select(c => c as ICommentModel).ToList(),
|
||||
BuildComponents = BuildComponents
|
||||
};
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ComputerHardwareStoreDatabaseImplement.Models
|
||||
{
|
||||
public class BuildComponent
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[Required]
|
||||
public int BuildId { get; set; }
|
||||
[Required]
|
||||
public int ComponentId { get; set; }
|
||||
[Required]
|
||||
public int Count { get; set; }
|
||||
public virtual Build Build { get; set; } = new();
|
||||
public virtual Component Component { get; set; } = new();
|
||||
}
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
using ComputerHardwareStoreContracts.BindingModels;
|
||||
using ComputerHardwareStoreContracts.ViewModels;
|
||||
using ComputerHardwareStoreDataModels.Models;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace ComputerHardwareStoreDatabaseImplement.Models
|
||||
{
|
||||
public class Comment : ICommentModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[Required]
|
||||
public DateTime Date { get; set; }
|
||||
[Required]
|
||||
public string Text { get; set; } = string.Empty;
|
||||
[Required]
|
||||
public int BuildId { get; set; }
|
||||
public virtual Build Build { get; set; } = new();
|
||||
public static Comment? Create(CommentBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new()
|
||||
{
|
||||
Id = model.Id,
|
||||
Date = model.Date,
|
||||
Text = model.Text,
|
||||
BuildId = model.BuildId,
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(CommentBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Text = model.Text;
|
||||
}
|
||||
|
||||
public CommentViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
Date = Date,
|
||||
Text = Text,
|
||||
};
|
||||
}
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
using ComputerHardwareStoreContracts.BindingModels;
|
||||
using ComputerHardwareStoreContracts.ViewModels;
|
||||
using ComputerHardwareStoreDataModels.Models;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace ComputerHardwareStoreDatabaseImplement.Models
|
||||
{
|
||||
public class Component : IComponentModel
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
[Required]
|
||||
public string Name { get; private set; } = string.Empty;
|
||||
[Required]
|
||||
public double Cost { get; set; }
|
||||
[Required]
|
||||
public virtual StoreKeeper? StoreKeeperЗЛ { get; set; }
|
||||
[NotMapped]
|
||||
public IStoreKeeperModel? StoreKeeper { get; set; }
|
||||
|
||||
[ForeignKey("ComponentId")]
|
||||
public virtual List<ProductComponent> ProductComponents { get; set; } = new();
|
||||
[ForeignKey("ComponentId")]
|
||||
public virtual List<BuildComponent> BuldComponents { get; set; } = new();
|
||||
public static Component? Create(ComponentBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Component()
|
||||
{
|
||||
Id = model.Id,
|
||||
Name = model.Name,
|
||||
Cost = model.Cost,
|
||||
StoreKeeper = model.StoreKeeper
|
||||
};
|
||||
}
|
||||
public void Update (ComponentBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Name = string.IsNullOrEmpty(model.Name) ? Name : model.Name;
|
||||
Cost = model.Cost;
|
||||
}
|
||||
|
||||
public ComponentViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
Name = Name,
|
||||
Cost = Cost
|
||||
};
|
||||
}
|
||||
}
|
@ -0,0 +1,84 @@
|
||||
using ComputerHardwareStoreContracts.BindingModels;
|
||||
using ComputerHardwareStoreContracts.ViewModels;
|
||||
using ComputerHardwareStoreDataModels.Enums;
|
||||
using ComputerHardwareStoreDataModels.Models;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace ComputerHardwareStoreDatabaseImplement.Models
|
||||
{
|
||||
public class Order : IOrderModel
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
[Required]
|
||||
public int Count { get; set; }
|
||||
[Required]
|
||||
public double Sum { get; set; }
|
||||
[Required]
|
||||
public OrderStatus Status { get; set; } = OrderStatus.Неизвестен;
|
||||
[Required]
|
||||
public DateTime DateCreate { get; set; } = DateTime.Now;
|
||||
public DateTime? DateImplement { get; set; }
|
||||
|
||||
private Dictionary<int, (IProductModel, int)>? _orderProducts = null;
|
||||
[NotMapped]
|
||||
public Dictionary<int, (IProductModel, int)> OrderProducts
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_orderProducts == null)
|
||||
{
|
||||
_orderProducts = Products
|
||||
.ToDictionary(
|
||||
op => op.ProductId,
|
||||
op => (op.Product as IProductModel, op.Count));
|
||||
}
|
||||
return _orderProducts;
|
||||
}
|
||||
}
|
||||
[ForeignKey("OrderId")]
|
||||
public virtual List<OrderProduct> Products { get; set; } = new();
|
||||
public static Order? Create(ComputerHardwareStoreDBContext context, OrderBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Order()
|
||||
{
|
||||
Id = model.Id,
|
||||
Sum = model.Sum,
|
||||
Status = model.Status,
|
||||
DateCreate = model.DateCreate,
|
||||
DateImplement = model.DateImplement,
|
||||
Products = context.Products
|
||||
.Where(p => model.OrderProducts.ContainsKey(p.Id))
|
||||
.Select(p => new OrderProduct()
|
||||
{
|
||||
OrderId = model.Id,
|
||||
ProductId = p.Id,
|
||||
Product = p,
|
||||
Count = model.OrderProducts[p.Id].Item2
|
||||
})
|
||||
.ToList()
|
||||
};
|
||||
}
|
||||
public void Update(OrderBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Status = model.Status;
|
||||
DateImplement = model.DateImplement;
|
||||
}
|
||||
public OrderViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
Sum = Sum,
|
||||
Status = Status,
|
||||
DateCreate = DateCreate,
|
||||
DateImplement = DateImplement,
|
||||
};
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace ComputerHardwareStoreDatabaseImplement.Models
|
||||
{
|
||||
public class OrderProduct
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[Required]
|
||||
public int OrderId { get; set; }
|
||||
[Required]
|
||||
public int ProductId { get; set; }
|
||||
[Required]
|
||||
public int Count { get; set; }
|
||||
public virtual Product Product { get; set; } = new();
|
||||
public virtual Order Order { get; set; } = new();
|
||||
}
|
||||
}
|
@ -0,0 +1,102 @@
|
||||
using ComputerHardwareStoreContracts.BindingModels;
|
||||
using ComputerHardwareStoreContracts.ViewModels;
|
||||
using ComputerHardwareStoreDataModels.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace ComputerHardwareStoreDatabaseImplement.Models
|
||||
{
|
||||
public class Product : IProductModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[Required]
|
||||
public string Name { get; set; } = string.Empty;
|
||||
[Required]
|
||||
public double Price { get; set; }
|
||||
[NotMapped]
|
||||
IStoreKeeperModel IProductModel.StoreKeeper => StoreKeeper;
|
||||
public virtual StoreKeeper StoreKeeper {get; set;} = new();
|
||||
private Dictionary<int, (IComponentModel, int)>? _productComponents = null;
|
||||
[NotMapped]
|
||||
public Dictionary<int, (IComponentModel, int)> ProductComponents
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_productComponents == null)
|
||||
{
|
||||
_productComponents = Components
|
||||
.ToDictionary(c => c.ComponentId, c => (c.Component as IComponentModel, c.Count));
|
||||
}
|
||||
return _productComponents;
|
||||
}
|
||||
}
|
||||
[ForeignKey("ProductId")]
|
||||
public virtual List<ProductComponent> Components { get; set; } = new();
|
||||
[ForeignKey("ProductId")]
|
||||
public virtual List<Order> Orders { get; set; } = new();
|
||||
public static Product Create(ComputerHardwareStoreDBContext context, ProductBindingModel model)
|
||||
{
|
||||
return new Product()
|
||||
{
|
||||
Id = model.Id,
|
||||
Name = model.Name,
|
||||
Price = model.Price,
|
||||
Components = context.Components
|
||||
.Where(c => model.ProductComponents.ContainsKey(c.Id))
|
||||
.Select(c => new ProductComponent()
|
||||
{
|
||||
ProductId = model.Id,
|
||||
ComponentId = c.Id,
|
||||
Component = c,
|
||||
Count = model.ProductComponents[c.Id].Item2
|
||||
}).ToList(),
|
||||
};
|
||||
}
|
||||
public void Update(ProductBindingModel model)
|
||||
{
|
||||
Name = string.IsNullOrEmpty(model.Name) ? Name : model.Name;
|
||||
Price = model.Price;
|
||||
|
||||
}
|
||||
public ProductViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
Name = Name,
|
||||
Price = Price,
|
||||
ProductComponents = ProductComponents,
|
||||
StoreKeeper = StoreKeeper,
|
||||
};
|
||||
|
||||
public static void UpdateComponents(ComputerHardwareStoreDBContext context, ProductBindingModel model)
|
||||
{
|
||||
var productComponents = context.ProductComponents
|
||||
.Where(pc => pc.ProductId == model.Id)
|
||||
.ToList();
|
||||
if (productComponents.Count != 0 && productComponents.Count > 0)
|
||||
{
|
||||
// удалили те, которых нет в модели
|
||||
context.ProductComponents
|
||||
.Where(pc => !model.ProductComponents.ContainsKey(pc.ComponentId))
|
||||
.ExecuteDelete();
|
||||
// обновили количество у существующих записей
|
||||
productComponents
|
||||
.ForEach(updateComponent =>
|
||||
{
|
||||
updateComponent.Count = model.ProductComponents[updateComponent.ComponentId].Item2;
|
||||
model.ProductComponents.Remove(updateComponent.ComponentId);
|
||||
});
|
||||
}
|
||||
// добавили новые
|
||||
context.ProductComponents
|
||||
.AddRange(model.ProductComponents.Values
|
||||
.Select(val => new ProductComponent()
|
||||
{
|
||||
ProductId = model.Id,
|
||||
ComponentId = val.Item1.Id,
|
||||
Count = val.Item2
|
||||
}));
|
||||
context.SaveChanges();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace ComputerHardwareStoreDatabaseImplement.Models
|
||||
{
|
||||
public class ProductComponent
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[Required]
|
||||
public int ProductId { get; set; }
|
||||
[Required]
|
||||
public int ComponentId { get; set; }
|
||||
[Required]
|
||||
public int Count { get; set; }
|
||||
public virtual Component Component { get; set; } = new();
|
||||
public virtual Product Product { get; set; } = new();
|
||||
}
|
||||
}
|
@ -0,0 +1,159 @@
|
||||
|
||||
using ComputerHardwareStoreContracts.BindingModels;
|
||||
using ComputerHardwareStoreContracts.ViewModels;
|
||||
using ComputerHardwareStoreDataModels.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace ComputerHardwareStoreDatabaseImplement.Models
|
||||
{
|
||||
public class Purchase : IPurchaseModel
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
[Required]
|
||||
public int VendorId { get; set; }
|
||||
[Required]
|
||||
public double Cost { get; set; }
|
||||
[Required]
|
||||
public DateTime DateCreate { get; set; } = DateTime.Now;
|
||||
public DateTime? DateImplement { get; set; } = null;
|
||||
private Dictionary<int, (IBuildModel, int)>? _purchaseBuilds = null;
|
||||
[NotMapped]
|
||||
public Dictionary<int, (IBuildModel, int)> PurchaseBuilds
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_purchaseBuilds == null)
|
||||
{
|
||||
_purchaseBuilds = Builds
|
||||
.ToDictionary(op => op.BuildId, op => (op.Build as IBuildModel, op.Count));
|
||||
}
|
||||
return _purchaseBuilds;
|
||||
}
|
||||
}
|
||||
|
||||
[ForeignKey("PurchaseId")]
|
||||
public virtual List<PurchaseBuild> Builds { get; set; } = new();
|
||||
private Dictionary<int, (IProductModel, int)>? _purchaseProducts = null;
|
||||
[NotMapped]
|
||||
public Dictionary<int, (IProductModel, int)> PurchaseProducts
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_purchaseProducts == null)
|
||||
{
|
||||
_purchaseProducts = Products
|
||||
.ToDictionary(op => op.ProductId, op => (op.Product as IProductModel, op.Count));
|
||||
}
|
||||
return _purchaseProducts;
|
||||
}
|
||||
}
|
||||
[ForeignKey("PurchaseId")]
|
||||
public virtual List<PurchaseProduct> Products { get; set; } = new();
|
||||
|
||||
public static Purchase Create(ComputerHardwareStoreDBContext context, PurchaseBindingModel model)
|
||||
{
|
||||
return new Purchase()
|
||||
{
|
||||
Id = model.Id,
|
||||
Cost = model.Cost,
|
||||
DateCreate = model.DateCreate,
|
||||
Builds = context.Builds
|
||||
.Where(b => model.PurchaseBuilds.ContainsKey(b.Id))
|
||||
.Select(b => new PurchaseBuild()
|
||||
{
|
||||
PurchaseId = model.Id,
|
||||
BuildId = b.Id,
|
||||
Build = b,
|
||||
Count = model.PurchaseProducts[b.Id].Item2
|
||||
}).ToList(),
|
||||
Products = context.Products
|
||||
.Where(p => model.PurchaseProducts.ContainsKey(p.Id))
|
||||
.Select (p => new PurchaseProduct()
|
||||
{
|
||||
PurchaseId = model.Id,
|
||||
ProductId = p.Id,
|
||||
Product = p,
|
||||
Count = model.PurchaseProducts[p.Id].Item2
|
||||
})
|
||||
.ToList()
|
||||
};
|
||||
}
|
||||
public void Update(PurchaseBindingModel model)
|
||||
{
|
||||
Cost = model.Cost;
|
||||
|
||||
}
|
||||
public PurchaseViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
Cost = Cost,
|
||||
DateCreate = DateCreate,
|
||||
PurchaseBuilds = PurchaseBuilds,
|
||||
PurchaseProducts = PurchaseProducts
|
||||
};
|
||||
|
||||
public static void UpdateBuilds(ComputerHardwareStoreDBContext context, PurchaseBindingModel model)
|
||||
{
|
||||
var productBuilds = context.PurchaseBuilds
|
||||
.Where(pc => pc.PurchaseId == model.Id)
|
||||
.ToList();
|
||||
if (productBuilds.Count != 0 && productBuilds.Count > 0)
|
||||
{
|
||||
// удалили те, которых нет в модели
|
||||
context.PurchaseBuilds
|
||||
.Where(pc => !model.PurchaseBuilds.ContainsKey(pc.BuildId))
|
||||
.ExecuteDelete();
|
||||
// обновили количество у существующих записей
|
||||
productBuilds
|
||||
.ForEach(updateBuild =>
|
||||
{
|
||||
updateBuild.Count = model.PurchaseBuilds[updateBuild.BuildId].Item2;
|
||||
model.PurchaseBuilds.Remove(updateBuild.BuildId);
|
||||
});
|
||||
}
|
||||
// добавили новые
|
||||
context.PurchaseBuilds
|
||||
.AddRange(model.PurchaseBuilds.Values
|
||||
.Select(val => new PurchaseBuild()
|
||||
{
|
||||
PurchaseId = model.Id,
|
||||
BuildId = val.Item1.Id,
|
||||
Count = val.Item2
|
||||
}));
|
||||
context.SaveChanges();
|
||||
}
|
||||
|
||||
public static void UpdateProducts(ComputerHardwareStoreDBContext context, PurchaseBindingModel model)
|
||||
{
|
||||
var productProducts = context.PurchaseProducts
|
||||
.Where(pc => pc.PurchaseId == model.Id)
|
||||
.ToList();
|
||||
if (productProducts.Count != 0 && productProducts.Count > 0)
|
||||
{
|
||||
// удалили те, которых нет в модели
|
||||
context.PurchaseProducts
|
||||
.Where(pc => !model.PurchaseProducts.ContainsKey(pc.ProductId))
|
||||
.ExecuteDelete();
|
||||
// обновили количество у существующих записей
|
||||
productProducts
|
||||
.ForEach(updateProduct =>
|
||||
{
|
||||
updateProduct.Count = model.PurchaseProducts[updateProduct.ProductId].Item2;
|
||||
model.PurchaseProducts.Remove(updateProduct.ProductId);
|
||||
});
|
||||
}
|
||||
// добавили новые
|
||||
context.PurchaseProducts
|
||||
.AddRange(model.PurchaseProducts.Values
|
||||
.Select(val => new PurchaseProduct()
|
||||
{
|
||||
PurchaseId = model.Id,
|
||||
ProductId = val.Item1.Id,
|
||||
Count = val.Item2
|
||||
}));
|
||||
context.SaveChanges();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace ComputerHardwareStoreDatabaseImplement.Models
|
||||
{
|
||||
public class PurchaseBuild
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[Required]
|
||||
public int PurchaseId { get; set; }
|
||||
[Required]
|
||||
public int BuildId { get; set; }
|
||||
[Required]
|
||||
public int Count { get; set; }
|
||||
public virtual Purchase Purchase { get; set; } = new();
|
||||
public virtual Build Build { get; set; } = new();
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace ComputerHardwareStoreDatabaseImplement.Models
|
||||
{
|
||||
public class PurchaseProduct
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[Required]
|
||||
public int PurchaseId { get; set; }
|
||||
[Required]
|
||||
public int ProductId { get; set; }
|
||||
[Required]
|
||||
public int Count { get; set; }
|
||||
public virtual Purchase Purchase { get; set; } = new();
|
||||
public virtual Product Product { get; set; } = new();
|
||||
}
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
using ComputerHardwareStoreContracts.BindingModels;
|
||||
using ComputerHardwareStoreContracts.ViewModels;
|
||||
using ComputerHardwareStoreDataModels.Models;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace ComputerHardwareStoreDatabaseImplement.Models
|
||||
{
|
||||
public class StoreKeeper : IStoreKeeperModel
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
[Required]
|
||||
public string Name { get; private set; } = string.Empty;
|
||||
[Required]
|
||||
|
||||
public string Login { get; private set; } = string.Empty;
|
||||
[Required]
|
||||
public string Password { get; private set; } = string.Empty;
|
||||
[ForeignKey("StoreKeeperId")]
|
||||
public virtual List<Product> Products { get; set; } = new();
|
||||
[ForeignKey("StoreKeeperId")]
|
||||
public virtual List<Component> Components { get; set; } = new();
|
||||
|
||||
public static StoreKeeper? Create(ComputerHardwareStoreDBContext context, StoreKeeperBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new StoreKeeper()
|
||||
{
|
||||
Id = model.Id,
|
||||
Name = model.Name,
|
||||
Login = model.Login,
|
||||
Password = model.Password,
|
||||
};
|
||||
}
|
||||
public void Update(StoreKeeperBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Name = string.IsNullOrEmpty(model.Name) ? Name : model.Name;
|
||||
Password = string.IsNullOrEmpty(model.Password) ? Password : model.Password;
|
||||
}
|
||||
|
||||
public StoreKeeperViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
Name = Name,
|
||||
Login = Login,
|
||||
Password = Password
|
||||
};
|
||||
}
|
||||
}
|
@ -0,0 +1,57 @@
|
||||
using ComputerHardwareStoreContracts.BindingModels;
|
||||
using ComputerHardwareStoreContracts.ViewModels;
|
||||
using ComputerHardwareStoreDataModels.Models;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace ComputerHardwareStoreDatabaseImplement.Models
|
||||
{
|
||||
public class Vendor : IVendorModel
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
[Required]
|
||||
public string Name { get; private set; } = string.Empty;
|
||||
[Required]
|
||||
|
||||
public string Login { get; private set; } = string.Empty;
|
||||
[Required]
|
||||
|
||||
public string Password { get; private set; } = string.Empty;
|
||||
[ForeignKey("VendorId")]
|
||||
public virtual List<Purchase> Purchases { get; set; } = new();
|
||||
[ForeignKey("VendorId")]
|
||||
public virtual List<Build> Builds { get; set; } = new();
|
||||
|
||||
public static Vendor? Create(ComputerHardwareStoreDBContext context, VendorBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Vendor()
|
||||
{
|
||||
Id = model.Id,
|
||||
Name = model.Name,
|
||||
Login = model.Login,
|
||||
Password = model.Password,
|
||||
};
|
||||
}
|
||||
public void Update(VendorBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Name = string.IsNullOrEmpty(model.Name) ? Name : model.Name;
|
||||
Password = string.IsNullOrEmpty(model.Password) ? Password : model.Password;
|
||||
}
|
||||
|
||||
public VendorViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
Name = Name,
|
||||
Login = Login,
|
||||
Password = Password
|
||||
};
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.4">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.4">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="8.0.2" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\ComputerHardwareStoreDatabaseImplement\ComputerHardwareStoreDatabaseImplement.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
@ -0,0 +1,87 @@
|
||||
using ComputerHardwareStoreContracts.BindingModels;
|
||||
using ComputerHardwareStoreContracts.SearchModels;
|
||||
using ComputerHardwareStoreContracts.StorageContracts;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace ComputerHardwareStoreREST.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Route("[controller]")]
|
||||
public class BuildController : Controller
|
||||
{
|
||||
private readonly ILogger<BuildController> _logger;
|
||||
private readonly IBuildStorage _storage;
|
||||
|
||||
public BuildController(ILogger<BuildController> logger, IBuildStorage storage)
|
||||
{
|
||||
_logger = logger;
|
||||
_storage = storage;
|
||||
}
|
||||
|
||||
[HttpPost("get/filter")]
|
||||
public IActionResult GetByFilter([FromBody] BuildSearchModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = _storage.GetFilteredList(model);
|
||||
return Ok(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return BadRequest(ex.Message);
|
||||
}
|
||||
}
|
||||
[HttpPost("get")]
|
||||
public IActionResult GetById([FromBody] BuildSearchModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = _storage.GetElement(model);
|
||||
return Ok(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return BadRequest(ex.Message);
|
||||
}
|
||||
}
|
||||
[HttpPost("create")]
|
||||
public IActionResult Create([FromBody] BuildBindingModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = _storage.Insert(model);
|
||||
return Ok(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return BadRequest(ex.Message);
|
||||
}
|
||||
}
|
||||
[HttpPut("update")]
|
||||
public IActionResult Update([FromBody] BuildBindingModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = _storage.Update(model);
|
||||
return Ok(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return BadRequest(ex.Message);
|
||||
}
|
||||
}
|
||||
[HttpPost("delete")]
|
||||
public IActionResult Delete([FromBody] BuildBindingModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = _storage.Delete(model);
|
||||
return Ok(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return BadRequest(ex.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,87 @@
|
||||
using ComputerHardwareStoreContracts.BindingModels;
|
||||
using ComputerHardwareStoreContracts.SearchModels;
|
||||
using ComputerHardwareStoreContracts.StorageContracts;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace ComputerHardwareStoreREST.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Route("[controller]")]
|
||||
public class CommentController : Controller
|
||||
{
|
||||
private readonly ILogger<CommentController> _logger;
|
||||
private readonly ICommentStorage _storage;
|
||||
|
||||
public CommentController(ILogger<CommentController> logger, ICommentStorage storage)
|
||||
{
|
||||
_logger = logger;
|
||||
_storage = storage;
|
||||
}
|
||||
|
||||
[HttpPost("get/filter")]
|
||||
public IActionResult GetByFilter([FromBody] CommentSearchModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = _storage.GetFilteredList(model);
|
||||
return Ok(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return BadRequest(ex.Message);
|
||||
}
|
||||
}
|
||||
[HttpPost("get")]
|
||||
public IActionResult GetById([FromBody] CommentSearchModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = _storage.GetElement(model);
|
||||
return Ok(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return BadRequest(ex.Message);
|
||||
}
|
||||
}
|
||||
[HttpPost("create")]
|
||||
public IActionResult Create([FromBody] CommentBindingModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = _storage.Insert(model);
|
||||
return Ok(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return BadRequest(ex.Message);
|
||||
}
|
||||
}
|
||||
[HttpPut("update")]
|
||||
public IActionResult Update([FromBody] CommentBindingModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = _storage.Update(model);
|
||||
return Ok(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return BadRequest(ex.Message);
|
||||
}
|
||||
}
|
||||
[HttpPost("delete")]
|
||||
public IActionResult Delete([FromBody] CommentBindingModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = _storage.Delete(model);
|
||||
return Ok(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return BadRequest(ex.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,87 @@
|
||||
using ComputerHardwareStoreContracts.BindingModels;
|
||||
using ComputerHardwareStoreContracts.SearchModels;
|
||||
using ComputerHardwareStoreContracts.StorageContracts;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace ComputerHardwareStoreREST.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Route("[controller]")]
|
||||
public class OrderController : Controller
|
||||
{
|
||||
private readonly ILogger<OrderController> _logger;
|
||||
private readonly IOrderStorage _storage;
|
||||
|
||||
public OrderController(ILogger<OrderController> logger, IOrderStorage storage)
|
||||
{
|
||||
_logger = logger;
|
||||
_storage = storage;
|
||||
}
|
||||
|
||||
[HttpPost("get/filter")]
|
||||
public IActionResult GetByFilter([FromBody] OrderSearchModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = _storage.GetFilteredList(model);
|
||||
return Ok(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return BadRequest(ex.Message);
|
||||
}
|
||||
}
|
||||
[HttpPost("get")]
|
||||
public IActionResult GetById([FromBody] OrderSearchModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = _storage.GetElement(model);
|
||||
return Ok(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return BadRequest(ex.Message);
|
||||
}
|
||||
}
|
||||
[HttpPost("create")]
|
||||
public IActionResult Create([FromBody] OrderBindingModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = _storage.Insert(model);
|
||||
return Ok(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return BadRequest(ex.Message);
|
||||
}
|
||||
}
|
||||
[HttpPut("update")]
|
||||
public IActionResult Update([FromBody] OrderBindingModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = _storage.Update(model);
|
||||
return Ok(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return BadRequest(ex.Message);
|
||||
}
|
||||
}
|
||||
[HttpPost("delete")]
|
||||
public IActionResult Delete([FromBody] OrderBindingModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = _storage.Delete(model);
|
||||
return Ok(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return BadRequest(ex.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,87 @@
|
||||
using ComputerHardwareStoreContracts.BindingModels;
|
||||
using ComputerHardwareStoreContracts.SearchModels;
|
||||
using ComputerHardwareStoreContracts.StorageContracts;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace ComputerHardwareStoreREST.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Route("[controller]")]
|
||||
public class ProductController : Controller
|
||||
{
|
||||
private readonly ILogger<ProductController> _logger;
|
||||
private readonly IProductStorage _storage;
|
||||
|
||||
public ProductController(ILogger<ProductController> logger, IProductStorage storage)
|
||||
{
|
||||
_logger = logger;
|
||||
_storage = storage;
|
||||
}
|
||||
|
||||
[HttpPost("get/filter")]
|
||||
public IActionResult GetByFilter([FromBody] ProductSearchModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = _storage.GetFilteredList(model);
|
||||
return Ok(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return BadRequest(ex.Message);
|
||||
}
|
||||
}
|
||||
[HttpPost("get")]
|
||||
public IActionResult GetById([FromBody] ProductSearchModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = _storage.GetElement(model);
|
||||
return Ok(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return BadRequest(ex.Message);
|
||||
}
|
||||
}
|
||||
[HttpPost("create")]
|
||||
public IActionResult Create([FromBody] ProductBindingModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = _storage.Insert(model);
|
||||
return Ok(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return BadRequest(ex.Message);
|
||||
}
|
||||
}
|
||||
[HttpPut("update")]
|
||||
public IActionResult Update([FromBody] ProductBindingModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = _storage.Update(model);
|
||||
return Ok(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return BadRequest(ex.Message);
|
||||
}
|
||||
}
|
||||
[HttpPost("delete")]
|
||||
public IActionResult Delete([FromBody] ProductBindingModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = _storage.Delete(model);
|
||||
return Ok(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return BadRequest(ex.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,87 @@
|
||||
using ComputerHardwareStoreContracts.BindingModels;
|
||||
using ComputerHardwareStoreContracts.SearchModels;
|
||||
using ComputerHardwareStoreContracts.StorageContracts;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace ComputerHardwareStoreREST.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Route("[controller]")]
|
||||
public class PurchaseController : Controller
|
||||
{
|
||||
private readonly ILogger<PurchaseController> _logger;
|
||||
private readonly IPurchaseStorage _storage;
|
||||
|
||||
public PurchaseController(ILogger<PurchaseController> logger, IPurchaseStorage storage)
|
||||
{
|
||||
_logger = logger;
|
||||
_storage = storage;
|
||||
}
|
||||
|
||||
[HttpPost("get/filter")]
|
||||
public IActionResult GetByFilter([FromBody] PurchaseSearchModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = _storage.GetFilteredList(model);
|
||||
return Ok(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return BadRequest(ex.Message);
|
||||
}
|
||||
}
|
||||
[HttpPost("get")]
|
||||
public IActionResult GetById([FromBody] PurchaseSearchModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = _storage.GetElement(model);
|
||||
return Ok(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return BadRequest(ex.Message);
|
||||
}
|
||||
}
|
||||
[HttpPost("create")]
|
||||
public IActionResult Create([FromBody] PurchaseBindingModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = _storage.Insert(model);
|
||||
return Ok(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return BadRequest(ex.Message);
|
||||
}
|
||||
}
|
||||
[HttpPut("update")]
|
||||
public IActionResult Update([FromBody] PurchaseBindingModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = _storage.Update(model);
|
||||
return Ok(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return BadRequest(ex.Message);
|
||||
}
|
||||
}
|
||||
[HttpPost("delete")]
|
||||
public IActionResult Delete([FromBody] PurchaseBindingModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = _storage.Delete(model);
|
||||
return Ok(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return BadRequest(ex.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,88 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using ComputerHardwareStoreContracts.BindingModels;
|
||||
using ComputerHardwareStoreContracts.SearchModels;
|
||||
using ComputerHardwareStoreContracts.StorageContracts;
|
||||
|
||||
namespace ComputerHardwareStoreREST.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Route("[controller]")]
|
||||
public class StoreKeepersController : Controller
|
||||
{
|
||||
private readonly ILogger<StoreKeepersController> _logger;
|
||||
private readonly IStoreKeeperStorage _storage;
|
||||
|
||||
public StoreKeepersController(ILogger<StoreKeepersController> logger, IStoreKeeperStorage storage)
|
||||
{
|
||||
_logger = logger;
|
||||
_storage = storage;
|
||||
}
|
||||
|
||||
[HttpPost("get/filter")]
|
||||
public IActionResult GetByFilter([FromBody] StoreKeeperSearchModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = _storage.GetFilteredList(model);
|
||||
return Ok(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return BadRequest(ex.Message);
|
||||
}
|
||||
}
|
||||
[HttpPost("get")]
|
||||
public IActionResult GetById([FromBody] StoreKeeperSearchModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = _storage.GetElement(model);
|
||||
return Ok(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return BadRequest(ex.Message);
|
||||
}
|
||||
}
|
||||
[HttpPost("create")]
|
||||
public IActionResult Create([FromBody] StoreKeeperBindingModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = _storage.Insert(model);
|
||||
return Ok(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return BadRequest(ex.Message);
|
||||
}
|
||||
}
|
||||
[HttpPut("update")]
|
||||
public IActionResult Update([FromBody] StoreKeeperBindingModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = _storage.Update(model);
|
||||
return Ok(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return BadRequest(ex.Message);
|
||||
}
|
||||
}
|
||||
[HttpPost("delete")]
|
||||
public IActionResult Delete([FromBody] StoreKeeperBindingModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = _storage.Delete(model);
|
||||
return Ok(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return BadRequest(ex.Message);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user