сё
This commit is contained in:
parent
a8b4c76b91
commit
4605c83128
@ -15,6 +15,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LawFirmBusinessLogic", "Law
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LawFirmFileImplement", "LawFirmFileImplement\LawFirmFileImplement.csproj", "{5CAEEF2D-864E-4EA6-9051-AD57284623E1}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LawFirmFileImplement", "LawFirmFileImplement\LawFirmFileImplement.csproj", "{5CAEEF2D-864E-4EA6-9051-AD57284623E1}"
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LawFirmDatabaseImplement", "LawFirmDatabaseImplement\LawFirmDatabaseImplement.csproj", "{7015B886-71AF-4B4F-A398-9F968CFA8F39}"
|
||||||
|
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
|
|||||||
{5CAEEF2D-864E-4EA6-9051-AD57284623E1}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{5CAEEF2D-864E-4EA6-9051-AD57284623E1}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{5CAEEF2D-864E-4EA6-9051-AD57284623E1}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{5CAEEF2D-864E-4EA6-9051-AD57284623E1}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{5CAEEF2D-864E-4EA6-9051-AD57284623E1}.Release|Any CPU.Build.0 = Release|Any CPU
|
{5CAEEF2D-864E-4EA6-9051-AD57284623E1}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{7015B886-71AF-4B4F-A398-9F968CFA8F39}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{7015B886-71AF-4B4F-A398-9F968CFA8F39}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{7015B886-71AF-4B4F-A398-9F968CFA8F39}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{7015B886-71AF-4B4F-A398-9F968CFA8F39}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
@ -9,6 +9,10 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.3">
|
||||||
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
</PackageReference>
|
||||||
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
|
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
|
||||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
|
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
|
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
|
||||||
@ -19,6 +23,7 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\LawFirmBusinessLogic\LawFirmBusinessLogic.csproj" />
|
<ProjectReference Include="..\LawFirmBusinessLogic\LawFirmBusinessLogic.csproj" />
|
||||||
<ProjectReference Include="..\LawFirmContracts\LawFirmContracts.csproj" />
|
<ProjectReference Include="..\LawFirmContracts\LawFirmContracts.csproj" />
|
||||||
|
<ProjectReference Include="..\LawFirmDatabaseImplement\LawFirmDatabaseImplement.csproj" />
|
||||||
<ProjectReference Include="..\LawFirmDataModels\LawFirmDataModels.csproj" />
|
<ProjectReference Include="..\LawFirmDataModels\LawFirmDataModels.csproj" />
|
||||||
<ProjectReference Include="..\LawFirmFileImplement\LawFirmFileImplement.csproj" />
|
<ProjectReference Include="..\LawFirmFileImplement\LawFirmFileImplement.csproj" />
|
||||||
<ProjectReference Include="..\LawFirmListImplement\LawFirmListImplement.csproj" />
|
<ProjectReference Include="..\LawFirmListImplement\LawFirmListImplement.csproj" />
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
using LawFirmBusinessLogic.BusinessLogics;
|
using LawFirmBusinessLogic.BusinessLogics;
|
||||||
using LawFirmContracts.BusinessLogicsContracts;
|
using LawFirmContracts.BusinessLogicsContracts;
|
||||||
using LawFirmContracts.StoragesContracts;
|
using LawFirmContracts.StoragesContracts;
|
||||||
using LawFirmFileImplement.Implements;
|
using LawFirmDatabaseImplement.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;
|
||||||
|
@ -47,7 +47,7 @@ namespace LawFirmBusinessLogic.BusinessLogics
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
model.Status = newStatus;
|
model.Status = newStatus;
|
||||||
if (model.Status == OrderStatus.Готов) model.DateImplement = DateTime.Now;
|
if (model.Status == OrderStatus.Готов) model.DateImplement = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
model.DateImplement = viewModel.DateImplement;
|
model.DateImplement = viewModel.DateImplement;
|
||||||
|
@ -10,7 +10,7 @@ namespace LawFirmContracts.BindingModels
|
|||||||
public int Count { get; set; }
|
public int Count { get; set; }
|
||||||
public double Sum { get; set; }
|
public double Sum { get; set; }
|
||||||
public OrderStatus Status { get; set; } = OrderStatus.Неизвестен;
|
public OrderStatus Status { get; set; } = OrderStatus.Неизвестен;
|
||||||
public DateTime DateCreate { get; set; } = DateTime.Now;
|
public DateTime DateCreate { get; set; } = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc);
|
||||||
public DateTime? DateImplement { get; set; }
|
public DateTime? DateImplement { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
78
LawFirm/LawFirmDatabaseImplement/Implements/BlankStorage.cs
Normal file
78
LawFirm/LawFirmDatabaseImplement/Implements/BlankStorage.cs
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
using LawFirmContracts.BindingModels;
|
||||||
|
using LawFirmContracts.SearchModels;
|
||||||
|
using LawFirmContracts.StoragesContracts;
|
||||||
|
using LawFirmContracts.ViewModels;
|
||||||
|
using LawFirmDatabaseImplement.Models;
|
||||||
|
|
||||||
|
namespace LawFirmDatabaseImplement.Implements
|
||||||
|
{
|
||||||
|
public class BlankStorage : IBlankStorage
|
||||||
|
{
|
||||||
|
public BlankViewModel? GetElement(BlankSearchModel model)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(model.BlankName) && !model.Id.HasValue)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
using var context = new LawFirmDatabase();
|
||||||
|
return context.Blanks.FirstOrDefault(x =>
|
||||||
|
(!string.IsNullOrEmpty(model.BlankName) && x.BlankName == model.BlankName)
|
||||||
|
|| (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
|
||||||
|
|
||||||
|
}
|
||||||
|
public List<BlankViewModel> GetFilteredList(BlankSearchModel model)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(model.BlankName))
|
||||||
|
{
|
||||||
|
return new();
|
||||||
|
}
|
||||||
|
using var context = new LawFirmDatabase();
|
||||||
|
return context.Blanks
|
||||||
|
.Where(x => x.BlankName.Contains(model.BlankName))
|
||||||
|
.Select(x => x.GetViewModel)
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
public List<BlankViewModel> GetFullList()
|
||||||
|
{
|
||||||
|
using var context = new LawFirmDatabase();
|
||||||
|
return context.Blanks.Select(x => x.GetViewModel).ToList();
|
||||||
|
}
|
||||||
|
public BlankViewModel? Insert(BlankBindingModel model)
|
||||||
|
{
|
||||||
|
var newBlank = Blank.Create(model);
|
||||||
|
if (newBlank == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
using var context = new LawFirmDatabase();
|
||||||
|
context.Blanks.Add(newBlank);
|
||||||
|
context.SaveChanges();
|
||||||
|
return newBlank.GetViewModel;
|
||||||
|
|
||||||
|
}
|
||||||
|
public BlankViewModel? Update(BlankBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new LawFirmDatabase();
|
||||||
|
var blank = context.Blanks.FirstOrDefault(x => x.Id == model.Id);
|
||||||
|
if (blank == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
blank.Update(model);
|
||||||
|
context.SaveChanges();
|
||||||
|
return blank.GetViewModel;
|
||||||
|
}
|
||||||
|
public BlankViewModel? Delete(BlankBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new LawFirmDatabase();
|
||||||
|
var element = context.Blanks.FirstOrDefault(rec => rec.Id == model.Id);
|
||||||
|
if (element != null)
|
||||||
|
{
|
||||||
|
context.Blanks.Remove(element);
|
||||||
|
context.SaveChanges();
|
||||||
|
return element.GetViewModel;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
105
LawFirm/LawFirmDatabaseImplement/Implements/DocumentStorage.cs
Normal file
105
LawFirm/LawFirmDatabaseImplement/Implements/DocumentStorage.cs
Normal file
@ -0,0 +1,105 @@
|
|||||||
|
using LawFirmContracts.BindingModels;
|
||||||
|
using LawFirmContracts.SearchModels;
|
||||||
|
using LawFirmContracts.StoragesContracts;
|
||||||
|
using LawFirmContracts.ViewModels;
|
||||||
|
using LawFirmDatabaseImplement.Models;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
|
namespace LawFirmDatabaseImplement.Implements
|
||||||
|
{
|
||||||
|
public class DocumentStorage : IDocumentStorage
|
||||||
|
{
|
||||||
|
public List<DocumentViewModel> GetFullList()
|
||||||
|
{
|
||||||
|
using var context = new LawFirmDatabase();
|
||||||
|
return context.Documents
|
||||||
|
.Include(x => x.Blanks)
|
||||||
|
.ThenInclude(x => x.Blank)
|
||||||
|
.ToList()
|
||||||
|
.Select(x => x.GetViewModel)
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
public List<DocumentViewModel> GetFilteredList(DocumentSearchModel model)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(model.DocumentName))
|
||||||
|
{
|
||||||
|
return new();
|
||||||
|
}
|
||||||
|
using var context = new LawFirmDatabase();
|
||||||
|
return context.Documents
|
||||||
|
.Include(x => x.Blanks)
|
||||||
|
.ThenInclude(x => x.Blank)
|
||||||
|
.Where(x => x.DocumentName.Contains(model.DocumentName))
|
||||||
|
.ToList()
|
||||||
|
.Select(x => x.GetViewModel)
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
public DocumentViewModel? GetElement(DocumentSearchModel model)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(model.DocumentName) &&
|
||||||
|
!model.Id.HasValue)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
using var context = new LawFirmDatabase();
|
||||||
|
return context.Documents
|
||||||
|
.Include(x => x.Blanks)
|
||||||
|
.ThenInclude(x => x.Blank)
|
||||||
|
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.DocumentName) &&
|
||||||
|
x.DocumentName == model.DocumentName) ||
|
||||||
|
(model.Id.HasValue && x.Id ==
|
||||||
|
model.Id))
|
||||||
|
?.GetViewModel;
|
||||||
|
}
|
||||||
|
public DocumentViewModel? Insert(DocumentBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new LawFirmDatabase();
|
||||||
|
var newDocument = Document.Create(context, model);
|
||||||
|
if (newDocument == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
context.Documents.Add(newDocument);
|
||||||
|
context.SaveChanges();
|
||||||
|
return newDocument.GetViewModel;
|
||||||
|
}
|
||||||
|
public DocumentViewModel? Update(DocumentBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new LawFirmDatabase();
|
||||||
|
using var transaction = context.Database.BeginTransaction();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var product = context.Documents.FirstOrDefault(rec =>
|
||||||
|
rec.Id == model.Id);
|
||||||
|
if (product == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
product.Update(model);
|
||||||
|
context.SaveChanges();
|
||||||
|
product.UpdateBlanks(context, model);
|
||||||
|
transaction.Commit();
|
||||||
|
return product.GetViewModel;
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
transaction.Rollback();
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public DocumentViewModel? Delete(DocumentBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new LawFirmDatabase();
|
||||||
|
var element = context.Documents
|
||||||
|
.Include(x => x.Blanks)
|
||||||
|
.FirstOrDefault(rec => rec.Id == model.Id);
|
||||||
|
if (element != null)
|
||||||
|
{
|
||||||
|
context.Documents.Remove(element);
|
||||||
|
context.SaveChanges();
|
||||||
|
return element.GetViewModel;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
76
LawFirm/LawFirmDatabaseImplement/Implements/OrderStorage.cs
Normal file
76
LawFirm/LawFirmDatabaseImplement/Implements/OrderStorage.cs
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
using LawFirmContracts.BindingModels;
|
||||||
|
using LawFirmContracts.SearchModels;
|
||||||
|
using LawFirmContracts.StoragesContracts;
|
||||||
|
using LawFirmContracts.ViewModels;
|
||||||
|
using LawFirmDatabaseImplement.Models;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
|
namespace LawFirmDatabaseImplement.Implements
|
||||||
|
{
|
||||||
|
public class OrderStorage : IOrderStorage
|
||||||
|
{
|
||||||
|
public OrderViewModel? GetElement(OrderSearchModel model)
|
||||||
|
{
|
||||||
|
if (!model.Id.HasValue)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
using var context = new LawFirmDatabase();
|
||||||
|
return context.Orders.Include(x => x.Document).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 LawFirmDatabase();
|
||||||
|
return context.Orders
|
||||||
|
.Where(x => x.Id == model.Id)
|
||||||
|
.Include(x => x.Document)
|
||||||
|
.Select(x => x.GetViewModel)
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
public List<OrderViewModel> GetFullList()
|
||||||
|
{
|
||||||
|
using var context = new LawFirmDatabase();
|
||||||
|
return context.Orders.Include(x => x.Document).Select(x => x.GetViewModel).ToList();
|
||||||
|
}
|
||||||
|
public OrderViewModel? Insert(OrderBindingModel model)
|
||||||
|
{
|
||||||
|
var newOrder = Order.Create(model);
|
||||||
|
if (newOrder == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
using var context = new LawFirmDatabase();
|
||||||
|
context.Orders.Add(newOrder);
|
||||||
|
context.SaveChanges();
|
||||||
|
return context.Orders.Include(x => x.Document).FirstOrDefault(x => x.Id == newOrder.Id)?.GetViewModel;
|
||||||
|
}
|
||||||
|
public OrderViewModel? Update(OrderBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new LawFirmDatabase();
|
||||||
|
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.Document).FirstOrDefault(x => x.Id == model.Id)?.GetViewModel;
|
||||||
|
}
|
||||||
|
public OrderViewModel? Delete(OrderBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new LawFirmDatabase();
|
||||||
|
var element = context.Orders.FirstOrDefault(rec => rec.Id == model.Id);
|
||||||
|
if (element != null)
|
||||||
|
{
|
||||||
|
context.Orders.Remove(element);
|
||||||
|
context.SaveChanges();
|
||||||
|
return element.GetViewModel;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
21
LawFirm/LawFirmDatabaseImplement/LawFirmDatabase.cs
Normal file
21
LawFirm/LawFirmDatabaseImplement/LawFirmDatabase.cs
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
using LawFirmDatabaseImplement.Models;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
|
namespace LawFirmDatabaseImplement
|
||||||
|
{
|
||||||
|
public class LawFirmDatabase : DbContext
|
||||||
|
{
|
||||||
|
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||||
|
{
|
||||||
|
if (optionsBuilder.IsConfigured == false)
|
||||||
|
{
|
||||||
|
optionsBuilder.UseSqlServer(@"Data Source=localhost\SQLEXPRESS; Initial Catalog=LawFirmDatabaseFull;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True");
|
||||||
|
}
|
||||||
|
base.OnConfiguring(optionsBuilder);
|
||||||
|
}
|
||||||
|
public virtual DbSet<Blank> Blanks { set; get; }
|
||||||
|
public virtual DbSet<Document> Documents { set; get; }
|
||||||
|
public virtual DbSet<DocumentBlank> DocumentBlanks { set; get; }
|
||||||
|
public virtual DbSet<Order> Orders { set; get; }
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,24 @@
|
|||||||
|
<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.3" />
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.3" />
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.3">
|
||||||
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
</PackageReference>
|
||||||
|
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="7.0.3" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\LawFirmContracts\LawFirmContracts.csproj" />
|
||||||
|
<ProjectReference Include="..\LawFirmDataModels\LawFirmDataModels.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
171
LawFirm/LawFirmDatabaseImplement/Migrations/20240422203642_InitialCreate.Designer.cs
generated
Normal file
171
LawFirm/LawFirmDatabaseImplement/Migrations/20240422203642_InitialCreate.Designer.cs
generated
Normal file
@ -0,0 +1,171 @@
|
|||||||
|
// <auto-generated />
|
||||||
|
using System;
|
||||||
|
using LawFirmDatabaseImplement;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||||
|
using Microsoft.EntityFrameworkCore.Metadata;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace LawFirmDatabaseImplement.Migrations
|
||||||
|
{
|
||||||
|
[DbContext(typeof(LawFirmDatabase))]
|
||||||
|
[Migration("20240422203642_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("LawFirmDatabaseImplement.Models.Blank", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<string>("BlankName")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.Property<double>("Price")
|
||||||
|
.HasColumnType("float");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("Blanks");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("LawFirmDatabaseImplement.Models.Document", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<string>("DocumentName")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.Property<double>("Price")
|
||||||
|
.HasColumnType("float");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("Documents");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("LawFirmDatabaseImplement.Models.DocumentBlank", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<int>("BlankId")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<int>("Count")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<int>("DocumentId")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("BlankId");
|
||||||
|
|
||||||
|
b.HasIndex("DocumentId");
|
||||||
|
|
||||||
|
b.ToTable("DocumentBlanks");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("LawFirmDatabaseImplement.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>("DocumentId")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<int>("Status")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<double>("Sum")
|
||||||
|
.HasColumnType("float");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("DocumentId");
|
||||||
|
|
||||||
|
b.ToTable("Orders");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("LawFirmDatabaseImplement.Models.DocumentBlank", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("LawFirmDatabaseImplement.Models.Blank", "Blank")
|
||||||
|
.WithMany("DocumentBlanks")
|
||||||
|
.HasForeignKey("BlankId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.HasOne("LawFirmDatabaseImplement.Models.Document", "Document")
|
||||||
|
.WithMany("Blanks")
|
||||||
|
.HasForeignKey("DocumentId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("Blank");
|
||||||
|
|
||||||
|
b.Navigation("Document");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("LawFirmDatabaseImplement.Models.Order", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("LawFirmDatabaseImplement.Models.Document", "Document")
|
||||||
|
.WithMany("Orders")
|
||||||
|
.HasForeignKey("DocumentId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("Document");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("LawFirmDatabaseImplement.Models.Blank", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("DocumentBlanks");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("LawFirmDatabaseImplement.Models.Document", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("Blanks");
|
||||||
|
|
||||||
|
b.Navigation("Orders");
|
||||||
|
});
|
||||||
|
#pragma warning restore 612, 618
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,125 @@
|
|||||||
|
using System;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace LawFirmDatabaseImplement.Migrations
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
public partial class InitialCreate : Migration
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "Blanks",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<int>(type: "int", nullable: false)
|
||||||
|
.Annotation("SqlServer:Identity", "1, 1"),
|
||||||
|
BlankName = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||||
|
Price = table.Column<double>(type: "float", nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_Blanks", x => x.Id);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "Documents",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<int>(type: "int", nullable: false)
|
||||||
|
.Annotation("SqlServer:Identity", "1, 1"),
|
||||||
|
DocumentName = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||||
|
Price = table.Column<double>(type: "float", nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_Documents", x => x.Id);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "DocumentBlanks",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<int>(type: "int", nullable: false)
|
||||||
|
.Annotation("SqlServer:Identity", "1, 1"),
|
||||||
|
DocumentId = table.Column<int>(type: "int", nullable: false),
|
||||||
|
BlankId = table.Column<int>(type: "int", nullable: false),
|
||||||
|
Count = table.Column<int>(type: "int", nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_DocumentBlanks", x => x.Id);
|
||||||
|
table.ForeignKey(
|
||||||
|
name: "FK_DocumentBlanks_Blanks_BlankId",
|
||||||
|
column: x => x.BlankId,
|
||||||
|
principalTable: "Blanks",
|
||||||
|
principalColumn: "Id",
|
||||||
|
onDelete: ReferentialAction.Cascade);
|
||||||
|
table.ForeignKey(
|
||||||
|
name: "FK_DocumentBlanks_Documents_DocumentId",
|
||||||
|
column: x => x.DocumentId,
|
||||||
|
principalTable: "Documents",
|
||||||
|
principalColumn: "Id",
|
||||||
|
onDelete: ReferentialAction.Cascade);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "Orders",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<int>(type: "int", nullable: false)
|
||||||
|
.Annotation("SqlServer:Identity", "1, 1"),
|
||||||
|
DocumentId = 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_Documents_DocumentId",
|
||||||
|
column: x => x.DocumentId,
|
||||||
|
principalTable: "Documents",
|
||||||
|
principalColumn: "Id",
|
||||||
|
onDelete: ReferentialAction.Cascade);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_DocumentBlanks_BlankId",
|
||||||
|
table: "DocumentBlanks",
|
||||||
|
column: "BlankId");
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_DocumentBlanks_DocumentId",
|
||||||
|
table: "DocumentBlanks",
|
||||||
|
column: "DocumentId");
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_Orders_DocumentId",
|
||||||
|
table: "Orders",
|
||||||
|
column: "DocumentId");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "DocumentBlanks");
|
||||||
|
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "Orders");
|
||||||
|
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "Blanks");
|
||||||
|
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "Documents");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,168 @@
|
|||||||
|
// <auto-generated />
|
||||||
|
using System;
|
||||||
|
using LawFirmDatabaseImplement;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||||
|
using Microsoft.EntityFrameworkCore.Metadata;
|
||||||
|
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace LawFirmDatabaseImplement.Migrations
|
||||||
|
{
|
||||||
|
[DbContext(typeof(LawFirmDatabase))]
|
||||||
|
partial class LawFirmDatabaseModelSnapshot : 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("LawFirmDatabaseImplement.Models.Blank", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<string>("BlankName")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.Property<double>("Price")
|
||||||
|
.HasColumnType("float");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("Blanks");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("LawFirmDatabaseImplement.Models.Document", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<string>("DocumentName")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.Property<double>("Price")
|
||||||
|
.HasColumnType("float");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("Documents");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("LawFirmDatabaseImplement.Models.DocumentBlank", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<int>("BlankId")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<int>("Count")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<int>("DocumentId")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("BlankId");
|
||||||
|
|
||||||
|
b.HasIndex("DocumentId");
|
||||||
|
|
||||||
|
b.ToTable("DocumentBlanks");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("LawFirmDatabaseImplement.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>("DocumentId")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<int>("Status")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<double>("Sum")
|
||||||
|
.HasColumnType("float");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("DocumentId");
|
||||||
|
|
||||||
|
b.ToTable("Orders");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("LawFirmDatabaseImplement.Models.DocumentBlank", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("LawFirmDatabaseImplement.Models.Blank", "Blank")
|
||||||
|
.WithMany("DocumentBlanks")
|
||||||
|
.HasForeignKey("BlankId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.HasOne("LawFirmDatabaseImplement.Models.Document", "Document")
|
||||||
|
.WithMany("Blanks")
|
||||||
|
.HasForeignKey("DocumentId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("Blank");
|
||||||
|
|
||||||
|
b.Navigation("Document");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("LawFirmDatabaseImplement.Models.Order", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("LawFirmDatabaseImplement.Models.Document", "Document")
|
||||||
|
.WithMany("Orders")
|
||||||
|
.HasForeignKey("DocumentId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("Document");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("LawFirmDatabaseImplement.Models.Blank", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("DocumentBlanks");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("LawFirmDatabaseImplement.Models.Document", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("Blanks");
|
||||||
|
|
||||||
|
b.Navigation("Orders");
|
||||||
|
});
|
||||||
|
#pragma warning restore 612, 618
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
56
LawFirm/LawFirmDatabaseImplement/Models/Blank.cs
Normal file
56
LawFirm/LawFirmDatabaseImplement/Models/Blank.cs
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
using LawFirmContracts.BindingModels;
|
||||||
|
using LawFirmContracts.ViewModels;
|
||||||
|
using LawFirmDataModels.Models;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
|
|
||||||
|
namespace LawFirmDatabaseImplement.Models
|
||||||
|
{
|
||||||
|
public class Blank : IBlankModel
|
||||||
|
{
|
||||||
|
public int Id { get; private set; }
|
||||||
|
[Required]
|
||||||
|
public string BlankName { get; private set; } = string.Empty;
|
||||||
|
[Required]
|
||||||
|
public double Price { get; set; }
|
||||||
|
[ForeignKey("BlankId")]
|
||||||
|
public virtual List<DocumentBlank> DocumentBlanks { get; set; } = new();
|
||||||
|
public static Blank? Create(BlankBindingModel model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new Blank()
|
||||||
|
{
|
||||||
|
Id = model.Id,
|
||||||
|
BlankName = model.BlankName,
|
||||||
|
Price = model.Price
|
||||||
|
};
|
||||||
|
}
|
||||||
|
public static Blank Create(BlankViewModel model)
|
||||||
|
{
|
||||||
|
return new Blank
|
||||||
|
{
|
||||||
|
Id = model.Id,
|
||||||
|
BlankName = model.BlankName,
|
||||||
|
Price = model.Price
|
||||||
|
};
|
||||||
|
}
|
||||||
|
public void Update(BlankBindingModel model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
BlankName = model.BlankName;
|
||||||
|
Price = model.Price;
|
||||||
|
}
|
||||||
|
public BlankViewModel GetViewModel => new()
|
||||||
|
{
|
||||||
|
Id = Id,
|
||||||
|
BlankName = BlankName,
|
||||||
|
Price = Price
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
94
LawFirm/LawFirmDatabaseImplement/Models/Document.cs
Normal file
94
LawFirm/LawFirmDatabaseImplement/Models/Document.cs
Normal file
@ -0,0 +1,94 @@
|
|||||||
|
using LawFirmContracts.BindingModels;
|
||||||
|
using LawFirmContracts.ViewModels;
|
||||||
|
using LawFirmDataModels.Models;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
|
|
||||||
|
namespace LawFirmDatabaseImplement.Models
|
||||||
|
{
|
||||||
|
public class Document : IDocumentModel
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
[Required]
|
||||||
|
public string DocumentName { get; set; } = string.Empty;
|
||||||
|
[Required]
|
||||||
|
public double Price { get; set; }
|
||||||
|
private Dictionary<int, (IBlankModel, int)>? _documentBlanks = null;
|
||||||
|
[NotMapped]
|
||||||
|
public Dictionary<int, (IBlankModel, int)> DocumentBlanks
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (_documentBlanks == null)
|
||||||
|
{
|
||||||
|
_documentBlanks = Blanks
|
||||||
|
.ToDictionary(recPC => recPC.BlankId, recPC =>
|
||||||
|
(recPC.Blank as IBlankModel, recPC.Count));
|
||||||
|
}
|
||||||
|
return _documentBlanks;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
[ForeignKey("DocumentId")]
|
||||||
|
public virtual List<DocumentBlank> Blanks { get; set; } = new();
|
||||||
|
[ForeignKey("DocumentId")]
|
||||||
|
public virtual List<Order> Orders { get; set; } = new();
|
||||||
|
public static Document Create(LawFirmDatabase context, DocumentBindingModel model)
|
||||||
|
{
|
||||||
|
return new Document()
|
||||||
|
{
|
||||||
|
Id = model.Id,
|
||||||
|
DocumentName = model.DocumentName,
|
||||||
|
Price = model.Price,
|
||||||
|
Blanks = model.DocumentBlanks.Select(x => new DocumentBlank
|
||||||
|
{
|
||||||
|
Blank = context.Blanks.First(y => y.Id == x.Key),
|
||||||
|
Count = x.Value.Item2
|
||||||
|
}).ToList()
|
||||||
|
};
|
||||||
|
}
|
||||||
|
public void Update(DocumentBindingModel model)
|
||||||
|
{
|
||||||
|
DocumentName = model.DocumentName;
|
||||||
|
Price = model.Price;
|
||||||
|
}
|
||||||
|
public DocumentViewModel GetViewModel => new()
|
||||||
|
{
|
||||||
|
Id = Id,
|
||||||
|
DocumentName = DocumentName,
|
||||||
|
Price = Price,
|
||||||
|
DocumentBlanks = DocumentBlanks
|
||||||
|
};
|
||||||
|
public void UpdateBlanks(LawFirmDatabase context,
|
||||||
|
DocumentBindingModel model)
|
||||||
|
{
|
||||||
|
var documentBlanks = context.DocumentBlanks.Where(rec =>
|
||||||
|
rec.DocumentId == model.Id).ToList();
|
||||||
|
if (documentBlanks != null && documentBlanks.Count > 0)
|
||||||
|
{ // удалили те, которых нет в модели
|
||||||
|
context.DocumentBlanks.RemoveRange(documentBlanks.Where(rec
|
||||||
|
=> !model.DocumentBlanks.ContainsKey(rec.BlankId)));
|
||||||
|
context.SaveChanges();
|
||||||
|
// обновили количество у существующих записей
|
||||||
|
foreach (var updateBlank in documentBlanks)
|
||||||
|
{
|
||||||
|
updateBlank.Count =
|
||||||
|
model.DocumentBlanks[updateBlank.BlankId].Item2;
|
||||||
|
model.DocumentBlanks.Remove(updateBlank.BlankId);
|
||||||
|
}
|
||||||
|
context.SaveChanges();
|
||||||
|
}
|
||||||
|
var document = context.Documents.First(x => x.Id == Id);
|
||||||
|
foreach (var pc in model.DocumentBlanks)
|
||||||
|
{
|
||||||
|
context.DocumentBlanks.Add(new DocumentBlank
|
||||||
|
{
|
||||||
|
Document = document,
|
||||||
|
Blank = context.Blanks.First(x => x.Id == pc.Key),
|
||||||
|
Count = pc.Value.Item2
|
||||||
|
});
|
||||||
|
context.SaveChanges();
|
||||||
|
}
|
||||||
|
_documentBlanks = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
18
LawFirm/LawFirmDatabaseImplement/Models/DocumentBlank.cs
Normal file
18
LawFirm/LawFirmDatabaseImplement/Models/DocumentBlank.cs
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
using System.ComponentModel;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
|
||||||
|
namespace LawFirmDatabaseImplement.Models
|
||||||
|
{
|
||||||
|
public class DocumentBlank
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
[Required]
|
||||||
|
public int DocumentId { get; set; }
|
||||||
|
[Required]
|
||||||
|
public int BlankId { get; set; }
|
||||||
|
[Required]
|
||||||
|
public int Count { get; set; }
|
||||||
|
public virtual Blank Blank { get; set; } = new();
|
||||||
|
public virtual Document Document { get; set; } = new();
|
||||||
|
}
|
||||||
|
}
|
63
LawFirm/LawFirmDatabaseImplement/Models/Order.cs
Normal file
63
LawFirm/LawFirmDatabaseImplement/Models/Order.cs
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
using LawFirmContracts.BindingModels;
|
||||||
|
using LawFirmContracts.ViewModels;
|
||||||
|
using LawFirmDataModels.Enums;
|
||||||
|
using LawFirmDataModels.Models;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
|
|
||||||
|
namespace LawFirmDatabaseImplement.Models
|
||||||
|
{
|
||||||
|
public class Order : IOrderModel
|
||||||
|
{
|
||||||
|
[Required]
|
||||||
|
public int DocumentId { 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 Document Document { get; set; }
|
||||||
|
public static Order? Create(OrderBindingModel? model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new Order()
|
||||||
|
{
|
||||||
|
Id = model.Id,
|
||||||
|
DocumentId = model.DocumentId,
|
||||||
|
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,
|
||||||
|
DocumentId = DocumentId,
|
||||||
|
Count = Count,
|
||||||
|
Sum = Sum,
|
||||||
|
Status = Status,
|
||||||
|
DateCreate = DateCreate,
|
||||||
|
DateImplement = DateImplement,
|
||||||
|
DocumentName = Document.DocumentName
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user