Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 37977850dc | |||
| 6a6b063244 |
@@ -3,15 +3,19 @@ Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.7.34031.279
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SecuritySystem", "SecuritySystem\SecuritySystem.csproj", "{0548AE9D-59FF-4288-A519-85FF31627D7E}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SecuritySystem", "SecuritySystem\SecuritySystem.csproj", "{0548AE9D-59FF-4288-A519-85FF31627D7E}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SecuritySystemDataModels", "SecuritySystemDataModels\SecuritySystemDataModels.csproj", "{0A4860B4-91DC-4174-A4A5-789729F0E206}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SecuritySystemDataModels", "SecuritySystemDataModels\SecuritySystemDataModels.csproj", "{0A4860B4-91DC-4174-A4A5-789729F0E206}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SecuritySystemBusinessLogiс", "SecuritySystemBusinessLogiс\SecuritySystemBusinessLogiс.csproj", "{4A8ECDB2-CD12-4A42-8580-C75F044851A0}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SecuritySystemBusinessLogiс", "SecuritySystemBusinessLogiс\SecuritySystemBusinessLogiс.csproj", "{4A8ECDB2-CD12-4A42-8580-C75F044851A0}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SecuritySystemContracts", "SecuritySystemContracts\SecuritySystemContracts.csproj", "{96317F35-0916-4563-B898-069D6EC0B303}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SecuritySystemContracts", "SecuritySystemContracts\SecuritySystemContracts.csproj", "{96317F35-0916-4563-B898-069D6EC0B303}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SecuritySystemListImplement", "SecuritySystemListImplement\SecuritySystemListImplement.csproj", "{EEFB1807-2668-4DBF-80A0-06594D2C811C}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SecuritySystemListImplement", "SecuritySystemListImplement\SecuritySystemListImplement.csproj", "{EEFB1807-2668-4DBF-80A0-06594D2C811C}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SecuritySystemFileImplement", "SecuritySystemFileImplement\SecuritySystemFileImplement.csproj", "{2F21ABC1-9037-47B7-A9F8-4590BF86848D}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SecuritySystemDatabaseImplement", "SecuritySystemDatabaseImplement\SecuritySystemDatabaseImplement.csproj", "{7FB0519E-D039-4204-9E34-58ED0F52CF8F}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
@@ -39,6 +43,14 @@ Global
|
||||
{EEFB1807-2668-4DBF-80A0-06594D2C811C}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{EEFB1807-2668-4DBF-80A0-06594D2C811C}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{EEFB1807-2668-4DBF-80A0-06594D2C811C}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{2F21ABC1-9037-47B7-A9F8-4590BF86848D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{2F21ABC1-9037-47B7-A9F8-4590BF86848D}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{2F21ABC1-9037-47B7-A9F8-4590BF86848D}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{2F21ABC1-9037-47B7-A9F8-4590BF86848D}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{7FB0519E-D039-4204-9E34-58ED0F52CF8F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{7FB0519E-D039-4204-9E34-58ED0F52CF8F}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{7FB0519E-D039-4204-9E34-58ED0F52CF8F}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{7FB0519E-D039-4204-9E34-58ED0F52CF8F}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
using SecuritySystemBusinessLogic.BusinessLogic;
|
||||
using SecuritySystemContracts.BusinessLogicsContracts;
|
||||
using SecuritySystemContracts.StoragesContracts;
|
||||
using SecuritySystemListImplement.Implements;
|
||||
using SecuritySystemDatabaseImplement.Implements;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using NLog.Extensions.Logging;
|
||||
|
||||
using System.Drawing;
|
||||
|
||||
namespace SecuritySystem
|
||||
{
|
||||
internal static class Program
|
||||
{
|
||||
private static ServiceProvider? _serviceProvider;
|
||||
|
||||
public static ServiceProvider? ServiceProvider => _serviceProvider;
|
||||
|
||||
/// <summary>
|
||||
/// The main entry point for the application.
|
||||
/// </summary>
|
||||
@@ -28,6 +28,7 @@ namespace SecuritySystem
|
||||
_serviceProvider = services.BuildServiceProvider();
|
||||
Application.Run(_serviceProvider.GetRequiredService<FormMain>());
|
||||
}
|
||||
|
||||
private static void ConfigureServices(ServiceCollection services)
|
||||
{
|
||||
services.AddLogging(option =>
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\SecuritySystemBusinessLogiс\SecuritySystemBusinessLogiс.csproj" />
|
||||
<ProjectReference Include="..\SecuritySystemContracts\SecuritySystemContracts.csproj" />
|
||||
<ProjectReference Include="..\SecuritySystemFileImplement\SecuritySystemFileImplement.csproj" />
|
||||
<ProjectReference Include="..\SecuritySystemListImplement\SecuritySystemListImplement.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
@@ -0,0 +1,107 @@
|
||||
using SecuritySystemContracts.BindingModels;
|
||||
using SecuritySystemContracts.SearchModels;
|
||||
using SecuritySystemContracts.StoragesContracts;
|
||||
using SecuritySystemContracts.ViewModels;
|
||||
using SecuritySystemDatabaseImplement.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
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)
|
||||
{
|
||||
context.Orders.Remove(element);
|
||||
context.SaveChanges();
|
||||
|
||||
return element.GetViewModel;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public OrderViewModel? GetElement(OrderSearchModel model)
|
||||
{
|
||||
if (!model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
using var context = new SecuritySystemDatabase();
|
||||
|
||||
return context.Orders
|
||||
.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 order.GetViewModel;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,127 @@
|
||||
using SecuritySystemContracts.BindingModels;
|
||||
using SecuritySystemContracts.SearchModels;
|
||||
using SecuritySystemContracts.StoragesContracts;
|
||||
using SecuritySystemContracts.ViewModels;
|
||||
using SecuritySystemDatabaseImplement.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SecuritySystemDatabaseImplement.Implements
|
||||
{
|
||||
public class SecureStorage : ISecureStorage
|
||||
{
|
||||
public List<SecureViewModel> GetFullList()
|
||||
{
|
||||
using var context = new SecuritySystemDatabase();
|
||||
|
||||
return context.Secures
|
||||
.Include(x => x.Sensors)
|
||||
.ThenInclude(x => x.Sensor)
|
||||
.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.Sensors)
|
||||
.ThenInclude(x => x.Sensor)
|
||||
.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.Sensors)
|
||||
.ThenInclude(x => x.Sensor)
|
||||
.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.UpdateSensors(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.Sensors)
|
||||
.Include(x => x.Orders)
|
||||
.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
|
||||
if (element != null)
|
||||
{
|
||||
context.Secures.Remove(element);
|
||||
context.SaveChanges();
|
||||
|
||||
return element.GetViewModel;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
using SecuritySystemContracts.BindingModels;
|
||||
using SecuritySystemContracts.SearchModels;
|
||||
using SecuritySystemContracts.StoragesContracts;
|
||||
using SecuritySystemContracts.ViewModels;
|
||||
using SecuritySystemDatabaseImplement.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SecuritySystemDatabaseImplement.Implements
|
||||
{
|
||||
public class SensorStorage : ISensorStorage
|
||||
{
|
||||
public List<SensorViewModel> GetFullList()
|
||||
{
|
||||
using var context = new SecuritySystemDatabase();
|
||||
|
||||
return context.Sensors
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public List<SensorViewModel> GetFilteredList(SensorSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.SensorName))
|
||||
{
|
||||
return new();
|
||||
}
|
||||
|
||||
using var context = new SecuritySystemDatabase();
|
||||
|
||||
return context.Sensors
|
||||
.Where(x => x.SensorName.Contains(model.SensorName))
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public SensorViewModel? GetElement(SensorSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.SensorName) && !model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
using var context = new SecuritySystemDatabase();
|
||||
|
||||
return context.Sensors
|
||||
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.SensorName) && x.SensorName == model.SensorName) ||
|
||||
(model.Id.HasValue && x.Id == model.Id))
|
||||
?.GetViewModel;
|
||||
}
|
||||
|
||||
public SensorViewModel? Insert(SensorBindingModel model)
|
||||
{
|
||||
var newSensor = Sensor.Create(model);
|
||||
|
||||
if (newSensor == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
using var context = new SecuritySystemDatabase();
|
||||
context.Sensors.Add(newSensor);
|
||||
context.SaveChanges();
|
||||
|
||||
return newSensor.GetViewModel;
|
||||
}
|
||||
|
||||
public SensorViewModel? Update(SensorBindingModel model)
|
||||
{
|
||||
using var context = new SecuritySystemDatabase();
|
||||
var sensor = context.Sensors.FirstOrDefault(x => x.Id == model.Id);
|
||||
|
||||
if (sensor == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
sensor.Update(model);
|
||||
context.SaveChanges();
|
||||
|
||||
return sensor.GetViewModel;
|
||||
}
|
||||
|
||||
public SensorViewModel? Delete(SensorBindingModel model)
|
||||
{
|
||||
using var context = new SecuritySystemDatabase();
|
||||
var element = context.Sensors.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
|
||||
if (element != null)
|
||||
{
|
||||
context.Sensors.Remove(element);
|
||||
context.SaveChanges();
|
||||
|
||||
return element.GetViewModel;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
171
SecuritySystem/SecuritySystemDatabaseImplement/Migrations/20240424022741_InitialCreate.Designer.cs
generated
Normal file
171
SecuritySystem/SecuritySystemDatabaseImplement/Migrations/20240424022741_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("20240424022741_InitialCreate")]
|
||||
partial class InitialCreate
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "7.0.3")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 128);
|
||||
|
||||
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
|
||||
|
||||
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.SecureSensor", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("SecureId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("SensorId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("SecureId");
|
||||
|
||||
b.HasIndex("SensorId");
|
||||
|
||||
b.ToTable("SecureSensors");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SecuritySystemDatabaseImplement.Models.Sensor", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<double>("Cost")
|
||||
.HasColumnType("float");
|
||||
|
||||
b.Property<string>("SensorName")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Sensors");
|
||||
});
|
||||
|
||||
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.SecureSensor", b =>
|
||||
{
|
||||
b.HasOne("SecuritySystemDatabaseImplement.Models.Secure", "Secure")
|
||||
.WithMany("Sensors")
|
||||
.HasForeignKey("SecureId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("SecuritySystemDatabaseImplement.Models.Sensor", "Sensor")
|
||||
.WithMany("SecureSensors")
|
||||
.HasForeignKey("SensorId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Secure");
|
||||
|
||||
b.Navigation("Sensor");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SecuritySystemDatabaseImplement.Models.Secure", b =>
|
||||
{
|
||||
b.Navigation("Orders");
|
||||
|
||||
b.Navigation("Sensors");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SecuritySystemDatabaseImplement.Models.Sensor", b =>
|
||||
{
|
||||
b.Navigation("SecureSensors");
|
||||
});
|
||||
#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: "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: "Sensors",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
SensorName = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
Cost = table.Column<double>(type: "float", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Sensors", 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: "SecureSensors",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
SecureId = table.Column<int>(type: "int", nullable: false),
|
||||
SensorId = table.Column<int>(type: "int", nullable: false),
|
||||
Count = table.Column<int>(type: "int", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_SecureSensors", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_SecureSensors_Secures_SecureId",
|
||||
column: x => x.SecureId,
|
||||
principalTable: "Secures",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
table.ForeignKey(
|
||||
name: "FK_SecureSensors_Sensors_SensorId",
|
||||
column: x => x.SensorId,
|
||||
principalTable: "Sensors",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Orders_SecureId",
|
||||
table: "Orders",
|
||||
column: "SecureId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_SecureSensors_SecureId",
|
||||
table: "SecureSensors",
|
||||
column: "SecureId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_SecureSensors_SensorId",
|
||||
table: "SecureSensors",
|
||||
column: "SensorId");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "Orders");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "SecureSensors");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Secures");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Sensors");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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.3")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 128);
|
||||
|
||||
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
|
||||
|
||||
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.SecureSensor", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("SecureId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("SensorId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("SecureId");
|
||||
|
||||
b.HasIndex("SensorId");
|
||||
|
||||
b.ToTable("SecureSensors");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SecuritySystemDatabaseImplement.Models.Sensor", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<double>("Cost")
|
||||
.HasColumnType("float");
|
||||
|
||||
b.Property<string>("SensorName")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Sensors");
|
||||
});
|
||||
|
||||
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.SecureSensor", b =>
|
||||
{
|
||||
b.HasOne("SecuritySystemDatabaseImplement.Models.Secure", "Secure")
|
||||
.WithMany("Sensors")
|
||||
.HasForeignKey("SecureId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("SecuritySystemDatabaseImplement.Models.Sensor", "Sensor")
|
||||
.WithMany("SecureSensors")
|
||||
.HasForeignKey("SensorId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Secure");
|
||||
|
||||
b.Navigation("Sensor");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SecuritySystemDatabaseImplement.Models.Secure", b =>
|
||||
{
|
||||
b.Navigation("Orders");
|
||||
|
||||
b.Navigation("Sensors");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SecuritySystemDatabaseImplement.Models.Sensor", b =>
|
||||
{
|
||||
b.Navigation("SecureSensors");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
using SecuritySystemContracts.BindingModels;
|
||||
using SecuritySystemContracts.ViewModels;
|
||||
using SecuritySystemDataModels.Enums;
|
||||
using SecuritySystemDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace SecuritySystemDatabaseImplement.Models
|
||||
{
|
||||
public class Order : IOrderModel
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
|
||||
[Required]
|
||||
public int SecureId { get; private set; }
|
||||
|
||||
[Required]
|
||||
public int Count { get; private set; }
|
||||
|
||||
[Required]
|
||||
public double Sum { get; private set; }
|
||||
|
||||
[Required]
|
||||
public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен;
|
||||
|
||||
[Required]
|
||||
public DateTime DateCreate { get; private set; } = DateTime.Now;
|
||||
|
||||
public DateTime? DateImplement { get; private 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
|
||||
};
|
||||
}
|
||||
}
|
||||
118
SecuritySystem/SecuritySystemDatabaseImplement/Models/Secure.cs
Normal file
118
SecuritySystem/SecuritySystemDatabaseImplement/Models/Secure.cs
Normal file
@@ -0,0 +1,118 @@
|
||||
using SecuritySystemContracts.BindingModels;
|
||||
using SecuritySystemContracts.ViewModels;
|
||||
using SecuritySystemDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
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; }
|
||||
|
||||
public Dictionary<int, (ISensorModel, int)>? _secureSensors = null;
|
||||
|
||||
//это поле не будет "мапиться" в бд
|
||||
[NotMapped]
|
||||
public Dictionary<int, (ISensorModel, int)> SecureSensors
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_secureSensors == null)
|
||||
{
|
||||
_secureSensors = Sensors
|
||||
.ToDictionary(recPC => recPC.SensorId, recPC => (recPC.Sensor as ISensorModel, recPC.Count));
|
||||
}
|
||||
|
||||
return _secureSensors;
|
||||
}
|
||||
}
|
||||
|
||||
//для реализации связи многие ко многим с заготовками
|
||||
[ForeignKey("SecureId")]
|
||||
public virtual List<SecureSensor> Sensors { 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,
|
||||
Sensors = model.SecureSensors.Select(x => new SecureSensor
|
||||
{
|
||||
Sensor = context.Sensors.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,
|
||||
SecureSensors = SecureSensors
|
||||
};
|
||||
|
||||
Dictionary<int, (ISensorModel, int)> ISecureModel.SecureSensors => throw new NotImplementedException();
|
||||
|
||||
public void UpdateSensors(SecuritySystemDatabase context, SecureBindingModel model)
|
||||
{
|
||||
var secureSensors = context.SecureSensors.Where(rec => rec.SecureId == model.Id).ToList();
|
||||
|
||||
if (secureSensors != null && secureSensors.Count > 0)
|
||||
{
|
||||
// удалили те, которых нет в модели
|
||||
context.SecureSensors.RemoveRange(secureSensors.Where(rec => !model.SecureSensors.ContainsKey(rec.SecureId)));
|
||||
context.SaveChanges();
|
||||
|
||||
// обновили количество у существующих записей
|
||||
foreach (var updateSecure in secureSensors)
|
||||
{
|
||||
updateSecure.Count = model.SecureSensors[updateSecure.SecureId].Item2;
|
||||
model.SecureSensors.Remove(updateSecure.SecureId);
|
||||
}
|
||||
|
||||
context.SaveChanges();
|
||||
}
|
||||
|
||||
var secure = context.Secures.First(x => x.Id == Id);
|
||||
|
||||
foreach (var pc in model.SecureSensors)
|
||||
{
|
||||
context.SecureSensors.Add(new SecureSensor
|
||||
{
|
||||
Secure = secure,
|
||||
Sensor = context.Sensors.First(x => x.Id == pc.Key),
|
||||
Count = pc.Value.Item2
|
||||
});
|
||||
|
||||
context.SaveChanges();
|
||||
}
|
||||
|
||||
_secureSensors = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SecuritySystemDatabaseImplement.Models
|
||||
{
|
||||
public class SecureSensor
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
[Required]
|
||||
public int SecureId { get; set; }
|
||||
|
||||
[Required]
|
||||
public int SensorId { get; set; }
|
||||
|
||||
[Required]
|
||||
public int Count { get; set; }
|
||||
|
||||
public virtual Sensor Sensor { get; set; } = new();
|
||||
|
||||
public virtual Secure Secure { get; set; } = new();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
using SecuritySystemContracts.BindingModels;
|
||||
using SecuritySystemContracts.ViewModels;
|
||||
using SecuritySystemDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SecuritySystemDatabaseImplement.Models
|
||||
{
|
||||
public class Sensor : ISensorModel
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
|
||||
[Required]
|
||||
public string SensorName { get; private set; } = string.Empty;
|
||||
|
||||
[Required]
|
||||
public double Cost { get; set; }
|
||||
|
||||
//для реализации связи многие ко многим с изделиями
|
||||
[ForeignKey("SensorId")]
|
||||
public virtual List<SecureSensor> SecureSensors { get; set; } = new();
|
||||
|
||||
public static Sensor? Create(SensorBindingModel model)
|
||||
{
|
||||
if(model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return new Sensor()
|
||||
{
|
||||
Id = model.Id,
|
||||
SensorName = model.SensorName,
|
||||
Cost = model.Cost
|
||||
};
|
||||
}
|
||||
|
||||
public static Sensor Create(SensorViewModel model)
|
||||
{
|
||||
return new Sensor
|
||||
{
|
||||
Id = model.Id,
|
||||
SensorName = model.SensorName,
|
||||
Cost = model.Cost
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(SensorBindingModel model)
|
||||
{
|
||||
if(model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
SensorName = model.SensorName;
|
||||
Cost = model.Cost;
|
||||
}
|
||||
|
||||
public SensorViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
SensorName = SensorName,
|
||||
Cost = Cost
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
using SecuritySystemDatabaseImplement.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SecuritySystemDatabaseImplement
|
||||
{
|
||||
public class SecuritySystemDatabase : DbContext
|
||||
{
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||
{
|
||||
if (optionsBuilder.IsConfigured == false)
|
||||
{
|
||||
optionsBuilder.UseSqlServer(@"Data Source=WIN-GKU3FFNUNO6;Initial Catalog=SecuritySystemDatabase;Integrated Security=True;MultipleActiveResultSets=True;TrustServerCertificate=True");
|
||||
|
||||
}
|
||||
|
||||
base.OnConfiguring(optionsBuilder);
|
||||
}
|
||||
|
||||
public virtual DbSet<Sensor> Sensors { set; get; }
|
||||
|
||||
public virtual DbSet<Secure> Secures { set; get; }
|
||||
|
||||
public virtual DbSet<SecureSensor> SecureSensors { set; get; }
|
||||
|
||||
public virtual DbSet<Order> Orders { set; get; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,68 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Linq;
|
||||
using SecuritySystemFileImplement.Models;
|
||||
|
||||
namespace SecuritySystemFileImplement
|
||||
{
|
||||
public class DataFileSingleton
|
||||
{
|
||||
private static DataFileSingleton? instance;
|
||||
|
||||
private readonly string SensorFileName = "Sensor.xml";
|
||||
|
||||
private readonly string OrderFileName = "Order.xml";
|
||||
|
||||
private readonly string SecureFileName = "Secure.xml";
|
||||
|
||||
public List<Sensor> Sensors { get; private set; }
|
||||
|
||||
public List<Order> Orders { get; private set; }
|
||||
|
||||
public List<Secure> Secures { get; private set; }
|
||||
|
||||
public static DataFileSingleton GetInstance()
|
||||
{
|
||||
if (instance == null)
|
||||
{
|
||||
instance = new DataFileSingleton();
|
||||
}
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
public void SaveSensors() => SaveData(Sensors, SensorFileName, "Sensors", x => x.GetXElement);
|
||||
|
||||
public void SaveSecures() => SaveData(Secures, SecureFileName, "Secures", x => x.GetXElement);
|
||||
|
||||
public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement);
|
||||
|
||||
private DataFileSingleton()
|
||||
{
|
||||
Sensors = LoadData(SensorFileName, "Sensor", x => Sensor.Create(x)!)!;
|
||||
Secures = LoadData(SecureFileName, "Secure", x => Secure.Create(x)!)!;
|
||||
Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!;
|
||||
}
|
||||
|
||||
private static List<T>? LoadData<T>(string filename, string xmlNodeName, Func<XElement, T> selectFunction)
|
||||
{
|
||||
if (File.Exists(filename))
|
||||
{
|
||||
return XDocument.Load(filename)?.Root?.Elements(xmlNodeName)?.Select(selectFunction)?.ToList();
|
||||
}
|
||||
|
||||
return new List<T>();
|
||||
}
|
||||
|
||||
private static void SaveData<T>(List<T> data, string filename, string xmlNodeName, Func<T, XElement> selectFunction)
|
||||
{
|
||||
if (data != null)
|
||||
{
|
||||
new XDocument(new XElement(xmlNodeName, data.Select(selectFunction).ToArray())).Save(filename);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
using SecuritySystemContracts.BindingModels;
|
||||
using SecuritySystemContracts.SearchModels;
|
||||
using SecuritySystemContracts.StoragesContracts;
|
||||
using SecuritySystemContracts.ViewModels;
|
||||
using SecuritySystemFileImplement.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SecuritySystemFileImplement.Implements
|
||||
{
|
||||
//реализация интерфейса хранилища заказов
|
||||
public class OrderStorage : IOrderStorage
|
||||
{
|
||||
private readonly DataFileSingleton source;
|
||||
|
||||
public OrderStorage()
|
||||
{
|
||||
source = DataFileSingleton.GetInstance();
|
||||
}
|
||||
|
||||
public List<OrderViewModel> GetFullList()
|
||||
{
|
||||
return source.Orders.Select(x => GetViewModel(x)).ToList();
|
||||
}
|
||||
|
||||
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
|
||||
{
|
||||
if (!model.Id.HasValue)
|
||||
{
|
||||
return new();
|
||||
}
|
||||
|
||||
return source.Orders.Where(x => x.Id == model.Id).Select(x => GetViewModel(x)).ToList();
|
||||
}
|
||||
|
||||
public OrderViewModel? GetElement(OrderSearchModel model)
|
||||
{
|
||||
if (!model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return source.Orders.FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
|
||||
}
|
||||
|
||||
//для загрузки названий изделия в заказе
|
||||
private OrderViewModel GetViewModel(Order order)
|
||||
{
|
||||
var viewModel = order.GetViewModel;
|
||||
|
||||
var secure = source.Secures.FirstOrDefault(x => x.Id == order.SecureId);
|
||||
|
||||
if (secure != null)
|
||||
{
|
||||
viewModel.SecureName = secure.SecureName;
|
||||
}
|
||||
|
||||
return viewModel;
|
||||
}
|
||||
|
||||
public OrderViewModel? Insert(OrderBindingModel model)
|
||||
{
|
||||
model.Id = source.Orders.Count > 0 ? source.Orders.Max(x => x.Id) + 1 : 1;
|
||||
|
||||
var newOrder = Order.Create(model);
|
||||
|
||||
if (newOrder == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
source.Orders.Add(newOrder);
|
||||
source.SaveOrders();
|
||||
|
||||
return GetViewModel(newOrder);
|
||||
}
|
||||
|
||||
public OrderViewModel? Update(OrderBindingModel model)
|
||||
{
|
||||
var order = source.Orders.FirstOrDefault(x => x.Id == model.Id);
|
||||
|
||||
if (order == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
order.Update(model);
|
||||
source.SaveOrders();
|
||||
|
||||
return GetViewModel(order);
|
||||
}
|
||||
|
||||
public OrderViewModel? Delete(OrderBindingModel model)
|
||||
{
|
||||
var element = source.Orders.FirstOrDefault(x => x.Id == model.Id);
|
||||
|
||||
if (element != null)
|
||||
{
|
||||
source.Orders.Remove(element);
|
||||
source.SaveOrders();
|
||||
|
||||
return GetViewModel(element);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
using SecuritySystemContracts.BindingModels;
|
||||
using SecuritySystemContracts.SearchModels;
|
||||
using SecuritySystemContracts.StoragesContracts;
|
||||
using SecuritySystemContracts.ViewModels;
|
||||
using SecuritySystemFileImplement.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SecuritySystemFileImplement.Implements
|
||||
{
|
||||
//реализация интерфейса хранилища изделий
|
||||
public class SecureStorage : ISecureStorage
|
||||
{
|
||||
private readonly DataFileSingleton source;
|
||||
|
||||
public SecureStorage()
|
||||
{
|
||||
source = DataFileSingleton.GetInstance();
|
||||
}
|
||||
|
||||
public List<SecureViewModel> GetFullList()
|
||||
{
|
||||
return source.Secures.Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public List<SecureViewModel> GetFilteredList(SecureSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.SecureName))
|
||||
{
|
||||
return new();
|
||||
}
|
||||
|
||||
return source.Secures.Where(x => x.SecureName.Contains(model.SecureName)).Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public SecureViewModel? GetElement(SecureSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.SecureName) && !model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return source.Secures.FirstOrDefault(x => (!string.IsNullOrEmpty(model.SecureName) && x.SecureName == model.SecureName)
|
||||
|| (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
|
||||
}
|
||||
|
||||
public SecureViewModel? Insert(SecureBindingModel model)
|
||||
{
|
||||
model.Id = source.Secures.Count > 0 ? source.Secures.Max(x => x.Id) + 1 : 1;
|
||||
|
||||
var newSecure = Secure.Create(model);
|
||||
|
||||
if (newSecure == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
source.Secures.Add(newSecure);
|
||||
source.SaveSecures();
|
||||
|
||||
return newSecure.GetViewModel;
|
||||
}
|
||||
|
||||
public SecureViewModel? Update(SecureBindingModel model)
|
||||
{
|
||||
var secure = source.Secures.FirstOrDefault(x => x.Id == model.Id);
|
||||
|
||||
if (secure == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
secure.Update(model);
|
||||
source.SaveSecures();
|
||||
|
||||
return secure.GetViewModel;
|
||||
}
|
||||
|
||||
public SecureViewModel? Delete(SecureBindingModel model)
|
||||
{
|
||||
var element = source.Secures.FirstOrDefault(x => x.Id == model.Id);
|
||||
|
||||
if (element != null)
|
||||
{
|
||||
source.Secures.Remove(element);
|
||||
source.SaveSecures();
|
||||
|
||||
return element.GetViewModel;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
using SecuritySystemContracts.BindingModels;
|
||||
using SecuritySystemContracts.SearchModels;
|
||||
using SecuritySystemContracts.StoragesContracts;
|
||||
using SecuritySystemContracts.ViewModels;
|
||||
using SecuritySystemFileImplement.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SecuritySystemFileImplement.Implements
|
||||
{
|
||||
//реализация интерфейса хранилища заготовок
|
||||
public class SensorStorage : ISensorStorage
|
||||
{
|
||||
private readonly DataFileSingleton source;
|
||||
|
||||
public SensorStorage()
|
||||
{
|
||||
source = DataFileSingleton.GetInstance();
|
||||
}
|
||||
|
||||
public List<SensorViewModel> GetFullList()
|
||||
{
|
||||
return source.Sensors.Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public List<SensorViewModel> GetFilteredList(SensorSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.SensorName))
|
||||
{
|
||||
return new();
|
||||
}
|
||||
|
||||
return source.Sensors.Where(x => x.SensorName.Contains(model.SensorName)).Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public SensorViewModel? GetElement(SensorSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.SensorName) && !model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return source.Sensors.FirstOrDefault(x => (!string.IsNullOrEmpty(model.SensorName) && x.SensorName == model.SensorName)
|
||||
|| (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
|
||||
}
|
||||
|
||||
public SensorViewModel? Insert(SensorBindingModel model)
|
||||
{
|
||||
model.Id = source.Sensors.Count > 0 ? source.Sensors.Max(x => x.Id) + 1 : 1;
|
||||
|
||||
var newSensor = Sensor.Create(model);
|
||||
|
||||
if (newSensor == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
source.Sensors.Add(newSensor);
|
||||
source.SaveSensors();
|
||||
|
||||
return newSensor.GetViewModel;
|
||||
}
|
||||
|
||||
public SensorViewModel? Update(SensorBindingModel model)
|
||||
{
|
||||
var sensor = source.Sensors.FirstOrDefault(x => x.Id == model.Id);
|
||||
|
||||
if (sensor == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
sensor.Update(model);
|
||||
source.SaveSensors();
|
||||
|
||||
return sensor.GetViewModel;
|
||||
}
|
||||
|
||||
public SensorViewModel? Delete(SensorBindingModel model)
|
||||
{
|
||||
var element = source.Sensors.FirstOrDefault(x => x.Id == model.Id);
|
||||
|
||||
if (element != null)
|
||||
{
|
||||
source.Sensors.Remove(element);
|
||||
source.SaveSensors();
|
||||
|
||||
return element.GetViewModel;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
103
SecuritySystem/SecuritySystemFileImplement/Models/Order.cs
Normal file
103
SecuritySystem/SecuritySystemFileImplement/Models/Order.cs
Normal file
@@ -0,0 +1,103 @@
|
||||
using SecuritySystemContracts.BindingModels;
|
||||
using SecuritySystemContracts.ViewModels;
|
||||
using SecuritySystemDataModels.Enums;
|
||||
using SecuritySystemDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace SecuritySystemFileImplement.Models
|
||||
{
|
||||
//класс, реализующий интерфейс модели заказа
|
||||
public class Order : IOrderModel
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
|
||||
public int SecureId { get; private set; }
|
||||
|
||||
public int Count { get; private set; }
|
||||
|
||||
public double Sum { get; private set; }
|
||||
|
||||
public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен;
|
||||
|
||||
public DateTime DateCreate { get; private set; } = DateTime.Now;
|
||||
|
||||
public DateTime? DateImplement { get; private set; }
|
||||
|
||||
public 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 static Order? Create(XElement element)
|
||||
{
|
||||
if (element == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return new Order()
|
||||
{
|
||||
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
|
||||
SecureId = Convert.ToInt32(element.Element("SecureId")!.Value),
|
||||
Count = Convert.ToInt32(element.Element("Count")!.Value),
|
||||
Sum = Convert.ToDouble(element.Element("Sum")!.Value),
|
||||
Status = (OrderStatus)Enum.Parse(typeof(OrderStatus), element.Element("Status")!.Value),
|
||||
DateCreate = Convert.ToDateTime(element.Element("DateCreate")!.Value),
|
||||
DateImplement = string.IsNullOrEmpty(element.Element("DateImplement")!.Value) ? null :
|
||||
Convert.ToDateTime(element.Element("DateImplement")!.Value)
|
||||
};
|
||||
}
|
||||
|
||||
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
|
||||
};
|
||||
|
||||
|
||||
public XElement GetXElement => new("Order",
|
||||
new XAttribute("Id", Id),
|
||||
new XElement("SecureId", SecureId.ToString()),
|
||||
new XElement("Count", Count.ToString()),
|
||||
new XElement("Sum", Sum.ToString()),
|
||||
new XElement("Status", Status.ToString()),
|
||||
new XElement("DateCreate", DateCreate.ToString()),
|
||||
new XElement("DateImplement", DateImplement.ToString()));
|
||||
}
|
||||
}
|
||||
108
SecuritySystem/SecuritySystemFileImplement/Models/Secure.cs
Normal file
108
SecuritySystem/SecuritySystemFileImplement/Models/Secure.cs
Normal file
@@ -0,0 +1,108 @@
|
||||
using SecuritySystemContracts.BindingModels;
|
||||
using SecuritySystemContracts.ViewModels;
|
||||
using SecuritySystemDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace SecuritySystemFileImplement.Models
|
||||
{
|
||||
//класс реализующий интерфейс модели изделия
|
||||
public class Secure : ISecureModel
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
|
||||
public string SecureName { get; private set; } = string.Empty;
|
||||
|
||||
public double Price { get; private set; }
|
||||
|
||||
public Dictionary<int, int> Sensors { get; private set; } = new();
|
||||
|
||||
|
||||
private Dictionary<int, (ISensorModel, int)>? _secureSensors = null;
|
||||
|
||||
public Dictionary<int, (ISensorModel, int)> SecureSensors
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_secureSensors == null)
|
||||
{
|
||||
var source = DataFileSingleton.GetInstance();
|
||||
|
||||
_secureSensors = Sensors.ToDictionary(x => x.Key,
|
||||
y => ((source.Sensors.FirstOrDefault(z => z.Id == y.Key) as ISensorModel)!, y.Value));
|
||||
}
|
||||
|
||||
return _secureSensors;
|
||||
}
|
||||
}
|
||||
|
||||
public static Secure? Create(SecureBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return new Secure()
|
||||
{
|
||||
Id = model.Id,
|
||||
SecureName = model.SecureName,
|
||||
Price = model.Price,
|
||||
Sensors = model.SecureSensors.ToDictionary(x => x.Key, x => x.Value.Item2)
|
||||
};
|
||||
}
|
||||
|
||||
public static Secure? Create(XElement element)
|
||||
{
|
||||
if (element == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return new Secure()
|
||||
{
|
||||
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
|
||||
SecureName = element.Element("SecureName")!.Value,
|
||||
Price = Convert.ToDouble(element.Element("Price")!.Value),
|
||||
Sensors = element.Element("SecureSensors")!.Elements("SecureSensors").ToDictionary(
|
||||
x => Convert.ToInt32(x.Element("Key")?.Value),
|
||||
x => Convert.ToInt32(x.Element("Value")?.Value))
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(SecureBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
SecureName = model.SecureName;
|
||||
Price = model.Price;
|
||||
Sensors = model.SecureSensors.ToDictionary(x => x.Key, x => x.Value.Item2);
|
||||
_secureSensors = null;
|
||||
}
|
||||
|
||||
public SecureViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
SecureName = SecureName,
|
||||
Price = Price,
|
||||
SecureSensors = SecureSensors
|
||||
};
|
||||
|
||||
public XElement GetXElement => new("Secure",
|
||||
new XAttribute("Id", Id),
|
||||
new XElement("SecureName", SecureName),
|
||||
new XElement("Price", Price.ToString()),
|
||||
new XElement("SecureSensors", Sensors.Select(
|
||||
x => new XElement("SecureSensors",
|
||||
new XElement("Key", x.Key),
|
||||
new XElement("Value", x.Value))
|
||||
).ToArray()));
|
||||
}
|
||||
}
|
||||
76
SecuritySystem/SecuritySystemFileImplement/Models/Sensor.cs
Normal file
76
SecuritySystem/SecuritySystemFileImplement/Models/Sensor.cs
Normal file
@@ -0,0 +1,76 @@
|
||||
using SecuritySystemContracts.BindingModels;
|
||||
using SecuritySystemContracts.ViewModels;
|
||||
using SecuritySystemDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace SecuritySystemFileImplement.Models
|
||||
{
|
||||
//реализация интерфейса модели заготовки
|
||||
public class Sensor : ISensorModel
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
|
||||
public string SensorName { get; private set; } = string.Empty;
|
||||
|
||||
public double Cost { get; set; }
|
||||
|
||||
public static Sensor? Create(SensorBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return new Sensor()
|
||||
{
|
||||
Id = model.Id,
|
||||
SensorName = model.SensorName,
|
||||
Cost = model.Cost
|
||||
};
|
||||
}
|
||||
|
||||
public static Sensor? Create(XElement element)
|
||||
{
|
||||
if (element == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return new Sensor()
|
||||
{
|
||||
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
|
||||
SensorName = element.Element("SensorName")!.Value,
|
||||
Cost = Convert.ToDouble(element.Element("Cost")!.Value)
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(SensorBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
SensorName = model.SensorName;
|
||||
Cost = model.Cost;
|
||||
}
|
||||
|
||||
public SensorViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
SensorName = SensorName,
|
||||
Cost = Cost
|
||||
};
|
||||
|
||||
public XElement GetXElement => new("Sensor",
|
||||
new XAttribute("Id", Id),
|
||||
new XElement("SensorName", SensorName),
|
||||
new XElement("Cost", Cost.ToString()));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\SecuritySystemContracts\SecuritySystemContracts.csproj" />
|
||||
<ProjectReference Include="..\SecuritySystemDataModels\SecuritySystemDataModels.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
Reference in New Issue
Block a user