done
This commit is contained in:
parent
4ab8a1e27e
commit
50dd6505af
@ -15,6 +15,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SecureShopListImplement", "
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SecureShopFileImplement", "SecureShopFileImplement\SecureShopFileImplement.csproj", "{3E416EAB-041A-46EE-9017-2C3D7127D802}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SecureShopFileImplement", "SecureShopFileImplement\SecureShopFileImplement.csproj", "{3E416EAB-041A-46EE-9017-2C3D7127D802}"
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SecureShopDatabaseImplement", "SecureShopDatabaseImplement\SecureShopDatabaseImplement.csproj", "{E6A53ECF-5E75-4124-B2A3-5BAECD2F2609}"
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
Debug|Any CPU = Debug|Any CPU
|
||||||
@ -45,6 +47,10 @@ Global
|
|||||||
{3E416EAB-041A-46EE-9017-2C3D7127D802}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{3E416EAB-041A-46EE-9017-2C3D7127D802}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{3E416EAB-041A-46EE-9017-2C3D7127D802}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{3E416EAB-041A-46EE-9017-2C3D7127D802}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{3E416EAB-041A-46EE-9017-2C3D7127D802}.Release|Any CPU.Build.0 = Release|Any CPU
|
{3E416EAB-041A-46EE-9017-2C3D7127D802}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{E6A53ECF-5E75-4124-B2A3-5BAECD2F2609}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{E6A53ECF-5E75-4124-B2A3-5BAECD2F2609}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{E6A53ECF-5E75-4124-B2A3-5BAECD2F2609}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{E6A53ECF-5E75-4124-B2A3-5BAECD2F2609}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
using SecureShopBusinessLogic.BusinessLogics;
|
using SecureShopBusinessLogic.BusinessLogics;
|
||||||
using SecureShopContracts.BusinessLogicsContracts;
|
using SecureShopContracts.BusinessLogicsContracts;
|
||||||
using SecureShopContracts.StoragesContracts;
|
using SecureShopContracts.StoragesContracts;
|
||||||
using SecureShopFileImplement.Implements;
|
using SecureShopDataBaseImplement.Implements;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using NLog.Extensions.Logging;
|
using NLog.Extensions.Logging;
|
||||||
|
@ -9,6 +9,10 @@
|
|||||||
</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="Microsoft.Extensions.Logging.Abstractions" Version="7.0.0" />
|
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.0" />
|
||||||
<PackageReference Include="NLog.Extensions.Logging" Version="5.2.1" />
|
<PackageReference Include="NLog.Extensions.Logging" Version="5.2.1" />
|
||||||
@ -17,6 +21,7 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\SecureShopBusinessLogic\SecureShopBusinessLogic.csproj" />
|
<ProjectReference Include="..\SecureShopBusinessLogic\SecureShopBusinessLogic.csproj" />
|
||||||
<ProjectReference Include="..\SecureShopContracts\SecureShopContracts.csproj" />
|
<ProjectReference Include="..\SecureShopContracts\SecureShopContracts.csproj" />
|
||||||
|
<ProjectReference Include="..\SecureShopDatabaseImplement\SecureShopDatabaseImplement.csproj" />
|
||||||
<ProjectReference Include="..\SecureShopFileImplement\SecureShopFileImplement.csproj" />
|
<ProjectReference Include="..\SecureShopFileImplement\SecureShopFileImplement.csproj" />
|
||||||
<ProjectReference Include="..\SecureShopListImplement\SecureShopListImplement.csproj" />
|
<ProjectReference Include="..\SecureShopListImplement\SecureShopListImplement.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
@ -0,0 +1,84 @@
|
|||||||
|
using SecureShopContracts.BindingModels;
|
||||||
|
using SecureShopContracts.SearchModels;
|
||||||
|
using SecureShopContracts.StoragesContracts;
|
||||||
|
using SecureShopContracts.ViewModels;
|
||||||
|
using SecureShopDatabaseImplement.Models;
|
||||||
|
|
||||||
|
namespace SecureShopDatabaseImplement.Implements
|
||||||
|
{
|
||||||
|
public class FacilitiesStorage : IFacilitiesStorage
|
||||||
|
{
|
||||||
|
public List<FacilitiesViewModel> GetFullList()
|
||||||
|
{
|
||||||
|
using var context = new SecureShopDatabase();
|
||||||
|
return context.Facilitiess
|
||||||
|
.Select(x => x.GetViewModel)
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<FacilitiesViewModel> GetFilteredList(FacilitiesSearchModel model)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(model.FacilitiesName))
|
||||||
|
{
|
||||||
|
return new();
|
||||||
|
}
|
||||||
|
using var context = new SecureShopDatabase();
|
||||||
|
return context.Facilitiess
|
||||||
|
.Where(x => x.FacilitiesName.Contains(model.FacilitiesName))
|
||||||
|
.Select(x => x.GetViewModel)
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public FacilitiesViewModel? GetElement(FacilitiesSearchModel model)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(model.FacilitiesName) && !model.Id.HasValue)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
using var context = new SecureShopDatabase();
|
||||||
|
return context.Facilitiess
|
||||||
|
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.FacilitiesName) && x.FacilitiesName == model.FacilitiesName) ||
|
||||||
|
(model.Id.HasValue && x.Id == model.Id))
|
||||||
|
?.GetViewModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public FacilitiesViewModel? Insert(FacilitiesBindingModel model)
|
||||||
|
{
|
||||||
|
var newFacilities = Facilities.Create(model);
|
||||||
|
if (newFacilities == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
using var context = new SecureShopDatabase();
|
||||||
|
context.Facilitiess.Add(newFacilities);
|
||||||
|
context.SaveChanges();
|
||||||
|
return newFacilities.GetViewModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public FacilitiesViewModel? Update(FacilitiesBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new SecureShopDatabase();
|
||||||
|
var Facilities = context.Facilitiess.FirstOrDefault(x => x.Id == model.Id);
|
||||||
|
if (Facilities == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
Facilities.Update(model);
|
||||||
|
context.SaveChanges();
|
||||||
|
return Facilities.GetViewModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public FacilitiesViewModel? Delete(FacilitiesBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new SecureShopDatabase();
|
||||||
|
var element = context.Facilitiess.FirstOrDefault(rec => rec.Id == model.Id);
|
||||||
|
if (element != null)
|
||||||
|
{
|
||||||
|
context.Facilitiess.Remove(element);
|
||||||
|
context.SaveChanges();
|
||||||
|
return element.GetViewModel;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,99 @@
|
|||||||
|
using SecureShopContracts.BindingModels;
|
||||||
|
using SecureShopContracts.SearchModels;
|
||||||
|
using SecureShopContracts.StoragesContracts;
|
||||||
|
using SecureShopContracts.ViewModels;
|
||||||
|
using SecureShopDatabaseImplement.Models;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
|
namespace SecureShopDatabaseImplement.Implements
|
||||||
|
{
|
||||||
|
public class OrderStorage : IOrderStorage
|
||||||
|
{
|
||||||
|
public OrderViewModel? Delete(OrderBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new SecureShopDatabase();
|
||||||
|
var element = context.Orders
|
||||||
|
.FirstOrDefault(rec => rec.Id == model.Id);
|
||||||
|
if (element != null)
|
||||||
|
{
|
||||||
|
// для отображения КОРРЕКТНОЙ viewmodelи
|
||||||
|
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 SecureShopDatabase();
|
||||||
|
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 SecureShopDatabase();
|
||||||
|
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 SecureShopDatabase();
|
||||||
|
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 SecureShopDatabase();
|
||||||
|
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 SecureShopDatabase();
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
107
Secure/SecureShopDatabaseImplement/Implements/SecureStorage.cs
Normal file
107
Secure/SecureShopDatabaseImplement/Implements/SecureStorage.cs
Normal file
@ -0,0 +1,107 @@
|
|||||||
|
using SecureShopContracts.BindingModels;
|
||||||
|
using SecureShopContracts.SearchModels;
|
||||||
|
using SecureShopContracts.StoragesContracts;
|
||||||
|
using SecureShopContracts.ViewModels;
|
||||||
|
using SecureShopDatabaseImplement.Models;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
|
namespace SecureShopDatabaseImplement.Implements
|
||||||
|
{
|
||||||
|
public class SecureStorage : ISecureStorage
|
||||||
|
{
|
||||||
|
public List<SecureViewModel> GetFullList()
|
||||||
|
{
|
||||||
|
using var context = new SecureShopDatabase();
|
||||||
|
return context.Secures
|
||||||
|
.Include(x => x.Facilitiess)
|
||||||
|
.ThenInclude(x => x.Facilities)
|
||||||
|
.ToList()
|
||||||
|
.Select(x => x.GetViewModel)
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<SecureViewModel> GetFilteredList(SecureSearchModel model)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(model.SecureName))
|
||||||
|
{
|
||||||
|
return new();
|
||||||
|
}
|
||||||
|
using var context = new SecureShopDatabase();
|
||||||
|
return context.Secures
|
||||||
|
.Include(x => x.Facilitiess)
|
||||||
|
.ThenInclude(x => x.Facilities)
|
||||||
|
.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 SecureShopDatabase();
|
||||||
|
return context.Secures
|
||||||
|
.Include(x => x.Facilitiess)
|
||||||
|
.ThenInclude(x => x.Facilities)
|
||||||
|
.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 SecureShopDatabase();
|
||||||
|
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 SecureShopDatabase();
|
||||||
|
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.UpdateFacilitiess(context, model);
|
||||||
|
transaction.Commit();
|
||||||
|
return Secure.GetViewModel;
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
transaction.Rollback();
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public SecureViewModel? Delete(SecureBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new SecureShopDatabase();
|
||||||
|
var element = context.Secures
|
||||||
|
.Include(x => x.Facilitiess)
|
||||||
|
.Include(x => x.Orders)
|
||||||
|
.FirstOrDefault(rec => rec.Id == model.Id);
|
||||||
|
if (element != null)
|
||||||
|
{
|
||||||
|
context.Secures.Remove(element);
|
||||||
|
context.SaveChanges();
|
||||||
|
return element.GetViewModel;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
171
Secure/SecureShopDatabaseImplement/Migrations/20230406085714_init.Designer.cs
generated
Normal file
171
Secure/SecureShopDatabaseImplement/Migrations/20230406085714_init.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 SecureShopDatabaseImplement;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace SecureShopDatabaseImplement.Migrations
|
||||||
|
{
|
||||||
|
[DbContext(typeof(SecureShopDatabase))]
|
||||||
|
[Migration("20230406085714_init")]
|
||||||
|
partial class init
|
||||||
|
{
|
||||||
|
/// <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("SecureShopDatabaseImplement.Models.Facilities", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<double>("Cost")
|
||||||
|
.HasColumnType("float");
|
||||||
|
|
||||||
|
b.Property<string>("FacilitiesName")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("Facilitiess");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("SecureShopDatabaseImplement.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("SecureShopDatabaseImplement.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("SecureShopDatabaseImplement.Models.SecureFacilities", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<int>("Count")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<int>("FacilitiesId")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<int>("SecureId")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("FacilitiesId");
|
||||||
|
|
||||||
|
b.HasIndex("SecureId");
|
||||||
|
|
||||||
|
b.ToTable("SecureFacilitiess");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("SecureShopDatabaseImplement.Models.Order", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("SecureShopDatabaseImplement.Models.Secure", "Secure")
|
||||||
|
.WithMany("Orders")
|
||||||
|
.HasForeignKey("SecureId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("Secure");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("SecureShopDatabaseImplement.Models.SecureFacilities", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("SecureShopDatabaseImplement.Models.Facilities", "Facilities")
|
||||||
|
.WithMany("SecureFacilitiess")
|
||||||
|
.HasForeignKey("FacilitiesId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.HasOne("SecureShopDatabaseImplement.Models.Secure", "Secure")
|
||||||
|
.WithMany("Facilitiess")
|
||||||
|
.HasForeignKey("SecureId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("Facilities");
|
||||||
|
|
||||||
|
b.Navigation("Secure");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("SecureShopDatabaseImplement.Models.Facilities", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("SecureFacilitiess");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("SecureShopDatabaseImplement.Models.Secure", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("Facilitiess");
|
||||||
|
|
||||||
|
b.Navigation("Orders");
|
||||||
|
});
|
||||||
|
#pragma warning restore 612, 618
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,125 @@
|
|||||||
|
using System;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace SecureShopDatabaseImplement.Migrations
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
public partial class init : Migration
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "Facilitiess",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<int>(type: "int", nullable: false)
|
||||||
|
.Annotation("SqlServer:Identity", "1, 1"),
|
||||||
|
FacilitiesName = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||||
|
Cost = table.Column<double>(type: "float", nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_Facilitiess", 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: "SecureFacilitiess",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<int>(type: "int", nullable: false)
|
||||||
|
.Annotation("SqlServer:Identity", "1, 1"),
|
||||||
|
SecureId = table.Column<int>(type: "int", nullable: false),
|
||||||
|
FacilitiesId = table.Column<int>(type: "int", nullable: false),
|
||||||
|
Count = table.Column<int>(type: "int", nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_SecureFacilitiess", x => x.Id);
|
||||||
|
table.ForeignKey(
|
||||||
|
name: "FK_SecureFacilitiess_Facilitiess_FacilitiesId",
|
||||||
|
column: x => x.FacilitiesId,
|
||||||
|
principalTable: "Facilitiess",
|
||||||
|
principalColumn: "Id",
|
||||||
|
onDelete: ReferentialAction.Cascade);
|
||||||
|
table.ForeignKey(
|
||||||
|
name: "FK_SecureFacilitiess_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_SecureFacilitiess_FacilitiesId",
|
||||||
|
table: "SecureFacilitiess",
|
||||||
|
column: "FacilitiesId");
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_SecureFacilitiess_SecureId",
|
||||||
|
table: "SecureFacilitiess",
|
||||||
|
column: "SecureId");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "Orders");
|
||||||
|
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "SecureFacilitiess");
|
||||||
|
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "Facilitiess");
|
||||||
|
|
||||||
|
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 SecureShopDatabaseImplement;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace SecureShopDatabaseImplement.Migrations
|
||||||
|
{
|
||||||
|
[DbContext(typeof(SecureShopDatabase))]
|
||||||
|
partial class SecureShopDatabaseModelSnapshot : 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("SecureShopDatabaseImplement.Models.Facilities", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<double>("Cost")
|
||||||
|
.HasColumnType("float");
|
||||||
|
|
||||||
|
b.Property<string>("FacilitiesName")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("Facilitiess");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("SecureShopDatabaseImplement.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("SecureShopDatabaseImplement.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("SecureShopDatabaseImplement.Models.SecureFacilities", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<int>("Count")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<int>("FacilitiesId")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<int>("SecureId")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("FacilitiesId");
|
||||||
|
|
||||||
|
b.HasIndex("SecureId");
|
||||||
|
|
||||||
|
b.ToTable("SecureFacilitiess");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("SecureShopDatabaseImplement.Models.Order", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("SecureShopDatabaseImplement.Models.Secure", "Secure")
|
||||||
|
.WithMany("Orders")
|
||||||
|
.HasForeignKey("SecureId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("Secure");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("SecureShopDatabaseImplement.Models.SecureFacilities", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("SecureShopDatabaseImplement.Models.Facilities", "Facilities")
|
||||||
|
.WithMany("SecureFacilitiess")
|
||||||
|
.HasForeignKey("FacilitiesId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.HasOne("SecureShopDatabaseImplement.Models.Secure", "Secure")
|
||||||
|
.WithMany("Facilitiess")
|
||||||
|
.HasForeignKey("SecureId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("Facilities");
|
||||||
|
|
||||||
|
b.Navigation("Secure");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("SecureShopDatabaseImplement.Models.Facilities", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("SecureFacilitiess");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("SecureShopDatabaseImplement.Models.Secure", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("Facilitiess");
|
||||||
|
|
||||||
|
b.Navigation("Orders");
|
||||||
|
});
|
||||||
|
#pragma warning restore 612, 618
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
63
Secure/SecureShopDatabaseImplement/Models/Facilities.cs
Normal file
63
Secure/SecureShopDatabaseImplement/Models/Facilities.cs
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
using SecureShopContracts.BindingModels;
|
||||||
|
using SecureShopContracts.ViewModels;
|
||||||
|
using SecureShopDataModels.Models;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
|
|
||||||
|
namespace SecureShopDatabaseImplement.Models
|
||||||
|
{
|
||||||
|
public class Facilities : IFacilitiesModel
|
||||||
|
{
|
||||||
|
public int Id { get; private set; }
|
||||||
|
|
||||||
|
[Required]
|
||||||
|
public string FacilitiesName { get; private set; } = string.Empty;
|
||||||
|
|
||||||
|
[Required]
|
||||||
|
public double Cost { get; set; }
|
||||||
|
|
||||||
|
[ForeignKey("FacilitiesId")]
|
||||||
|
public virtual List<SecureFacilities> SecureFacilitiess { get; set; } = new();
|
||||||
|
|
||||||
|
public static Facilities? Create(FacilitiesBindingModel model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new Facilities()
|
||||||
|
{
|
||||||
|
Id = model.Id,
|
||||||
|
FacilitiesName = model.FacilitiesName,
|
||||||
|
Cost = model.Cost
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Facilities Create(FacilitiesViewModel model)
|
||||||
|
{
|
||||||
|
return new Facilities
|
||||||
|
{
|
||||||
|
Id = model.Id,
|
||||||
|
FacilitiesName = model.FacilitiesName,
|
||||||
|
Cost = model.Cost
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Update(FacilitiesBindingModel model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
FacilitiesName = model.FacilitiesName;
|
||||||
|
Cost = model.Cost;
|
||||||
|
}
|
||||||
|
|
||||||
|
public FacilitiesViewModel GetViewModel => new()
|
||||||
|
{
|
||||||
|
Id = Id,
|
||||||
|
FacilitiesName = FacilitiesName,
|
||||||
|
Cost = Cost
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
67
Secure/SecureShopDatabaseImplement/Models/Order.cs
Normal file
67
Secure/SecureShopDatabaseImplement/Models/Order.cs
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
using SecureShopContracts.BindingModels;
|
||||||
|
using SecureShopContracts.ViewModels;
|
||||||
|
using SecureShopDataModels.Enums;
|
||||||
|
using SecureShopDataModels.Models;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
|
|
||||||
|
namespace SecureShopDatabaseImplement.Models
|
||||||
|
{
|
||||||
|
public class Order : IOrderModel
|
||||||
|
{
|
||||||
|
[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 int Id { 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,
|
||||||
|
Count = Count,
|
||||||
|
Sum = Sum,
|
||||||
|
Status = Status,
|
||||||
|
DateCreate = DateCreate,
|
||||||
|
DateImplement = DateImplement,
|
||||||
|
SecureName = Secure.SecureName
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
99
Secure/SecureShopDatabaseImplement/Models/Secure.cs
Normal file
99
Secure/SecureShopDatabaseImplement/Models/Secure.cs
Normal file
@ -0,0 +1,99 @@
|
|||||||
|
using SecureShopContracts.BindingModels;
|
||||||
|
using SecureShopContracts.ViewModels;
|
||||||
|
using SecureShopDataModels.Models;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
|
|
||||||
|
namespace SecureShopDatabaseImplement.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, (IFacilitiesModel, int)>? _SecureFacilitiess = null;
|
||||||
|
|
||||||
|
[NotMapped]
|
||||||
|
public Dictionary<int, (IFacilitiesModel, int)> SecureFacilitiess
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (_SecureFacilitiess == null)
|
||||||
|
{
|
||||||
|
_SecureFacilitiess = Facilitiess
|
||||||
|
.ToDictionary(recPC => recPC.FacilitiesId, recPC => (recPC.Facilities as IFacilitiesModel, recPC.Count));
|
||||||
|
}
|
||||||
|
return _SecureFacilitiess;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[ForeignKey("SecureId")]
|
||||||
|
public virtual List<SecureFacilities> Facilitiess { get; set; } = new();
|
||||||
|
|
||||||
|
[ForeignKey("SecureId")]
|
||||||
|
public virtual List<Order> Orders { get; set; } = new();
|
||||||
|
|
||||||
|
public static Secure Create(SecureShopDatabase context, SecureBindingModel model)
|
||||||
|
{
|
||||||
|
return new Secure()
|
||||||
|
{
|
||||||
|
Id = model.Id,
|
||||||
|
SecureName = model.SecureName,
|
||||||
|
Price = model.Price,
|
||||||
|
Facilitiess = model.SecureFacilitiess.Select(x => new SecureFacilities
|
||||||
|
{
|
||||||
|
Facilities = context.Facilitiess.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,
|
||||||
|
SecureFacilitiess = SecureFacilitiess
|
||||||
|
};
|
||||||
|
|
||||||
|
public void UpdateFacilitiess(SecureShopDatabase context, SecureBindingModel model)
|
||||||
|
{
|
||||||
|
var SecureFacilitiess = context.SecureFacilitiess.Where(rec => rec.SecureId == model.Id).ToList();
|
||||||
|
if (SecureFacilitiess != null && SecureFacilitiess.Count > 0)
|
||||||
|
{ // удалили те, которых нет в модели
|
||||||
|
context.SecureFacilitiess.RemoveRange(SecureFacilitiess.Where(rec => !model.SecureFacilitiess.ContainsKey(rec.FacilitiesId)));
|
||||||
|
context.SaveChanges();
|
||||||
|
// обновили количество у существующих записей
|
||||||
|
foreach (var updateFacilities in SecureFacilitiess)
|
||||||
|
{
|
||||||
|
updateFacilities.Count = model.SecureFacilitiess[updateFacilities.FacilitiesId].Item2;
|
||||||
|
model.SecureFacilitiess.Remove(updateFacilities.FacilitiesId);
|
||||||
|
}
|
||||||
|
context.SaveChanges();
|
||||||
|
}
|
||||||
|
var Secure = context.Secures.First(x => x.Id == Id);
|
||||||
|
foreach (var ia in model.SecureFacilitiess)
|
||||||
|
{
|
||||||
|
context.SecureFacilitiess.Add(new SecureFacilities
|
||||||
|
{
|
||||||
|
Secure = Secure,
|
||||||
|
Facilities = context.Facilitiess.First(x => x.Id == ia.Key),
|
||||||
|
Count = ia.Value.Item2
|
||||||
|
});
|
||||||
|
context.SaveChanges();
|
||||||
|
}
|
||||||
|
_SecureFacilitiess = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,22 @@
|
|||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
|
||||||
|
namespace SecureShopDatabaseImplement.Models
|
||||||
|
{
|
||||||
|
public class SecureFacilities
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
|
||||||
|
[Required]
|
||||||
|
public int SecureId { get; set; }
|
||||||
|
|
||||||
|
[Required]
|
||||||
|
public int FacilitiesId { get; set; }
|
||||||
|
|
||||||
|
[Required]
|
||||||
|
public int Count { get; set; }
|
||||||
|
|
||||||
|
public virtual Facilities Facilities { get; set; } = new();
|
||||||
|
|
||||||
|
public virtual Secure Secure { get; set; } = new();
|
||||||
|
}
|
||||||
|
}
|
25
Secure/SecureShopDatabaseImplement/SecureShopDatabase.cs
Normal file
25
Secure/SecureShopDatabaseImplement/SecureShopDatabase.cs
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
using SecureShopDatabaseImplement.Models;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
|
namespace SecureShopDatabaseImplement
|
||||||
|
{
|
||||||
|
public class SecureShopDatabase : DbContext
|
||||||
|
{
|
||||||
|
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||||
|
{
|
||||||
|
if (optionsBuilder.IsConfigured == false)
|
||||||
|
{
|
||||||
|
optionsBuilder.UseSqlServer(@"Data Source=DESKTOP-E9D4764\SQLEXPRESS;Initial Catalog=SecureShopDatabase;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True");
|
||||||
|
}
|
||||||
|
base.OnConfiguring(optionsBuilder);
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual DbSet<Facilities> Facilitiess { set; get; }
|
||||||
|
|
||||||
|
public virtual DbSet<Secure> Secures { set; get; }
|
||||||
|
|
||||||
|
public virtual DbSet<SecureFacilities> SecureFacilitiess { 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="..\SecureShopBusinessLogic\SecureShopBusinessLogic.csproj" />
|
||||||
|
<ProjectReference Include="..\SecureShopContracts\SecureShopContracts.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
@ -1,7 +1,7 @@
|
|||||||
using SecureShopFileImplement.Models;
|
using SecureShopDataBaseImplement.Models;
|
||||||
using System.Xml.Linq;
|
using System.Xml.Linq;
|
||||||
|
|
||||||
namespace SecureShopFileImplement
|
namespace SecureShopDataBaseImplement
|
||||||
{
|
{
|
||||||
public class DataFileSingleton
|
public class DataFileSingleton
|
||||||
{
|
{
|
||||||
|
@ -2,9 +2,9 @@
|
|||||||
using SecureShopContracts.SearchModels;
|
using SecureShopContracts.SearchModels;
|
||||||
using SecureShopContracts.StoragesContracts;
|
using SecureShopContracts.StoragesContracts;
|
||||||
using SecureShopContracts.ViewModels;
|
using SecureShopContracts.ViewModels;
|
||||||
using SecureShopFileImplement.Models;
|
using SecureShopDataBaseImplement.Models;
|
||||||
|
|
||||||
namespace SecureShopFileImplement.Implements
|
namespace SecureShopDataBaseImplement.Implements
|
||||||
{
|
{
|
||||||
public class FacilitiesStorage : IFacilitiesStorage
|
public class FacilitiesStorage : IFacilitiesStorage
|
||||||
{
|
{
|
||||||
|
@ -2,9 +2,9 @@
|
|||||||
using SecureShopContracts.SearchModels;
|
using SecureShopContracts.SearchModels;
|
||||||
using SecureShopContracts.StoragesContracts;
|
using SecureShopContracts.StoragesContracts;
|
||||||
using SecureShopContracts.ViewModels;
|
using SecureShopContracts.ViewModels;
|
||||||
using SecureShopFileImplement.Models;
|
using SecureShopDataBaseImplement.Models;
|
||||||
|
|
||||||
namespace SecureShopFileImplement.Implements
|
namespace SecureShopDataBaseImplement.Implements
|
||||||
{
|
{
|
||||||
public class OrderStorage : IOrderStorage
|
public class OrderStorage : IOrderStorage
|
||||||
{
|
{
|
||||||
|
@ -2,9 +2,9 @@
|
|||||||
using SecureShopContracts.SearchModels;
|
using SecureShopContracts.SearchModels;
|
||||||
using SecureShopContracts.StoragesContracts;
|
using SecureShopContracts.StoragesContracts;
|
||||||
using SecureShopContracts.ViewModels;
|
using SecureShopContracts.ViewModels;
|
||||||
using SecureShopFileImplement.Models;
|
using SecureShopDataBaseImplement.Models;
|
||||||
|
|
||||||
namespace SecureShopFileImplement.Implements
|
namespace SecureShopDataBaseImplement.Implements
|
||||||
{
|
{
|
||||||
public class SecureStorage : ISecureStorage
|
public class SecureStorage : ISecureStorage
|
||||||
{
|
{
|
||||||
|
@ -3,7 +3,7 @@ using SecureShopContracts.ViewModels;
|
|||||||
using SecureShopDataModels.Models;
|
using SecureShopDataModels.Models;
|
||||||
using System.Xml.Linq;
|
using System.Xml.Linq;
|
||||||
|
|
||||||
namespace SecureShopFileImplement.Models
|
namespace SecureShopDataBaseImplement.Models
|
||||||
{
|
{
|
||||||
public class Facilities : IFacilitiesModel
|
public class Facilities : IFacilitiesModel
|
||||||
{
|
{
|
||||||
|
@ -4,7 +4,7 @@ using SecureShopDataModels.Enums;
|
|||||||
using SecureShopDataModels.Models;
|
using SecureShopDataModels.Models;
|
||||||
using System.Xml.Linq;
|
using System.Xml.Linq;
|
||||||
|
|
||||||
namespace SecureShopFileImplement.Models
|
namespace SecureShopDataBaseImplement.Models
|
||||||
{
|
{
|
||||||
public class Order : IOrderModel
|
public class Order : IOrderModel
|
||||||
{
|
{
|
||||||
|
@ -3,7 +3,7 @@ using SecureShopContracts.ViewModels;
|
|||||||
using SecureShopDataModels.Models;
|
using SecureShopDataModels.Models;
|
||||||
using System.Xml.Linq;
|
using System.Xml.Linq;
|
||||||
|
|
||||||
namespace SecureShopFileImplement.Models
|
namespace SecureShopDataBaseImplement.Models
|
||||||
{
|
{
|
||||||
public class Secure : ISecureModel
|
public class Secure : ISecureModel
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user