lab3 done?
This commit is contained in:
parent
f9a5b37fe4
commit
5d384b8cf9
@ -3,7 +3,7 @@ using SecuritySystemBusinessLogic.BusinessLogics;
|
|||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using NLog.Extensions.Logging;
|
using NLog.Extensions.Logging;
|
||||||
using SecuritySystemFileImplement.Implements;
|
using SecuritySystemDatabaseImplement.Implements;
|
||||||
using SecuritySystemBusinessLogic;
|
using SecuritySystemBusinessLogic;
|
||||||
using SecuritySystemContracts.BusinessLogicsContracts;
|
using SecuritySystemContracts.BusinessLogicsContracts;
|
||||||
using SecuritySystemContracts.StoragesContracts;
|
using SecuritySystemContracts.StoragesContracts;
|
||||||
|
8
SecuritySystem/Properties/launchSettings.json
Normal file
8
SecuritySystem/Properties/launchSettings.json
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"profiles": {
|
||||||
|
"SecuritySystemView": {
|
||||||
|
"commandName": "Project",
|
||||||
|
"sqlDebugging": false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -13,7 +13,13 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SecuritySystemListImplement
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SecuritySystemBusinessLogic", "..\SecuritySystemBusinessLogic\SecuritySystemBusinessLogic.csproj", "{EF5F4167-954D-4414-8F76-372410029641}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SecuritySystemBusinessLogic", "..\SecuritySystemBusinessLogic\SecuritySystemBusinessLogic.csproj", "{EF5F4167-954D-4414-8F76-372410029641}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SecuritySystemFileImplement", "..\SecuritySystemFileImplement\SecuritySystemFileImplement.csproj", "{08B396D8-3E24-48A8-8976-834DCE258DFD}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SecuritySystemFileImplement", "..\SecuritySystemFileImplement\SecuritySystemFileImplement.csproj", "{08B396D8-3E24-48A8-8976-834DCE258DFD}"
|
||||||
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SecuritySystemDatabaseImplement", "..\SecuritySystemDatabaseImplement\SecuritySystemDatabaseImplement.csproj", "{AB7134B4-1BEF-44FC-91DF-76D99BD7C065}"
|
||||||
|
ProjectSection(ProjectDependencies) = postProject
|
||||||
|
{C1C491F5-4CB7-4B6B-92CE-41688769709A} = {C1C491F5-4CB7-4B6B-92CE-41688769709A}
|
||||||
|
{D12D1329-4362-472B-B6E6-D62B0FF00C63} = {D12D1329-4362-472B-B6E6-D62B0FF00C63}
|
||||||
|
EndProjectSection
|
||||||
EndProject
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
@ -45,6 +51,10 @@ Global
|
|||||||
{08B396D8-3E24-48A8-8976-834DCE258DFD}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{08B396D8-3E24-48A8-8976-834DCE258DFD}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{08B396D8-3E24-48A8-8976-834DCE258DFD}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{08B396D8-3E24-48A8-8976-834DCE258DFD}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{08B396D8-3E24-48A8-8976-834DCE258DFD}.Release|Any CPU.Build.0 = Release|Any CPU
|
{08B396D8-3E24-48A8-8976-834DCE258DFD}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{AB7134B4-1BEF-44FC-91DF-76D99BD7C065}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{AB7134B4-1BEF-44FC-91DF-76D99BD7C065}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{AB7134B4-1BEF-44FC-91DF-76D99BD7C065}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{AB7134B4-1BEF-44FC-91DF-76D99BD7C065}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
@ -9,12 +9,17 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.4">
|
||||||
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
</PackageReference>
|
||||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
|
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
|
||||||
<PackageReference Include="NLog.Extensions.Logging" Version="5.2.2" />
|
<PackageReference Include="NLog.Extensions.Logging" Version="5.2.2" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\SecuritySystemBusinessLogic\SecuritySystemBusinessLogic.csproj" />
|
<ProjectReference Include="..\SecuritySystemBusinessLogic\SecuritySystemBusinessLogic.csproj" />
|
||||||
|
<ProjectReference Include="..\SecuritySystemDatabaseImplement\SecuritySystemDatabaseImplement.csproj" />
|
||||||
<ProjectReference Include="..\SecuritySystemFileImplement\SecuritySystemFileImplement.csproj" />
|
<ProjectReference Include="..\SecuritySystemFileImplement\SecuritySystemFileImplement.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
@ -0,0 +1,74 @@
|
|||||||
|
using SecuritySystemDatabaseImplement.Models;
|
||||||
|
using SecuritySystemContracts.BindingModels;
|
||||||
|
using SecuritySystemContracts.SearchModels;
|
||||||
|
using SecuritySystemContracts.StoragesContracts;
|
||||||
|
using SecuritySystemContracts.ViewModels;
|
||||||
|
|
||||||
|
namespace SecuritySystemDatabaseImplement.Implements
|
||||||
|
{
|
||||||
|
public class ComponentStorage : IComponentStorage
|
||||||
|
{
|
||||||
|
public List<ComponentViewModel> GetFullList()
|
||||||
|
{
|
||||||
|
using var context = new SecuritySystemDatabase();
|
||||||
|
return context.Components.Select(x => x.GetViewModel).ToList();
|
||||||
|
}
|
||||||
|
public List<ComponentViewModel> GetFilteredList(ComponentSearchModel model)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(model.ComponentName))
|
||||||
|
{
|
||||||
|
return new();
|
||||||
|
}
|
||||||
|
using var context = new SecuritySystemDatabase();
|
||||||
|
return context.Components
|
||||||
|
.Where(x => x.ComponentName.Contains(model.ComponentName))
|
||||||
|
.Select(x => x.GetViewModel).ToList();
|
||||||
|
}
|
||||||
|
public ComponentViewModel? GetElement(ComponentSearchModel model)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(model.ComponentName) && !model.Id.HasValue)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
using var context = new SecuritySystemDatabase();
|
||||||
|
return context.Components.FirstOrDefault(x => (!string.IsNullOrEmpty(model.ComponentName) && x.ComponentName == model.ComponentName) ||
|
||||||
|
(model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
|
||||||
|
}
|
||||||
|
public ComponentViewModel? Insert(ComponentBindingModel model)
|
||||||
|
{
|
||||||
|
var newComponent = Component.Create(model);
|
||||||
|
if (newComponent == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
using var context = new SecuritySystemDatabase();
|
||||||
|
context.Components.Add(newComponent);
|
||||||
|
context.SaveChanges();
|
||||||
|
return newComponent.GetViewModel;
|
||||||
|
}
|
||||||
|
public ComponentViewModel? Update(ComponentBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new SecuritySystemDatabase();
|
||||||
|
var component = context.Components.FirstOrDefault(x => x.Id == model.Id);
|
||||||
|
if (component == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
component.Update(model);
|
||||||
|
context.SaveChanges();
|
||||||
|
return component.GetViewModel;
|
||||||
|
}
|
||||||
|
public ComponentViewModel? Delete(ComponentBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new SecuritySystemDatabase();
|
||||||
|
var element = context.Components.FirstOrDefault(rec => rec.Id == model.Id);
|
||||||
|
if (element != null)
|
||||||
|
{
|
||||||
|
context.Components.Remove(element);
|
||||||
|
context.SaveChanges();
|
||||||
|
return element.GetViewModel;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
77
SecuritySystemDatabaseImplement/Implements/OrderStorage.cs
Normal file
77
SecuritySystemDatabaseImplement/Implements/OrderStorage.cs
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
using SecuritySystemContracts.BindingModels;
|
||||||
|
using SecuritySystemContracts.SearchModels;
|
||||||
|
using SecuritySystemContracts.StoragesContracts;
|
||||||
|
using SecuritySystemContracts.ViewModels;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using SecuritySystemDatabaseImplement.Models;
|
||||||
|
using SecuritySystemContracts.BindingModels;
|
||||||
|
using SecuritySystemContracts.SearchModels;
|
||||||
|
using SecuritySystemContracts.StoragesContracts;
|
||||||
|
using SecuritySystemContracts.ViewModels;
|
||||||
|
|
||||||
|
namespace SecuritySystemDatabaseImplement.Implements
|
||||||
|
{
|
||||||
|
public class OrderStorage : IOrderStorage
|
||||||
|
{
|
||||||
|
public OrderViewModel? Delete(OrderBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new SecuritySystemDatabase();
|
||||||
|
var element = context.Orders.FirstOrDefault(rec => rec.Id == model.Id);
|
||||||
|
if (element != null)
|
||||||
|
{
|
||||||
|
var deletedElement = context.Orders.Include(x => x.Secure).FirstOrDefault(x => x.Id == model.Id)?.GetViewModel;
|
||||||
|
context.Orders.Remove(element);
|
||||||
|
context.SaveChanges();
|
||||||
|
return deletedElement;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
public OrderViewModel? GetElement(OrderSearchModel model)
|
||||||
|
{
|
||||||
|
if (!model.Id.HasValue)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
using var context = new SecuritySystemDatabase();
|
||||||
|
return context.Orders.Include(x => x.Secure).FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)?.GetViewModel;
|
||||||
|
}
|
||||||
|
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
|
||||||
|
{
|
||||||
|
if (!model.Id.HasValue)
|
||||||
|
{
|
||||||
|
return new();
|
||||||
|
}
|
||||||
|
using var context = new SecuritySystemDatabase();
|
||||||
|
return context.Orders.Include(x => x.Secure).Where(x => x.Id == model.Id).Select(x => x.GetViewModel).ToList();
|
||||||
|
}
|
||||||
|
public List<OrderViewModel> GetFullList()
|
||||||
|
{
|
||||||
|
using var context = new SecuritySystemDatabase();
|
||||||
|
return context.Orders.Include(x => x.Secure).Select(x => x.GetViewModel).ToList();
|
||||||
|
}
|
||||||
|
public OrderViewModel? Insert(OrderBindingModel model)
|
||||||
|
{
|
||||||
|
var newOrder = Order.Create(model);
|
||||||
|
if (newOrder == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
using var context = new SecuritySystemDatabase();
|
||||||
|
context.Orders.Add(newOrder);
|
||||||
|
context.SaveChanges();
|
||||||
|
return context.Orders.Include(x => x.Secure).FirstOrDefault(x => x.Id == newOrder.Id)?.GetViewModel;
|
||||||
|
}
|
||||||
|
public OrderViewModel? Update(OrderBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new SecuritySystemDatabase();
|
||||||
|
var order = context.Orders.FirstOrDefault(x => x.Id == model.Id);
|
||||||
|
if (order == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
order.Update(model);
|
||||||
|
context.SaveChanges();
|
||||||
|
return context.Orders.Include(x => x.Secure).FirstOrDefault(x => x.Id == model.Id)?.GetViewModel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
86
SecuritySystemDatabaseImplement/Implements/SecureStorage.cs
Normal file
86
SecuritySystemDatabaseImplement/Implements/SecureStorage.cs
Normal file
@ -0,0 +1,86 @@
|
|||||||
|
using SecuritySystemContracts.BindingModels;
|
||||||
|
using SecuritySystemContracts.SearchModels;
|
||||||
|
using SecuritySystemContracts.StoragesContracts;
|
||||||
|
using SecuritySystemContracts.ViewModels;
|
||||||
|
using SecuritySystemDatabaseImplement.Models;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
namespace SecuritySystemDatabaseImplement.Implements
|
||||||
|
{
|
||||||
|
public class SecureStorage : ISecureStorage
|
||||||
|
{
|
||||||
|
public List<SecureViewModel> GetFullList()
|
||||||
|
{
|
||||||
|
using var context = new SecuritySystemDatabase();
|
||||||
|
return context.Secures.Include(x => x.Components).ThenInclude(x => x.Component).ToList().Select(x => x.GetViewModel).ToList();
|
||||||
|
}
|
||||||
|
public List<SecureViewModel> GetFilteredList(SecureSearchModel model)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(model.SecureName))
|
||||||
|
{
|
||||||
|
return new();
|
||||||
|
}
|
||||||
|
using var context = new SecuritySystemDatabase();
|
||||||
|
return context.Secures.Include(x => x.Components).ThenInclude(x => x.Component).Where(x => x.SecureName.Contains(model.SecureName)).ToList()
|
||||||
|
.Select(x => x.GetViewModel).ToList();
|
||||||
|
}
|
||||||
|
public SecureViewModel? GetElement(SecureSearchModel model)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(model.SecureName) &&
|
||||||
|
!model.Id.HasValue)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
using var context = new SecuritySystemDatabase();
|
||||||
|
return context.Secures.Include(x => x.Components).ThenInclude(x => x.Component)
|
||||||
|
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.SecureName) && x.SecureName == model.SecureName) || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
|
||||||
|
}
|
||||||
|
public SecureViewModel? Insert(SecureBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new SecuritySystemDatabase();
|
||||||
|
var newSecure = Secure.Create(context, model);
|
||||||
|
if (newSecure == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
context.Secures.Add(newSecure);
|
||||||
|
context.SaveChanges();
|
||||||
|
return newSecure.GetViewModel;
|
||||||
|
}
|
||||||
|
public SecureViewModel? Update(SecureBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new SecuritySystemDatabase();
|
||||||
|
using var transaction = context.Database.BeginTransaction();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var Secure = context.Secures.FirstOrDefault(rec =>
|
||||||
|
rec.Id == model.Id);
|
||||||
|
if (Secure == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
Secure.Update(model);
|
||||||
|
context.SaveChanges();
|
||||||
|
Secure.UpdateComponents(context, model);
|
||||||
|
transaction.Commit();
|
||||||
|
return Secure.GetViewModel;
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
transaction.Rollback();
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public SecureViewModel? Delete(SecureBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new SecuritySystemDatabase();
|
||||||
|
var element = context.Secures.Include(x => x.Components).FirstOrDefault(rec => rec.Id == model.Id);
|
||||||
|
if (element != null)
|
||||||
|
{
|
||||||
|
context.Secures.Remove(element);
|
||||||
|
context.SaveChanges();
|
||||||
|
return element.GetViewModel;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
171
SecuritySystemDatabaseImplement/Migrations/20230320130415_InitialCreate.Designer.cs
generated
Normal file
171
SecuritySystemDatabaseImplement/Migrations/20230320130415_InitialCreate.Designer.cs
generated
Normal file
@ -0,0 +1,171 @@
|
|||||||
|
// <auto-generated />
|
||||||
|
using System;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||||
|
using Microsoft.EntityFrameworkCore.Metadata;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||||
|
using SecuritySystemDatabaseImplement;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace SecuritySystemDatabaseImplement.Migrations
|
||||||
|
{
|
||||||
|
[DbContext(typeof(SecuritySystemDatabase))]
|
||||||
|
[Migration("20230320130415_InitialCreate")]
|
||||||
|
partial class InitialCreate
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||||
|
{
|
||||||
|
#pragma warning disable 612, 618
|
||||||
|
modelBuilder
|
||||||
|
.HasAnnotation("ProductVersion", "7.0.4")
|
||||||
|
.HasAnnotation("Relational:MaxIdentifierLength", 128);
|
||||||
|
|
||||||
|
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
|
||||||
|
|
||||||
|
modelBuilder.Entity("SecuritySystemDatabaseImplement.Models.Component", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<string>("ComponentName")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.Property<double>("Cost")
|
||||||
|
.HasColumnType("float");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("Components");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("SecuritySystemDatabaseImplement.Models.Order", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<int>("Count")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<DateTime>("DateCreate")
|
||||||
|
.HasColumnType("datetime2");
|
||||||
|
|
||||||
|
b.Property<DateTime?>("DateImplement")
|
||||||
|
.HasColumnType("datetime2");
|
||||||
|
|
||||||
|
b.Property<int>("SecureId")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<int>("Status")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<double>("Sum")
|
||||||
|
.HasColumnType("float");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("SecureId");
|
||||||
|
|
||||||
|
b.ToTable("Orders");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("SecuritySystemDatabaseImplement.Models.Secure", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<double>("Price")
|
||||||
|
.HasColumnType("float");
|
||||||
|
|
||||||
|
b.Property<string>("SecureName")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("Secures");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("SecuritySystemDatabaseImplement.Models.SecureComponent", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<int>("ComponentId")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<int>("Count")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<int>("SecureId")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("ComponentId");
|
||||||
|
|
||||||
|
b.HasIndex("SecureId");
|
||||||
|
|
||||||
|
b.ToTable("SecureComponents");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("SecuritySystemDatabaseImplement.Models.Order", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("SecuritySystemDatabaseImplement.Models.Secure", "Secure")
|
||||||
|
.WithMany("Orders")
|
||||||
|
.HasForeignKey("SecureId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("Secure");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("SecuritySystemDatabaseImplement.Models.SecureComponent", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("SecuritySystemDatabaseImplement.Models.Component", "Component")
|
||||||
|
.WithMany("SecureComponents")
|
||||||
|
.HasForeignKey("ComponentId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.HasOne("SecuritySystemDatabaseImplement.Models.Secure", "Secure")
|
||||||
|
.WithMany("Components")
|
||||||
|
.HasForeignKey("SecureId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("Component");
|
||||||
|
|
||||||
|
b.Navigation("Secure");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("SecuritySystemDatabaseImplement.Models.Component", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("SecureComponents");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("SecuritySystemDatabaseImplement.Models.Secure", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("Components");
|
||||||
|
|
||||||
|
b.Navigation("Orders");
|
||||||
|
});
|
||||||
|
#pragma warning restore 612, 618
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,125 @@
|
|||||||
|
using System;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace SecuritySystemDatabaseImplement.Migrations
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
public partial class InitialCreate : Migration
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "Components",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<int>(type: "int", nullable: false)
|
||||||
|
.Annotation("SqlServer:Identity", "1, 1"),
|
||||||
|
ComponentName = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||||
|
Cost = table.Column<double>(type: "float", nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_Components", x => x.Id);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "Secures",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<int>(type: "int", nullable: false)
|
||||||
|
.Annotation("SqlServer:Identity", "1, 1"),
|
||||||
|
SecureName = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||||
|
Price = table.Column<double>(type: "float", nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_Secures", x => x.Id);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "Orders",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<int>(type: "int", nullable: false)
|
||||||
|
.Annotation("SqlServer:Identity", "1, 1"),
|
||||||
|
SecureId = table.Column<int>(type: "int", nullable: false),
|
||||||
|
Count = table.Column<int>(type: "int", nullable: false),
|
||||||
|
Sum = table.Column<double>(type: "float", nullable: false),
|
||||||
|
Status = table.Column<int>(type: "int", nullable: false),
|
||||||
|
DateCreate = table.Column<DateTime>(type: "datetime2", nullable: false),
|
||||||
|
DateImplement = table.Column<DateTime>(type: "datetime2", nullable: true)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_Orders", x => x.Id);
|
||||||
|
table.ForeignKey(
|
||||||
|
name: "FK_Orders_Secures_SecureId",
|
||||||
|
column: x => x.SecureId,
|
||||||
|
principalTable: "Secures",
|
||||||
|
principalColumn: "Id",
|
||||||
|
onDelete: ReferentialAction.Cascade);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "SecureComponents",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<int>(type: "int", nullable: false)
|
||||||
|
.Annotation("SqlServer:Identity", "1, 1"),
|
||||||
|
SecureId = table.Column<int>(type: "int", nullable: false),
|
||||||
|
ComponentId = table.Column<int>(type: "int", nullable: false),
|
||||||
|
Count = table.Column<int>(type: "int", nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_SecureComponents", x => x.Id);
|
||||||
|
table.ForeignKey(
|
||||||
|
name: "FK_SecureComponents_Components_ComponentId",
|
||||||
|
column: x => x.ComponentId,
|
||||||
|
principalTable: "Components",
|
||||||
|
principalColumn: "Id",
|
||||||
|
onDelete: ReferentialAction.Cascade);
|
||||||
|
table.ForeignKey(
|
||||||
|
name: "FK_SecureComponents_Secures_SecureId",
|
||||||
|
column: x => x.SecureId,
|
||||||
|
principalTable: "Secures",
|
||||||
|
principalColumn: "Id",
|
||||||
|
onDelete: ReferentialAction.Cascade);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_Orders_SecureId",
|
||||||
|
table: "Orders",
|
||||||
|
column: "SecureId");
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_SecureComponents_ComponentId",
|
||||||
|
table: "SecureComponents",
|
||||||
|
column: "ComponentId");
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_SecureComponents_SecureId",
|
||||||
|
table: "SecureComponents",
|
||||||
|
column: "SecureId");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "Orders");
|
||||||
|
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "SecureComponents");
|
||||||
|
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "Components");
|
||||||
|
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "Secures");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,168 @@
|
|||||||
|
// <auto-generated />
|
||||||
|
using System;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||||
|
using Microsoft.EntityFrameworkCore.Metadata;
|
||||||
|
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||||
|
using SecuritySystemDatabaseImplement;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace SecuritySystemDatabaseImplement.Migrations
|
||||||
|
{
|
||||||
|
[DbContext(typeof(SecuritySystemDatabase))]
|
||||||
|
partial class SecuritySystemDatabaseModelSnapshot : ModelSnapshot
|
||||||
|
{
|
||||||
|
protected override void BuildModel(ModelBuilder modelBuilder)
|
||||||
|
{
|
||||||
|
#pragma warning disable 612, 618
|
||||||
|
modelBuilder
|
||||||
|
.HasAnnotation("ProductVersion", "7.0.4")
|
||||||
|
.HasAnnotation("Relational:MaxIdentifierLength", 128);
|
||||||
|
|
||||||
|
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
|
||||||
|
|
||||||
|
modelBuilder.Entity("SecuritySystemDatabaseImplement.Models.Component", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<string>("ComponentName")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.Property<double>("Cost")
|
||||||
|
.HasColumnType("float");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("Components");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("SecuritySystemDatabaseImplement.Models.Order", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<int>("Count")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<DateTime>("DateCreate")
|
||||||
|
.HasColumnType("datetime2");
|
||||||
|
|
||||||
|
b.Property<DateTime?>("DateImplement")
|
||||||
|
.HasColumnType("datetime2");
|
||||||
|
|
||||||
|
b.Property<int>("SecureId")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<int>("Status")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<double>("Sum")
|
||||||
|
.HasColumnType("float");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("SecureId");
|
||||||
|
|
||||||
|
b.ToTable("Orders");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("SecuritySystemDatabaseImplement.Models.Secure", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<double>("Price")
|
||||||
|
.HasColumnType("float");
|
||||||
|
|
||||||
|
b.Property<string>("SecureName")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("Secures");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("SecuritySystemDatabaseImplement.Models.SecureComponent", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<int>("ComponentId")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<int>("Count")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<int>("SecureId")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("ComponentId");
|
||||||
|
|
||||||
|
b.HasIndex("SecureId");
|
||||||
|
|
||||||
|
b.ToTable("SecureComponents");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("SecuritySystemDatabaseImplement.Models.Order", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("SecuritySystemDatabaseImplement.Models.Secure", "Secure")
|
||||||
|
.WithMany("Orders")
|
||||||
|
.HasForeignKey("SecureId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("Secure");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("SecuritySystemDatabaseImplement.Models.SecureComponent", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("SecuritySystemDatabaseImplement.Models.Component", "Component")
|
||||||
|
.WithMany("SecureComponents")
|
||||||
|
.HasForeignKey("ComponentId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.HasOne("SecuritySystemDatabaseImplement.Models.Secure", "Secure")
|
||||||
|
.WithMany("Components")
|
||||||
|
.HasForeignKey("SecureId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("Component");
|
||||||
|
|
||||||
|
b.Navigation("Secure");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("SecuritySystemDatabaseImplement.Models.Component", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("SecureComponents");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("SecuritySystemDatabaseImplement.Models.Secure", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("Components");
|
||||||
|
|
||||||
|
b.Navigation("Orders");
|
||||||
|
});
|
||||||
|
#pragma warning restore 612, 618
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
56
SecuritySystemDatabaseImplement/Models/Component.cs
Normal file
56
SecuritySystemDatabaseImplement/Models/Component.cs
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
using SecuritySystemContracts.BindingModels;
|
||||||
|
using SecuritySystemContracts.ViewModels;
|
||||||
|
using SecuritySystemDataModels.Models;
|
||||||
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
|
||||||
|
namespace SecuritySystemDatabaseImplement.Models
|
||||||
|
{
|
||||||
|
public class Component : IComponentModel
|
||||||
|
{
|
||||||
|
public int Id { get; private set; }
|
||||||
|
[Required]
|
||||||
|
public string ComponentName { get; private set; } = string.Empty;
|
||||||
|
[Required]
|
||||||
|
public double Cost { get; set; }
|
||||||
|
[ForeignKey("ComponentId")]
|
||||||
|
public virtual List<SecureComponent> SecureComponents { get; set; } = new();
|
||||||
|
public static Component? Create(ComponentBindingModel model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new Component()
|
||||||
|
{
|
||||||
|
Id = model.Id,
|
||||||
|
ComponentName = model.ComponentName,
|
||||||
|
Cost = model.Cost
|
||||||
|
};
|
||||||
|
}
|
||||||
|
public static Component Create(ComponentViewModel model)
|
||||||
|
{
|
||||||
|
return new Component
|
||||||
|
{
|
||||||
|
Id = model.Id,
|
||||||
|
ComponentName = model.ComponentName,
|
||||||
|
Cost = model.Cost
|
||||||
|
};
|
||||||
|
}
|
||||||
|
public void Update(ComponentBindingModel model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ComponentName = model.ComponentName;
|
||||||
|
Cost = model.Cost;
|
||||||
|
}
|
||||||
|
public ComponentViewModel GetViewModel => new()
|
||||||
|
{
|
||||||
|
Id = Id,
|
||||||
|
ComponentName = ComponentName,
|
||||||
|
Cost = Cost
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
72
SecuritySystemDatabaseImplement/Models/Order.cs
Normal file
72
SecuritySystemDatabaseImplement/Models/Order.cs
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
using SecuritySystemContracts.BindingModels;
|
||||||
|
using SecuritySystemContracts.ViewModels;
|
||||||
|
using SecuritySystemDataModels.Enums;
|
||||||
|
using SecuritySystemDataModels.Models;
|
||||||
|
using SecuritySystemContracts.BindingModels;
|
||||||
|
using SecuritySystemContracts.ViewModels;
|
||||||
|
using SecuritySystemDataModels.Enums;
|
||||||
|
using SecuritySystemDataModels.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace SecuritySystemDatabaseImplement.Models
|
||||||
|
{
|
||||||
|
public class Order : IOrderModel
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
[Required]
|
||||||
|
public int SecureId { get; set; }
|
||||||
|
[Required]
|
||||||
|
public int Count { get; set; }
|
||||||
|
[Required]
|
||||||
|
public double Sum { get; set; }
|
||||||
|
[Required]
|
||||||
|
public OrderStatus Status { get; set; }
|
||||||
|
[Required]
|
||||||
|
public DateTime DateCreate { get; set; }
|
||||||
|
public DateTime? DateImplement { get; set; }
|
||||||
|
public virtual Secure Secure { get; set; }
|
||||||
|
public static Order? Create(OrderBindingModel? model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new Order()
|
||||||
|
{
|
||||||
|
Id = model.Id,
|
||||||
|
SecureId = model.SecureId,
|
||||||
|
Count = model.Count,
|
||||||
|
Sum = model.Sum,
|
||||||
|
Status = model.Status,
|
||||||
|
DateCreate = model.DateCreate,
|
||||||
|
DateImplement = model.DateImplement
|
||||||
|
};
|
||||||
|
}
|
||||||
|
public void Update(OrderBindingModel? model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Status = model.Status;
|
||||||
|
DateImplement = model.DateImplement;
|
||||||
|
}
|
||||||
|
public OrderViewModel GetViewModel => new()
|
||||||
|
{
|
||||||
|
Id = Id,
|
||||||
|
SecureId = SecureId,
|
||||||
|
SecureName = Secure.SecureName,
|
||||||
|
Count = Count,
|
||||||
|
Sum = Sum,
|
||||||
|
Status = Status,
|
||||||
|
DateCreate = DateCreate,
|
||||||
|
DateImplement = DateImplement
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
91
SecuritySystemDatabaseImplement/Models/Secure.cs
Normal file
91
SecuritySystemDatabaseImplement/Models/Secure.cs
Normal file
@ -0,0 +1,91 @@
|
|||||||
|
using SecuritySystemContracts.BindingModels;
|
||||||
|
using SecuritySystemContracts.ViewModels;
|
||||||
|
using SecuritySystemDataModels.Models;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
|
namespace SecuritySystemDatabaseImplement.Models
|
||||||
|
{
|
||||||
|
public class Secure : ISecureModel
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
[Required]
|
||||||
|
public string SecureName { get; set; } = string.Empty;
|
||||||
|
[Required]
|
||||||
|
public double Price { get; set; }
|
||||||
|
private Dictionary<int, (IComponentModel, int)>? _SecureComponents = null;
|
||||||
|
[NotMapped]
|
||||||
|
public Dictionary<int, (IComponentModel, int)> SecureComponents
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (_SecureComponents == null)
|
||||||
|
{
|
||||||
|
_SecureComponents = Components
|
||||||
|
.ToDictionary(recPC => recPC.ComponentId, recPC =>
|
||||||
|
(recPC.Component as IComponentModel, recPC.Count));
|
||||||
|
}
|
||||||
|
return _SecureComponents;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
[ForeignKey("SecureId")]
|
||||||
|
public virtual List<SecureComponent> Components { get; set; } = new();
|
||||||
|
[ForeignKey("SecureId")]
|
||||||
|
public virtual List<Order> Orders { get; set; } = new();
|
||||||
|
public static Secure Create(SecuritySystemDatabase context, SecureBindingModel model)
|
||||||
|
{
|
||||||
|
return new Secure()
|
||||||
|
{
|
||||||
|
Id = model.Id,
|
||||||
|
SecureName = model.SecureName,
|
||||||
|
Price = model.Price,
|
||||||
|
Components = model.SecureComponents.Select(x => new SecureComponent
|
||||||
|
{
|
||||||
|
Component = context.Components.First(y => y.Id == x.Key),
|
||||||
|
Count = x.Value.Item2
|
||||||
|
}).ToList()
|
||||||
|
};
|
||||||
|
}
|
||||||
|
public void Update(SecureBindingModel model)
|
||||||
|
{
|
||||||
|
SecureName = model.SecureName;
|
||||||
|
Price = model.Price;
|
||||||
|
}
|
||||||
|
public SecureViewModel GetViewModel => new()
|
||||||
|
{
|
||||||
|
Id = Id,
|
||||||
|
SecureName = SecureName,
|
||||||
|
Price = Price,
|
||||||
|
SecureComponents = SecureComponents
|
||||||
|
};
|
||||||
|
public void UpdateComponents(SecuritySystemDatabase context, SecureBindingModel model)
|
||||||
|
{
|
||||||
|
var SecureComponents = context.SecureComponents.Where(rec =>
|
||||||
|
rec.SecureId == model.Id).ToList();
|
||||||
|
if (SecureComponents != null && SecureComponents.Count > 0)
|
||||||
|
{ // удалили те, которых нет в модели
|
||||||
|
context.SecureComponents.RemoveRange(SecureComponents.Where(rec
|
||||||
|
=> !model.SecureComponents.ContainsKey(rec.ComponentId)));
|
||||||
|
context.SaveChanges();
|
||||||
|
// обновили количество у существующих записей
|
||||||
|
foreach (var updateComponent in SecureComponents)
|
||||||
|
{
|
||||||
|
updateComponent.Count = model.SecureComponents[updateComponent.ComponentId].Item2;
|
||||||
|
model.SecureComponents.Remove(updateComponent.ComponentId);
|
||||||
|
}
|
||||||
|
context.SaveChanges();
|
||||||
|
}
|
||||||
|
var Secure = context.Secures.First(x => x.Id == Id);
|
||||||
|
foreach (var pc in model.SecureComponents)
|
||||||
|
{
|
||||||
|
context.SecureComponents.Add(new SecureComponent
|
||||||
|
{
|
||||||
|
Secure = Secure,
|
||||||
|
Component = context.Components.First(x => x.Id == pc.Key),
|
||||||
|
Count = pc.Value.Item2
|
||||||
|
});
|
||||||
|
context.SaveChanges();
|
||||||
|
}
|
||||||
|
_SecureComponents = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
17
SecuritySystemDatabaseImplement/Models/SecureComponent.cs
Normal file
17
SecuritySystemDatabaseImplement/Models/SecureComponent.cs
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
|
||||||
|
namespace SecuritySystemDatabaseImplement.Models
|
||||||
|
{
|
||||||
|
public class SecureComponent
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
[Required]
|
||||||
|
public int SecureId { get; set; }
|
||||||
|
[Required]
|
||||||
|
public int ComponentId { get; set; }
|
||||||
|
[Required]
|
||||||
|
public int Count { get; set; }
|
||||||
|
public virtual Component Component { get; set; } = new();
|
||||||
|
public virtual Secure Secure { get; set; } = new();
|
||||||
|
}
|
||||||
|
}
|
21
SecuritySystemDatabaseImplement/SecuritySystem.cs
Normal file
21
SecuritySystemDatabaseImplement/SecuritySystem.cs
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
using SecuritySystemDatabaseImplement.Models;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
|
namespace SecuritySystemDatabaseImplement
|
||||||
|
{
|
||||||
|
public class SecuritySystemDatabase : DbContext
|
||||||
|
{
|
||||||
|
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||||
|
{
|
||||||
|
if (optionsBuilder.IsConfigured == false)
|
||||||
|
{
|
||||||
|
optionsBuilder.UseSqlServer(@"Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=SecuritySystemDatabase;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True");
|
||||||
|
}
|
||||||
|
base.OnConfiguring(optionsBuilder);
|
||||||
|
}
|
||||||
|
public virtual DbSet<Component> Components { set; get; }
|
||||||
|
public virtual DbSet<Secure> Secures { set; get; }
|
||||||
|
public virtual DbSet<SecureComponent> SecureComponents { set; get; }
|
||||||
|
public virtual DbSet<Order> Orders { set; get; }
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,23 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.4" />
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.4" />
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.4">
|
||||||
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
</PackageReference>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\SecuritySystemContracts\SecuritySystemContracts.csproj" />
|
||||||
|
<ProjectReference Include="..\SecuritySystemDataModels\SecuritySystemDataModels.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
Loading…
x
Reference in New Issue
Block a user