lab is done
This commit is contained in:
parent
7c2e0f5168
commit
6b33bac4c0
@ -13,7 +13,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FurnitureAssemblyListImplem
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FurnitureAssemblyBusinessLogic", "FurnitureAssemblyBusinessLogic\FurnitureAssemblyBusinessLogic.csproj", "{D5118A99-17DE-4722-AA56-3A358CE0BB62}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FurnitureAssemblyBusinessLogic", "FurnitureAssemblyBusinessLogic\FurnitureAssemblyBusinessLogic.csproj", "{D5118A99-17DE-4722-AA56-3A358CE0BB62}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FurnitureAssemblyFileImplement", "FurnitureAssemblyFileImplement\FurnitureAssemblyFileImplement.csproj", "{AD1729BF-2142-4014-9C7C-A2BAF426DFEB}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FurnitureAssemblyFileImplement", "FurnitureAssemblyFileImplement\FurnitureAssemblyFileImplement.csproj", "{AD1729BF-2142-4014-9C7C-A2BAF426DFEB}"
|
||||||
|
EndProject
|
||||||
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FurnitureAssemblyDatabaseImplement", "FurnitureAssemblyDatabaseImplement\FurnitureAssemblyDatabaseImplement.csproj", "{C069851C-EA8C-4738-A31B-3FC6BA27634D}"
|
||||||
EndProject
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
@ -45,6 +47,10 @@ Global
|
|||||||
{AD1729BF-2142-4014-9C7C-A2BAF426DFEB}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{AD1729BF-2142-4014-9C7C-A2BAF426DFEB}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{AD1729BF-2142-4014-9C7C-A2BAF426DFEB}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{AD1729BF-2142-4014-9C7C-A2BAF426DFEB}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{AD1729BF-2142-4014-9C7C-A2BAF426DFEB}.Release|Any CPU.Build.0 = Release|Any CPU
|
{AD1729BF-2142-4014-9C7C-A2BAF426DFEB}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{C069851C-EA8C-4738-A31B-3FC6BA27634D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{C069851C-EA8C-4738-A31B-3FC6BA27634D}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{C069851C-EA8C-4738-A31B-3FC6BA27634D}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{C069851C-EA8C-4738-A31B-3FC6BA27634D}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
@ -19,6 +19,10 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.7">
|
||||||
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
</PackageReference>
|
||||||
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="8.0.0" />
|
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" 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.Abstractions" Version="8.0.0" />
|
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.0" />
|
||||||
@ -28,6 +32,7 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\FurnitureAssemblyBusinessLogic\FurnitureAssemblyBusinessLogic.csproj" />
|
<ProjectReference Include="..\FurnitureAssemblyBusinessLogic\FurnitureAssemblyBusinessLogic.csproj" />
|
||||||
<ProjectReference Include="..\FurnitureAssemblyContracts\FurnitureAssemblyContracts.csproj" />
|
<ProjectReference Include="..\FurnitureAssemblyContracts\FurnitureAssemblyContracts.csproj" />
|
||||||
|
<ProjectReference Include="..\FurnitureAssemblyDatabaseImplement\FurnitureAssemblyDatabaseImplement.csproj" />
|
||||||
<ProjectReference Include="..\FurnitureAssemblyFileImplement\FurnitureAssemblyFileImplement.csproj" />
|
<ProjectReference Include="..\FurnitureAssemblyFileImplement\FurnitureAssemblyFileImplement.csproj" />
|
||||||
<ProjectReference Include="..\FurnitureAssemblyListImplement\FurnitureAssemblyListImplement.csproj" />
|
<ProjectReference Include="..\FurnitureAssemblyListImplement\FurnitureAssemblyListImplement.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
@ -2,7 +2,7 @@ using FurnitureAssemblyBusinessLogic;
|
|||||||
using FurnitureAssemblyBusinessLogic.BusinessLogics;
|
using FurnitureAssemblyBusinessLogic.BusinessLogics;
|
||||||
using FurnitureAssemblyContracts.BusinessLogicsContracts;
|
using FurnitureAssemblyContracts.BusinessLogicsContracts;
|
||||||
using FurnitureAssemblyContracts.StoragesContracts;
|
using FurnitureAssemblyContracts.StoragesContracts;
|
||||||
using FurnitureAssemblyFileImplement.Implements;
|
using FurnitureAssemblyDatabaseImplement.Implements;
|
||||||
using FurnitureAssemblyView;
|
using FurnitureAssemblyView;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
@ -134,7 +134,7 @@ namespace FurnitureAssemblyBusinessLogic
|
|||||||
|
|
||||||
if (model.Status == OrderStatus.Выдан)
|
if (model.Status == OrderStatus.Выдан)
|
||||||
{
|
{
|
||||||
model.DateImplement = DateTime.Now;
|
model.DateImplement = DateTime.Now.ToUniversalTime();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -15,7 +15,7 @@ namespace FurnitureAssemblyContracts.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.Now.ToUniversalTime();
|
||||||
public DateTime? DateImplement { get; set; }
|
public DateTime? DateImplement { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,33 @@
|
|||||||
|
using FurnitureAssemblyDatabaseImplement.Models;
|
||||||
|
using FurnitureAssemblyListImplement.Models;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace FurnitureAssemblyDatabaseImplement
|
||||||
|
{
|
||||||
|
public class FurnitureAssemblyDatabase : DbContext
|
||||||
|
{
|
||||||
|
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||||
|
{
|
||||||
|
if (optionsBuilder.IsConfigured == false)
|
||||||
|
{
|
||||||
|
optionsBuilder.UseNpgsql("Host=10.211.55.3;Database=FurnitureAssemblyDatabaseFull;Username=postgres;Password=postgres");
|
||||||
|
}
|
||||||
|
|
||||||
|
base.OnConfiguring(optionsBuilder);
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual DbSet<Models.Workpiece> Workpieces { set; get; }
|
||||||
|
|
||||||
|
public virtual DbSet<Models.Furniture> Furnitures { set; get; }
|
||||||
|
|
||||||
|
public virtual DbSet<Models.FurnitureWorkpiece> FurnitureWorkpieces { set; get; }
|
||||||
|
|
||||||
|
public virtual DbSet<Models.Order> Orders { set; get; }
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,23 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.3" />
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.0" />
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.1">
|
||||||
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
</PackageReference>
|
||||||
|
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="7.0.0" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\FurnitureAssemblyListImplement\FurnitureAssemblyListImplement.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
@ -0,0 +1,126 @@
|
|||||||
|
using FurnitureAssemblyContracts.BindingModels;
|
||||||
|
using FurnitureAssemblyContracts.SearchModels;
|
||||||
|
using FurnitureAssemblyContracts.StoragesContracts;
|
||||||
|
using FurnitureAssemblyContracts.ViewModels;
|
||||||
|
using FurnitureAssemblyDatabaseImplement.Models;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace FurnitureAssemblyDatabaseImplement.Implements
|
||||||
|
{
|
||||||
|
public class FurnitureStorage : IFurnitureStorage
|
||||||
|
{
|
||||||
|
public List<FurnitureViewModel> GetFullList()
|
||||||
|
{
|
||||||
|
using var context = new FurnitureAssemblyDatabase();
|
||||||
|
|
||||||
|
return context.Furnitures
|
||||||
|
.Include(x => x.Workpieces)
|
||||||
|
.ThenInclude(x => x.Workpiece)
|
||||||
|
.ToList()
|
||||||
|
.Select(x => x.GetViewModel)
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<FurnitureViewModel> GetFilteredList(FurnitureSearchModel model)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(model.FurnitureName))
|
||||||
|
{
|
||||||
|
return new();
|
||||||
|
}
|
||||||
|
|
||||||
|
using var context = new FurnitureAssemblyDatabase();
|
||||||
|
|
||||||
|
return context.Furnitures
|
||||||
|
.Include(x => x.Workpieces)
|
||||||
|
.ThenInclude(x => x.Workpiece)
|
||||||
|
.Where(x => x.FurnitureName.Contains(model.FurnitureName))
|
||||||
|
.ToList()
|
||||||
|
.Select(x => x.GetViewModel)
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public FurnitureViewModel? GetElement(FurnitureSearchModel model)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(model.FurnitureName) && !model.Id.HasValue)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
using var context = new FurnitureAssemblyDatabase();
|
||||||
|
|
||||||
|
return context.Furnitures
|
||||||
|
.Include(x => x.Workpieces)
|
||||||
|
.ThenInclude(x => x.Workpiece)
|
||||||
|
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.FurnitureName) && x.FurnitureName == model.FurnitureName) ||
|
||||||
|
model.Id.HasValue && x.Id == model.Id)?.GetViewModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public FurnitureViewModel? Insert(FurnitureBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new FurnitureAssemblyDatabase();
|
||||||
|
var newFurniture = Furniture.Create(context, model);
|
||||||
|
|
||||||
|
if (newFurniture == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
context.Furnitures.Add(newFurniture);
|
||||||
|
context.SaveChanges();
|
||||||
|
|
||||||
|
return newFurniture.GetViewModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public FurnitureViewModel? Update(FurnitureBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new FurnitureAssemblyDatabase();
|
||||||
|
using var transaction = context.Database.BeginTransaction();
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var furniture = context.Furnitures.FirstOrDefault(rec => rec.Id == model.Id);
|
||||||
|
|
||||||
|
if (furniture == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
furniture.Update(model);
|
||||||
|
context.SaveChanges();
|
||||||
|
furniture.UpdateWorkpieces(context, model);
|
||||||
|
transaction.Commit();
|
||||||
|
|
||||||
|
return furniture.GetViewModel;
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
transaction.Rollback();
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public FurnitureViewModel? Delete(FurnitureBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new FurnitureAssemblyDatabase();
|
||||||
|
var element = context.Furnitures
|
||||||
|
.Include(x => x.Workpieces)
|
||||||
|
.Include(x => x.Orders)
|
||||||
|
.FirstOrDefault(rec => rec.Id == model.Id);
|
||||||
|
|
||||||
|
if (element != null)
|
||||||
|
{
|
||||||
|
context.Furnitures.Remove(element);
|
||||||
|
context.SaveChanges();
|
||||||
|
|
||||||
|
return element.GetViewModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,103 @@
|
|||||||
|
using FurnitureAssemblyContracts.BindingModels;
|
||||||
|
using FurnitureAssemblyContracts.SearchModels;
|
||||||
|
using FurnitureAssemblyContracts.StoragesContracts;
|
||||||
|
using FurnitureAssemblyContracts.ViewModels;
|
||||||
|
using FurnitureAssemblyDatabaseImplement.Models;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace FurnitureAssemblyDatabaseImplement.Implements
|
||||||
|
{
|
||||||
|
public class OrderStorage : IOrderStorage
|
||||||
|
{
|
||||||
|
public OrderViewModel? GetElement(OrderSearchModel model)
|
||||||
|
{
|
||||||
|
if (!model.Id.HasValue)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
using var context = new FurnitureAssemblyDatabase();
|
||||||
|
|
||||||
|
return context.Orders.Include(x => x.Furniture).
|
||||||
|
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 FurnitureAssemblyDatabase();
|
||||||
|
|
||||||
|
return context.Orders
|
||||||
|
.Include(x => x.Furniture)
|
||||||
|
.Where(x => x.Id == model.Id)
|
||||||
|
.Select(x => x.GetViewModel)
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<OrderViewModel> GetFullList()
|
||||||
|
{
|
||||||
|
using var context = new FurnitureAssemblyDatabase();
|
||||||
|
|
||||||
|
return context.Orders.Include(x => x.Furniture)
|
||||||
|
.Select(x => x.GetViewModel).ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public OrderViewModel? Insert(OrderBindingModel model)
|
||||||
|
{
|
||||||
|
var newOrder = Order.Create(model);
|
||||||
|
|
||||||
|
if (newOrder == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
using var context = new FurnitureAssemblyDatabase();
|
||||||
|
context.Orders.Add(newOrder);
|
||||||
|
context.SaveChanges();
|
||||||
|
|
||||||
|
return context.Orders.Include(x => x.Furniture)
|
||||||
|
.FirstOrDefault(x => x.Id == newOrder.Id)?.GetViewModel;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public OrderViewModel? Update(OrderBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new FurnitureAssemblyDatabase();
|
||||||
|
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.Furniture).FirstOrDefault(x => x.Id == model.Id)?.GetViewModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OrderViewModel? Delete(OrderBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new FurnitureAssemblyDatabase();
|
||||||
|
var element = context.Orders.FirstOrDefault(rec => rec.Id == model.Id);
|
||||||
|
|
||||||
|
if (element != null)
|
||||||
|
{
|
||||||
|
context.Orders.Remove(element);
|
||||||
|
context.SaveChanges();
|
||||||
|
|
||||||
|
return element.GetViewModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,100 @@
|
|||||||
|
using FurnitureAssemblyContracts.BindingModels;
|
||||||
|
using FurnitureAssemblyContracts.SearchModels;
|
||||||
|
using FurnitureAssemblyContracts.StoragesContracts;
|
||||||
|
using FurnitureAssemblyContracts.ViewModels;
|
||||||
|
using FurnitureAssemblyDatabaseImplement.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace FurnitureAssemblyDatabaseImplement.Implements
|
||||||
|
{
|
||||||
|
public class WorkpieceStorage : IWorkpieceStorage
|
||||||
|
{
|
||||||
|
public List<WorkpieceViewModel> GetFullList()
|
||||||
|
{
|
||||||
|
using var context = new FurnitureAssemblyDatabase();
|
||||||
|
return context.Workpieces
|
||||||
|
.Select(x => x.GetViewModel)
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<WorkpieceViewModel> GetFilteredList(WorkpieceSearchModel model)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(model.WorkpieceName))
|
||||||
|
{
|
||||||
|
return new();
|
||||||
|
}
|
||||||
|
|
||||||
|
using var context = new FurnitureAssemblyDatabase();
|
||||||
|
|
||||||
|
return context.Workpieces
|
||||||
|
.Where(x => x.WorkpieceName.Contains(model.WorkpieceName))
|
||||||
|
.Select(x => x.GetViewModel)
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public WorkpieceViewModel? GetElement(WorkpieceSearchModel model)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(model.WorkpieceName) && !model.Id.HasValue)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
using var context = new FurnitureAssemblyDatabase();
|
||||||
|
|
||||||
|
return context.Workpieces
|
||||||
|
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.WorkpieceName) && x.WorkpieceName == model.WorkpieceName) ||
|
||||||
|
(model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public WorkpieceViewModel? Insert(WorkpieceBindingModel model)
|
||||||
|
{
|
||||||
|
var newWorkpiece = Workpiece.Create(model);
|
||||||
|
|
||||||
|
if (newWorkpiece == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
using var context = new FurnitureAssemblyDatabase();
|
||||||
|
context.Workpieces.Add(newWorkpiece);
|
||||||
|
context.SaveChanges();
|
||||||
|
|
||||||
|
return newWorkpiece.GetViewModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public WorkpieceViewModel? Update(WorkpieceBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new FurnitureAssemblyDatabase();
|
||||||
|
var workPiece = context.Workpieces.FirstOrDefault(x => x.Id == model.Id);
|
||||||
|
|
||||||
|
if (workPiece == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
workPiece.Update(model);
|
||||||
|
context.SaveChanges();
|
||||||
|
|
||||||
|
return workPiece.GetViewModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public WorkpieceViewModel? Delete(WorkpieceBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new FurnitureAssemblyDatabase();
|
||||||
|
var element = context.Workpieces.FirstOrDefault(rec => rec.Id == model.Id);
|
||||||
|
|
||||||
|
if (element != null)
|
||||||
|
{
|
||||||
|
context.Workpieces.Remove(element);
|
||||||
|
context.SaveChanges();
|
||||||
|
|
||||||
|
return element.GetViewModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
171
FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Migrations/20240401175259_init.Designer.cs
generated
Normal file
171
FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Migrations/20240401175259_init.Designer.cs
generated
Normal file
@ -0,0 +1,171 @@
|
|||||||
|
// <auto-generated />
|
||||||
|
using System;
|
||||||
|
using FurnitureAssemblyDatabaseImplement;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||||
|
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace FurnitureAssemblyDatabaseImplement.Migrations
|
||||||
|
{
|
||||||
|
[DbContext(typeof(FurnitureAssemblyDatabase))]
|
||||||
|
[Migration("20240401175259_init")]
|
||||||
|
partial class init
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||||
|
{
|
||||||
|
#pragma warning disable 612, 618
|
||||||
|
modelBuilder
|
||||||
|
.HasAnnotation("ProductVersion", "7.0.7")
|
||||||
|
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||||
|
|
||||||
|
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||||
|
|
||||||
|
modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.Furniture", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<string>("FurnitureName")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<double>("Price")
|
||||||
|
.HasColumnType("double precision");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("Furnitures");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.FurnitureWorkpiece", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<int>("Count")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.Property<int>("FurnitureId")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.Property<int>("WorkpieceId")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("FurnitureId");
|
||||||
|
|
||||||
|
b.HasIndex("WorkpieceId");
|
||||||
|
|
||||||
|
b.ToTable("FurnitureWorkpieces");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.Order", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<int>("Count")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.Property<DateTime>("DateCreate")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<DateTime?>("DateImplement")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<int>("FurnitureId")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.Property<int>("Status")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.Property<double>("Sum")
|
||||||
|
.HasColumnType("double precision");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("FurnitureId");
|
||||||
|
|
||||||
|
b.ToTable("Orders");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.Workpiece", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<double>("Cost")
|
||||||
|
.HasColumnType("double precision");
|
||||||
|
|
||||||
|
b.Property<string>("WorkpieceName")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("Workpieces");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.FurnitureWorkpiece", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("FurnitureAssemblyDatabaseImplement.Models.Furniture", "Furniture")
|
||||||
|
.WithMany("Workpieces")
|
||||||
|
.HasForeignKey("FurnitureId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.HasOne("FurnitureAssemblyDatabaseImplement.Models.Workpiece", "Workpiece")
|
||||||
|
.WithMany("FurnitureWorkpieces")
|
||||||
|
.HasForeignKey("WorkpieceId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("Furniture");
|
||||||
|
|
||||||
|
b.Navigation("Workpiece");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.Order", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("FurnitureAssemblyDatabaseImplement.Models.Furniture", "Furniture")
|
||||||
|
.WithMany("Orders")
|
||||||
|
.HasForeignKey("FurnitureId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("Furniture");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.Furniture", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("Orders");
|
||||||
|
|
||||||
|
b.Navigation("Workpieces");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.Workpiece", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("FurnitureWorkpieces");
|
||||||
|
});
|
||||||
|
#pragma warning restore 612, 618
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,126 @@
|
|||||||
|
using System;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace FurnitureAssemblyDatabaseImplement.Migrations
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
public partial class init : Migration
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "Furnitures",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<int>(type: "integer", nullable: false)
|
||||||
|
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||||
|
FurnitureName = table.Column<string>(type: "text", nullable: false),
|
||||||
|
Price = table.Column<double>(type: "double precision", nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_Furnitures", x => x.Id);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "Workpieces",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<int>(type: "integer", nullable: false)
|
||||||
|
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||||
|
WorkpieceName = table.Column<string>(type: "text", nullable: false),
|
||||||
|
Cost = table.Column<double>(type: "double precision", nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_Workpieces", x => x.Id);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "Orders",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<int>(type: "integer", nullable: false)
|
||||||
|
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||||
|
FurnitureId = table.Column<int>(type: "integer", nullable: false),
|
||||||
|
Count = table.Column<int>(type: "integer", nullable: false),
|
||||||
|
Sum = table.Column<double>(type: "double precision", nullable: false),
|
||||||
|
Status = table.Column<int>(type: "integer", nullable: false),
|
||||||
|
DateCreate = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
|
||||||
|
DateImplement = table.Column<DateTime>(type: "timestamp with time zone", nullable: true)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_Orders", x => x.Id);
|
||||||
|
table.ForeignKey(
|
||||||
|
name: "FK_Orders_Furnitures_FurnitureId",
|
||||||
|
column: x => x.FurnitureId,
|
||||||
|
principalTable: "Furnitures",
|
||||||
|
principalColumn: "Id",
|
||||||
|
onDelete: ReferentialAction.Cascade);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "FurnitureWorkpieces",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<int>(type: "integer", nullable: false)
|
||||||
|
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||||
|
FurnitureId = table.Column<int>(type: "integer", nullable: false),
|
||||||
|
WorkpieceId = table.Column<int>(type: "integer", nullable: false),
|
||||||
|
Count = table.Column<int>(type: "integer", nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_FurnitureWorkpieces", x => x.Id);
|
||||||
|
table.ForeignKey(
|
||||||
|
name: "FK_FurnitureWorkpieces_Furnitures_FurnitureId",
|
||||||
|
column: x => x.FurnitureId,
|
||||||
|
principalTable: "Furnitures",
|
||||||
|
principalColumn: "Id",
|
||||||
|
onDelete: ReferentialAction.Cascade);
|
||||||
|
table.ForeignKey(
|
||||||
|
name: "FK_FurnitureWorkpieces_Workpieces_WorkpieceId",
|
||||||
|
column: x => x.WorkpieceId,
|
||||||
|
principalTable: "Workpieces",
|
||||||
|
principalColumn: "Id",
|
||||||
|
onDelete: ReferentialAction.Cascade);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_FurnitureWorkpieces_FurnitureId",
|
||||||
|
table: "FurnitureWorkpieces",
|
||||||
|
column: "FurnitureId");
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_FurnitureWorkpieces_WorkpieceId",
|
||||||
|
table: "FurnitureWorkpieces",
|
||||||
|
column: "WorkpieceId");
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_Orders_FurnitureId",
|
||||||
|
table: "Orders",
|
||||||
|
column: "FurnitureId");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "FurnitureWorkpieces");
|
||||||
|
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "Orders");
|
||||||
|
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "Workpieces");
|
||||||
|
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "Furnitures");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,168 @@
|
|||||||
|
// <auto-generated />
|
||||||
|
using System;
|
||||||
|
using FurnitureAssemblyDatabaseImplement;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||||
|
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||||
|
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace FurnitureAssemblyDatabaseImplement.Migrations
|
||||||
|
{
|
||||||
|
[DbContext(typeof(FurnitureAssemblyDatabase))]
|
||||||
|
partial class FurnitureAssemblyDatabaseModelSnapshot : ModelSnapshot
|
||||||
|
{
|
||||||
|
protected override void BuildModel(ModelBuilder modelBuilder)
|
||||||
|
{
|
||||||
|
#pragma warning disable 612, 618
|
||||||
|
modelBuilder
|
||||||
|
.HasAnnotation("ProductVersion", "7.0.7")
|
||||||
|
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||||
|
|
||||||
|
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||||
|
|
||||||
|
modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.Furniture", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<string>("FurnitureName")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<double>("Price")
|
||||||
|
.HasColumnType("double precision");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("Furnitures");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.FurnitureWorkpiece", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<int>("Count")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.Property<int>("FurnitureId")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.Property<int>("WorkpieceId")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("FurnitureId");
|
||||||
|
|
||||||
|
b.HasIndex("WorkpieceId");
|
||||||
|
|
||||||
|
b.ToTable("FurnitureWorkpieces");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.Order", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<int>("Count")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.Property<DateTime>("DateCreate")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<DateTime?>("DateImplement")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<int>("FurnitureId")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.Property<int>("Status")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.Property<double>("Sum")
|
||||||
|
.HasColumnType("double precision");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("FurnitureId");
|
||||||
|
|
||||||
|
b.ToTable("Orders");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.Workpiece", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<double>("Cost")
|
||||||
|
.HasColumnType("double precision");
|
||||||
|
|
||||||
|
b.Property<string>("WorkpieceName")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("Workpieces");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.FurnitureWorkpiece", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("FurnitureAssemblyDatabaseImplement.Models.Furniture", "Furniture")
|
||||||
|
.WithMany("Workpieces")
|
||||||
|
.HasForeignKey("FurnitureId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.HasOne("FurnitureAssemblyDatabaseImplement.Models.Workpiece", "Workpiece")
|
||||||
|
.WithMany("FurnitureWorkpieces")
|
||||||
|
.HasForeignKey("WorkpieceId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("Furniture");
|
||||||
|
|
||||||
|
b.Navigation("Workpiece");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.Order", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("FurnitureAssemblyDatabaseImplement.Models.Furniture", "Furniture")
|
||||||
|
.WithMany("Orders")
|
||||||
|
.HasForeignKey("FurnitureId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("Furniture");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.Furniture", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("Orders");
|
||||||
|
|
||||||
|
b.Navigation("Workpieces");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.Workpiece", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("FurnitureWorkpieces");
|
||||||
|
});
|
||||||
|
#pragma warning restore 612, 618
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,118 @@
|
|||||||
|
using FurnitureAssemblyContracts.BindingModels;
|
||||||
|
using FurnitureAssemblyContracts.ViewModels;
|
||||||
|
using FurnitureAssemblyDataModels.Models;
|
||||||
|
using Microsoft.EntityFrameworkCore.Diagnostics;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace FurnitureAssemblyDatabaseImplement.Models
|
||||||
|
{
|
||||||
|
public class Furniture : IFurnitureModel
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
|
||||||
|
[Required]
|
||||||
|
public string FurnitureName { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
[Required]
|
||||||
|
public double Price { get; set; }
|
||||||
|
|
||||||
|
public Dictionary<int, (IWorkpieceModel, int)>? _furnitureWorkpieces = null;
|
||||||
|
|
||||||
|
// Это поле не будет "мапиться" в бд
|
||||||
|
[NotMapped]
|
||||||
|
public Dictionary<int, (IWorkpieceModel, int)> FurnitureWorkpieces
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (_furnitureWorkpieces == null)
|
||||||
|
{
|
||||||
|
_furnitureWorkpieces = Workpieces
|
||||||
|
.ToDictionary(recPC => recPC.WorkpieceId, recPC => (recPC.Workpiece as IWorkpieceModel, recPC.Count));
|
||||||
|
}
|
||||||
|
|
||||||
|
return _furnitureWorkpieces;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Для реализации связи многие ко многим с заготовками
|
||||||
|
[ForeignKey("FurnitureId")]
|
||||||
|
public virtual List<FurnitureWorkpiece> Workpieces { get; set; } = new();
|
||||||
|
|
||||||
|
[ForeignKey("FurnitureId")]
|
||||||
|
public virtual List<Order> Orders { get; set; } = new();
|
||||||
|
|
||||||
|
public static Furniture Create(FurnitureAssemblyDatabase context, FurnitureBindingModel model)
|
||||||
|
{
|
||||||
|
return new Furniture()
|
||||||
|
{
|
||||||
|
Id = model.Id,
|
||||||
|
FurnitureName = model.FurnitureName,
|
||||||
|
Price = model.Price,
|
||||||
|
Workpieces = model.FurnitureWorkpieces.Select(x => new FurnitureWorkpiece
|
||||||
|
{
|
||||||
|
Workpiece = context.Workpieces.First(y => y.Id == x.Key),
|
||||||
|
Count = x.Value.Item2
|
||||||
|
}).ToList()
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Update(FurnitureBindingModel model)
|
||||||
|
{
|
||||||
|
FurnitureName = model.FurnitureName;
|
||||||
|
Price = model.Price;
|
||||||
|
}
|
||||||
|
|
||||||
|
public FurnitureViewModel GetViewModel => new()
|
||||||
|
{
|
||||||
|
Id = Id,
|
||||||
|
FurnitureName = FurnitureName,
|
||||||
|
Price = Price,
|
||||||
|
FurnitureWorkpieces = FurnitureWorkpieces
|
||||||
|
};
|
||||||
|
|
||||||
|
Dictionary<int, (IWorkpieceModel, int)> IFurnitureModel.FurnitureWorkpieces => throw new NotImplementedException();
|
||||||
|
|
||||||
|
public void UpdateWorkpieces(FurnitureAssemblyDatabase context, FurnitureBindingModel model)
|
||||||
|
{
|
||||||
|
var furnitureWorkpieces = context.FurnitureWorkpieces.Where(rec => rec.FurnitureId == model.Id).ToList();
|
||||||
|
|
||||||
|
if (furnitureWorkpieces != null && furnitureWorkpieces.Count > 0)
|
||||||
|
{
|
||||||
|
// удалили те, которых нет в модели
|
||||||
|
context.FurnitureWorkpieces.RemoveRange(furnitureWorkpieces.Where(rec => !model.FurnitureWorkpieces.ContainsKey(rec.FurnitureId)));
|
||||||
|
context.SaveChanges();
|
||||||
|
|
||||||
|
// обновили количество у существующих записей
|
||||||
|
foreach (var updateFurniture in furnitureWorkpieces)
|
||||||
|
{
|
||||||
|
updateFurniture.Count = model.FurnitureWorkpieces[updateFurniture.FurnitureId].Item2;
|
||||||
|
model.FurnitureWorkpieces.Remove(updateFurniture.FurnitureId);
|
||||||
|
}
|
||||||
|
|
||||||
|
context.SaveChanges();
|
||||||
|
}
|
||||||
|
|
||||||
|
var furniture = context.Furnitures.First(x => x.Id == Id);
|
||||||
|
|
||||||
|
foreach (var pc in model.FurnitureWorkpieces)
|
||||||
|
{
|
||||||
|
context.FurnitureWorkpieces.Add(new FurnitureWorkpiece
|
||||||
|
{
|
||||||
|
Furniture = furniture,
|
||||||
|
Workpiece = context.Workpieces.First(x => x.Id == pc.Key),
|
||||||
|
Count = pc.Value.Item2
|
||||||
|
});
|
||||||
|
|
||||||
|
context.SaveChanges();
|
||||||
|
}
|
||||||
|
|
||||||
|
_furnitureWorkpieces = 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 FurnitureAssemblyDatabaseImplement.Models
|
||||||
|
{
|
||||||
|
public class FurnitureWorkpiece
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
|
||||||
|
[Required]
|
||||||
|
public int FurnitureId { get; set; }
|
||||||
|
|
||||||
|
[Required]
|
||||||
|
public int WorkpieceId { get; set; }
|
||||||
|
|
||||||
|
[Required]
|
||||||
|
public int Count { get; set; }
|
||||||
|
|
||||||
|
public virtual Workpiece Workpiece { get; set; } = new();
|
||||||
|
|
||||||
|
public virtual Furniture Furniture { get; set; } = new();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,80 @@
|
|||||||
|
using FurnitureAssemblyContracts.BindingModels;
|
||||||
|
using FurnitureAssemblyContracts.ViewModels;
|
||||||
|
using FurnitureAssemblyDataModels.Enums;
|
||||||
|
using FurnitureAssemblyDataModels.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
|
||||||
|
namespace FurnitureAssemblyDatabaseImplement.Models
|
||||||
|
{
|
||||||
|
public class Order : IOrderModel
|
||||||
|
{
|
||||||
|
public int Id { get; private set; }
|
||||||
|
|
||||||
|
[Required]
|
||||||
|
public int FurnitureId { 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.ToUniversalTime();
|
||||||
|
|
||||||
|
public DateTime? DateImplement { get; private set; }
|
||||||
|
|
||||||
|
public virtual Furniture Furniture { get; set; }
|
||||||
|
|
||||||
|
public static Order? Create(OrderBindingModel model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Order()
|
||||||
|
{
|
||||||
|
Id = model.Id,
|
||||||
|
FurnitureId = model.FurnitureId,
|
||||||
|
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,
|
||||||
|
FurnitureId = FurnitureId,
|
||||||
|
Count = Count,
|
||||||
|
Sum = Sum,
|
||||||
|
Status = Status,
|
||||||
|
DateCreate = DateCreate,
|
||||||
|
DateImplement = DateImplement,
|
||||||
|
FurnitureName = Furniture.FurnitureName
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,71 @@
|
|||||||
|
using FurnitureAssemblyContracts.BindingModels;
|
||||||
|
using FurnitureAssemblyContracts.ViewModels;
|
||||||
|
using FurnitureAssemblyDataModels.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace FurnitureAssemblyDatabaseImplement.Models
|
||||||
|
{
|
||||||
|
public class Workpiece : IWorkpieceModel
|
||||||
|
{
|
||||||
|
public int Id { get; private set; }
|
||||||
|
|
||||||
|
[Required]
|
||||||
|
public string WorkpieceName { get; private set; } = string.Empty;
|
||||||
|
|
||||||
|
[Required]
|
||||||
|
public double Cost { get; set; }
|
||||||
|
|
||||||
|
// для реализации связи многие ко многим с изделиями
|
||||||
|
[ForeignKey("WorkpieceId")]
|
||||||
|
public virtual List<FurnitureWorkpiece> FurnitureWorkpieces { get; set; } = new();
|
||||||
|
|
||||||
|
public static Workpiece? Create(WorkpieceBindingModel model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Workpiece()
|
||||||
|
{
|
||||||
|
Id = model.Id,
|
||||||
|
WorkpieceName = model.WorkpieceName,
|
||||||
|
Cost = model.Cost
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Workpiece Create(WorkpieceViewModel model)
|
||||||
|
{
|
||||||
|
return new Workpiece
|
||||||
|
{
|
||||||
|
Id = model.Id,
|
||||||
|
WorkpieceName = model.WorkpieceName,
|
||||||
|
Cost = model.Cost
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Update(WorkpieceBindingModel model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
WorkpieceName = model.WorkpieceName;
|
||||||
|
Cost = model.Cost;
|
||||||
|
}
|
||||||
|
|
||||||
|
public WorkpieceViewModel GetViewModel => new()
|
||||||
|
{
|
||||||
|
Id = Id,
|
||||||
|
WorkpieceName = WorkpieceName,
|
||||||
|
Cost = Cost
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user