дб и вьюв

This commit is contained in:
Daniel 2023-04-08 19:10:10 +04:00
parent 341de52e3d
commit 6b1213db93
32 changed files with 4091 additions and 0 deletions

View File

@ -0,0 +1,36 @@
using FactoryDatabaseImplement.Models;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FactoryDatabaseImplement
{
public class FactoryDatabase : DbContext
{
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
if (!optionsBuilder.IsConfigured)
{
optionsBuilder.UseSqlServer(); //todo привязывай данные
}
base.OnConfiguring(optionsBuilder);
}
public virtual DbSet<Master> Masters { set; get; }
public virtual DbSet<Engenier> Engeniers { set; get; }
public virtual DbSet<Reinforced> Reinforceds { set; get; }
public virtual DbSet<Component> Components { set; get; }
public virtual DbSet<ReinforcedComponent> ReinforcedComponents { set; get; }
public virtual DbSet<Lathe> Lathes { set; get; }
public virtual DbSet<LatheBusy> LatheBusies { set; get; }
public virtual DbSet<LatheReinforced> LatheReinforcedes { set; get; }
public virtual DbSet<Plan> Plans { set; get; }
public virtual DbSet<Stage> Stages { set; get; }
public virtual DbSet<PlanLathe> PlanLathes { set; get; }
public virtual DbSet<PlanComponents> PlanComponents { set; get; }
}
}

View File

@ -0,0 +1,84 @@
using FactoryContracts.BindingModels;
using FactoryContracts.SearchModels;
using FactoryContracts.StoragesContracts;
using FactoryContracts.ViewModels;
using FactoryDatabaseImplement.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FactoryDatabaseImplement.Implements
{
public class ComponentStorage : IComponentStorage
{
public List<ComponentViewModel> GetFullList()
{
using var context = new FactoryDatabase();
return context.Components.Select(x => x.GetViewModel).ToList();
}
public List<ComponentViewModel> GetFilteredList(ComponentSearchModel model)
{
if (string.IsNullOrEmpty(model.ComponentName))
{
return new();
}
using var context = new FactoryDatabase();
return context.Components.Where(x => x.ComponentName.Contains(model.ComponentName)).Select(x => x.GetViewModel).ToList();
}
public ComponentViewModel? GetElement(ComponentSearchModel model)
{
if (string.IsNullOrEmpty(model.ComponentName) && !model.Id.HasValue)
{
return null;
}
using var context = new FactoryDatabase();
return context.Components.FirstOrDefault(x =>
(!string.IsNullOrEmpty(model.ComponentName) && x.ComponentName == model.ComponentName) ||
(model.Id.HasValue && x.Id == model.Id))
?.GetViewModel;
}
public ComponentViewModel? Insert(ComponentBindingModel model)
{
var newComponent = Component.Create(model);
if (newComponent == null)
{
return null;
}
using var context = new FactoryDatabase();
context.Components.Add(newComponent);
context.SaveChanges();
return newComponent.GetViewModel;
}
public ComponentViewModel? Update(ComponentBindingModel model)
{
using var context = new FactoryDatabase();
var component = context.Components.FirstOrDefault(x => x.Id == model.Id);
if (component == null)
{
return null;
}
component.Update(model);
context.SaveChanges();
return component.GetViewModel;
}
public ComponentViewModel? Delete(ComponentBindingModel model)
{
using var context = new FactoryDatabase();
var element = context.Components.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
context.Components.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return null;
}
}
}

View File

@ -0,0 +1,83 @@
using FactoryContracts.BindingModels;
using FactoryContracts.SearchModels;
using FactoryContracts.ViewModels;
using FactoryDatabaseImplement.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FactoryDatabaseImplement.Implements
{
public class EngenierStorage
{
public EngenierViewModel? Delete(EngenierBindingModel model)
{
using var context = new FactoryDatabase();
var element = context.Engeniers.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
context.Engeniers.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return null;
}
public EngenierViewModel? GetElement(EngenierSearchModel model)
{
if (string.IsNullOrEmpty(model.Email) && string.IsNullOrEmpty(model.Password) && !model.Id.HasValue)
{
return null;
}
using var context = new FactoryDatabase();
return context.Engeniers.FirstOrDefault(x =>
(!string.IsNullOrEmpty(model.Email) && x.Email == model.Email && !string.IsNullOrEmpty(model.Password) && x.Password == model.Password) ||
(model.Id.HasValue && x.Id == model.Id))
?.GetViewModel;
}
public List<EngenierViewModel> GetFilteredList(EngenierSearchModel model)
{
if (string.IsNullOrEmpty(model.Name))
{
return new();
}
using var context = new FactoryDatabase();
return context.Engeniers.Where(x => x.Fio.Contains(model.Name)).Select(x => x.GetViewModel).ToList();
}
public List<EngenierViewModel> GetFullList()
{
using var context = new FactoryDatabase();
return context.Engeniers.Select(x => x.GetViewModel).ToList();
}
public EngenierViewModel? Insert(EngenierBindingModel model)
{
var newEngenier = Engenier.Create(model);
if (newEngenier == null)
{
return null;
}
using var context = new FactoryDatabase();
context.Engeniers.Add(newEngenier);
context.SaveChanges();
return newEngenier.GetViewModel;
}
public EngenierViewModel? Update(EngenierBindingModel model)
{
using var context = new FactoryDatabase();
var engenier = context.Engeniers.FirstOrDefault(x => x.Id == model.Id);
if (engenier == null)
{
return null;
}
engenier.Update(model);
context.SaveChanges();
return engenier.GetViewModel;
}
}
}

View File

@ -0,0 +1,81 @@
using FactoryContracts.BindingModels;
using FactoryContracts.SearchModels;
using FactoryContracts.StoragesContracts;
using FactoryContracts.ViewModels;
using FactoryDatabaseImplement.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FactoryDatabaseImplement.Implements
{
public class LatheBusyStorage : ILatheBusyStorage
{
public List<LatheBusyViewModel> GetFullList()
{
using var context = new FactoryDatabase();
return context.LatheBusies.Select(x => x.GetViewModel).ToList();
}
public List<LatheBusyViewModel> GetFilteredList(LatheBusySearchModel model)
{
if (model.Id is null)
{
return new();
}
using var context = new FactoryDatabase();
return context.LatheBusies.Where(x => x.Percent == model.Percent).Select(x => x.GetViewModel).ToList();
}
public LatheBusyViewModel? GetElement(LatheBusySearchModel model)
{
if (model.Id is null)
{
return new();
}
using var context = new FactoryDatabase();
return context.LatheBusies.FirstOrDefault(x => x.Percent == model.Percent)?.GetViewModel;
}
public LatheBusyViewModel? Insert(LatheBusyBindingModel model)
{
var newLatheBusy = LatheBusy.Create(new FactoryDatabase(), model);
if (newLatheBusy == null)
{
return null;
}
using var context = new FactoryDatabase();
context.LatheBusies.Add(newLatheBusy);
context.SaveChanges();
return newLatheBusy.GetViewModel;
}
public LatheBusyViewModel? Update(LatheBusyBindingModel model)
{
using var context = new FactoryDatabase();
var latheBusy = context.LatheBusies.FirstOrDefault(x => x.Id == model.Id);
if (latheBusy == null)
{
return null;
}
latheBusy.Update(model);
context.SaveChanges();
return latheBusy.GetViewModel;
}
public LatheBusyViewModel? Delete(LatheBusyBindingModel model)
{
using var context = new FactoryDatabase();
var element = context.LatheBusies.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
context.LatheBusies.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return null;
}
}
}

View File

@ -0,0 +1,95 @@
using FactoryContracts.BindingModels;
using FactoryContracts.SearchModels;
using FactoryContracts.StoragesContracts;
using FactoryContracts.ViewModels;
using FactoryDatabaseImplement.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FactoryDatabaseImplement.Implements
{
public class LatheStorage : ILatheStorage
{
public List<LatheViewModel> GetFullList()
{
using var context = new FactoryDatabase();
return context.Lathes.Select(x => x.GetViewModel).ToList();
}
public List<LatheViewModel> GetFilteredList(LatheSearchModel model)
{
if (string.IsNullOrEmpty(model.LatheName))
{
return new();
}
using var context = new FactoryDatabase();
return context.Lathes.Where(x => x.LatheName.Contains(model.LatheName)).Select(x => x.GetViewModel).ToList();
}
public LatheViewModel? GetElement(LatheSearchModel model)
{
if (string.IsNullOrEmpty(model.LatheName) && !model.Id.HasValue)
{
return null;
}
using var context = new FactoryDatabase();
return context.Lathes.FirstOrDefault(x =>
(!string.IsNullOrEmpty(model.LatheName) && x.LatheName == model.LatheName) ||
(model.Id.HasValue && x.Id == model.Id))
?.GetViewModel;
}
public LatheViewModel? Insert(LatheBindingModel model)
{
var newLathe = Lathe.Create(new FactoryDatabase(), model);
if (newLathe == null)
{
return null;
}
using var context = new FactoryDatabase();
context.Lathes.Add(newLathe);
context.SaveChanges();
return newLathe.GetViewModel;
}
public LatheViewModel? Update(LatheBindingModel model)
{
using var context = new FactoryDatabase();
using var transaction = context.Database.BeginTransaction();
try
{
var Lathe = context.Lathes.FirstOrDefault(rec => rec.Id == model.Id);
if (Lathe == null)
{
return null;
}
Lathe.Update(model);
context.SaveChanges();
Lathe.UpdateComponents(context, model);
transaction.Commit();
return Lathe.GetViewModel;
}
catch
{
transaction.Rollback();
throw;
}
}
public LatheViewModel? Delete(LatheBindingModel model)
{
using var context = new FactoryDatabase();
var element = context.Lathes.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
context.Lathes.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return null;
}
}
}

View File

@ -0,0 +1,105 @@
using FactoryContracts.BindingModels;
using FactoryContracts.SearchModels;
using FactoryContracts.StoragesContracts;
using FactoryContracts.ViewModels;
using FactoryDatabaseImplement.Models;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FactoryDatabaseImplement.Implements
{
public class MasterStorage : IMasterStorage
{
public List<MasterViewModel> GetFullList()
{
using var context = new FactoryDatabase();
return context.Masters
.Select(x => x.GetViewModel)
.ToList();
}
public List<MasterViewModel> GetFilteredList(MasterSearchModel model)
{
if (string.IsNullOrEmpty(model.Email))
{
return new();
}
using var context = new FactoryDatabase();
return context.Masters
.Where(x => x.Email.Contains(model.Email))
.Select(x => x.GetViewModel)
.ToList();
}
public MasterViewModel? GetElement(MasterSearchModel model)
{
if (string.IsNullOrEmpty(model.Email) && !model.Id.HasValue)
{
return null;
}
using var context = new FactoryDatabase();
return context.Masters
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.Email) && x.Email == model.Email) ||
(model.Id.HasValue && x.Id == model.Id))
?.GetViewModel;
}
public MasterViewModel? Insert(MasterBindingModel model)
{
using var context = new FactoryDatabase();
var newMaster = Master.Create(context, model);
if (newMaster == null)
{
return null;
}
context.Masters.Add(newMaster);
context.SaveChanges();
return newMaster.GetViewModel;
}
public MasterViewModel? Update(MasterBindingModel model)
{
using var context = new FactoryDatabase();
var master = context.Masters.FirstOrDefault(x => x.Id == model.Id);
if (master == null)
{
return null;
}
master.Update(model);
context.SaveChanges();
return master.GetViewModel;
}
public MasterViewModel? Delete(MasterBindingModel model)
{
using var context = new FactoryDatabase();
var element = context.Masters.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
context.Masters.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return null;
}
}
}

View File

@ -0,0 +1,101 @@
using Microsoft.EntityFrameworkCore;
using FactoryContracts.BindingModels;
using FactoryContracts.SearchModels;
using FactoryContracts.StoragesContracts;
using FactoryContracts.ViewModels;
using FactoryDatabaseImplement.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using FactoryDatabaseImplement;
namespace PrecastConcretePlantDatabaseImplement.Implements
{
public class PlanStorage : IPlanStorage
{
public List<PlanViewModel> GetFullList()
{
using var context = new FactoryDatabase();
return context.Plans.Include(x => x.Components).ThenInclude(x => x.Component).Include(x => x.Lathes).ThenInclude(x => x.Lathe).ToList()
.Select(x => x.GetViewModel).ToList();
}
public List<PlanViewModel> GetFilteredList(PlanSearchModel model)
{
if (string.IsNullOrEmpty(model.PlanName))
{
return new();
}
using var context = new FactoryDatabase();
return context.Plans.Include(x => x.Components).ThenInclude(x => x.Component).Include(x => x.Lathes).ThenInclude(x => x.Lathe)
.Where(x => x.PlanName.Contains(model.PlanName)).ToList().Select(x => x.GetViewModel).ToList();
}
public PlanViewModel? GetElement(PlanSearchModel model)
{
if (string.IsNullOrEmpty(model.PlanName) && !model.Id.HasValue)
{
return null;
}
using var context = new FactoryDatabase();
return context.Plans.Include(x => x.Components).ThenInclude(x => x.Component).Include(x => x.Lathes).ThenInclude(x => x.Lathe)
.FirstOrDefault(x =>
(!string.IsNullOrEmpty(model.PlanName) && x.PlanName == model.PlanName) ||
(model.Id.HasValue && x.Id == model.Id))
?.GetViewModel;
}
public PlanViewModel? Insert(PlanBindingModel model)
{
using var context = new FactoryDatabase();
var newPlan = Plan.Create(context, model);
if (newPlan == null)
{
return null;
}
context.Plans.Add(newPlan);
context.SaveChanges();
return newPlan.GetViewModel;
}
public PlanViewModel? Update(PlanBindingModel model)
{
using var context = new FactoryDatabase();
using var transaction = context.Database.BeginTransaction();
try
{
var Plan = context.Plans.FirstOrDefault(rec => rec.Id == model.Id);
if (Plan == null)
{
return null;
}
Plan.Update(model);
context.SaveChanges();
Plan.UpdateComponents(context, model);
Plan.UpdateLathes(context, model);
transaction.Commit();
return Plan.GetViewModel;
}
catch
{
transaction.Rollback();
throw;
}
}
public PlanViewModel? Delete(PlanBindingModel model)
{
using var context = new FactoryDatabase();
var element = context.Plans.Include(x => x.Components).Include(x => x.Lathes).FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
context.Plans.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return null;
}
}
}

View File

@ -0,0 +1,100 @@
using Microsoft.EntityFrameworkCore;
using FactoryContracts.BindingModels;
using FactoryContracts.SearchModels;
using FactoryContracts.StoragesContracts;
using FactoryContracts.ViewModels;
using FactoryDatabaseImplement.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using FactoryDatabaseImplement;
namespace PrecastConcretePlantDatabaseImplement.Implements
{
public class ReinforcedStorage : IReinforcedStorage
{
public List<ReinforcedViewModel> GetFullList()
{
using var context = new FactoryDatabase();
return context.Reinforceds.Include(x => x.Components).ThenInclude(x => x.Component).ToList()
.Select(x => x.GetViewModel).ToList();
}
public List<ReinforcedViewModel> GetFilteredList(ReinforcedSearchModel model)
{
if (string.IsNullOrEmpty(model.ReinforcedName))
{
return new();
}
using var context = new FactoryDatabase();
return context.Reinforceds.Include(x => x.Components).ThenInclude(x => x.Component)
.Where(x => x.ReinforcedName.Contains(model.ReinforcedName)).ToList().Select(x => x.GetViewModel).ToList();
}
public ReinforcedViewModel? GetElement(ReinforcedSearchModel model)
{
if (string.IsNullOrEmpty(model.ReinforcedName) && !model.Id.HasValue)
{
return null;
}
using var context = new FactoryDatabase();
return context.Reinforceds.Include(x => x.Components).ThenInclude(x => x.Component)
.FirstOrDefault(x =>
(!string.IsNullOrEmpty(model.ReinforcedName) && x.ReinforcedName == model.ReinforcedName) ||
(model.Id.HasValue && x.Id == model.Id))
?.GetViewModel;
}
public ReinforcedViewModel? Insert(ReinforcedBindingModel model)
{
using var context = new FactoryDatabase();
var newReinforced = Reinforced.Create(context, model);
if (newReinforced == null)
{
return null;
}
context.Reinforceds.Add(newReinforced);
context.SaveChanges();
return newReinforced.GetViewModel;
}
public ReinforcedViewModel? Update(ReinforcedBindingModel model)
{
using var context = new FactoryDatabase();
using var transaction = context.Database.BeginTransaction();
try
{
var Reinforced = context.Reinforceds.FirstOrDefault(rec => rec.Id == model.Id);
if (Reinforced == null)
{
return null;
}
Reinforced.Update(model);
context.SaveChanges();
Reinforced.UpdateComponents(context, model);
transaction.Commit();
return Reinforced.GetViewModel;
}
catch
{
transaction.Rollback();
throw;
}
}
public ReinforcedViewModel? Delete(ReinforcedBindingModel model)
{
using var context = new FactoryDatabase();
var element = context.Reinforceds.Include(x => x.Components).FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
context.Reinforceds.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return null;
}
}
}

View File

@ -0,0 +1,104 @@
using FactoryContracts.BindingModels;
using FactoryContracts.SearchModels;
using FactoryContracts.StoragesContracts;
using FactoryContracts.ViewModels;
using FactoryDatabaseImplement.Models;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FactoryDatabaseImplement.Implements
{
public class StageStorage : IStageStorage
{
public List<StageViewModel> GetFullList()
{
using var context = new FactoryDatabase();
return context.Stages
.Select(x => x.GetViewModel)
.ToList();
}
public List<StageViewModel> GetFilteredList(StageSearchModel model)
{
if (model.Id is null)
{
return new();
}
using var context = new FactoryDatabase();
return context.Stages
.Where(x => x.Id.Equals(model.Id))
.Select(x => x.GetViewModel)
.ToList();
}
public StageViewModel? GetElement(StageSearchModel model)
{
if (model.Id is null)
{
return new();
}
using var context = new FactoryDatabase();
return context.Stages
.FirstOrDefault(x => x.Id.Equals(model.Id))
?.GetViewModel;
}
public StageViewModel? Insert(StageBindingModel model)
{
using var context = new FactoryDatabase();
var newStage = Stage.Create(context, model);
if (newStage == null)
{
return null;
}
context.Stages.Add(newStage);
context.SaveChanges();
return newStage.GetViewModel;
}
public StageViewModel? Update(StageBindingModel model)
{
using var context = new FactoryDatabase();
var Stage = context.Stages.FirstOrDefault(x => x.Id == model.Id);
if (Stage == null)
{
return null;
}
Stage.Update(model);
context.SaveChanges();
return Stage.GetViewModel;
}
public StageViewModel? Delete(StageBindingModel model)
{
using var context = new FactoryDatabase();
var element = context.Stages.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
context.Stages.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return null;
}
}
}

View File

@ -0,0 +1,447 @@
// <auto-generated />
using FactoryDatabaseImplement;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
#nullable disable
namespace FactoryDatabaseImplement.Migrations
{
[DbContext(typeof(FactoryDatabase))]
[Migration("20230402190902_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", 128);
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
modelBuilder.Entity("FactoryDatabaseImplement.Models.Component", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("ComponentName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<double>("Cost")
.HasColumnType("float");
b.Property<int>("EnginierId")
.HasColumnType("int");
b.HasKey("Id");
b.ToTable("Components");
});
modelBuilder.Entity("FactoryDatabaseImplement.Models.Engenier", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("Email")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Fio")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Password")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("Engeniers");
});
modelBuilder.Entity("FactoryDatabaseImplement.Models.Lathe", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("BusyId")
.HasColumnType("int");
b.Property<string>("LatheName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<int>("MasterId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("BusyId");
b.HasIndex("MasterId");
b.ToTable("Lathes");
});
modelBuilder.Entity("FactoryDatabaseImplement.Models.LatheBusy", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("Percent")
.HasColumnType("int");
b.HasKey("Id");
b.ToTable("LatheBusies");
});
modelBuilder.Entity("FactoryDatabaseImplement.Models.LatheReinforced", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("Count")
.HasColumnType("int");
b.Property<int>("LatheId")
.HasColumnType("int");
b.Property<int>("ReinforcedId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("LatheId");
b.HasIndex("ReinforcedId");
b.ToTable("LatheReinforcedes");
});
modelBuilder.Entity("FactoryDatabaseImplement.Models.Master", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("Email")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Fio")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Password")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("Masters");
});
modelBuilder.Entity("FactoryDatabaseImplement.Models.Plan", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("PlanName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("Plans");
});
modelBuilder.Entity("FactoryDatabaseImplement.Models.PlanComponents", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("ComponentId")
.HasColumnType("int");
b.Property<int>("Count")
.HasColumnType("int");
b.Property<int>("PlanId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("ComponentId");
b.HasIndex("PlanId");
b.ToTable("PlanComponents");
});
modelBuilder.Entity("FactoryDatabaseImplement.Models.PlanLathe", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("Count")
.HasColumnType("int");
b.Property<int>("LatheId")
.HasColumnType("int");
b.Property<int>("PlanId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("LatheId");
b.HasIndex("PlanId");
b.ToTable("PlanLathes");
});
modelBuilder.Entity("FactoryDatabaseImplement.Models.Reinforced", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("EngenierId")
.HasColumnType("int");
b.Property<double>("Price")
.HasColumnType("float");
b.Property<string>("ReinforcedName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.HasIndex("EngenierId");
b.ToTable("Reinforceds");
});
modelBuilder.Entity("FactoryDatabaseImplement.Models.ReinforcedComponent", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("ComponentId")
.HasColumnType("int");
b.Property<int>("Count")
.HasColumnType("int");
b.Property<int>("ReinforcedId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("ComponentId");
b.HasIndex("ReinforcedId");
b.ToTable("ReinforcedComponents");
});
modelBuilder.Entity("FactoryDatabaseImplement.Models.Stage", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("PlanId")
.HasColumnType("int");
b.Property<int>("ReinforsedId")
.HasColumnType("int");
b.HasKey("Id");
b.ToTable("Stages");
});
modelBuilder.Entity("FactoryDatabaseImplement.Models.Lathe", b =>
{
b.HasOne("FactoryDatabaseImplement.Models.LatheBusy", null)
.WithMany("Lathes")
.HasForeignKey("BusyId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("FactoryDatabaseImplement.Models.Master", null)
.WithMany("LatheId")
.HasForeignKey("MasterId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("FactoryDatabaseImplement.Models.LatheReinforced", b =>
{
b.HasOne("FactoryDatabaseImplement.Models.Lathe", "Lathe")
.WithMany("Reinforceds")
.HasForeignKey("LatheId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("FactoryDatabaseImplement.Models.Reinforced", "Reinforced")
.WithMany()
.HasForeignKey("ReinforcedId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Lathe");
b.Navigation("Reinforced");
});
modelBuilder.Entity("FactoryDatabaseImplement.Models.PlanComponents", b =>
{
b.HasOne("FactoryDatabaseImplement.Models.Component", "Component")
.WithMany()
.HasForeignKey("ComponentId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("FactoryDatabaseImplement.Models.Plan", "Plan")
.WithMany("Components")
.HasForeignKey("PlanId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Component");
b.Navigation("Plan");
});
modelBuilder.Entity("FactoryDatabaseImplement.Models.PlanLathe", b =>
{
b.HasOne("FactoryDatabaseImplement.Models.Lathe", "Lathe")
.WithMany()
.HasForeignKey("LatheId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("FactoryDatabaseImplement.Models.Plan", "Plan")
.WithMany("Lathes")
.HasForeignKey("PlanId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Lathe");
b.Navigation("Plan");
});
modelBuilder.Entity("FactoryDatabaseImplement.Models.Reinforced", b =>
{
b.HasOne("FactoryDatabaseImplement.Models.Engenier", null)
.WithMany("Reinforceds")
.HasForeignKey("EngenierId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("FactoryDatabaseImplement.Models.ReinforcedComponent", b =>
{
b.HasOne("FactoryDatabaseImplement.Models.Component", "Component")
.WithMany("ReinforcedComponents")
.HasForeignKey("ComponentId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("FactoryDatabaseImplement.Models.Reinforced", "Reinforced")
.WithMany("Components")
.HasForeignKey("ReinforcedId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Component");
b.Navigation("Reinforced");
});
modelBuilder.Entity("FactoryDatabaseImplement.Models.Component", b =>
{
b.Navigation("ReinforcedComponents");
});
modelBuilder.Entity("FactoryDatabaseImplement.Models.Engenier", b =>
{
b.Navigation("Reinforceds");
});
modelBuilder.Entity("FactoryDatabaseImplement.Models.Lathe", b =>
{
b.Navigation("Reinforceds");
});
modelBuilder.Entity("FactoryDatabaseImplement.Models.LatheBusy", b =>
{
b.Navigation("Lathes");
});
modelBuilder.Entity("FactoryDatabaseImplement.Models.Master", b =>
{
b.Navigation("LatheId");
});
modelBuilder.Entity("FactoryDatabaseImplement.Models.Plan", b =>
{
b.Navigation("Components");
b.Navigation("Lathes");
});
modelBuilder.Entity("FactoryDatabaseImplement.Models.Reinforced", b =>
{
b.Navigation("Components");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -0,0 +1,350 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace FactoryDatabaseImplement.Migrations
{
/// <inheritdoc />
public partial class initmigration : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Components",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
ComponentName = table.Column<string>(type: "nvarchar(max)", nullable: false),
Cost = table.Column<double>(type: "float", nullable: false),
EnginierId = table.Column<int>(type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Components", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Engeniers",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
Fio = table.Column<string>(type: "nvarchar(max)", nullable: false),
Email = table.Column<string>(type: "nvarchar(max)", nullable: false),
Password = table.Column<string>(type: "nvarchar(max)", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Engeniers", x => x.Id);
});
migrationBuilder.CreateTable(
name: "LatheBusies",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
Percent = table.Column<int>(type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_LatheBusies", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Masters",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
Password = table.Column<string>(type: "nvarchar(max)", nullable: false),
Fio = table.Column<string>(type: "nvarchar(max)", nullable: false),
Email = table.Column<string>(type: "nvarchar(max)", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Masters", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Plans",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
PlanName = table.Column<string>(type: "nvarchar(max)", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Plans", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Stages",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
PlanId = table.Column<int>(type: "int", nullable: false),
ReinforsedId = table.Column<int>(type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Stages", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Reinforceds",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
ReinforcedName = table.Column<string>(type: "nvarchar(max)", nullable: false),
Price = table.Column<double>(type: "float", nullable: false),
EngenierId = table.Column<int>(type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Reinforceds", x => x.Id);
table.ForeignKey(
name: "FK_Reinforceds_Engeniers_EngenierId",
column: x => x.EngenierId,
principalTable: "Engeniers",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "Lathes",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
LatheName = table.Column<string>(type: "nvarchar(max)", nullable: false),
MasterId = table.Column<int>(type: "int", nullable: false),
BusyId = table.Column<int>(type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Lathes", x => x.Id);
table.ForeignKey(
name: "FK_Lathes_LatheBusies_BusyId",
column: x => x.BusyId,
principalTable: "LatheBusies",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_Lathes_Masters_MasterId",
column: x => x.MasterId,
principalTable: "Masters",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "PlanComponents",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
PlanId = table.Column<int>(type: "int", nullable: false),
ComponentId = table.Column<int>(type: "int", nullable: false),
Count = table.Column<int>(type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_PlanComponents", x => x.Id);
table.ForeignKey(
name: "FK_PlanComponents_Components_ComponentId",
column: x => x.ComponentId,
principalTable: "Components",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_PlanComponents_Plans_PlanId",
column: x => x.PlanId,
principalTable: "Plans",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "ReinforcedComponents",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
ReinforcedId = table.Column<int>(type: "int", nullable: false),
ComponentId = table.Column<int>(type: "int", nullable: false),
Count = table.Column<int>(type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_ReinforcedComponents", x => x.Id);
table.ForeignKey(
name: "FK_ReinforcedComponents_Components_ComponentId",
column: x => x.ComponentId,
principalTable: "Components",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_ReinforcedComponents_Reinforceds_ReinforcedId",
column: x => x.ReinforcedId,
principalTable: "Reinforceds",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "LatheReinforcedes",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
LatheId = table.Column<int>(type: "int", nullable: false),
ReinforcedId = table.Column<int>(type: "int", nullable: false),
Count = table.Column<int>(type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_LatheReinforcedes", x => x.Id);
table.ForeignKey(
name: "FK_LatheReinforcedes_Lathes_LatheId",
column: x => x.LatheId,
principalTable: "Lathes",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_LatheReinforcedes_Reinforceds_ReinforcedId",
column: x => x.ReinforcedId,
principalTable: "Reinforceds",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "PlanLathes",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
PlanId = table.Column<int>(type: "int", nullable: false),
LatheId = table.Column<int>(type: "int", nullable: false),
Count = table.Column<int>(type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_PlanLathes", x => x.Id);
table.ForeignKey(
name: "FK_PlanLathes_Lathes_LatheId",
column: x => x.LatheId,
principalTable: "Lathes",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_PlanLathes_Plans_PlanId",
column: x => x.PlanId,
principalTable: "Plans",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_LatheReinforcedes_LatheId",
table: "LatheReinforcedes",
column: "LatheId");
migrationBuilder.CreateIndex(
name: "IX_LatheReinforcedes_ReinforcedId",
table: "LatheReinforcedes",
column: "ReinforcedId");
migrationBuilder.CreateIndex(
name: "IX_Lathes_BusyId",
table: "Lathes",
column: "BusyId");
migrationBuilder.CreateIndex(
name: "IX_Lathes_MasterId",
table: "Lathes",
column: "MasterId");
migrationBuilder.CreateIndex(
name: "IX_PlanComponents_ComponentId",
table: "PlanComponents",
column: "ComponentId");
migrationBuilder.CreateIndex(
name: "IX_PlanComponents_PlanId",
table: "PlanComponents",
column: "PlanId");
migrationBuilder.CreateIndex(
name: "IX_PlanLathes_LatheId",
table: "PlanLathes",
column: "LatheId");
migrationBuilder.CreateIndex(
name: "IX_PlanLathes_PlanId",
table: "PlanLathes",
column: "PlanId");
migrationBuilder.CreateIndex(
name: "IX_ReinforcedComponents_ComponentId",
table: "ReinforcedComponents",
column: "ComponentId");
migrationBuilder.CreateIndex(
name: "IX_ReinforcedComponents_ReinforcedId",
table: "ReinforcedComponents",
column: "ReinforcedId");
migrationBuilder.CreateIndex(
name: "IX_Reinforceds_EngenierId",
table: "Reinforceds",
column: "EngenierId");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "LatheReinforcedes");
migrationBuilder.DropTable(
name: "PlanComponents");
migrationBuilder.DropTable(
name: "PlanLathes");
migrationBuilder.DropTable(
name: "ReinforcedComponents");
migrationBuilder.DropTable(
name: "Stages");
migrationBuilder.DropTable(
name: "Lathes");
migrationBuilder.DropTable(
name: "Plans");
migrationBuilder.DropTable(
name: "Components");
migrationBuilder.DropTable(
name: "Reinforceds");
migrationBuilder.DropTable(
name: "LatheBusies");
migrationBuilder.DropTable(
name: "Masters");
migrationBuilder.DropTable(
name: "Engeniers");
}
}
}

View File

@ -0,0 +1,473 @@
// <auto-generated />
using System;
using FactoryDatabaseImplement;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
#nullable disable
namespace FactoryDatabaseImplement.Migrations
{
[DbContext(typeof(FactoryDatabase))]
[Migration("20230402191341_initmigration1")]
partial class initmigration1
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "7.0.4")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
modelBuilder.Entity("FactoryDatabaseImplement.Models.Component", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("ComponentName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<double>("Cost")
.HasColumnType("float");
b.Property<int>("EnginierId")
.HasColumnType("int");
b.HasKey("Id");
b.ToTable("Components");
});
modelBuilder.Entity("FactoryDatabaseImplement.Models.Engenier", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("Email")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Fio")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Password")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("Engeniers");
});
modelBuilder.Entity("FactoryDatabaseImplement.Models.Lathe", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("BusyId")
.HasColumnType("int");
b.Property<string>("LatheName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<int>("MasterId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("BusyId");
b.HasIndex("MasterId");
b.ToTable("Lathes");
});
modelBuilder.Entity("FactoryDatabaseImplement.Models.LatheBusy", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("Percent")
.HasColumnType("int");
b.HasKey("Id");
b.ToTable("LatheBusies");
});
modelBuilder.Entity("FactoryDatabaseImplement.Models.LatheReinforced", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("Count")
.HasColumnType("int");
b.Property<int>("LatheId")
.HasColumnType("int");
b.Property<int>("ReinforcedId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("LatheId");
b.HasIndex("ReinforcedId");
b.ToTable("LatheReinforcedes");
});
modelBuilder.Entity("FactoryDatabaseImplement.Models.Master", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("Email")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Fio")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Password")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("Masters");
});
modelBuilder.Entity("FactoryDatabaseImplement.Models.Plan", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int?>("ComponentId")
.HasColumnType("int");
b.Property<int?>("PlanId")
.HasColumnType("int");
b.Property<string>("PlanName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.HasIndex("ComponentId");
b.HasIndex("PlanId");
b.ToTable("Plans");
});
modelBuilder.Entity("FactoryDatabaseImplement.Models.PlanComponents", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("ComponentId")
.HasColumnType("int");
b.Property<int>("Count")
.HasColumnType("int");
b.Property<int>("PlanId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("ComponentId");
b.HasIndex("PlanId");
b.ToTable("PlanComponents");
});
modelBuilder.Entity("FactoryDatabaseImplement.Models.PlanLathe", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("Count")
.HasColumnType("int");
b.Property<int>("LatheId")
.HasColumnType("int");
b.Property<int>("PlanId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("LatheId");
b.HasIndex("PlanId");
b.ToTable("PlanLathes");
});
modelBuilder.Entity("FactoryDatabaseImplement.Models.Reinforced", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("EngenierId")
.HasColumnType("int");
b.Property<double>("Price")
.HasColumnType("float");
b.Property<string>("ReinforcedName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.HasIndex("EngenierId");
b.ToTable("Reinforceds");
});
modelBuilder.Entity("FactoryDatabaseImplement.Models.ReinforcedComponent", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("ComponentId")
.HasColumnType("int");
b.Property<int>("Count")
.HasColumnType("int");
b.Property<int>("ReinforcedId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("ComponentId");
b.HasIndex("ReinforcedId");
b.ToTable("ReinforcedComponents");
});
modelBuilder.Entity("FactoryDatabaseImplement.Models.Stage", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("PlanId")
.HasColumnType("int");
b.Property<int>("ReinforsedId")
.HasColumnType("int");
b.HasKey("Id");
b.ToTable("Stages");
});
modelBuilder.Entity("FactoryDatabaseImplement.Models.Lathe", b =>
{
b.HasOne("FactoryDatabaseImplement.Models.LatheBusy", null)
.WithMany("Lathes")
.HasForeignKey("BusyId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("FactoryDatabaseImplement.Models.Master", null)
.WithMany("LatheId")
.HasForeignKey("MasterId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("FactoryDatabaseImplement.Models.LatheReinforced", b =>
{
b.HasOne("FactoryDatabaseImplement.Models.Lathe", "Lathe")
.WithMany("Reinforceds")
.HasForeignKey("LatheId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("FactoryDatabaseImplement.Models.Reinforced", "Reinforced")
.WithMany()
.HasForeignKey("ReinforcedId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Lathe");
b.Navigation("Reinforced");
});
modelBuilder.Entity("FactoryDatabaseImplement.Models.Plan", b =>
{
b.HasOne("FactoryDatabaseImplement.Models.Component", null)
.WithMany("Plans")
.HasForeignKey("ComponentId");
b.HasOne("FactoryDatabaseImplement.Models.Plan", null)
.WithMany("Plans")
.HasForeignKey("PlanId");
});
modelBuilder.Entity("FactoryDatabaseImplement.Models.PlanComponents", b =>
{
b.HasOne("FactoryDatabaseImplement.Models.Component", "Component")
.WithMany()
.HasForeignKey("ComponentId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("FactoryDatabaseImplement.Models.Plan", "Plan")
.WithMany("Components")
.HasForeignKey("PlanId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Component");
b.Navigation("Plan");
});
modelBuilder.Entity("FactoryDatabaseImplement.Models.PlanLathe", b =>
{
b.HasOne("FactoryDatabaseImplement.Models.Lathe", "Lathe")
.WithMany()
.HasForeignKey("LatheId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("FactoryDatabaseImplement.Models.Plan", "Plan")
.WithMany("Lathes")
.HasForeignKey("PlanId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Lathe");
b.Navigation("Plan");
});
modelBuilder.Entity("FactoryDatabaseImplement.Models.Reinforced", b =>
{
b.HasOne("FactoryDatabaseImplement.Models.Engenier", null)
.WithMany("Reinforceds")
.HasForeignKey("EngenierId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("FactoryDatabaseImplement.Models.ReinforcedComponent", b =>
{
b.HasOne("FactoryDatabaseImplement.Models.Component", "Component")
.WithMany("ReinforcedComponents")
.HasForeignKey("ComponentId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("FactoryDatabaseImplement.Models.Reinforced", "Reinforced")
.WithMany("Components")
.HasForeignKey("ReinforcedId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Component");
b.Navigation("Reinforced");
});
modelBuilder.Entity("FactoryDatabaseImplement.Models.Component", b =>
{
b.Navigation("Plans");
b.Navigation("ReinforcedComponents");
});
modelBuilder.Entity("FactoryDatabaseImplement.Models.Engenier", b =>
{
b.Navigation("Reinforceds");
});
modelBuilder.Entity("FactoryDatabaseImplement.Models.Lathe", b =>
{
b.Navigation("Reinforceds");
});
modelBuilder.Entity("FactoryDatabaseImplement.Models.LatheBusy", b =>
{
b.Navigation("Lathes");
});
modelBuilder.Entity("FactoryDatabaseImplement.Models.Master", b =>
{
b.Navigation("LatheId");
});
modelBuilder.Entity("FactoryDatabaseImplement.Models.Plan", b =>
{
b.Navigation("Components");
b.Navigation("Lathes");
b.Navigation("Plans");
});
modelBuilder.Entity("FactoryDatabaseImplement.Models.Reinforced", b =>
{
b.Navigation("Components");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -0,0 +1,78 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace FactoryDatabaseImplement.Migrations
{
/// <inheritdoc />
public partial class initmigration1 : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<int>(
name: "ComponentId",
table: "Plans",
type: "int",
nullable: true);
migrationBuilder.AddColumn<int>(
name: "PlanId",
table: "Plans",
type: "int",
nullable: true);
migrationBuilder.CreateIndex(
name: "IX_Plans_ComponentId",
table: "Plans",
column: "ComponentId");
migrationBuilder.CreateIndex(
name: "IX_Plans_PlanId",
table: "Plans",
column: "PlanId");
migrationBuilder.AddForeignKey(
name: "FK_Plans_Components_ComponentId",
table: "Plans",
column: "ComponentId",
principalTable: "Components",
principalColumn: "Id");
migrationBuilder.AddForeignKey(
name: "FK_Plans_Plans_PlanId",
table: "Plans",
column: "PlanId",
principalTable: "Plans",
principalColumn: "Id");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_Plans_Components_ComponentId",
table: "Plans");
migrationBuilder.DropForeignKey(
name: "FK_Plans_Plans_PlanId",
table: "Plans");
migrationBuilder.DropIndex(
name: "IX_Plans_ComponentId",
table: "Plans");
migrationBuilder.DropIndex(
name: "IX_Plans_PlanId",
table: "Plans");
migrationBuilder.DropColumn(
name: "ComponentId",
table: "Plans");
migrationBuilder.DropColumn(
name: "PlanId",
table: "Plans");
}
}
}

View File

@ -0,0 +1,472 @@
// <auto-generated />
using System;
using FactoryDatabaseImplement;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
#nullable disable
namespace FactoryDatabaseImplement.Migrations
{
[DbContext(typeof(FactoryDatabase))]
[Migration("20230402191647_initmigration2")]
partial class initmigration2
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "7.0.4")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
modelBuilder.Entity("FactoryDatabaseImplement.Models.Component", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("ComponentName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<double>("Cost")
.HasColumnType("float");
b.Property<int>("EnginierId")
.HasColumnType("int");
b.HasKey("Id");
b.ToTable("Components");
});
modelBuilder.Entity("FactoryDatabaseImplement.Models.Engenier", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("Email")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Fio")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Password")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("Engeniers");
});
modelBuilder.Entity("FactoryDatabaseImplement.Models.Lathe", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("BusyId")
.HasColumnType("int");
b.Property<string>("LatheName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<int>("MasterId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("BusyId");
b.HasIndex("MasterId");
b.ToTable("Lathes");
});
modelBuilder.Entity("FactoryDatabaseImplement.Models.LatheBusy", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("Percent")
.HasColumnType("int");
b.HasKey("Id");
b.ToTable("LatheBusies");
});
modelBuilder.Entity("FactoryDatabaseImplement.Models.LatheReinforced", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("Count")
.HasColumnType("int");
b.Property<int>("LatheId")
.HasColumnType("int");
b.Property<int>("ReinforcedId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("LatheId");
b.HasIndex("ReinforcedId");
b.ToTable("LatheReinforcedes");
});
modelBuilder.Entity("FactoryDatabaseImplement.Models.Master", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("Email")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Fio")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Password")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("Masters");
});
modelBuilder.Entity("FactoryDatabaseImplement.Models.Plan", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("PlanName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("Plans");
});
modelBuilder.Entity("FactoryDatabaseImplement.Models.PlanComponents", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("ComponentId")
.HasColumnType("int");
b.Property<int>("Count")
.HasColumnType("int");
b.Property<int>("PlanId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("ComponentId");
b.HasIndex("PlanId");
b.ToTable("PlanComponents");
});
modelBuilder.Entity("FactoryDatabaseImplement.Models.PlanLathe", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("Count")
.HasColumnType("int");
b.Property<int>("LatheId")
.HasColumnType("int");
b.Property<int>("PlanId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("LatheId");
b.HasIndex("PlanId");
b.ToTable("PlanLathes");
});
modelBuilder.Entity("FactoryDatabaseImplement.Models.Reinforced", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("EngenierId")
.HasColumnType("int");
b.Property<double>("Price")
.HasColumnType("float");
b.Property<string>("ReinforcedName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.HasIndex("EngenierId");
b.ToTable("Reinforceds");
});
modelBuilder.Entity("FactoryDatabaseImplement.Models.ReinforcedComponent", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("ComponentId")
.HasColumnType("int");
b.Property<int>("Count")
.HasColumnType("int");
b.Property<int>("ReinforcedId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("ComponentId");
b.HasIndex("ReinforcedId");
b.ToTable("ReinforcedComponents");
});
modelBuilder.Entity("FactoryDatabaseImplement.Models.Stage", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int?>("ComponentId")
.HasColumnType("int");
b.Property<int>("PlanId")
.HasColumnType("int");
b.Property<int>("ReinforsedId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("ComponentId");
b.HasIndex("PlanId");
b.ToTable("Stages");
});
modelBuilder.Entity("FactoryDatabaseImplement.Models.Lathe", b =>
{
b.HasOne("FactoryDatabaseImplement.Models.LatheBusy", null)
.WithMany("Lathes")
.HasForeignKey("BusyId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("FactoryDatabaseImplement.Models.Master", null)
.WithMany("LatheId")
.HasForeignKey("MasterId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("FactoryDatabaseImplement.Models.LatheReinforced", b =>
{
b.HasOne("FactoryDatabaseImplement.Models.Lathe", "Lathe")
.WithMany("Reinforceds")
.HasForeignKey("LatheId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("FactoryDatabaseImplement.Models.Reinforced", "Reinforced")
.WithMany()
.HasForeignKey("ReinforcedId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Lathe");
b.Navigation("Reinforced");
});
modelBuilder.Entity("FactoryDatabaseImplement.Models.PlanComponents", b =>
{
b.HasOne("FactoryDatabaseImplement.Models.Component", "Component")
.WithMany()
.HasForeignKey("ComponentId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("FactoryDatabaseImplement.Models.Plan", "Plan")
.WithMany("Components")
.HasForeignKey("PlanId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Component");
b.Navigation("Plan");
});
modelBuilder.Entity("FactoryDatabaseImplement.Models.PlanLathe", b =>
{
b.HasOne("FactoryDatabaseImplement.Models.Lathe", "Lathe")
.WithMany()
.HasForeignKey("LatheId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("FactoryDatabaseImplement.Models.Plan", "Plan")
.WithMany("Lathes")
.HasForeignKey("PlanId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Lathe");
b.Navigation("Plan");
});
modelBuilder.Entity("FactoryDatabaseImplement.Models.Reinforced", b =>
{
b.HasOne("FactoryDatabaseImplement.Models.Engenier", null)
.WithMany("Reinforceds")
.HasForeignKey("EngenierId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("FactoryDatabaseImplement.Models.ReinforcedComponent", b =>
{
b.HasOne("FactoryDatabaseImplement.Models.Component", "Component")
.WithMany("ReinforcedComponents")
.HasForeignKey("ComponentId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("FactoryDatabaseImplement.Models.Reinforced", "Reinforced")
.WithMany("Components")
.HasForeignKey("ReinforcedId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Component");
b.Navigation("Reinforced");
});
modelBuilder.Entity("FactoryDatabaseImplement.Models.Stage", b =>
{
b.HasOne("FactoryDatabaseImplement.Models.Component", null)
.WithMany("Stages")
.HasForeignKey("ComponentId");
b.HasOne("FactoryDatabaseImplement.Models.Plan", null)
.WithMany("Stages")
.HasForeignKey("PlanId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("FactoryDatabaseImplement.Models.Component", b =>
{
b.Navigation("ReinforcedComponents");
b.Navigation("Stages");
});
modelBuilder.Entity("FactoryDatabaseImplement.Models.Engenier", b =>
{
b.Navigation("Reinforceds");
});
modelBuilder.Entity("FactoryDatabaseImplement.Models.Lathe", b =>
{
b.Navigation("Reinforceds");
});
modelBuilder.Entity("FactoryDatabaseImplement.Models.LatheBusy", b =>
{
b.Navigation("Lathes");
});
modelBuilder.Entity("FactoryDatabaseImplement.Models.Master", b =>
{
b.Navigation("LatheId");
});
modelBuilder.Entity("FactoryDatabaseImplement.Models.Plan", b =>
{
b.Navigation("Components");
b.Navigation("Lathes");
b.Navigation("Stages");
});
modelBuilder.Entity("FactoryDatabaseImplement.Models.Reinforced", b =>
{
b.Navigation("Components");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -0,0 +1,129 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace FactoryDatabaseImplement.Migrations
{
/// <inheritdoc />
public partial class initmigration2 : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_Plans_Components_ComponentId",
table: "Plans");
migrationBuilder.DropForeignKey(
name: "FK_Plans_Plans_PlanId",
table: "Plans");
migrationBuilder.DropIndex(
name: "IX_Plans_ComponentId",
table: "Plans");
migrationBuilder.DropIndex(
name: "IX_Plans_PlanId",
table: "Plans");
migrationBuilder.DropColumn(
name: "ComponentId",
table: "Plans");
migrationBuilder.DropColumn(
name: "PlanId",
table: "Plans");
migrationBuilder.AddColumn<int>(
name: "ComponentId",
table: "Stages",
type: "int",
nullable: true);
migrationBuilder.CreateIndex(
name: "IX_Stages_ComponentId",
table: "Stages",
column: "ComponentId");
migrationBuilder.CreateIndex(
name: "IX_Stages_PlanId",
table: "Stages",
column: "PlanId");
migrationBuilder.AddForeignKey(
name: "FK_Stages_Components_ComponentId",
table: "Stages",
column: "ComponentId",
principalTable: "Components",
principalColumn: "Id");
migrationBuilder.AddForeignKey(
name: "FK_Stages_Plans_PlanId",
table: "Stages",
column: "PlanId",
principalTable: "Plans",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_Stages_Components_ComponentId",
table: "Stages");
migrationBuilder.DropForeignKey(
name: "FK_Stages_Plans_PlanId",
table: "Stages");
migrationBuilder.DropIndex(
name: "IX_Stages_ComponentId",
table: "Stages");
migrationBuilder.DropIndex(
name: "IX_Stages_PlanId",
table: "Stages");
migrationBuilder.DropColumn(
name: "ComponentId",
table: "Stages");
migrationBuilder.AddColumn<int>(
name: "ComponentId",
table: "Plans",
type: "int",
nullable: true);
migrationBuilder.AddColumn<int>(
name: "PlanId",
table: "Plans",
type: "int",
nullable: true);
migrationBuilder.CreateIndex(
name: "IX_Plans_ComponentId",
table: "Plans",
column: "ComponentId");
migrationBuilder.CreateIndex(
name: "IX_Plans_PlanId",
table: "Plans",
column: "PlanId");
migrationBuilder.AddForeignKey(
name: "FK_Plans_Components_ComponentId",
table: "Plans",
column: "ComponentId",
principalTable: "Components",
principalColumn: "Id");
migrationBuilder.AddForeignKey(
name: "FK_Plans_Plans_PlanId",
table: "Plans",
column: "PlanId",
principalTable: "Plans",
principalColumn: "Id");
}
}
}

View File

@ -0,0 +1,469 @@
// <auto-generated />
using System;
using FactoryDatabaseImplement;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
#nullable disable
namespace FactoryDatabaseImplement.Migrations
{
[DbContext(typeof(FactoryDatabase))]
partial class FactoryDatabaseModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "7.0.4")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
modelBuilder.Entity("FactoryDatabaseImplement.Models.Component", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("ComponentName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<double>("Cost")
.HasColumnType("float");
b.Property<int>("EnginierId")
.HasColumnType("int");
b.HasKey("Id");
b.ToTable("Components");
});
modelBuilder.Entity("FactoryDatabaseImplement.Models.Engenier", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("Email")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Fio")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Password")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("Engeniers");
});
modelBuilder.Entity("FactoryDatabaseImplement.Models.Lathe", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("BusyId")
.HasColumnType("int");
b.Property<string>("LatheName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<int>("MasterId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("BusyId");
b.HasIndex("MasterId");
b.ToTable("Lathes");
});
modelBuilder.Entity("FactoryDatabaseImplement.Models.LatheBusy", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("Percent")
.HasColumnType("int");
b.HasKey("Id");
b.ToTable("LatheBusies");
});
modelBuilder.Entity("FactoryDatabaseImplement.Models.LatheReinforced", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("Count")
.HasColumnType("int");
b.Property<int>("LatheId")
.HasColumnType("int");
b.Property<int>("ReinforcedId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("LatheId");
b.HasIndex("ReinforcedId");
b.ToTable("LatheReinforcedes");
});
modelBuilder.Entity("FactoryDatabaseImplement.Models.Master", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("Email")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Fio")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Password")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("Masters");
});
modelBuilder.Entity("FactoryDatabaseImplement.Models.Plan", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("PlanName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("Plans");
});
modelBuilder.Entity("FactoryDatabaseImplement.Models.PlanComponents", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("ComponentId")
.HasColumnType("int");
b.Property<int>("Count")
.HasColumnType("int");
b.Property<int>("PlanId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("ComponentId");
b.HasIndex("PlanId");
b.ToTable("PlanComponents");
});
modelBuilder.Entity("FactoryDatabaseImplement.Models.PlanLathe", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("Count")
.HasColumnType("int");
b.Property<int>("LatheId")
.HasColumnType("int");
b.Property<int>("PlanId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("LatheId");
b.HasIndex("PlanId");
b.ToTable("PlanLathes");
});
modelBuilder.Entity("FactoryDatabaseImplement.Models.Reinforced", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("EngenierId")
.HasColumnType("int");
b.Property<double>("Price")
.HasColumnType("float");
b.Property<string>("ReinforcedName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.HasIndex("EngenierId");
b.ToTable("Reinforceds");
});
modelBuilder.Entity("FactoryDatabaseImplement.Models.ReinforcedComponent", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("ComponentId")
.HasColumnType("int");
b.Property<int>("Count")
.HasColumnType("int");
b.Property<int>("ReinforcedId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("ComponentId");
b.HasIndex("ReinforcedId");
b.ToTable("ReinforcedComponents");
});
modelBuilder.Entity("FactoryDatabaseImplement.Models.Stage", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int?>("ComponentId")
.HasColumnType("int");
b.Property<int>("PlanId")
.HasColumnType("int");
b.Property<int>("ReinforsedId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("ComponentId");
b.HasIndex("PlanId");
b.ToTable("Stages");
});
modelBuilder.Entity("FactoryDatabaseImplement.Models.Lathe", b =>
{
b.HasOne("FactoryDatabaseImplement.Models.LatheBusy", null)
.WithMany("Lathes")
.HasForeignKey("BusyId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("FactoryDatabaseImplement.Models.Master", null)
.WithMany("LatheId")
.HasForeignKey("MasterId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("FactoryDatabaseImplement.Models.LatheReinforced", b =>
{
b.HasOne("FactoryDatabaseImplement.Models.Lathe", "Lathe")
.WithMany("Reinforceds")
.HasForeignKey("LatheId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("FactoryDatabaseImplement.Models.Reinforced", "Reinforced")
.WithMany()
.HasForeignKey("ReinforcedId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Lathe");
b.Navigation("Reinforced");
});
modelBuilder.Entity("FactoryDatabaseImplement.Models.PlanComponents", b =>
{
b.HasOne("FactoryDatabaseImplement.Models.Component", "Component")
.WithMany()
.HasForeignKey("ComponentId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("FactoryDatabaseImplement.Models.Plan", "Plan")
.WithMany("Components")
.HasForeignKey("PlanId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Component");
b.Navigation("Plan");
});
modelBuilder.Entity("FactoryDatabaseImplement.Models.PlanLathe", b =>
{
b.HasOne("FactoryDatabaseImplement.Models.Lathe", "Lathe")
.WithMany()
.HasForeignKey("LatheId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("FactoryDatabaseImplement.Models.Plan", "Plan")
.WithMany("Lathes")
.HasForeignKey("PlanId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Lathe");
b.Navigation("Plan");
});
modelBuilder.Entity("FactoryDatabaseImplement.Models.Reinforced", b =>
{
b.HasOne("FactoryDatabaseImplement.Models.Engenier", null)
.WithMany("Reinforceds")
.HasForeignKey("EngenierId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("FactoryDatabaseImplement.Models.ReinforcedComponent", b =>
{
b.HasOne("FactoryDatabaseImplement.Models.Component", "Component")
.WithMany("ReinforcedComponents")
.HasForeignKey("ComponentId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("FactoryDatabaseImplement.Models.Reinforced", "Reinforced")
.WithMany("Components")
.HasForeignKey("ReinforcedId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Component");
b.Navigation("Reinforced");
});
modelBuilder.Entity("FactoryDatabaseImplement.Models.Stage", b =>
{
b.HasOne("FactoryDatabaseImplement.Models.Component", null)
.WithMany("Stages")
.HasForeignKey("ComponentId");
b.HasOne("FactoryDatabaseImplement.Models.Plan", null)
.WithMany("Stages")
.HasForeignKey("PlanId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("FactoryDatabaseImplement.Models.Component", b =>
{
b.Navigation("ReinforcedComponents");
b.Navigation("Stages");
});
modelBuilder.Entity("FactoryDatabaseImplement.Models.Engenier", b =>
{
b.Navigation("Reinforceds");
});
modelBuilder.Entity("FactoryDatabaseImplement.Models.Lathe", b =>
{
b.Navigation("Reinforceds");
});
modelBuilder.Entity("FactoryDatabaseImplement.Models.LatheBusy", b =>
{
b.Navigation("Lathes");
});
modelBuilder.Entity("FactoryDatabaseImplement.Models.Master", b =>
{
b.Navigation("LatheId");
});
modelBuilder.Entity("FactoryDatabaseImplement.Models.Plan", b =>
{
b.Navigation("Components");
b.Navigation("Lathes");
b.Navigation("Stages");
});
modelBuilder.Entity("FactoryDatabaseImplement.Models.Reinforced", b =>
{
b.Navigation("Components");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -0,0 +1,61 @@

using FactoryContracts.BindingModels;
using FactoryContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using FactoryDataModels.Models;
namespace FactoryDatabaseImplement.Models
{
public class Component : IComponentModel
{
public int Id { get; private set; }
[Required]
public string ComponentName { get; private set; } = string.Empty;
[Required]
public double Cost { get; set; }
[Required]
public int EnginierId { get; set; }
[ForeignKey("ComponentId")]
public virtual List<ReinforcedComponent> ReinforcedComponents { get; set; } = new();
[ForeignKey("ComponentId")]
public virtual List<Stage> Stages { get; set; } = new();
public static Component Create(ComponentBindingModel model)
{
return new Component
{
Id = model.Id,
ComponentName = model.ComponentName,
};
}
public void Update(ComponentBindingModel model)
{
if (model == null)
{
return;
}
ComponentName = model.ComponentName;
}
public ComponentViewModel GetViewModel => new()
{
Id = Id,
ComponentName = ComponentName,
};
}
}

View File

@ -0,0 +1,58 @@
using FactoryContracts.BindingModels;
using FactoryContracts.ViewModels;
using FactoryDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FactoryDatabaseImplement.Models
{
public class Engenier : IEngenierModel
{
public int Id { get; set; }
[Required]
public string Fio { get; set; } = string.Empty;
[Required]
public string Email { get; set; } = string.Empty;
[Required]
public string Password { get; set; } = string.Empty;
[ForeignKey("EngenierId")]
public virtual List<Reinforced> Reinforceds { get; set; } = new();
public EngenierViewModel GetViewModel => new()
{
Id = Id,
Fio = Fio,
Email = Email,
Password = Password
};
public static Engenier Create(EngenierBindingModel model)
{
return new Engenier()
{
Id = model.Id,
Fio = model.Fio,
Email = model.Email,
Password = model.Password
};
}
public void Update(EngenierBindingModel model)
{
Fio = model.Fio;
Email = model.Email;
Password = model.Password;
}
}
}

View File

@ -0,0 +1,92 @@
using FactoryContracts.BindingModels;
using FactoryContracts.ViewModels;
using FactoryDataModels.Models;
using Microsoft.Data.SqlClient.DataClassification;
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 FactoryDatabaseImplement.Models
{
public class Lathe : ILatheModel
{
public int Id { get; set; }
[Required]
public string LatheName { get; set; } = String.Empty;
[Required]
public int MasterId { get; set; }
[Required]
public int BusyId { get; set; }
[Required]
private Dictionary<int, (IReinforcedModel, int)>? _latheReinforcedes = null;
[NotMapped]
public Dictionary<int, (IReinforcedModel, int)> LatheReinforcedes {
get {
if (_latheReinforcedes == null)
{
_latheReinforcedes = Reinforceds.ToDictionary(recLR => recLR.ReinforcedId, recLR =>
(recLR.Reinforced as IReinforcedModel, recLR.Count));
}
return _latheReinforcedes;
}
}
[ForeignKey("LatheId")]
public virtual List<LatheReinforced> Reinforceds { get; set; } = new();
public static Lathe Create(FactoryDatabase context, LatheBindingModel model)
{
return new Lathe()
{
Id = model.Id,
LatheName = model.LatheName,
};
}
public void Update(LatheBindingModel model)
{
Id = model.Id;
LatheName = model.LatheName;
}
public LatheViewModel GetViewModel => new()
{
Id = Id,
LatheName = LatheName,
};
public void UpdateComponents(FactoryDatabase context, LatheBindingModel model)
{
var LatheReinforsed = context.LatheReinforcedes.Where(rec => rec.LatheId == model.Id).ToList();
if (LatheReinforsed != null && LatheReinforsed.Count > 0)
{
context.LatheReinforcedes.RemoveRange(LatheReinforsed.Where(rec => !model.LatheReinforcedes.ContainsKey(rec.LatheId)));
context.SaveChanges();
LatheReinforsed = context.LatheReinforcedes.Where(rec => rec.LatheId == model.Id).ToList();
foreach (var updateComponent in LatheReinforsed)
{
updateComponent.Count = model.LatheReinforcedes[updateComponent.LatheId].Item2;
model.LatheReinforcedes.Remove(updateComponent.LatheId);
}
context.SaveChanges();
}
var Lathe = context.Lathes.First(x => x.Id == Id);
foreach (var pc in model.LatheReinforcedes)
{
context.LatheReinforcedes.Add(new LatheReinforced
{
Lathe = Lathe,
Reinforced = context.Reinforceds.First(x => x.Id == pc.Key),
Count = pc.Value.Item2
});
context.SaveChanges();
}
_latheReinforcedes = null;
}
}
}

View File

@ -0,0 +1,51 @@
using FactoryContracts.BindingModels;
using FactoryContracts.ViewModels;
using FactoryDataModels.Models;
using Microsoft.Data.SqlClient.DataClassification;
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 FactoryDatabaseImplement.Models
{
public class LatheBusy : ILatheBusyModel
{
public int Id { get; set; }
[Required]
public int Percent { get; set; }
[ForeignKey("BusyId")]
public virtual List<Lathe> Lathes { get; set; } = new();
[Required]
public DateTime Date { get; set; }
public static LatheBusy Create(FactoryDatabase context, LatheBusyBindingModel model)
{
return new LatheBusy()
{
Id = model.Id,
Percent = model.Percent,
};
}
public void Update(LatheBusyBindingModel model)
{
Id = model.Id;
Id = model.Id;
Percent = model.Percent;
}
public LatheBusyViewModel GetViewModel => new()
{
Id = Id,
Percent = Percent,
};
}
}

View File

@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FactoryDatabaseImplement.Models
{
public class LatheReinforced
{
public int Id { get; set; }
[Required]
public int LatheId { get; set; }
[Required]
public int ReinforcedId { get; set; }
[Required]
public int Count { get; set; }
public virtual Lathe Lathe { get; set; } = new();
public virtual Reinforced Reinforced { get; set; } = new();
}
}

View File

@ -0,0 +1,58 @@
using FactoryContracts.BindingModels;
using FactoryContracts.ViewModels;
using FactoryDataModels.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 FactoryDatabaseImplement.Models
{
public class Master : IMasterModel
{
public int Id { get; set; }
[Required]
public string Password { get; set; } = string.Empty;
[Required]
public string Fio { get; set; } = string.Empty;
[Required]
public string Email { get; set; } = string.Empty;
[ForeignKey("MasterId")]
public virtual List<Lathe> LatheId { get; set; } = new();
public static Master Create(FactoryDatabase context, MasterBindingModel model)
{
return new Master()
{
Id = model.Id,
Fio = model.Fio,
Email = model.Email,
Password = model.Password
};
}
public void Update(MasterBindingModel model)
{
Id = model.Id;
Fio = model.Fio;
Email = model.Email;
Password = model.Password;
}
public MasterViewModel GetViewModel => new()
{
Id = Id,
Fio = Fio,
Email = Email,
Password = Password
};
}
}

View File

@ -0,0 +1,147 @@
using FactoryContracts.BindingModels;
using FactoryContracts.ViewModels;
using FactoryDataModels.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 FactoryDatabaseImplement.Models
{
public class Plan : IPlanModel
{
public int Id { get; set; }
[Required]
public string PlanName { get; set; } = String.Empty;
[Required]
public DateTime date { get; set; }
[Required]
private Dictionary<int, (ILatheModel, int)>? _planLathes { get; set; } = null;
[NotMapped]
public Dictionary<int, (ILatheModel, int)> PlanLathes
{
get
{
if (_planLathes == null)
{
_planLathes = Lathes.ToDictionary(recPL => recPL.LatheId, recPL =>
(recPL.Lathe as ILatheModel, recPL.Count));
}
return _planLathes;
}
}
[ForeignKey("PlanId")]
public virtual List<PlanLathe> Lathes { get; set; } = new();
[Required]
private Dictionary<int, (IComponentModel, int)> _planComponents { get; set; } = null;
[NotMapped]
public Dictionary<int, (IComponentModel, int)> PlanComponents
{
get
{
if (_planComponents == null)
{
_planComponents = Components.ToDictionary(recPL => recPL.ComponentId, recPL =>
(recPL.Component as IComponentModel, recPL.Count));
}
return _planComponents;
}
}
[ForeignKey("PlanId")]
public virtual List<PlanComponents> Components { get; set; } = new();
public static Plan Create(FactoryDatabase context, PlanBindingModel model)
{
return new Plan()
{
Id = model.Id,
PlanName = model.PlanName,
};
}
[ForeignKey("PlanId")]
public virtual List<Stage> Stages { get; set; } = new();
public void Update(PlanBindingModel model)
{
PlanName = model.PlanName;
}
public PlanViewModel GetViewModel => new()
{
Id = Id,
PlanName = PlanName,
};
public void UpdateLathes(FactoryDatabase context, PlanBindingModel model)
{
var PlanLathes = context.PlanLathes.Where(rec => rec.PlanId == model.Id).ToList();
if (PlanLathes != null && PlanLathes.Count > 0)
{
context.PlanLathes.RemoveRange(PlanLathes.Where(rec => !model.PlanLathes.ContainsKey(rec.LatheId)));
context.SaveChanges();
foreach (var updateComponent in PlanLathes)
{
updateComponent.Count = model.PlanLathes[updateComponent.LatheId].Item2;
model.PlanLathes.Remove(updateComponent.LatheId);
}
context.SaveChanges();
}
var Plans = context.Plans.First(x => x.Id == Id);
foreach (var pc in model.PlanLathes)
{
context.PlanLathes.Add(new PlanLathe
{
Plan = Plans,
Lathe = context.Lathes.First(x => x.Id == pc.Key),
Count = pc.Value.Item2
});
context.SaveChanges();
}
_planLathes = null;
}
public void UpdateComponents(FactoryDatabase context, PlanBindingModel model)
{
var PlanComponents = context.PlanComponents.Where(rec => rec.PlanId == model.Id).ToList();
if (PlanComponents != null && PlanComponents.Count > 0)
{
context.PlanComponents.RemoveRange(PlanComponents.Where(rec => !model.PlanComponents.ContainsKey(rec.ComponentId)));
context.SaveChanges();
PlanComponents = context.PlanComponents.Where(rec => rec.PlanId == model.Id).ToList();
foreach (var updateComponent in PlanComponents)
{
updateComponent.Count = model.PlanComponents[updateComponent.ComponentId].Item2;
model.PlanComponents.Remove(updateComponent.ComponentId);
}
context.SaveChanges();
}
var Plans = context.Plans.First(x => x.Id == Id);
foreach (var pc in model.PlanComponents)
{
context.PlanComponents.Add(new PlanComponents
{
Plan = Plans,
Component = context.Components.First(x => x.Id == pc.Key),
Count = pc.Value.Item2
});
context.SaveChanges();
}
_planComponents = null;
}
}
}

View File

@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FactoryDatabaseImplement.Models
{
public class PlanComponents
{
public int Id { get; set; }
[Required]
public int PlanId { get; set; }
[Required]
public int ComponentId { get; set; }
[Required]
public int Count { get; set; }
public virtual Component Component { get; set; } = new();
public virtual Plan Plan { get; set; } = new();
}
}

View File

@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FactoryDatabaseImplement.Models
{
public class PlanLathe
{
public int Id { get; set; }
[Required]
public int PlanId { get; set; }
[Required]
public int LatheId { get; set; }
[Required]
public int Count { get; set; }
public virtual Plan Plan { get; set; } = new();
public virtual Lathe Lathe { get; set; } = new();
}
}

View File

@ -0,0 +1,102 @@
using FactoryDataModels.Models;
using FactoryContracts.BindingModels;
using FactoryContracts.ViewModels;
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 FactoryDatabaseImplement.Models
{
public class Reinforced : IReinforcedModel
{
public int Id { get; set; }
[Required]
public string ReinforcedName { get; set; } = string.Empty;
[Required]
public double Price { get; set; }
[Required]
public int EngenierId { get; set; }
private Dictionary<int, (IComponentModel, int)>? _reinforcedComponents = null;
[NotMapped]
public Dictionary<int, (IComponentModel, int)> ReinforcedComponents
{
get
{
if (_reinforcedComponents == null)
{
_reinforcedComponents = Components
.ToDictionary(recPC => recPC.ComponentId, recPC => (recPC.Component as IComponentModel, recPC.Count));
}
return _reinforcedComponents;
}
}
[ForeignKey("ReinforcedId")]
public virtual List<ReinforcedComponent> Components { get; set; } = new();
public static Reinforced Create(FactoryDatabase context, ReinforcedBindingModel model)
{
return new Reinforced()
{
Id = model.Id,
ReinforcedName = model.ReinforcedName,
Components = model.ReinforcedComponents.Select(x => new ReinforcedComponent
{
Component = context.Components.First(y => y.Id == x.Key),
Count = x.Value.Item2
}).ToList()
};
}
public void Update(ReinforcedBindingModel model)
{
ReinforcedName = model.ReinforcedName;
}
public ReinforcedViewModel GetViewModel => new()
{
Id = Id,
ReinforcedName = ReinforcedName,
ReinforcedComponents = ReinforcedComponents
};
public void UpdateComponents(FactoryDatabase context, ReinforcedBindingModel model)
{
var ReinforcedComponents = context.ReinforcedComponents.Where(rec => rec.ReinforcedId == model.Id).ToList();
if (ReinforcedComponents != null && ReinforcedComponents.Count > 0)
{
context.ReinforcedComponents.RemoveRange(ReinforcedComponents.Where(rec => !model.ReinforcedComponents.ContainsKey(rec.ComponentId)));
context.SaveChanges();
ReinforcedComponents = context.ReinforcedComponents.Where(rec => rec.ReinforcedId == model.Id).ToList();
foreach (var updateComponent in ReinforcedComponents)
{
updateComponent.Count = model.ReinforcedComponents[updateComponent.ComponentId].Item2;
model.ReinforcedComponents.Remove(updateComponent.ComponentId);
}
context.SaveChanges();
}
var Reinforced = context.Reinforceds.First(x => x.Id == Id);
foreach (var pc in model.ReinforcedComponents)
{
context.ReinforcedComponents.Add(new ReinforcedComponent
{
Reinforced = Reinforced,
Component = context.Components.First(x => x.Id == pc.Key),
Count = pc.Value.Item2
});
context.SaveChanges();
}
_reinforcedComponents = null;
}
}
}

View File

@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FactoryDatabaseImplement.Models
{
public class ReinforcedComponent
{
public int Id { get; set; }
[Required]
public int ReinforcedId { get; set; }
[Required]
public int ComponentId { get; set; }
[Required]
public int Count { get; set; }
public virtual Component Component { get; set; } = new();
public virtual Reinforced Reinforced { get; set; } = new();
}
}

View File

@ -0,0 +1,47 @@
using FactoryContracts.BindingModels;
using FactoryContracts.ViewModels;
using FactoryDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FactoryDatabaseImplement.Models
{
public class Stage : IStageModel
{
public int Id { get; set; }
[Required]
public int PlanId { get; set; }
[Required]
public int ReinforsedId { get; set; }
public static Stage Create(FactoryDatabase context, StageBindingModel model)
{
return new Stage()
{
Id = model.Id,
ReinforsedId = model.ReinforsedId,
PlanId = model.PlanId
};
}
public void Update(StageBindingModel model)
{
ReinforsedId = model.ReinforsedId;
PlanId = model.PlanId;
}
public StageViewModel GetViewModel => new()
{
Id = Id,
ReinforsedId = ReinforsedId,
PlanId = PlanId
};
}
}

View File

@ -0,0 +1,46 @@
namespace Factory
{
partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
SuspendLayout();
//
// Form1
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(800, 450);
Name = "Form1";
Text = "Form1";
Load += Form1_Load;
ResumeLayout(false);
}
#endregion
}
}

View File

@ -0,0 +1,15 @@
namespace Factory
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
}

View File

@ -0,0 +1,60 @@
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -0,0 +1,41 @@
using Factory;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using NLog.Extensions.Logging;
using System;
namespace FactoryView
{
internal static class Program
{
private static ServiceProvider? _serviceProvider;
public static ServiceProvider? ServiceProvider => _serviceProvider;
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
// To customize application configuration such as set high DPI settings or default font;
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
var services = new ServiceCollection();
ConfigureServices(services);
_serviceProvider = services.BuildServiceProvider();
Application.Run(_serviceProvider.GetRequiredService<Form1>());
}
private static void ConfigureServices(ServiceCollection services)
{
services.AddLogging(option =>
{
option.SetMinimumLevel(LogLevel.Information);
option.AddNLog("nlog.config");
});
services.AddTransient<Form1>();
}
}
}