Merge branch 'Kalyshev'
This commit is contained in:
commit
9b2215c7ae
@ -6,4 +6,15 @@
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.4">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\FurnitureAssembly_WorkerDatabaseImplement\FurnitureAssembly_WorkerDatabaseImplement.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
@ -9,11 +9,11 @@ namespace FurnitureAssembly_WorkerContracts.BindingModels
|
||||
{
|
||||
public class FurnitureBindingModel : IFurnitureModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; } = string.Empty;
|
||||
public double Cost { get; set; }
|
||||
public int UserId { get; set; }
|
||||
public DateTime DateCreate { get; set; } = DateTime.Now;
|
||||
public Dictionary<int, (IMaterialModel, int)> FurnitureMaterials { get; set; } = new();
|
||||
public IUserModel User { get; set; } = new UserBindingModel();
|
||||
public int Id { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ namespace FurnitureAssembly_WorkerContracts.BindingModels
|
||||
public string Name { get; set; } = string.Empty;
|
||||
public double Cost { get; set; }
|
||||
public DateTime DateCreate { get; set; }
|
||||
public IUserModel User { get; set; } = new UserViewModel();
|
||||
public Dictionary<int, (IFurnitureModel, int)> FurnitureFurnitureModules { get; set; } = new();
|
||||
public int UserId { get; set; }
|
||||
public Dictionary<int, (IFurnitureModel, int)> FurnitureModuleFurnitures { get; set; } = new();
|
||||
}
|
||||
}
|
||||
|
@ -10,9 +10,10 @@ namespace FurnitureAssembly_WorkerContracts.BindingModels
|
||||
{
|
||||
public class MaterialBindingModel : IMaterialModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; } = string.Empty;
|
||||
public double Cost { get; set; }
|
||||
public IScopeModel scope { get; set; } = new ScopeBindingModel();
|
||||
public int Id { get; set; }
|
||||
public int ScopeId { get; set; }
|
||||
public int UserId { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -15,8 +15,8 @@ namespace FurnitureAssembly_WorkerContracts.BindingModels
|
||||
public int Id { get; set; }
|
||||
public string CustomerName { get; set; } = string.Empty;
|
||||
public PaymentType PaymentType { get; set; } = PaymentType.Неизвестен;
|
||||
public Dictionary<int, (ISetModel, int)> OrderSets { get; set; } = new();
|
||||
public int SetId { get; set; }
|
||||
public DateTime DateCreate { get; set; }
|
||||
public IUserModel User { get; set; } = new UserViewModel();
|
||||
public int UserId { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ namespace FurnitureAssembly_WorkerContracts.BindingModels
|
||||
public string Name { get; set; } = string.Empty;
|
||||
public double Cost { get; set; }
|
||||
public DateTime DateCreate { get; set; }
|
||||
public IUserModel User { get; set; } = new UserViewModel();
|
||||
public int UserId { get; set; }
|
||||
public Dictionary<int, (IFurnitureModuleModel, int)> SetFurnitureModules { get; set; } = new();
|
||||
}
|
||||
}
|
||||
|
@ -13,6 +13,6 @@ namespace FurnitureAssembly_WorkerContracts.BindingModels
|
||||
public string Login { get; set; } = string.Empty;
|
||||
public string Password { get; set; } = string.Empty;
|
||||
public string Name { get; set; } = string.Empty;
|
||||
public IRoleModel Role { get; set; } = new RoleBindingModel();
|
||||
public int RoleId { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -10,5 +10,6 @@ namespace FurnitureAssembly_WorkerContracts.SearchModels
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
public string? Name { get; set; }
|
||||
public int? UserId { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -10,5 +10,6 @@ namespace FurnitureAssembly_WorkerContracts.SearchModels
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
public string? Name { get; set; }
|
||||
public int? UserId { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -10,5 +10,6 @@ namespace FurnitureAssembly_WorkerContracts.SearchModels
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
public string? Name { get; set; }
|
||||
public int? UserId { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -9,6 +9,7 @@ namespace FurnitureAssembly_WorkerContracts.SearchModels
|
||||
public class OrderSearchModel
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
public int? UserId { get; set; }
|
||||
public DateTime? DateFrom { get; set; }
|
||||
public DateTime? DateTo { get; set; }
|
||||
}
|
||||
|
@ -10,5 +10,6 @@ namespace FurnitureAssembly_WorkerContracts.SearchModels
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
public string? Name { get; set; }
|
||||
public int? UserId { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -9,6 +9,7 @@ namespace FurnitureAssembly_WorkerContracts.SearchModels
|
||||
public class UserSearchModel
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
public int? RoleId { get; set; }
|
||||
public string? Login { get; set; }
|
||||
public string? Password { get; set; }
|
||||
}
|
||||
|
@ -20,6 +20,6 @@ namespace FurnitureAssembly_WorkerContracts.ViewModels
|
||||
public int UserId { get; set; }
|
||||
[DisplayName("Изготовитель")]
|
||||
public string UserName { get; set; } = string.Empty;
|
||||
public Dictionary<int, (IFurnitureModel, int)> FurnitureFurnitureModules { get; set; } = new();
|
||||
public Dictionary<int, (IFurnitureModel, int)> FurnitureModuleFurnitures { get; set; } = new();
|
||||
}
|
||||
}
|
||||
|
@ -12,6 +12,6 @@ namespace FurnitureAssembly_WorkerDataModels.Models
|
||||
double Cost { get; }
|
||||
DateTime DateCreate { get; }
|
||||
int UserId { get; }
|
||||
Dictionary<int, (IFurnitureModel, int)> FurnitureFurnitureModules { get; }
|
||||
Dictionary<int, (IFurnitureModel, int)> FurnitureModuleFurnitures { get; }
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using FurnitureAssembly_WorkerDatabaseImplement.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@ -7,7 +8,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace FurnitureAssembly_WorkerDatabaseImplement
|
||||
{
|
||||
internal class FurnitureAssemblyDatabase : DbContext
|
||||
public class FurnitureAssemblyDatabase : DbContext
|
||||
{
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||
{
|
||||
@ -17,5 +18,16 @@ namespace FurnitureAssembly_WorkerDatabaseImplement
|
||||
}
|
||||
base.OnConfiguring(optionsBuilder);
|
||||
}
|
||||
public virtual DbSet<Set> Sets { get; set; }
|
||||
public virtual DbSet<SetFurnitureModule> SetFurnitureModules { get; set; }
|
||||
public virtual DbSet<FurnitureModule> FurnitureModules { get; set; }
|
||||
public virtual DbSet<FurnitureModuleFurniture> FurnitureModuleFurnitures { get; set; }
|
||||
public virtual DbSet<Furniture> Furnitures { get; set; }
|
||||
public virtual DbSet<FurnitureMaterial> FurnitureMaterials { get; set; }
|
||||
public virtual DbSet<Material> Materials { get; set; }
|
||||
public virtual DbSet<Role> Roles { get; set; }
|
||||
public virtual DbSet<Scope> Scopes { get; set; }
|
||||
public virtual DbSet<User> Users { get; set; }
|
||||
public virtual DbSet<Order> Orders { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,119 @@
|
||||
using FurnitureAssembly_WorkerContracts.BindingModels;
|
||||
using FurnitureAssembly_WorkerContracts.SearchModels;
|
||||
using FurnitureAssembly_WorkerContracts.StorageContracts;
|
||||
using FurnitureAssembly_WorkerContracts.ViewModels;
|
||||
using FurnitureAssembly_WorkerDatabaseImplement.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FurnitureAssembly_WorkerDatabaseImplement.Implements
|
||||
{
|
||||
public class FurnitureModuleStorage : IFurnitureModuleStorage
|
||||
{
|
||||
public List<FurnitureModuleViewModel> GetFullList()
|
||||
{
|
||||
using var context = new FurnitureAssemblyDatabase();
|
||||
return context.FurnitureModules
|
||||
.Include(x => x.User)
|
||||
.Include(x => x.Furnitures)
|
||||
.ThenInclude(x => x.Furniture).ToList()
|
||||
.Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
public List<FurnitureModuleViewModel> GetFilteredList(FurnitureModuleSearchModel model)
|
||||
{
|
||||
using var context = new FurnitureAssemblyDatabase();
|
||||
if (!string.IsNullOrEmpty(model.Name))
|
||||
{
|
||||
return context.FurnitureModules
|
||||
.Include(x => x.User)
|
||||
.Include(x => x.Furnitures)
|
||||
.ThenInclude(x => x.Furniture)
|
||||
.Where(x => x.Name.Contains(model.Name)).ToList()
|
||||
.Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
else if (model.UserId.HasValue)
|
||||
{
|
||||
return context.FurnitureModules
|
||||
.Include(x => x.User)
|
||||
.Include(x => x.Furnitures)
|
||||
.ThenInclude(x => x.Furniture)
|
||||
.Where(x => x.UserId == model.UserId)
|
||||
.Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
else
|
||||
{
|
||||
return new();
|
||||
}
|
||||
}
|
||||
public FurnitureModuleViewModel? GetElement(FurnitureModuleSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.Name) &&
|
||||
!model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new FurnitureAssemblyDatabase();
|
||||
return context.FurnitureModules
|
||||
.Include(x => x.User)
|
||||
.Include(x => x.Furnitures)
|
||||
.ThenInclude(x => x.Furniture)
|
||||
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.Name) && x.Name == model.Name) || (model.Id.HasValue && x.Id == model.Id))
|
||||
?.GetViewModel;
|
||||
}
|
||||
public FurnitureModuleViewModel? Insert(FurnitureModuleBindingModel model)
|
||||
{
|
||||
using var context = new FurnitureAssemblyDatabase();
|
||||
var newFurnitureModule = FurnitureModule.Create(context, model);
|
||||
if (newFurnitureModule == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
context.FurnitureModules.Add(newFurnitureModule);
|
||||
context.SaveChanges();
|
||||
return newFurnitureModule.GetViewModel;
|
||||
}
|
||||
public FurnitureModuleViewModel? Update(FurnitureModuleBindingModel model)
|
||||
{
|
||||
using var context = new FurnitureAssemblyDatabase();
|
||||
using var transaction = context.Database.BeginTransaction();
|
||||
try
|
||||
{
|
||||
var furnitureModule = context.FurnitureModules.FirstOrDefault(rec =>
|
||||
rec.Id == model.Id);
|
||||
if (furnitureModule == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
furnitureModule.Update(model);
|
||||
context.SaveChanges();
|
||||
furnitureModule.UpdateFurnitures(context, model);
|
||||
transaction.Commit();
|
||||
return furnitureModule.GetViewModel;
|
||||
}
|
||||
catch
|
||||
{
|
||||
transaction.Rollback();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
public FurnitureModuleViewModel? Delete(FurnitureModuleBindingModel model)
|
||||
{
|
||||
using var context = new FurnitureAssemblyDatabase();
|
||||
var element = context.FurnitureModules
|
||||
.Include(x => x.User)
|
||||
.Include(x => x.Furnitures)
|
||||
.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
if (element != null)
|
||||
{
|
||||
context.FurnitureModules.Remove(element);
|
||||
context.SaveChanges();
|
||||
return element.GetViewModel;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,117 @@
|
||||
using FurnitureAssembly_WorkerContracts.BindingModels;
|
||||
using FurnitureAssembly_WorkerContracts.SearchModels;
|
||||
using FurnitureAssembly_WorkerContracts.StorageContracts;
|
||||
using FurnitureAssembly_WorkerContracts.ViewModels;
|
||||
using FurnitureAssembly_WorkerDatabaseImplement.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FurnitureAssembly_WorkerDatabaseImplement.Implements
|
||||
{
|
||||
public class FurnitureStorage : IFurnitureStorage
|
||||
{
|
||||
public List<FurnitureViewModel> GetFullList()
|
||||
{
|
||||
using var context = new FurnitureAssemblyDatabase();
|
||||
return context.Furnitures
|
||||
.Include(x => x.User)
|
||||
.Include(x => x.Materials)
|
||||
.ThenInclude(x => x.Material).ToList()
|
||||
.Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
public List<FurnitureViewModel> GetFilteredList(FurnitureSearchModel model)
|
||||
{
|
||||
using var context = new FurnitureAssemblyDatabase();
|
||||
if (!string.IsNullOrEmpty(model.Name))
|
||||
{
|
||||
return context.Furnitures
|
||||
.Include(x => x.User)
|
||||
.Include(x => x.Materials)
|
||||
.ThenInclude(x => x.Material)
|
||||
.Where(x => x.Name.Contains(model.Name)).ToList()
|
||||
.Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
else if (model.UserId.HasValue)
|
||||
{
|
||||
return context.Furnitures
|
||||
.Include(x => x.User)
|
||||
.Include(x => x.Materials)
|
||||
.ThenInclude(x => x.Material)
|
||||
.Where(x => x.UserId == model.UserId)
|
||||
.Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
else
|
||||
{
|
||||
return new();
|
||||
}
|
||||
}
|
||||
public FurnitureViewModel? GetElement(FurnitureSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.Name) &&
|
||||
!model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new FurnitureAssemblyDatabase();
|
||||
return context.Furnitures.Include(x => x.User)
|
||||
.Include(x => x.Materials).ThenInclude(x => x.Material)
|
||||
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.Name) && x.Name == model.Name) || (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
|
||||
.Include(x => x.User)
|
||||
.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
if (furniture == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
furniture.Update(model);
|
||||
context.SaveChanges();
|
||||
furniture.UpdateMaterials(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.User)
|
||||
.Include(x => x.Materials)
|
||||
.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
if (element != null)
|
||||
{
|
||||
context.Furnitures.Remove(element);
|
||||
context.SaveChanges();
|
||||
return element.GetViewModel;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,106 @@
|
||||
using FurnitureAssembly_WorkerContracts.BindingModels;
|
||||
using FurnitureAssembly_WorkerContracts.SearchModels;
|
||||
using FurnitureAssembly_WorkerContracts.StorageContracts;
|
||||
using FurnitureAssembly_WorkerContracts.ViewModels;
|
||||
using FurnitureAssembly_WorkerDatabaseImplement.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FurnitureAssembly_WorkerDatabaseImplement.Implements
|
||||
{
|
||||
public class MaterialStorage : IMaterialStorage
|
||||
{
|
||||
public List<MaterialViewModel> GetFullList()
|
||||
{
|
||||
using var context = new FurnitureAssemblyDatabase();
|
||||
return context.Materials
|
||||
.Include(x => x.User)
|
||||
.Include(x => x.Scope)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
public List<MaterialViewModel> GetFilteredList(MaterialSearchModel model)
|
||||
{
|
||||
using var context = new FurnitureAssemblyDatabase();
|
||||
if (!string.IsNullOrEmpty(model.Name))
|
||||
{
|
||||
return context.Materials
|
||||
.Include(x => x.User)
|
||||
.Include(x => x.Scope)
|
||||
.Where(x => x.Name.Contains(model.Name))
|
||||
.Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
else if (model.UserId.HasValue)
|
||||
{
|
||||
return context.Materials
|
||||
.Include(x => x.User)
|
||||
.Include(x => x.Scope)
|
||||
.Where(x => x.UserId == model.UserId)
|
||||
.Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
else
|
||||
{
|
||||
return new();
|
||||
}
|
||||
}
|
||||
public MaterialViewModel? GetElement(MaterialSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.Name) && !model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new FurnitureAssemblyDatabase();
|
||||
return context.Materials
|
||||
.Include(x => x.User)
|
||||
.Include(x => x.Scope)
|
||||
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.Name) && x.Name == model.Name) ||
|
||||
(model.Id.HasValue && x.Id == model.Id))
|
||||
?.GetViewModel;
|
||||
}
|
||||
public MaterialViewModel? Insert(MaterialBindingModel model)
|
||||
{
|
||||
var newMaterial = Material.Create(model);
|
||||
if (newMaterial == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new FurnitureAssemblyDatabase();
|
||||
context.Materials.Add(newMaterial);
|
||||
context.SaveChanges();
|
||||
return newMaterial.GetViewModel;
|
||||
}
|
||||
public MaterialViewModel? Update(MaterialBindingModel model)
|
||||
{
|
||||
using var context = new FurnitureAssemblyDatabase();
|
||||
var material = context.Materials
|
||||
.Include(x => x.User)
|
||||
.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (material == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
material.Update(model);
|
||||
context.SaveChanges();
|
||||
return material.GetViewModel;
|
||||
}
|
||||
public MaterialViewModel? Delete(MaterialBindingModel model)
|
||||
{
|
||||
using var context = new FurnitureAssemblyDatabase();
|
||||
var element = context.Materials
|
||||
.Include(x => x.User)
|
||||
.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
if (element != null)
|
||||
{
|
||||
context.Materials.Remove(element);
|
||||
context.SaveChanges();
|
||||
return element.GetViewModel;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,124 @@
|
||||
using FurnitureAssembly_WorkerContracts.BindingModels;
|
||||
using FurnitureAssembly_WorkerContracts.SearchModels;
|
||||
using FurnitureAssembly_WorkerContracts.StorageContracts;
|
||||
using FurnitureAssembly_WorkerContracts.ViewModels;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using FurnitureAssembly_WorkerDatabaseImplement.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FurnitureAssembly_WorkerDatabaseImplement.Implements
|
||||
{
|
||||
public class OrderStorage : IOrderStorage
|
||||
{
|
||||
public OrderViewModel? Delete(OrderBindingModel model)
|
||||
{
|
||||
using var context = new FurnitureAssemblyDatabase();
|
||||
var element = context.Orders.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
if (element != null)
|
||||
{
|
||||
var deletedElement = context.Orders
|
||||
.Include(x => x.Set)
|
||||
.Include(x => x.User)
|
||||
.FirstOrDefault(x => x.Id == model.Id)
|
||||
?.GetViewModel;
|
||||
context.Orders.Remove(element);
|
||||
context.SaveChanges();
|
||||
return deletedElement;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public OrderViewModel? GetElement(OrderSearchModel model)
|
||||
{
|
||||
if (!model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new FurnitureAssemblyDatabase();
|
||||
return context.Orders
|
||||
.Include(x => x.Set)
|
||||
.Include(x => x.User)
|
||||
.FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)
|
||||
?.GetViewModel;
|
||||
}
|
||||
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
|
||||
{
|
||||
using var context = new FurnitureAssemblyDatabase();
|
||||
if (model.Id.HasValue)
|
||||
{
|
||||
return context.Orders
|
||||
.Include(x => x.Set)
|
||||
.Include(x => x.User)
|
||||
.Where(x => x.Id == model.Id)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
else if (model.DateFrom != null && model.DateTo != null)
|
||||
{
|
||||
return context.Orders
|
||||
.Include(x => x.Set)
|
||||
.Include(x => x.User)
|
||||
.Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
else if (model.UserId.HasValue)
|
||||
{
|
||||
return context.Orders
|
||||
.Include(x => x.Set)
|
||||
.Include(x => x.User)
|
||||
.Where(x => x.UserId == model.UserId)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
else
|
||||
{
|
||||
return new();
|
||||
}
|
||||
}
|
||||
public List<OrderViewModel> GetFullList()
|
||||
{
|
||||
using var context = new FurnitureAssemblyDatabase();
|
||||
return context.Orders
|
||||
.Include(x => x.Set)
|
||||
.Include(x => x.User)
|
||||
.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.Set)
|
||||
.Include(x => x.User)
|
||||
.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.Set)
|
||||
.Include(x => x.User)
|
||||
.FirstOrDefault(x => x.Id == model.Id)
|
||||
?.GetViewModel;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,99 @@
|
||||
using FurnitureAssembly_WorkerContracts.BindingModels;
|
||||
using FurnitureAssembly_WorkerContracts.SearchModels;
|
||||
using FurnitureAssembly_WorkerContracts.StorageContracts;
|
||||
using FurnitureAssembly_WorkerContracts.ViewModels;
|
||||
using FurnitureAssembly_WorkerDatabaseImplement.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FurnitureAssembly_WorkerDatabaseImplement.Implements
|
||||
{
|
||||
public class ScopeStorage : IScopeStorage
|
||||
{
|
||||
public List<ScopeViewModel> GetFullList()
|
||||
{
|
||||
using var context = new FurnitureAssemblyDatabase();
|
||||
return context.Scopes
|
||||
.Include(x => x.Materials)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
public List<ScopeViewModel> GetFilteredList(ScopeSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return new();
|
||||
}
|
||||
if (!string.IsNullOrEmpty(model.Name))
|
||||
{
|
||||
using var context = new FurnitureAssemblyDatabase();
|
||||
return context.Scopes
|
||||
.Include(x => x.Materials)
|
||||
.Where(x => x.Name.Contains(model.Name))
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
return new();
|
||||
}
|
||||
public ScopeViewModel? GetElement(ScopeSearchModel model)
|
||||
{
|
||||
using var context = new FurnitureAssemblyDatabase();
|
||||
if (model.Id.HasValue)
|
||||
{
|
||||
return context.Scopes
|
||||
.FirstOrDefault(x => (x.Id == model.Id))
|
||||
?.GetViewModel;
|
||||
}
|
||||
else if (!string.IsNullOrEmpty(model.Name))
|
||||
{
|
||||
return context.Scopes
|
||||
.FirstOrDefault(x => (x.Name == model.Name))
|
||||
?.GetViewModel;
|
||||
}
|
||||
return new();
|
||||
}
|
||||
public ScopeViewModel? Insert(ScopeBindingModel model)
|
||||
{
|
||||
var newScope = Scope.Create(model);
|
||||
if (newScope == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new FurnitureAssemblyDatabase();
|
||||
context.Scopes.Add(newScope);
|
||||
context.SaveChanges();
|
||||
return newScope.GetViewModel;
|
||||
}
|
||||
public ScopeViewModel? Update(ScopeBindingModel model)
|
||||
{
|
||||
using var context = new FurnitureAssemblyDatabase();
|
||||
var scope = context.Scopes
|
||||
.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (scope == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
scope.Update(model);
|
||||
context.SaveChanges();
|
||||
return scope.GetViewModel;
|
||||
}
|
||||
public ScopeViewModel? Delete(ScopeBindingModel model)
|
||||
{
|
||||
using var context = new FurnitureAssemblyDatabase();
|
||||
var element = context.Scopes
|
||||
.Include(x => x.Materials)
|
||||
.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
if (element != null)
|
||||
{
|
||||
context.Scopes.Remove(element);
|
||||
context.SaveChanges();
|
||||
return element.GetViewModel;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,120 @@
|
||||
using FurnitureAssembly_WorkerContracts.BindingModels;
|
||||
using FurnitureAssembly_WorkerContracts.SearchModels;
|
||||
using FurnitureAssembly_WorkerContracts.StorageContracts;
|
||||
using FurnitureAssembly_WorkerContracts.ViewModels;
|
||||
using FurnitureAssembly_WorkerDatabaseImplement.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FurnitureAssembly_WorkerDatabaseImplement.Implements
|
||||
{
|
||||
public class SetStorage : ISetStorage
|
||||
{
|
||||
public List<SetViewModel> GetFullList()
|
||||
{
|
||||
using var context = new FurnitureAssemblyDatabase();
|
||||
return context.Sets
|
||||
.Include(x => x.User)
|
||||
.Include(x => x.FurnitureModules)
|
||||
.ThenInclude(x => x.FurnitureModule).ToList()
|
||||
.Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
public List<SetViewModel> GetFilteredList(SetSearchModel model)
|
||||
{
|
||||
using var context = new FurnitureAssemblyDatabase();
|
||||
if (!string.IsNullOrEmpty(model.Name))
|
||||
{
|
||||
return context.Sets
|
||||
.Include(x => x.User)
|
||||
.Include(x => x.FurnitureModules)
|
||||
.ThenInclude(x => x.FurnitureModule)
|
||||
.Where(x => x.Name.Contains(model.Name)).ToList()
|
||||
.Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
else if (model.UserId.HasValue)
|
||||
{
|
||||
return context.Sets
|
||||
.Include(x => x.User)
|
||||
.Include(x => x.FurnitureModules)
|
||||
.ThenInclude(x => x.FurnitureModule)
|
||||
.Where(x => x.UserId == model.UserId)
|
||||
.Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
else
|
||||
{
|
||||
return new();
|
||||
}
|
||||
}
|
||||
public SetViewModel? GetElement(SetSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.Name) &&
|
||||
!model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new FurnitureAssemblyDatabase();
|
||||
return context.Sets
|
||||
.Include(x => x.User)
|
||||
.Include(x => x.FurnitureModules)
|
||||
.ThenInclude(x => x.FurnitureModule)
|
||||
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.Name) && x.Name == model.Name) || (model.Id.HasValue && x.Id == model.Id))
|
||||
?.GetViewModel;
|
||||
}
|
||||
public SetViewModel? Insert(SetBindingModel model)
|
||||
{
|
||||
using var context = new FurnitureAssemblyDatabase();
|
||||
var newSet = Set.Create(context, model);
|
||||
if (newSet == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
context.Sets.Add(newSet);
|
||||
context.SaveChanges();
|
||||
return newSet.GetViewModel;
|
||||
}
|
||||
public SetViewModel? Update(SetBindingModel model)
|
||||
{
|
||||
using var context = new FurnitureAssemblyDatabase();
|
||||
using var transaction = context.Database.BeginTransaction();
|
||||
try
|
||||
{
|
||||
var set = context.Sets
|
||||
.Include(x => x.User)
|
||||
.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
if (set == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
set.Update(model);
|
||||
context.SaveChanges();
|
||||
set.UpdateFurnitureModules(context, model);
|
||||
transaction.Commit();
|
||||
return set.GetViewModel;
|
||||
}
|
||||
catch
|
||||
{
|
||||
transaction.Rollback();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
public SetViewModel? Delete(SetBindingModel model)
|
||||
{
|
||||
using var context = new FurnitureAssemblyDatabase();
|
||||
var element = context.Sets
|
||||
.Include(x => x.User)
|
||||
.Include(x => x.FurnitureModules)
|
||||
.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
if (element != null)
|
||||
{
|
||||
context.Sets.Remove(element);
|
||||
context.SaveChanges();
|
||||
return element.GetViewModel;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,137 @@
|
||||
using FurnitureAssembly_WorkerContracts.BindingModels;
|
||||
using FurnitureAssembly_WorkerContracts.SearchModels;
|
||||
using FurnitureAssembly_WorkerContracts.StorageContracts;
|
||||
using FurnitureAssembly_WorkerContracts.ViewModels;
|
||||
using FurnitureAssembly_WorkerDatabaseImplement.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FurnitureAssembly_WorkerDatabaseImplement.Implements
|
||||
{
|
||||
public class UserStorage : IUserStorage
|
||||
{
|
||||
public UserViewModel? Delete(UserBindingModel model)
|
||||
{
|
||||
using var context = new FurnitureAssemblyDatabase();
|
||||
var element = context
|
||||
.Users.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
if (element != null)
|
||||
{
|
||||
var deletedElement = context.Users
|
||||
.Include(x => x.Sets)
|
||||
.Include(x => x.Orders)
|
||||
.Include(x => x.FurnitureModules)
|
||||
.Include(x => x.Furnitures)
|
||||
.Include(x => x.Materials)
|
||||
.FirstOrDefault(x => x.Id == model.Id)
|
||||
?.GetViewModel;
|
||||
context.Users.Remove(element);
|
||||
context.SaveChanges();
|
||||
return deletedElement;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public UserViewModel? GetElement(UserSearchModel model)
|
||||
{
|
||||
if (!model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new FurnitureAssemblyDatabase();
|
||||
return context.Users
|
||||
.Include(x => x.Sets)
|
||||
.Include(x => x.Orders)
|
||||
.Include(x => x.FurnitureModules)
|
||||
.Include(x => x.Furnitures)
|
||||
.Include(x => x.Materials)
|
||||
.FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)
|
||||
?.GetViewModel;
|
||||
}
|
||||
public List<UserViewModel> GetFilteredList(UserSearchModel model)
|
||||
{
|
||||
using var context = new FurnitureAssemblyDatabase();
|
||||
if (model.Id.HasValue)
|
||||
{
|
||||
return context.Users
|
||||
.Include(x => x.Sets)
|
||||
.Include(x => x.Orders)
|
||||
.Include(x => x.FurnitureModules)
|
||||
.Include(x => x.Furnitures)
|
||||
.Include(x => x.Materials)
|
||||
.Where(x => x.Id == model.Id)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
else if (model.RoleId.HasValue)
|
||||
{
|
||||
return context.Users
|
||||
.Include(x => x.Sets)
|
||||
.Include(x => x.Orders)
|
||||
.Include(x => x.FurnitureModules)
|
||||
.Include(x => x.Furnitures)
|
||||
.Include(x => x.Materials)
|
||||
.Where(x => x.RoleId == model.RoleId)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
else
|
||||
{
|
||||
return new();
|
||||
}
|
||||
}
|
||||
public List<UserViewModel> GetFullList()
|
||||
{
|
||||
using var context = new FurnitureAssemblyDatabase();
|
||||
return context.Users
|
||||
.Include(x => x.Sets)
|
||||
.Include(x => x.Orders)
|
||||
.Include(x => x.FurnitureModules)
|
||||
.Include(x => x.Furnitures)
|
||||
.Include(x => x.Materials)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
public UserViewModel? Insert(UserBindingModel model)
|
||||
{
|
||||
var newUser = User.Create(model);
|
||||
if (newUser == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new FurnitureAssemblyDatabase();
|
||||
context.Users.Add(newUser);
|
||||
context.SaveChanges();
|
||||
return context.Users
|
||||
.Include(x => x.Sets)
|
||||
.Include(x => x.Orders)
|
||||
.Include(x => x.FurnitureModules)
|
||||
.Include(x => x.Furnitures)
|
||||
.Include(x => x.Materials)
|
||||
.FirstOrDefault(x => x.Id == newUser.Id)
|
||||
?.GetViewModel;
|
||||
}
|
||||
public UserViewModel? Update(UserBindingModel model)
|
||||
{
|
||||
using var context = new FurnitureAssemblyDatabase();
|
||||
var user = context.Users.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (user == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
user.Update(model);
|
||||
context.SaveChanges();
|
||||
return context.Users
|
||||
.Include(x => x.Sets)
|
||||
.Include(x => x.Orders)
|
||||
.Include(x => x.FurnitureModules)
|
||||
.Include(x => x.Furnitures)
|
||||
.Include(x => x.Materials)
|
||||
.FirstOrDefault(x => x.Id == model.Id)
|
||||
?.GetViewModel;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,505 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using FurnitureAssembly_WorkerDatabaseImplement;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace FurnitureAssembly_WorkerDatabaseImplement.Migrations
|
||||
{
|
||||
[DbContext(typeof(FurnitureAssemblyDatabase))]
|
||||
[Migration("20230405211314_InitMigration")]
|
||||
partial class InitMigration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "7.0.4")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||
|
||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("FurnitureAssembly_WorkerDatabaseImplement.Models.Furniture", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<double>("Cost")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.Property<DateTime>("DateCreate")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int>("UserId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("UserId");
|
||||
|
||||
b.ToTable("Furnitures");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FurnitureAssembly_WorkerDatabaseImplement.Models.FurnitureMaterial", 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>("MaterialId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("FurnitureId");
|
||||
|
||||
b.HasIndex("MaterialId");
|
||||
|
||||
b.ToTable("FurnitureMaterials");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FurnitureAssembly_WorkerDatabaseImplement.Models.FurnitureModule", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<double>("Cost")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.Property<DateTime>("DateCreate")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int>("UserId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("UserId");
|
||||
|
||||
b.ToTable("FurnitureModules");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FurnitureAssembly_WorkerDatabaseImplement.Models.FurnitureModuleFurniture", 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>("FurnitureModuleId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("FurnitureId");
|
||||
|
||||
b.HasIndex("FurnitureModuleId");
|
||||
|
||||
b.ToTable("FurnitureModuleFurnitures");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FurnitureAssembly_WorkerDatabaseImplement.Models.Material", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<double>("Cost")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int>("ScopeId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("UserId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ScopeId");
|
||||
|
||||
b.HasIndex("UserId");
|
||||
|
||||
b.ToTable("Materials");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FurnitureAssembly_WorkerDatabaseImplement.Models.Order", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("CustomerName")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTime>("DateCreate")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<int>("PaymentType")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("SetId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("UserId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("SetId");
|
||||
|
||||
b.HasIndex("UserId");
|
||||
|
||||
b.ToTable("Orders");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FurnitureAssembly_WorkerDatabaseImplement.Models.Role", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Roles");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FurnitureAssembly_WorkerDatabaseImplement.Models.Scope", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Scopes");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FurnitureAssembly_WorkerDatabaseImplement.Models.Set", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<double>("Cost")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.Property<DateTime>("DateCreate")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int>("UserId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("UserId");
|
||||
|
||||
b.ToTable("Sets");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FurnitureAssembly_WorkerDatabaseImplement.Models.SetFurnitureModule", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("FurnitureModuleId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("SetId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("FurnitureModuleId");
|
||||
|
||||
b.HasIndex("SetId");
|
||||
|
||||
b.ToTable("SetFurnitureModules");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FurnitureAssembly_WorkerDatabaseImplement.Models.User", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Login")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("Password")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int>("RoleId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("RoleId");
|
||||
|
||||
b.ToTable("Users");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FurnitureAssembly_WorkerDatabaseImplement.Models.Furniture", b =>
|
||||
{
|
||||
b.HasOne("FurnitureAssembly_WorkerDatabaseImplement.Models.User", "User")
|
||||
.WithMany("Furnitures")
|
||||
.HasForeignKey("UserId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("User");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FurnitureAssembly_WorkerDatabaseImplement.Models.FurnitureMaterial", b =>
|
||||
{
|
||||
b.HasOne("FurnitureAssembly_WorkerDatabaseImplement.Models.Furniture", "Furniture")
|
||||
.WithMany("Materials")
|
||||
.HasForeignKey("FurnitureId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("FurnitureAssembly_WorkerDatabaseImplement.Models.Material", "Material")
|
||||
.WithMany("FurnitureMaterials")
|
||||
.HasForeignKey("MaterialId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Furniture");
|
||||
|
||||
b.Navigation("Material");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FurnitureAssembly_WorkerDatabaseImplement.Models.FurnitureModule", b =>
|
||||
{
|
||||
b.HasOne("FurnitureAssembly_WorkerDatabaseImplement.Models.User", "User")
|
||||
.WithMany("FurnitureModules")
|
||||
.HasForeignKey("UserId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("User");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FurnitureAssembly_WorkerDatabaseImplement.Models.FurnitureModuleFurniture", b =>
|
||||
{
|
||||
b.HasOne("FurnitureAssembly_WorkerDatabaseImplement.Models.Furniture", "Furniture")
|
||||
.WithMany()
|
||||
.HasForeignKey("FurnitureId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("FurnitureAssembly_WorkerDatabaseImplement.Models.FurnitureModule", "FurnitureModule")
|
||||
.WithMany("Furnitures")
|
||||
.HasForeignKey("FurnitureModuleId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Furniture");
|
||||
|
||||
b.Navigation("FurnitureModule");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FurnitureAssembly_WorkerDatabaseImplement.Models.Material", b =>
|
||||
{
|
||||
b.HasOne("FurnitureAssembly_WorkerDatabaseImplement.Models.Scope", "Scope")
|
||||
.WithMany("Materials")
|
||||
.HasForeignKey("ScopeId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("FurnitureAssembly_WorkerDatabaseImplement.Models.User", "User")
|
||||
.WithMany("Materials")
|
||||
.HasForeignKey("UserId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Scope");
|
||||
|
||||
b.Navigation("User");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FurnitureAssembly_WorkerDatabaseImplement.Models.Order", b =>
|
||||
{
|
||||
b.HasOne("FurnitureAssembly_WorkerDatabaseImplement.Models.Set", "Set")
|
||||
.WithMany("Orders")
|
||||
.HasForeignKey("SetId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("FurnitureAssembly_WorkerDatabaseImplement.Models.User", "User")
|
||||
.WithMany("Orders")
|
||||
.HasForeignKey("UserId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Set");
|
||||
|
||||
b.Navigation("User");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FurnitureAssembly_WorkerDatabaseImplement.Models.Set", b =>
|
||||
{
|
||||
b.HasOne("FurnitureAssembly_WorkerDatabaseImplement.Models.User", "User")
|
||||
.WithMany("Sets")
|
||||
.HasForeignKey("UserId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("User");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FurnitureAssembly_WorkerDatabaseImplement.Models.SetFurnitureModule", b =>
|
||||
{
|
||||
b.HasOne("FurnitureAssembly_WorkerDatabaseImplement.Models.FurnitureModule", "FurnitureModule")
|
||||
.WithMany("Sets")
|
||||
.HasForeignKey("FurnitureModuleId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("FurnitureAssembly_WorkerDatabaseImplement.Models.Set", "Set")
|
||||
.WithMany("FurnitureModules")
|
||||
.HasForeignKey("SetId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("FurnitureModule");
|
||||
|
||||
b.Navigation("Set");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FurnitureAssembly_WorkerDatabaseImplement.Models.User", b =>
|
||||
{
|
||||
b.HasOne("FurnitureAssembly_WorkerDatabaseImplement.Models.Role", "Role")
|
||||
.WithMany("Users")
|
||||
.HasForeignKey("RoleId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Role");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FurnitureAssembly_WorkerDatabaseImplement.Models.Furniture", b =>
|
||||
{
|
||||
b.Navigation("Materials");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FurnitureAssembly_WorkerDatabaseImplement.Models.FurnitureModule", b =>
|
||||
{
|
||||
b.Navigation("Furnitures");
|
||||
|
||||
b.Navigation("Sets");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FurnitureAssembly_WorkerDatabaseImplement.Models.Material", b =>
|
||||
{
|
||||
b.Navigation("FurnitureMaterials");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FurnitureAssembly_WorkerDatabaseImplement.Models.Role", b =>
|
||||
{
|
||||
b.Navigation("Users");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FurnitureAssembly_WorkerDatabaseImplement.Models.Scope", b =>
|
||||
{
|
||||
b.Navigation("Materials");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FurnitureAssembly_WorkerDatabaseImplement.Models.Set", b =>
|
||||
{
|
||||
b.Navigation("FurnitureModules");
|
||||
|
||||
b.Navigation("Orders");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FurnitureAssembly_WorkerDatabaseImplement.Models.User", b =>
|
||||
{
|
||||
b.Navigation("FurnitureModules");
|
||||
|
||||
b.Navigation("Furnitures");
|
||||
|
||||
b.Navigation("Materials");
|
||||
|
||||
b.Navigation("Orders");
|
||||
|
||||
b.Navigation("Sets");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,375 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace FurnitureAssembly_WorkerDatabaseImplement.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class InitMigration : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Roles",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "integer", nullable: false)
|
||||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||
Name = table.Column<string>(type: "text", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Roles", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Scopes",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "integer", nullable: false)
|
||||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||
Name = table.Column<string>(type: "text", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Scopes", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Users",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "integer", nullable: false)
|
||||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||
Login = table.Column<string>(type: "text", nullable: false),
|
||||
Password = table.Column<string>(type: "text", nullable: false),
|
||||
Name = table.Column<string>(type: "text", nullable: false),
|
||||
RoleId = table.Column<int>(type: "integer", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Users", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_Users_Roles_RoleId",
|
||||
column: x => x.RoleId,
|
||||
principalTable: "Roles",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "FurnitureModules",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "integer", nullable: false)
|
||||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||
Name = table.Column<string>(type: "text", nullable: false),
|
||||
Cost = table.Column<double>(type: "double precision", nullable: false),
|
||||
DateCreate = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
|
||||
UserId = table.Column<int>(type: "integer", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_FurnitureModules", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_FurnitureModules_Users_UserId",
|
||||
column: x => x.UserId,
|
||||
principalTable: "Users",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Furnitures",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "integer", nullable: false)
|
||||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||
Name = table.Column<string>(type: "text", nullable: false),
|
||||
Cost = table.Column<double>(type: "double precision", nullable: false),
|
||||
DateCreate = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
|
||||
UserId = table.Column<int>(type: "integer", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Furnitures", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_Furnitures_Users_UserId",
|
||||
column: x => x.UserId,
|
||||
principalTable: "Users",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Materials",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "integer", nullable: false)
|
||||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||
Name = table.Column<string>(type: "text", nullable: false),
|
||||
Cost = table.Column<double>(type: "double precision", nullable: false),
|
||||
ScopeId = table.Column<int>(type: "integer", nullable: false),
|
||||
UserId = table.Column<int>(type: "integer", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Materials", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_Materials_Scopes_ScopeId",
|
||||
column: x => x.ScopeId,
|
||||
principalTable: "Scopes",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
table.ForeignKey(
|
||||
name: "FK_Materials_Users_UserId",
|
||||
column: x => x.UserId,
|
||||
principalTable: "Users",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Sets",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "integer", nullable: false)
|
||||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||
Name = table.Column<string>(type: "text", nullable: false),
|
||||
Cost = table.Column<double>(type: "double precision", nullable: false),
|
||||
DateCreate = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
|
||||
UserId = table.Column<int>(type: "integer", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Sets", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_Sets_Users_UserId",
|
||||
column: x => x.UserId,
|
||||
principalTable: "Users",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "FurnitureModuleFurnitures",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "integer", nullable: false)
|
||||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||
FurnitureModuleId = table.Column<int>(type: "integer", nullable: false),
|
||||
FurnitureId = table.Column<int>(type: "integer", nullable: false),
|
||||
Count = table.Column<int>(type: "integer", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_FurnitureModuleFurnitures", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_FurnitureModuleFurnitures_FurnitureModules_FurnitureModuleId",
|
||||
column: x => x.FurnitureModuleId,
|
||||
principalTable: "FurnitureModules",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
table.ForeignKey(
|
||||
name: "FK_FurnitureModuleFurnitures_Furnitures_FurnitureId",
|
||||
column: x => x.FurnitureId,
|
||||
principalTable: "Furnitures",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "FurnitureMaterials",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "integer", nullable: false)
|
||||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||
FurnitureId = table.Column<int>(type: "integer", nullable: false),
|
||||
MaterialId = table.Column<int>(type: "integer", nullable: false),
|
||||
Count = table.Column<int>(type: "integer", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_FurnitureMaterials", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_FurnitureMaterials_Furnitures_FurnitureId",
|
||||
column: x => x.FurnitureId,
|
||||
principalTable: "Furnitures",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
table.ForeignKey(
|
||||
name: "FK_FurnitureMaterials_Materials_MaterialId",
|
||||
column: x => x.MaterialId,
|
||||
principalTable: "Materials",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Orders",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "integer", nullable: false)
|
||||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||
CustomerName = table.Column<string>(type: "text", nullable: false),
|
||||
PaymentType = table.Column<int>(type: "integer", nullable: false),
|
||||
SetId = table.Column<int>(type: "integer", nullable: false),
|
||||
DateCreate = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
|
||||
UserId = table.Column<int>(type: "integer", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Orders", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_Orders_Sets_SetId",
|
||||
column: x => x.SetId,
|
||||
principalTable: "Sets",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
table.ForeignKey(
|
||||
name: "FK_Orders_Users_UserId",
|
||||
column: x => x.UserId,
|
||||
principalTable: "Users",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "SetFurnitureModules",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "integer", nullable: false)
|
||||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||
SetId = table.Column<int>(type: "integer", nullable: false),
|
||||
FurnitureModuleId = table.Column<int>(type: "integer", nullable: false),
|
||||
Count = table.Column<int>(type: "integer", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_SetFurnitureModules", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_SetFurnitureModules_FurnitureModules_FurnitureModuleId",
|
||||
column: x => x.FurnitureModuleId,
|
||||
principalTable: "FurnitureModules",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
table.ForeignKey(
|
||||
name: "FK_SetFurnitureModules_Sets_SetId",
|
||||
column: x => x.SetId,
|
||||
principalTable: "Sets",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_FurnitureMaterials_FurnitureId",
|
||||
table: "FurnitureMaterials",
|
||||
column: "FurnitureId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_FurnitureMaterials_MaterialId",
|
||||
table: "FurnitureMaterials",
|
||||
column: "MaterialId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_FurnitureModuleFurnitures_FurnitureId",
|
||||
table: "FurnitureModuleFurnitures",
|
||||
column: "FurnitureId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_FurnitureModuleFurnitures_FurnitureModuleId",
|
||||
table: "FurnitureModuleFurnitures",
|
||||
column: "FurnitureModuleId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_FurnitureModules_UserId",
|
||||
table: "FurnitureModules",
|
||||
column: "UserId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Furnitures_UserId",
|
||||
table: "Furnitures",
|
||||
column: "UserId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Materials_ScopeId",
|
||||
table: "Materials",
|
||||
column: "ScopeId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Materials_UserId",
|
||||
table: "Materials",
|
||||
column: "UserId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Orders_SetId",
|
||||
table: "Orders",
|
||||
column: "SetId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Orders_UserId",
|
||||
table: "Orders",
|
||||
column: "UserId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_SetFurnitureModules_FurnitureModuleId",
|
||||
table: "SetFurnitureModules",
|
||||
column: "FurnitureModuleId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_SetFurnitureModules_SetId",
|
||||
table: "SetFurnitureModules",
|
||||
column: "SetId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Sets_UserId",
|
||||
table: "Sets",
|
||||
column: "UserId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Users_RoleId",
|
||||
table: "Users",
|
||||
column: "RoleId");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "FurnitureMaterials");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "FurnitureModuleFurnitures");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Orders");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "SetFurnitureModules");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Materials");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Furnitures");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "FurnitureModules");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Sets");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Scopes");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Users");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Roles");
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,502 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using FurnitureAssembly_WorkerDatabaseImplement;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace FurnitureAssembly_WorkerDatabaseImplement.Migrations
|
||||
{
|
||||
[DbContext(typeof(FurnitureAssemblyDatabase))]
|
||||
partial class FurnitureAssemblyDatabaseModelSnapshot : ModelSnapshot
|
||||
{
|
||||
protected override void BuildModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "7.0.4")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||
|
||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("FurnitureAssembly_WorkerDatabaseImplement.Models.Furniture", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<double>("Cost")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.Property<DateTime>("DateCreate")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int>("UserId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("UserId");
|
||||
|
||||
b.ToTable("Furnitures");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FurnitureAssembly_WorkerDatabaseImplement.Models.FurnitureMaterial", 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>("MaterialId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("FurnitureId");
|
||||
|
||||
b.HasIndex("MaterialId");
|
||||
|
||||
b.ToTable("FurnitureMaterials");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FurnitureAssembly_WorkerDatabaseImplement.Models.FurnitureModule", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<double>("Cost")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.Property<DateTime>("DateCreate")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int>("UserId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("UserId");
|
||||
|
||||
b.ToTable("FurnitureModules");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FurnitureAssembly_WorkerDatabaseImplement.Models.FurnitureModuleFurniture", 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>("FurnitureModuleId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("FurnitureId");
|
||||
|
||||
b.HasIndex("FurnitureModuleId");
|
||||
|
||||
b.ToTable("FurnitureModuleFurnitures");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FurnitureAssembly_WorkerDatabaseImplement.Models.Material", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<double>("Cost")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int>("ScopeId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("UserId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ScopeId");
|
||||
|
||||
b.HasIndex("UserId");
|
||||
|
||||
b.ToTable("Materials");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FurnitureAssembly_WorkerDatabaseImplement.Models.Order", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("CustomerName")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTime>("DateCreate")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<int>("PaymentType")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("SetId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("UserId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("SetId");
|
||||
|
||||
b.HasIndex("UserId");
|
||||
|
||||
b.ToTable("Orders");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FurnitureAssembly_WorkerDatabaseImplement.Models.Role", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Roles");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FurnitureAssembly_WorkerDatabaseImplement.Models.Scope", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Scopes");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FurnitureAssembly_WorkerDatabaseImplement.Models.Set", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<double>("Cost")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.Property<DateTime>("DateCreate")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int>("UserId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("UserId");
|
||||
|
||||
b.ToTable("Sets");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FurnitureAssembly_WorkerDatabaseImplement.Models.SetFurnitureModule", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("FurnitureModuleId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("SetId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("FurnitureModuleId");
|
||||
|
||||
b.HasIndex("SetId");
|
||||
|
||||
b.ToTable("SetFurnitureModules");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FurnitureAssembly_WorkerDatabaseImplement.Models.User", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Login")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("Password")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int>("RoleId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("RoleId");
|
||||
|
||||
b.ToTable("Users");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FurnitureAssembly_WorkerDatabaseImplement.Models.Furniture", b =>
|
||||
{
|
||||
b.HasOne("FurnitureAssembly_WorkerDatabaseImplement.Models.User", "User")
|
||||
.WithMany("Furnitures")
|
||||
.HasForeignKey("UserId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("User");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FurnitureAssembly_WorkerDatabaseImplement.Models.FurnitureMaterial", b =>
|
||||
{
|
||||
b.HasOne("FurnitureAssembly_WorkerDatabaseImplement.Models.Furniture", "Furniture")
|
||||
.WithMany("Materials")
|
||||
.HasForeignKey("FurnitureId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("FurnitureAssembly_WorkerDatabaseImplement.Models.Material", "Material")
|
||||
.WithMany("FurnitureMaterials")
|
||||
.HasForeignKey("MaterialId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Furniture");
|
||||
|
||||
b.Navigation("Material");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FurnitureAssembly_WorkerDatabaseImplement.Models.FurnitureModule", b =>
|
||||
{
|
||||
b.HasOne("FurnitureAssembly_WorkerDatabaseImplement.Models.User", "User")
|
||||
.WithMany("FurnitureModules")
|
||||
.HasForeignKey("UserId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("User");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FurnitureAssembly_WorkerDatabaseImplement.Models.FurnitureModuleFurniture", b =>
|
||||
{
|
||||
b.HasOne("FurnitureAssembly_WorkerDatabaseImplement.Models.Furniture", "Furniture")
|
||||
.WithMany()
|
||||
.HasForeignKey("FurnitureId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("FurnitureAssembly_WorkerDatabaseImplement.Models.FurnitureModule", "FurnitureModule")
|
||||
.WithMany("Furnitures")
|
||||
.HasForeignKey("FurnitureModuleId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Furniture");
|
||||
|
||||
b.Navigation("FurnitureModule");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FurnitureAssembly_WorkerDatabaseImplement.Models.Material", b =>
|
||||
{
|
||||
b.HasOne("FurnitureAssembly_WorkerDatabaseImplement.Models.Scope", "Scope")
|
||||
.WithMany("Materials")
|
||||
.HasForeignKey("ScopeId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("FurnitureAssembly_WorkerDatabaseImplement.Models.User", "User")
|
||||
.WithMany("Materials")
|
||||
.HasForeignKey("UserId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Scope");
|
||||
|
||||
b.Navigation("User");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FurnitureAssembly_WorkerDatabaseImplement.Models.Order", b =>
|
||||
{
|
||||
b.HasOne("FurnitureAssembly_WorkerDatabaseImplement.Models.Set", "Set")
|
||||
.WithMany("Orders")
|
||||
.HasForeignKey("SetId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("FurnitureAssembly_WorkerDatabaseImplement.Models.User", "User")
|
||||
.WithMany("Orders")
|
||||
.HasForeignKey("UserId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Set");
|
||||
|
||||
b.Navigation("User");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FurnitureAssembly_WorkerDatabaseImplement.Models.Set", b =>
|
||||
{
|
||||
b.HasOne("FurnitureAssembly_WorkerDatabaseImplement.Models.User", "User")
|
||||
.WithMany("Sets")
|
||||
.HasForeignKey("UserId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("User");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FurnitureAssembly_WorkerDatabaseImplement.Models.SetFurnitureModule", b =>
|
||||
{
|
||||
b.HasOne("FurnitureAssembly_WorkerDatabaseImplement.Models.FurnitureModule", "FurnitureModule")
|
||||
.WithMany("Sets")
|
||||
.HasForeignKey("FurnitureModuleId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("FurnitureAssembly_WorkerDatabaseImplement.Models.Set", "Set")
|
||||
.WithMany("FurnitureModules")
|
||||
.HasForeignKey("SetId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("FurnitureModule");
|
||||
|
||||
b.Navigation("Set");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FurnitureAssembly_WorkerDatabaseImplement.Models.User", b =>
|
||||
{
|
||||
b.HasOne("FurnitureAssembly_WorkerDatabaseImplement.Models.Role", "Role")
|
||||
.WithMany("Users")
|
||||
.HasForeignKey("RoleId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Role");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FurnitureAssembly_WorkerDatabaseImplement.Models.Furniture", b =>
|
||||
{
|
||||
b.Navigation("Materials");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FurnitureAssembly_WorkerDatabaseImplement.Models.FurnitureModule", b =>
|
||||
{
|
||||
b.Navigation("Furnitures");
|
||||
|
||||
b.Navigation("Sets");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FurnitureAssembly_WorkerDatabaseImplement.Models.Material", b =>
|
||||
{
|
||||
b.Navigation("FurnitureMaterials");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FurnitureAssembly_WorkerDatabaseImplement.Models.Role", b =>
|
||||
{
|
||||
b.Navigation("Users");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FurnitureAssembly_WorkerDatabaseImplement.Models.Scope", b =>
|
||||
{
|
||||
b.Navigation("Materials");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FurnitureAssembly_WorkerDatabaseImplement.Models.Set", b =>
|
||||
{
|
||||
b.Navigation("FurnitureModules");
|
||||
|
||||
b.Navigation("Orders");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FurnitureAssembly_WorkerDatabaseImplement.Models.User", b =>
|
||||
{
|
||||
b.Navigation("FurnitureModules");
|
||||
|
||||
b.Navigation("Furnitures");
|
||||
|
||||
b.Navigation("Materials");
|
||||
|
||||
b.Navigation("Orders");
|
||||
|
||||
b.Navigation("Sets");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,110 @@
|
||||
using FurnitureAssembly_WorkerContracts.BindingModels;
|
||||
using FurnitureAssembly_WorkerContracts.ViewModels;
|
||||
using FurnitureAssembly_WorkerDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FurnitureAssembly_WorkerDatabaseImplement.Models
|
||||
{
|
||||
public class Furniture : IFurnitureModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[Required]
|
||||
public string Name { get; set; } = string.Empty;
|
||||
[Required]
|
||||
public double Cost { get; set; }
|
||||
[Required]
|
||||
public DateTime DateCreate { get; set; } = DateTime.Now;
|
||||
[Required]
|
||||
public int UserId { get; set; }
|
||||
public virtual User User { get; set; }
|
||||
public Dictionary<int, (IMaterialModel, int)>? _furnitureMaterials = null;
|
||||
[NotMapped]
|
||||
public Dictionary<int, (IMaterialModel, int)> FurnitureMaterials
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_furnitureMaterials == null)
|
||||
{
|
||||
_furnitureMaterials = Materials
|
||||
.ToDictionary(recPC => recPC.MaterialId, recPC =>
|
||||
(recPC.Material as IMaterialModel, recPC.Count));
|
||||
}
|
||||
return _furnitureMaterials;
|
||||
}
|
||||
}
|
||||
[ForeignKey("FurnitureId")]
|
||||
public virtual List<FurnitureMaterial> Materials { get; set; } = new();
|
||||
public static Furniture Create(FurnitureAssemblyDatabase context, FurnitureBindingModel model)
|
||||
{
|
||||
return new Furniture()
|
||||
{
|
||||
Id = model.Id,
|
||||
Name = model.Name,
|
||||
Cost = model.Cost,
|
||||
UserId = model.UserId,
|
||||
DateCreate = model.DateCreate,
|
||||
Materials = model.FurnitureMaterials.Select(x => new FurnitureMaterial
|
||||
{
|
||||
Material = context.Materials.First(y => y.Id == x.Key),
|
||||
Count = x.Value.Item2
|
||||
}).ToList()
|
||||
};
|
||||
}
|
||||
public void Update(FurnitureBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Name = model.Name;
|
||||
Cost = model.Cost;
|
||||
}
|
||||
public FurnitureViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
Name = Name,
|
||||
Cost = Cost,
|
||||
UserId = UserId,
|
||||
UserName = User.Name,
|
||||
DateCreate = DateCreate,
|
||||
FurnitureMaterials = FurnitureMaterials
|
||||
};
|
||||
public void UpdateMaterials(FurnitureAssemblyDatabase context, FurnitureBindingModel model)
|
||||
{
|
||||
var furnitureMaterials = context.FurnitureMaterials.Where(rec =>
|
||||
rec.FurnitureId == model.Id).ToList();
|
||||
if (furnitureMaterials != null && furnitureMaterials.Count > 0)
|
||||
{ // удалили те, которых нет в модели
|
||||
context.FurnitureMaterials.RemoveRange(furnitureMaterials.Where(rec
|
||||
=> !model.FurnitureMaterials.ContainsKey(rec.MaterialId)));
|
||||
context.SaveChanges();
|
||||
// обновили количество у существующих записей
|
||||
foreach (var updateMaterial in furnitureMaterials)
|
||||
{
|
||||
updateMaterial.Count = model.FurnitureMaterials[updateMaterial.MaterialId].Item2;
|
||||
model.FurnitureMaterials.Remove(updateMaterial.MaterialId);
|
||||
}
|
||||
context.SaveChanges();
|
||||
}
|
||||
var furniture = context.Furnitures.First(x => x.Id == Id);
|
||||
foreach (var pc in model.FurnitureMaterials)
|
||||
{
|
||||
context.FurnitureMaterials.Add(new FurnitureMaterial
|
||||
{
|
||||
Furniture = furniture,
|
||||
Material = context.Materials.First(x => x.Id == pc.Key),
|
||||
Count = pc.Value.Item2
|
||||
});
|
||||
context.SaveChanges();
|
||||
}
|
||||
_furnitureMaterials = null;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FurnitureAssembly_WorkerDatabaseImplement.Models
|
||||
{
|
||||
public class FurnitureMaterial
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[Required]
|
||||
public int FurnitureId { get; set; }
|
||||
[Required]
|
||||
public int MaterialId { get; set; }
|
||||
[Required]
|
||||
public int Count { get; set; }
|
||||
public virtual Furniture Furniture { get; set; } = new();
|
||||
public virtual Material Material { get; set; } = new();
|
||||
}
|
||||
}
|
@ -0,0 +1,118 @@
|
||||
using FurnitureAssembly_WorkerContracts.BindingModels;
|
||||
using FurnitureAssembly_WorkerContracts.ViewModels;
|
||||
using FurnitureAssembly_WorkerDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FurnitureAssembly_WorkerDatabaseImplement.Models
|
||||
{
|
||||
public class FurnitureModule : IFurnitureModuleModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[Required]
|
||||
public string Name { get; set; } = string.Empty;
|
||||
[Required]
|
||||
public double Cost { get; set; }
|
||||
[Required]
|
||||
public DateTime DateCreate { get; set; }
|
||||
[Required]
|
||||
public int UserId { get; set; }
|
||||
public virtual User User { get; set; }
|
||||
public Dictionary<int, (IFurnitureModel, int)>? _furnitureModuleFurnitures = null;
|
||||
[NotMapped]
|
||||
public Dictionary<int, (IFurnitureModel, int)> FurnitureModuleFurnitures
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_furnitureModuleFurnitures == null)
|
||||
{
|
||||
_furnitureModuleFurnitures = Furnitures
|
||||
.ToDictionary(recPC => recPC.FurnitureId, recPC =>
|
||||
(recPC.Furniture as IFurnitureModel, recPC.Count));
|
||||
}
|
||||
return _furnitureModuleFurnitures;
|
||||
}
|
||||
}
|
||||
[ForeignKey("FurnitureModuleId")]
|
||||
public virtual List<FurnitureModuleFurniture> Furnitures { get; set; } = new();
|
||||
[ForeignKey("FurnitureModuleId")]
|
||||
public virtual List<SetFurnitureModule> Sets { get; set; } = new();
|
||||
public static FurnitureModule Create(FurnitureAssemblyDatabase context, FurnitureModuleBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new FurnitureModule()
|
||||
{
|
||||
Id = model.Id,
|
||||
Name = model.Name,
|
||||
Cost = model.Cost,
|
||||
DateCreate = model.DateCreate,
|
||||
UserId = model.UserId,
|
||||
Furnitures = model.FurnitureModuleFurnitures.Select(x => new FurnitureModuleFurniture
|
||||
{
|
||||
Furniture = context.Furnitures.First(y => y.Id == x.Key),
|
||||
Count = x.Value.Item2
|
||||
}).ToList()
|
||||
};
|
||||
}
|
||||
public void Update(FurnitureModuleBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Name = model.Name;
|
||||
Cost = model.Cost;
|
||||
}
|
||||
public FurnitureModuleViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
Name = Name,
|
||||
Cost = Cost,
|
||||
DateCreate = DateCreate,
|
||||
UserId = UserId,
|
||||
UserName = User.Name,
|
||||
FurnitureModuleFurnitures = FurnitureModuleFurnitures
|
||||
};
|
||||
public void UpdateFurnitures(FurnitureAssemblyDatabase context, FurnitureModuleBindingModel model)
|
||||
{
|
||||
var furnitureModuleFurnitures = context.FurnitureModuleFurnitures.Where(rec =>
|
||||
rec.FurnitureModuleId == model.Id).ToList();
|
||||
if (furnitureModuleFurnitures != null && furnitureModuleFurnitures.Count > 0)
|
||||
{ // удалили те, которых нет в модели
|
||||
context.FurnitureModuleFurnitures.RemoveRange(furnitureModuleFurnitures.Where(rec
|
||||
=> !model.FurnitureModuleFurnitures.ContainsKey(rec.FurnitureId)));
|
||||
context.SaveChanges();
|
||||
// обновили количество у существующих записей
|
||||
foreach (var updateFurniture in furnitureModuleFurnitures)
|
||||
{
|
||||
updateFurniture.Count = model.FurnitureModuleFurnitures[updateFurniture.FurnitureId].Item2;
|
||||
model.FurnitureModuleFurnitures.Remove(updateFurniture.FurnitureId);
|
||||
}
|
||||
context.SaveChanges();
|
||||
}
|
||||
var furnitureModule = context.FurnitureModules.First(x => x.Id == Id);
|
||||
foreach (var pc in model.FurnitureModuleFurnitures)
|
||||
{
|
||||
context.FurnitureModuleFurnitures.Add(new FurnitureModuleFurniture
|
||||
{
|
||||
FurnitureModule = furnitureModule,
|
||||
Furniture = context.Furnitures.First(x => x.Id == pc.Key),
|
||||
Count = pc.Value.Item2
|
||||
});
|
||||
context.SaveChanges();
|
||||
}
|
||||
_furnitureModuleFurnitures = null;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FurnitureAssembly_WorkerDatabaseImplement.Models
|
||||
{
|
||||
public class FurnitureModuleFurniture
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[Required]
|
||||
public int FurnitureModuleId { get; set; }
|
||||
[Required]
|
||||
public int FurnitureId { get; set; }
|
||||
[Required]
|
||||
public int Count { get; set; }
|
||||
public virtual FurnitureModule FurnitureModule { get; set; } = new();
|
||||
public virtual Furniture Furniture { get; set; } = new();
|
||||
}
|
||||
}
|
@ -0,0 +1,66 @@
|
||||
using FurnitureAssembly_WorkerContracts.BindingModels;
|
||||
using FurnitureAssembly_WorkerContracts.ViewModels;
|
||||
using FurnitureAssembly_WorkerDataModels.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 FurnitureAssembly_WorkerDatabaseImplement.Models
|
||||
{
|
||||
public class Material : IMaterialModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[Required]
|
||||
public string Name { get; set; } = string.Empty;
|
||||
[Required]
|
||||
public double Cost { get; set; }
|
||||
[Required]
|
||||
public int ScopeId { get; set; }
|
||||
public virtual Scope Scope { get; set; }
|
||||
[Required]
|
||||
public int UserId { get; set; }
|
||||
public virtual User User { get; set; }
|
||||
[ForeignKey("MaterialId")]
|
||||
public virtual List<FurnitureMaterial> FurnitureMaterials { get; set; } = new();
|
||||
public static Material? Create(MaterialBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Material()
|
||||
{
|
||||
Id = model.Id,
|
||||
Name = model.Name,
|
||||
Cost = model.Cost,
|
||||
ScopeId = model.ScopeId,
|
||||
UserId = model.UserId
|
||||
};
|
||||
}
|
||||
public void Update(MaterialBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Name = model.Name;
|
||||
Cost = model.Cost;
|
||||
ScopeId = model.ScopeId;
|
||||
}
|
||||
public MaterialViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
Name = Name,
|
||||
Cost = Cost,
|
||||
ScopeId = ScopeId,
|
||||
ScopeName = Scope.Name,
|
||||
UserId = UserId,
|
||||
UserName = User.Name
|
||||
};
|
||||
}
|
||||
}
|
@ -0,0 +1,68 @@
|
||||
using FurnitureAssembly_WorkerContracts.BindingModels;
|
||||
using FurnitureAssembly_WorkerContracts.ViewModels;
|
||||
using FurnitureAssembly_WorkerDataModels.Enums;
|
||||
using FurnitureAssembly_WorkerDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FurnitureAssembly_WorkerDatabaseImplement.Models
|
||||
{
|
||||
public class Order : IOrderModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[Required]
|
||||
public string CustomerName { get; set; } = string.Empty;
|
||||
[Required]
|
||||
public PaymentType PaymentType { get; set; } = PaymentType.Неизвестен;
|
||||
[Required]
|
||||
public int SetId { get; set; }
|
||||
public virtual Set Set { get; set; }
|
||||
[Required]
|
||||
public DateTime DateCreate { get; set; }
|
||||
[Required]
|
||||
public int UserId { get; set; }
|
||||
public virtual User User { get; set; }
|
||||
public static Order? Create(OrderBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Order()
|
||||
{
|
||||
Id = model.Id,
|
||||
CustomerName = model.CustomerName,
|
||||
PaymentType = model.PaymentType,
|
||||
SetId = model.SetId,
|
||||
DateCreate = model.DateCreate,
|
||||
UserId = model.UserId
|
||||
};
|
||||
}
|
||||
public void Update(OrderBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
CustomerName = model.CustomerName;
|
||||
PaymentType = model.PaymentType;
|
||||
SetId = model.SetId;
|
||||
UserId = model.UserId;
|
||||
}
|
||||
public OrderViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
CustomerName = CustomerName,
|
||||
PaymentType = PaymentType,
|
||||
SetId = SetId,
|
||||
SetName = Set.Name,
|
||||
DateCreate = DateCreate,
|
||||
UserId = UserId,
|
||||
UserName = User.Name
|
||||
};
|
||||
}
|
||||
}
|
@ -4,6 +4,7 @@ using FurnitureAssembly_WorkerDataModels.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;
|
||||
@ -15,6 +16,8 @@ namespace FurnitureAssembly_WorkerDatabaseImplement.Models
|
||||
public int Id { get; set; }
|
||||
[Required]
|
||||
public string Name { get; set; } = string.Empty;
|
||||
[ForeignKey("RoleId")]
|
||||
public virtual List<User> Users { get; set; } = new();
|
||||
public static Role? Create(RoleBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
|
@ -0,0 +1,47 @@
|
||||
using FurnitureAssembly_WorkerContracts.BindingModels;
|
||||
using FurnitureAssembly_WorkerContracts.ViewModels;
|
||||
using FurnitureAssembly_WorkerDataModels.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 FurnitureAssembly_WorkerDatabaseImplement.Models
|
||||
{
|
||||
public class Scope : IScopeModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[Required]
|
||||
public string Name { get; set; } = string.Empty;
|
||||
[ForeignKey("ScopeId")]
|
||||
public virtual List<Material> Materials { get; set; } = new();
|
||||
public static Scope? Create(ScopeBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Scope()
|
||||
{
|
||||
Id = model.Id,
|
||||
Name = model.Name
|
||||
};
|
||||
}
|
||||
public void Update(ScopeBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Name = model.Name;
|
||||
}
|
||||
public ScopeViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
Name = Name
|
||||
};
|
||||
}
|
||||
}
|
@ -0,0 +1,111 @@
|
||||
using FurnitureAssembly_WorkerContracts.BindingModels;
|
||||
using FurnitureAssembly_WorkerContracts.ViewModels;
|
||||
using FurnitureAssembly_WorkerDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FurnitureAssembly_WorkerDatabaseImplement.Models
|
||||
{
|
||||
public class Set : ISetModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[Required]
|
||||
public string Name { get; set; } = string.Empty;
|
||||
[Required]
|
||||
public double Cost { get; set; }
|
||||
[Required]
|
||||
public DateTime DateCreate { get; set; }
|
||||
[Required]
|
||||
public int UserId { get; set; }
|
||||
public virtual User User { get; set; }
|
||||
public Dictionary<int, (IFurnitureModuleModel, int)>? _setFurnitureModules = null;
|
||||
[NotMapped]
|
||||
public Dictionary<int, (IFurnitureModuleModel, int)> SetFurnitureModules
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_setFurnitureModules == null)
|
||||
{
|
||||
_setFurnitureModules = FurnitureModules
|
||||
.ToDictionary(recPC => recPC.FurnitureModuleId, recPC =>
|
||||
(recPC.FurnitureModule as IFurnitureModuleModel, recPC.Count));
|
||||
}
|
||||
return _setFurnitureModules;
|
||||
}
|
||||
}
|
||||
[ForeignKey("SetId")]
|
||||
public virtual List<SetFurnitureModule> FurnitureModules { get; set; } = new();
|
||||
[ForeignKey("SetId")]
|
||||
public virtual List<Order> Orders { get; set; } = new();
|
||||
public static Set Create(FurnitureAssemblyDatabase context, SetBindingModel model)
|
||||
{
|
||||
return new Set()
|
||||
{
|
||||
Id = model.Id,
|
||||
Name = model.Name,
|
||||
Cost = model.Cost,
|
||||
DateCreate = model.DateCreate,
|
||||
FurnitureModules = model.SetFurnitureModules.Select(x => new SetFurnitureModule
|
||||
{
|
||||
FurnitureModule = context.FurnitureModules.First(y => y.Id == x.Key),
|
||||
Count = x.Value.Item2
|
||||
}).ToList()
|
||||
};
|
||||
}
|
||||
public void Update(SetBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Name = model.Name;
|
||||
Cost = model.Cost;
|
||||
}
|
||||
public SetViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
Name = Name,
|
||||
Cost = Cost,
|
||||
DateCreate = DateCreate,
|
||||
UserId = UserId,
|
||||
UserName = User.Name,
|
||||
SetFurnitureModules = SetFurnitureModules
|
||||
};
|
||||
public void UpdateFurnitureModules(FurnitureAssemblyDatabase context, SetBindingModel model)
|
||||
{
|
||||
var setFurnitureModules = context.SetFurnitureModules.Where(rec =>
|
||||
rec.SetId == model.Id).ToList();
|
||||
if (setFurnitureModules != null && setFurnitureModules.Count > 0)
|
||||
{ // удалили те, которых нет в модели
|
||||
context.SetFurnitureModules.RemoveRange(setFurnitureModules.Where(rec
|
||||
=> !model.SetFurnitureModules.ContainsKey(rec.FurnitureModuleId)));
|
||||
context.SaveChanges();
|
||||
// обновили количество у существующих записей
|
||||
foreach (var updateFurnitureModule in setFurnitureModules)
|
||||
{
|
||||
updateFurnitureModule.Count = model.SetFurnitureModules[updateFurnitureModule.FurnitureModuleId].Item2;
|
||||
model.SetFurnitureModules.Remove(updateFurnitureModule.FurnitureModuleId);
|
||||
}
|
||||
context.SaveChanges();
|
||||
}
|
||||
var set = context.Sets.First(x => x.Id == Id);
|
||||
foreach (var pc in model.SetFurnitureModules)
|
||||
{
|
||||
context.SetFurnitureModules.Add(new SetFurnitureModule
|
||||
{
|
||||
Set = set,
|
||||
FurnitureModule = context.FurnitureModules.First(x => x.Id == pc.Key),
|
||||
Count = pc.Value.Item2
|
||||
});
|
||||
context.SaveChanges();
|
||||
}
|
||||
_setFurnitureModules = null;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FurnitureAssembly_WorkerDatabaseImplement.Models
|
||||
{
|
||||
public class SetFurnitureModule
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[Required]
|
||||
public int SetId { get; set; }
|
||||
[Required]
|
||||
public int FurnitureModuleId { get; set; }
|
||||
[Required]
|
||||
public int Count { get; set; }
|
||||
public virtual Set Set { get; set; } = new();
|
||||
public virtual FurnitureModule FurnitureModule { get; set; } = new();
|
||||
}
|
||||
}
|
@ -1,7 +1,10 @@
|
||||
using FurnitureAssembly_WorkerDataModels.Models;
|
||||
using FurnitureAssembly_WorkerContracts.BindingModels;
|
||||
using FurnitureAssembly_WorkerContracts.ViewModels;
|
||||
using FurnitureAssembly_WorkerDataModels.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;
|
||||
@ -20,5 +23,50 @@ namespace FurnitureAssembly_WorkerDatabaseImplement.Models
|
||||
[Required]
|
||||
public int RoleId { get; set; }
|
||||
public virtual Role Role { get; set; }
|
||||
[ForeignKey("UserId")]
|
||||
public virtual List<Order> Orders { get; set; } = new();
|
||||
[ForeignKey("UserId")]
|
||||
public virtual List<Set> Sets { get; set; } = new();
|
||||
[ForeignKey("UserId")]
|
||||
public virtual List<FurnitureModule> FurnitureModules { get; set; } = new();
|
||||
[ForeignKey("UserId")]
|
||||
public virtual List<Furniture> Furnitures { get; set; } = new();
|
||||
[ForeignKey("UserId")]
|
||||
public virtual List<Material> Materials { get; set; } = new();
|
||||
public static User? Create(UserBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new User()
|
||||
{
|
||||
Id = model.Id,
|
||||
Login = model.Login,
|
||||
Password = model.Password,
|
||||
Name = model.Name,
|
||||
RoleId = model.RoleId
|
||||
};
|
||||
}
|
||||
public void Update(UserBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Login = model.Login;
|
||||
Password = model.Password;
|
||||
Name = model.Name;
|
||||
RoleId = model.RoleId;
|
||||
}
|
||||
public UserViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
Password = Password,
|
||||
Login = Login,
|
||||
Name = Name,
|
||||
RoleId = RoleId,
|
||||
RoleName = Role.Name
|
||||
};
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user