From 697ef996b9ad39bb0c9f2b713861d82e7f8a7a2c Mon Sep 17 00:00:00 2001 From: Zakharov_Rostislav Date: Thu, 14 Mar 2024 18:53:43 +0400 Subject: [PATCH 01/10] lab-3 --- BlacksmithWorkshop/BlacksmithWorkshop.sln | 12 +- .../BlacksmithWorkshop.csproj | 5 + .../BlacksmithWorkshop/Program.cs | 2 +- .../BlacksmithWorkshopDataBase.cs | 26 +++ ...BlacksmithWorkshopDatabaseImplement.csproj | 23 +++ .../Implements/ComponentStorage.cs | 89 +++++++++ .../Implements/ManufactureStorage.cs | 109 +++++++++++ .../Implements/OrderStorage.cs | 99 ++++++++++ .../20240313061254_InitialCreate.Designer.cs | 169 ++++++++++++++++++ .../20240313061254_InitialCreate.cs | 125 +++++++++++++ ...BlacksmithWorkshopDataBaseModelSnapshot.cs | 166 +++++++++++++++++ .../Models/Component.cs | 62 +++++++ .../Models/Manufacture.cs | 101 +++++++++++ .../Models/ManufactureComponent.cs | 22 +++ .../Models/Order.cs | 66 +++++++ 15 files changed, 1074 insertions(+), 2 deletions(-) create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/BlacksmithWorkshopDataBase.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/BlacksmithWorkshopDatabaseImplement.csproj create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Implements/ComponentStorage.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Implements/ManufactureStorage.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Implements/OrderStorage.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20240313061254_InitialCreate.Designer.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20240313061254_InitialCreate.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/BlacksmithWorkshopDataBaseModelSnapshot.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Component.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Manufacture.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/ManufactureComponent.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Order.cs diff --git a/BlacksmithWorkshop/BlacksmithWorkshop.sln b/BlacksmithWorkshop/BlacksmithWorkshop.sln index 5d4e3e7..c88f4e0 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop.sln +++ b/BlacksmithWorkshop/BlacksmithWorkshop.sln @@ -13,7 +13,13 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlacksmithWorkshopBusinessL EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlacksmithWorkshopListImplement", "BlacksmithWorkshopListImplement\BlacksmithWorkshopListImplement.csproj", "{F6B2AA66-2A89-4DEA-AE90-84991C1EE424}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BlacksmithWorkshopFileImplement", "BlackcmithWorkshopFileImplement\BlacksmithWorkshopFileImplement.csproj", "{63C0A1A4-FA76-4F7C-8144-A33085F7DF08}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlacksmithWorkshopFileImplement", "BlackcmithWorkshopFileImplement\BlacksmithWorkshopFileImplement.csproj", "{63C0A1A4-FA76-4F7C-8144-A33085F7DF08}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BlacksmithWorkshopDatabaseImplement", "BlacksmithWorkshopDatabaseImplement\BlacksmithWorkshopDatabaseImplement.csproj", "{07550D11-E516-44E1-88A4-5B21E3EE72CC}" + ProjectSection(ProjectDependencies) = postProject + {40A50297-20F6-4F73-834D-0902F6F7965B} = {40A50297-20F6-4F73-834D-0902F6F7965B} + {96E8CFC7-A9D8-438B-AE8C-184ED25D5AAC} = {96E8CFC7-A9D8-438B-AE8C-184ED25D5AAC} + EndProjectSection EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -45,6 +51,10 @@ Global {63C0A1A4-FA76-4F7C-8144-A33085F7DF08}.Debug|Any CPU.Build.0 = Debug|Any CPU {63C0A1A4-FA76-4F7C-8144-A33085F7DF08}.Release|Any CPU.ActiveCfg = Release|Any CPU {63C0A1A4-FA76-4F7C-8144-A33085F7DF08}.Release|Any CPU.Build.0 = Release|Any CPU + {07550D11-E516-44E1-88A4-5B21E3EE72CC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {07550D11-E516-44E1-88A4-5B21E3EE72CC}.Debug|Any CPU.Build.0 = Debug|Any CPU + {07550D11-E516-44E1-88A4-5B21E3EE72CC}.Release|Any CPU.ActiveCfg = Release|Any CPU + {07550D11-E516-44E1-88A4-5B21E3EE72CC}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/BlacksmithWorkshop.csproj b/BlacksmithWorkshop/BlacksmithWorkshop/BlacksmithWorkshop.csproj index 537a10a..58ec7f4 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/BlacksmithWorkshop.csproj +++ b/BlacksmithWorkshop/BlacksmithWorkshop/BlacksmithWorkshop.csproj @@ -9,12 +9,17 @@ + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/Program.cs b/BlacksmithWorkshop/BlacksmithWorkshop/Program.cs index 7769977..78a7aa8 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/Program.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/Program.cs @@ -1,7 +1,7 @@ using BlacksmithWorkshopBusinessLogic.BusinessLogics; using BlacksmithWorkshopContracts.BusinessLogicsContracts; using BlacksmithWorkshopContracts.StoragesContracts; -using BlacksmithWorkshopFileImplement.Implements; +using BlacksmithWorkshopDatabaseImplement.Implements; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using NLog.Extensions.Logging; diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/BlacksmithWorkshopDataBase.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/BlacksmithWorkshopDataBase.cs new file mode 100644 index 0000000..c7639ab --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/BlacksmithWorkshopDataBase.cs @@ -0,0 +1,26 @@ +using BlacksmithWorkshopDatabaseImplement.Models; +using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopDatabaseImplement +{ + public class BlacksmithWorkshopDataBase : DbContext + { + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) + { + if (optionsBuilder.IsConfigured == false) + { + optionsBuilder.UseSqlServer(@"Data Source=localhost\SQLEXPRESS;Initial Catalog=BlacksmithWorkshopDataBase;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); + } + base.OnConfiguring(optionsBuilder); + } + public virtual DbSet Components { set; get; } + public virtual DbSet Manufactures { set; get; } + public virtual DbSet ManufactureComponents { set; get; } + public virtual DbSet Orders { set; get; } + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/BlacksmithWorkshopDatabaseImplement.csproj b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/BlacksmithWorkshopDatabaseImplement.csproj new file mode 100644 index 0000000..1cd795d --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/BlacksmithWorkshopDatabaseImplement.csproj @@ -0,0 +1,23 @@ + + + + net6.0 + enable + enable + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Implements/ComponentStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Implements/ComponentStorage.cs new file mode 100644 index 0000000..619b9ad --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Implements/ComponentStorage.cs @@ -0,0 +1,89 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.SearchModels; +using BlacksmithWorkshopContracts.StoragesContracts; +using BlacksmithWorkshopContracts.ViewModels; +using BlacksmithWorkshopDatabaseImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopDatabaseImplement.Implements +{ + public class ComponentStorage : IComponentStorage + { + public List GetFullList() + { + using var context = new BlacksmithWorkshopDataBase(); + return context.Components + .Select(x => x.GetViewModel) + .ToList(); + } + public List GetFilteredList(ComponentSearchModel + model) + { + if (string.IsNullOrEmpty(model.ComponentName)) + { + return new(); + } + using var context = new BlacksmithWorkshopDataBase(); + 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 BlacksmithWorkshopDataBase(); + 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 BlacksmithWorkshopDataBase(); + context.Components.Add(newComponent); + context.SaveChanges(); + return newComponent.GetViewModel; + } + public ComponentViewModel? Update(ComponentBindingModel model) + { + using var context = new BlacksmithWorkshopDataBase(); + 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 BlacksmithWorkshopDataBase(); + var element = context.Components.FirstOrDefault(rec => rec.Id == + model.Id); + if (element != null) + { + context.Components.Remove(element); + context.SaveChanges(); + return element.GetViewModel; + } + return null; + } + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Implements/ManufactureStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Implements/ManufactureStorage.cs new file mode 100644 index 0000000..1cffc12 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Implements/ManufactureStorage.cs @@ -0,0 +1,109 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.SearchModels; +using BlacksmithWorkshopContracts.StoragesContracts; +using BlacksmithWorkshopContracts.ViewModels; +using BlacksmithWorkshopDatabaseImplement.Models; +using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopDatabaseImplement.Implements +{ + public class ManufactureStorage : IManufactureStorage + { + public List GetFullList() + { + using var context = new BlacksmithWorkshopDataBase(); + return context.Manufactures + .Include(x => x.Components) + .ThenInclude(x => x.Component) + .ToList() + .Select(x => x.GetViewModel) + .ToList(); + } + public List GetFilteredList(ManufactureSearchModel model) + { + if (string.IsNullOrEmpty(model.ManufactureName)) + { + return new(); + } + using var context = new BlacksmithWorkshopDataBase(); + return context.Manufactures.Include(x => x.Components) + .ThenInclude(x => x.Component) + .Where(x => x.ManufactureName.Contains(model.ManufactureName)) + .ToList() + .Select(x => x.GetViewModel) + .ToList(); + } + public ManufactureViewModel? GetElement(ManufactureSearchModel model) + { + if (string.IsNullOrEmpty(model.ManufactureName) && + !model.Id.HasValue) + { + return null; + } + using var context = new BlacksmithWorkshopDataBase(); + return context.Manufactures + .Include(x => x.Components) + .ThenInclude(x => x.Component) + .FirstOrDefault(x => (!string.IsNullOrEmpty(model.ManufactureName) && + x.ManufactureName == model.ManufactureName) || + (model.Id.HasValue && x.Id == + model.Id)) + ?.GetViewModel; + } + public ManufactureViewModel? Insert(ManufactureBindingModel model) + { + using var context = new BlacksmithWorkshopDataBase(); + var newManufacture = Manufacture.Create(context, model); + if (newManufacture == null) + { + return null; + } + context.Manufactures.Add(newManufacture); + context.SaveChanges(); + return newManufacture.GetViewModel; + } + public ManufactureViewModel? Update(ManufactureBindingModel model) + { + using var context = new BlacksmithWorkshopDataBase(); + using var transaction = context.Database.BeginTransaction(); + try + { + var manufacture = context.Manufactures.FirstOrDefault(rec => + rec.Id == model.Id); + if (manufacture == null) + { + return null; + } + manufacture.Update(model); + context.SaveChanges(); + manufacture.UpdateComponents(context, model); + transaction.Commit(); + return manufacture.GetViewModel; + } + catch + { + transaction.Rollback(); + throw; + } + } + public ManufactureViewModel? Delete(ManufactureBindingModel model) + { + using var context = new BlacksmithWorkshopDataBase(); + var element = context.Manufactures + .Include(x => x.Components) + .FirstOrDefault(rec => rec.Id == model.Id); + if (element != null) + { + context.Manufactures.Remove(element); + context.SaveChanges(); + return element.GetViewModel; + } + return null; + } + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Implements/OrderStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Implements/OrderStorage.cs new file mode 100644 index 0000000..ba47328 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Implements/OrderStorage.cs @@ -0,0 +1,99 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.SearchModels; +using BlacksmithWorkshopContracts.StoragesContracts; +using BlacksmithWorkshopContracts.ViewModels; +using BlacksmithWorkshopDatabaseImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopDatabaseImplement.Implements +{ + public class OrderStorage : IOrderStorage + { + public List GetFullList() + { + using var context = new BlacksmithWorkshopDataBase(); + return context.Orders + .Select(x => AccessManufactureStorage(x.GetViewModel)) + .ToList(); + } + public List GetFilteredList(OrderSearchModel model) + { + if (!model.Id.HasValue) + { + return new(); + } + using var context = new BlacksmithWorkshopDataBase(); + return context.Orders + .Where(x => x.Id == model.Id) + .Select(x => AccessManufactureStorage(x.GetViewModel)) + .ToList(); + } + public OrderViewModel? GetElement(OrderSearchModel model) + { + if (!model.Id.HasValue) + { + return null; + } + using var context = new BlacksmithWorkshopDataBase(); + return AccessManufactureStorage(context.Orders.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel); + } + public OrderViewModel? Insert(OrderBindingModel model) + { + var newOrder = Order.Create(model); + if (newOrder == null) + { + return null; + } + using var context = new BlacksmithWorkshopDataBase(); + context.Orders.Add(newOrder); + context.SaveChanges(); + return AccessManufactureStorage(newOrder.GetViewModel); + } + public OrderViewModel? Update(OrderBindingModel model) + { + using var context = new BlacksmithWorkshopDataBase(); + var order = context.Orders.FirstOrDefault(x => x.Id == + model.Id); + if (order == null) + { + return null; + } + order.Update(model); + context.SaveChanges(); + return AccessManufactureStorage(order.GetViewModel); + } + public OrderViewModel? Delete(OrderBindingModel model) + { + using var context = new BlacksmithWorkshopDataBase(); + var element = context.Orders.FirstOrDefault(rec => rec.Id == + model.Id); + if (element != null) + { + context.Orders.Remove(element); + context.SaveChanges(); + return AccessManufactureStorage(element.GetViewModel); + } + return null; + } + + public static OrderViewModel AccessManufactureStorage(OrderViewModel model) + { + if (model == null) + return null; + using var context = new BlacksmithWorkshopDataBase(); + foreach (var manufacture in context.Manufactures) + { + if (manufacture.Id == model.ManufactureId) + { + model.ManufactureName = manufacture.ManufactureName; + break; + } + } + return model; + } + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20240313061254_InitialCreate.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20240313061254_InitialCreate.Designer.cs new file mode 100644 index 0000000..eafb33a --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20240313061254_InitialCreate.Designer.cs @@ -0,0 +1,169 @@ +// +using System; +using BlacksmithWorkshopDatabaseImplement; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace BlacksmithWorkshopDatabaseImplement.Migrations +{ + [DbContext(typeof(BlacksmithWorkshopDataBase))] + [Migration("20240313061254_InitialCreate")] + partial class InitialCreate + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.16") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Component", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ComponentName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Cost") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.ToTable("Components"); + }); + + modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Manufacture", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ManufactureName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Price") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.ToTable("Manufactures"); + }); + + modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.ManufactureComponent", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ComponentId") + .HasColumnType("int"); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("ManufactureId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ComponentId"); + + b.HasIndex("ManufactureId"); + + b.ToTable("ManufactureComponents"); + }); + + modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Order", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("DateCreate") + .HasColumnType("datetime2"); + + b.Property("DateImplement") + .HasColumnType("datetime2"); + + b.Property("ManufactureId") + .HasColumnType("int"); + + b.Property("Status") + .HasColumnType("int"); + + b.Property("Sum") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.HasIndex("ManufactureId"); + + b.ToTable("Orders"); + }); + + modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.ManufactureComponent", b => + { + b.HasOne("BlacksmithWorkshopDatabaseImplement.Models.Component", "Component") + .WithMany("ManufactureComponents") + .HasForeignKey("ComponentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("BlacksmithWorkshopDatabaseImplement.Models.Manufacture", "Manufacture") + .WithMany("Components") + .HasForeignKey("ManufactureId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Component"); + + b.Navigation("Manufacture"); + }); + + modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Order", b => + { + b.HasOne("BlacksmithWorkshopDatabaseImplement.Models.Manufacture", null) + .WithMany("Orders") + .HasForeignKey("ManufactureId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Component", b => + { + b.Navigation("ManufactureComponents"); + }); + + modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Manufacture", b => + { + b.Navigation("Components"); + + b.Navigation("Orders"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20240313061254_InitialCreate.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20240313061254_InitialCreate.cs new file mode 100644 index 0000000..7a57164 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20240313061254_InitialCreate.cs @@ -0,0 +1,125 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace BlacksmithWorkshopDatabaseImplement.Migrations +{ + /// + public partial class InitialCreate : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Components", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ComponentName = table.Column(type: "nvarchar(max)", nullable: false), + Cost = table.Column(type: "float", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Components", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Manufactures", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ManufactureName = table.Column(type: "nvarchar(max)", nullable: false), + Price = table.Column(type: "float", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Manufactures", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "ManufactureComponents", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ManufactureId = table.Column(type: "int", nullable: false), + ComponentId = table.Column(type: "int", nullable: false), + Count = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_ManufactureComponents", x => x.Id); + table.ForeignKey( + name: "FK_ManufactureComponents_Components_ComponentId", + column: x => x.ComponentId, + principalTable: "Components", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_ManufactureComponents_Manufactures_ManufactureId", + column: x => x.ManufactureId, + principalTable: "Manufactures", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "Orders", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + Count = table.Column(type: "int", nullable: false), + Sum = table.Column(type: "float", nullable: false), + Status = table.Column(type: "int", nullable: false), + DateCreate = table.Column(type: "datetime2", nullable: false), + DateImplement = table.Column(type: "datetime2", nullable: true), + ManufactureId = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Orders", x => x.Id); + table.ForeignKey( + name: "FK_Orders_Manufactures_ManufactureId", + column: x => x.ManufactureId, + principalTable: "Manufactures", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_ManufactureComponents_ComponentId", + table: "ManufactureComponents", + column: "ComponentId"); + + migrationBuilder.CreateIndex( + name: "IX_ManufactureComponents_ManufactureId", + table: "ManufactureComponents", + column: "ManufactureId"); + + migrationBuilder.CreateIndex( + name: "IX_Orders_ManufactureId", + table: "Orders", + column: "ManufactureId"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "ManufactureComponents"); + + migrationBuilder.DropTable( + name: "Orders"); + + migrationBuilder.DropTable( + name: "Components"); + + migrationBuilder.DropTable( + name: "Manufactures"); + } + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/BlacksmithWorkshopDataBaseModelSnapshot.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/BlacksmithWorkshopDataBaseModelSnapshot.cs new file mode 100644 index 0000000..ca4928d --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/BlacksmithWorkshopDataBaseModelSnapshot.cs @@ -0,0 +1,166 @@ +// +using System; +using BlacksmithWorkshopDatabaseImplement; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace BlacksmithWorkshopDatabaseImplement.Migrations +{ + [DbContext(typeof(BlacksmithWorkshopDataBase))] + partial class BlacksmithWorkshopDataBaseModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.16") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Component", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ComponentName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Cost") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.ToTable("Components"); + }); + + modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Manufacture", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ManufactureName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Price") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.ToTable("Manufactures"); + }); + + modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.ManufactureComponent", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ComponentId") + .HasColumnType("int"); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("ManufactureId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ComponentId"); + + b.HasIndex("ManufactureId"); + + b.ToTable("ManufactureComponents"); + }); + + modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Order", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("DateCreate") + .HasColumnType("datetime2"); + + b.Property("DateImplement") + .HasColumnType("datetime2"); + + b.Property("ManufactureId") + .HasColumnType("int"); + + b.Property("Status") + .HasColumnType("int"); + + b.Property("Sum") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.HasIndex("ManufactureId"); + + b.ToTable("Orders"); + }); + + modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.ManufactureComponent", b => + { + b.HasOne("BlacksmithWorkshopDatabaseImplement.Models.Component", "Component") + .WithMany("ManufactureComponents") + .HasForeignKey("ComponentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("BlacksmithWorkshopDatabaseImplement.Models.Manufacture", "Manufacture") + .WithMany("Components") + .HasForeignKey("ManufactureId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Component"); + + b.Navigation("Manufacture"); + }); + + modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Order", b => + { + b.HasOne("BlacksmithWorkshopDatabaseImplement.Models.Manufacture", null) + .WithMany("Orders") + .HasForeignKey("ManufactureId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Component", b => + { + b.Navigation("ManufactureComponents"); + }); + + modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Manufacture", b => + { + b.Navigation("Components"); + + b.Navigation("Orders"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Component.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Component.cs new file mode 100644 index 0000000..cbb7bd8 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Component.cs @@ -0,0 +1,62 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.ViewModels; +using BlacksmithWorkshopDataModels.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 BlacksmithWorkshopDatabaseImplement.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; } + [ForeignKey("ComponentId")] + public virtual List ManufactureComponents { get; set; } = + new(); + public static Component? Create(ComponentBindingModel model) + { + if (model == null) + { + return null; + } + return new Component() + { + Id = model.Id, + ComponentName = model.ComponentName, + Cost = model.Cost + }; + } + public static Component Create(ComponentViewModel model) + { + return new Component + { + Id = model.Id, + ComponentName = model.ComponentName, + Cost = model.Cost + }; + } + public void Update(ComponentBindingModel model) + { + if (model == null) + { + return; + } + ComponentName = model.ComponentName; + Cost = model.Cost; + } + public ComponentViewModel GetViewModel => new() + { + Id = Id, + ComponentName = ComponentName, + Cost = Cost + }; + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Manufacture.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Manufacture.cs new file mode 100644 index 0000000..24f00be --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Manufacture.cs @@ -0,0 +1,101 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.ViewModels; +using BlacksmithWorkshopDataModels.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 BlacksmithWorkshopDatabaseImplement.Models +{ + public class Manufacture : IManufactureModel + { + public int Id { get; set; } + [Required] + public string ManufactureName { get; set; } = string.Empty; + [Required] + public double Price { get; set; } + private Dictionary? _manufactureComponents = + null; + [NotMapped] + public Dictionary ManufactureComponents + { + get + { + if (_manufactureComponents == null) + { + _manufactureComponents = Components + .ToDictionary(recPC => recPC.ComponentId, recPC => + (recPC.Component as IComponentModel, recPC.Count)); + } + return _manufactureComponents; + } + } + [ForeignKey("ManufactureId")] + public virtual List Components { get; set; } = new(); + [ForeignKey("ManufactureId")] + public virtual List Orders { get; set; } = new(); + public static Manufacture Create(BlacksmithWorkshopDataBase context, + ManufactureBindingModel model) + { + return new Manufacture() + { + Id = model.Id, + ManufactureName = model.ManufactureName, + Price = model.Price, + Components = model.ManufactureComponents.Select(x => new + ManufactureComponent + { + Component = context.Components.First(y => y.Id == x.Key), + Count = x.Value.Item2 + }).ToList() + }; + } + public void Update(ManufactureBindingModel model) + { + ManufactureName = model.ManufactureName; + Price = model.Price; + } + public ManufactureViewModel GetViewModel => new() + { + Id = Id, + ManufactureName = ManufactureName, + Price = Price, + ManufactureComponents = ManufactureComponents + }; + public void UpdateComponents(BlacksmithWorkshopDataBase context, + ManufactureBindingModel model) + { + var manufactureComponents = context.ManufactureComponents.Where(rec => + rec.ManufactureId == model.Id).ToList(); + if (manufactureComponents != null && ManufactureComponents.Count > 0) + { + context.ManufactureComponents.RemoveRange(manufactureComponents.Where(rec + => !model.ManufactureComponents.ContainsKey(rec.ComponentId))); + context.SaveChanges(); + foreach (var updateComponent in manufactureComponents) + { + updateComponent.Count = + model.ManufactureComponents[updateComponent.ComponentId].Item2; + model.ManufactureComponents.Remove(updateComponent.ComponentId); + } + context.SaveChanges(); + } + var manufacture = context.Manufactures.First(x => x.Id == Id); + foreach (var pc in model.ManufactureComponents) + { + context.ManufactureComponents.Add(new ManufactureComponent + { + Manufacture = manufacture, + Component = context.Components.First(x => x.Id == pc.Key), + Count = pc.Value.Item2 + }); + context.SaveChanges(); + } + _manufactureComponents = null; + } + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/ManufactureComponent.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/ManufactureComponent.cs new file mode 100644 index 0000000..7fd8ef1 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/ManufactureComponent.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopDatabaseImplement.Models +{ + public class ManufactureComponent + { + public int Id { get; set; } + [Required] + public int ManufactureId { get; set; } + [Required] + public int ComponentId { get; set; } + [Required] + public int Count { get; set; } + public virtual Component Component { get; set; } = new(); + public virtual Manufacture Manufacture { get; set; } = new(); + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Order.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Order.cs new file mode 100644 index 0000000..0e51989 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Order.cs @@ -0,0 +1,66 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.ViewModels; +using BlacksmithWorkshopDataModels.Enums; +using BlacksmithWorkshopDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopDatabaseImplement.Models +{ + public class Order : IOrderModel + { + public int Id { get; private set; } + [Required] + public int Count { get; private set; } + [Required] + public double Sum { get; private set; } + [Required] + public OrderStatus Status { get; private set; } + [Required] + public DateTime DateCreate { get; private set; } + public DateTime? DateImplement { get; private set; } + [Required] + public int ManufactureId { get; private set; } + + public static Order? Create(OrderBindingModel model) + { + if (model == null) + { + return null; + } + return new Order() + { + Id = model.Id, + Count = model.Count, + Sum = model.Sum, + Status = model.Status, + DateCreate = model.DateCreate, + DateImplement = model.DateImplement, + ManufactureId = model.ManufactureId, + }; + } + public void Update(OrderBindingModel? model) + { + if (model == null) + { + return; + } + Status = model.Status; + DateImplement = model.DateImplement; + } + public OrderViewModel GetViewModel => new() + { + ManufactureId = ManufactureId, + Count = Count, + Sum = Sum, + Status = Status, + DateCreate = DateCreate, + DateImplement = DateImplement, + Id = Id, + }; + } +} -- 2.25.1 From 7c0f517716855290a811876d1e6855aaec758209 Mon Sep 17 00:00:00 2001 From: Zakharov_Rostislav Date: Sun, 24 Mar 2024 20:26:32 +0400 Subject: [PATCH 02/10] lab3 correcting some mistakes --- .../Implements/OrderStorage.cs | 28 ++++--------------- .../Models/Order.cs | 9 +++--- 2 files changed, 10 insertions(+), 27 deletions(-) diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Implements/OrderStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Implements/OrderStorage.cs index ba47328..2d8105c 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Implements/OrderStorage.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Implements/OrderStorage.cs @@ -17,7 +17,7 @@ namespace BlacksmithWorkshopDatabaseImplement.Implements { using var context = new BlacksmithWorkshopDataBase(); return context.Orders - .Select(x => AccessManufactureStorage(x.GetViewModel)) + .Select(x => x.GetViewModel) .ToList(); } public List GetFilteredList(OrderSearchModel model) @@ -29,7 +29,7 @@ namespace BlacksmithWorkshopDatabaseImplement.Implements using var context = new BlacksmithWorkshopDataBase(); return context.Orders .Where(x => x.Id == model.Id) - .Select(x => AccessManufactureStorage(x.GetViewModel)) + .Select(x => x.GetViewModel) .ToList(); } public OrderViewModel? GetElement(OrderSearchModel model) @@ -39,7 +39,7 @@ namespace BlacksmithWorkshopDatabaseImplement.Implements return null; } using var context = new BlacksmithWorkshopDataBase(); - return AccessManufactureStorage(context.Orders.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel); + return context.Orders.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel; } public OrderViewModel? Insert(OrderBindingModel model) { @@ -51,7 +51,7 @@ namespace BlacksmithWorkshopDatabaseImplement.Implements using var context = new BlacksmithWorkshopDataBase(); context.Orders.Add(newOrder); context.SaveChanges(); - return AccessManufactureStorage(newOrder.GetViewModel); + return newOrder.GetViewModel; } public OrderViewModel? Update(OrderBindingModel model) { @@ -64,7 +64,7 @@ namespace BlacksmithWorkshopDatabaseImplement.Implements } order.Update(model); context.SaveChanges(); - return AccessManufactureStorage(order.GetViewModel); + return order.GetViewModel; } public OrderViewModel? Delete(OrderBindingModel model) { @@ -75,25 +75,9 @@ namespace BlacksmithWorkshopDatabaseImplement.Implements { context.Orders.Remove(element); context.SaveChanges(); - return AccessManufactureStorage(element.GetViewModel); + return element.GetViewModel; } return null; } - - public static OrderViewModel AccessManufactureStorage(OrderViewModel model) - { - if (model == null) - return null; - using var context = new BlacksmithWorkshopDataBase(); - foreach (var manufacture in context.Manufactures) - { - if (manufacture.Id == model.ManufactureId) - { - model.ManufactureName = manufacture.ManufactureName; - break; - } - } - return model; - } } } diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Order.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Order.cs index 0e51989..bfa8c1e 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Order.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Order.cs @@ -25,13 +25,10 @@ namespace BlacksmithWorkshopDatabaseImplement.Models public DateTime? DateImplement { get; private set; } [Required] public int ManufactureId { get; private set; } + public virtual Manufacture Manufacture { get; set; } = new(); - public static Order? Create(OrderBindingModel model) + public static Order? Create(BlacksmithWorkshopDataBase context, OrderBindingModel model) { - if (model == null) - { - return null; - } return new Order() { Id = model.Id, @@ -41,6 +38,7 @@ namespace BlacksmithWorkshopDatabaseImplement.Models DateCreate = model.DateCreate, DateImplement = model.DateImplement, ManufactureId = model.ManufactureId, + Manufacture = context.Manufactures.First(y => y.Id == model.ManufactureId) }; } public void Update(OrderBindingModel? model) @@ -55,6 +53,7 @@ namespace BlacksmithWorkshopDatabaseImplement.Models public OrderViewModel GetViewModel => new() { ManufactureId = ManufactureId, + ManufactureName = Manufacture.ManufactureName, Count = Count, Sum = Sum, Status = Status, -- 2.25.1 From be9e85574b24aba296c691048a528c2fbcd93818 Mon Sep 17 00:00:00 2001 From: Zakharov_Rostislav Date: Sun, 24 Mar 2024 20:29:10 +0400 Subject: [PATCH 03/10] lab3 correcting is going on --- .../Implements/OrderStorage.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Implements/OrderStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Implements/OrderStorage.cs index 2d8105c..d2383c0 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Implements/OrderStorage.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Implements/OrderStorage.cs @@ -43,12 +43,12 @@ namespace BlacksmithWorkshopDatabaseImplement.Implements } public OrderViewModel? Insert(OrderBindingModel model) { - var newOrder = Order.Create(model); + using var context = new BlacksmithWorkshopDataBase(); + var newOrder = Order.Create(context, model); if (newOrder == null) { return null; } - using var context = new BlacksmithWorkshopDataBase(); context.Orders.Add(newOrder); context.SaveChanges(); return newOrder.GetViewModel; -- 2.25.1 From ad9bc8e6bc1d23be599ca4c03cac3a978be98dc6 Mon Sep 17 00:00:00 2001 From: Zakharov_Rostislav Date: Sun, 24 Mar 2024 21:24:03 +0400 Subject: [PATCH 04/10] lab3 corricting finished --- .../Implements/ComponentStorage.cs | 20 ++++++------- .../Implements/ManufactureStorage.cs | 30 +++++++++---------- .../Implements/OrderStorage.cs | 14 +++++---- ... 20240324164611_InitialCreate.Designer.cs} | 6 ++-- ...ate.cs => 20240324164611_InitialCreate.cs} | 0 ...BlacksmithWorkshopDataBaseModelSnapshot.cs | 4 ++- .../Models/Order.cs | 3 +- 7 files changed, 41 insertions(+), 36 deletions(-) rename BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/{20240313061254_InitialCreate.Designer.cs => 20240324164611_InitialCreate.Designer.cs} (97%) rename BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/{20240313061254_InitialCreate.cs => 20240324164611_InitialCreate.cs} (100%) diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Implements/ComponentStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Implements/ComponentStorage.cs index 619b9ad..41c1342 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Implements/ComponentStorage.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Implements/ComponentStorage.cs @@ -17,8 +17,8 @@ namespace BlacksmithWorkshopDatabaseImplement.Implements { using var context = new BlacksmithWorkshopDataBase(); return context.Components - .Select(x => x.GetViewModel) - .ToList(); + .Select(x => x.GetViewModel) + .ToList(); } public List GetFilteredList(ComponentSearchModel model) @@ -29,9 +29,9 @@ namespace BlacksmithWorkshopDatabaseImplement.Implements } using var context = new BlacksmithWorkshopDataBase(); return context.Components - .Where(x => x.ComponentName.Contains(model.ComponentName)) - .Select(x => x.GetViewModel) - .ToList(); + .Where(x => x.ComponentName.Contains(model.ComponentName)) + .Select(x => x.GetViewModel) + .ToList(); } public ComponentViewModel? GetElement(ComponentSearchModel model) { @@ -41,11 +41,11 @@ namespace BlacksmithWorkshopDatabaseImplement.Implements } using var context = new BlacksmithWorkshopDataBase(); return context.Components - .FirstOrDefault(x => - (!string.IsNullOrEmpty(model.ComponentName) && x.ComponentName == - model.ComponentName) || - (model.Id.HasValue && x.Id == model.Id)) - ?.GetViewModel; + .FirstOrDefault(x => + (!string.IsNullOrEmpty(model.ComponentName) && x.ComponentName == + model.ComponentName) || + (model.Id.HasValue && x.Id == model.Id)) + ?.GetViewModel; } public ComponentViewModel? Insert(ComponentBindingModel model) { diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Implements/ManufactureStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Implements/ManufactureStorage.cs index 1cffc12..4bd25fa 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Implements/ManufactureStorage.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Implements/ManufactureStorage.cs @@ -18,11 +18,11 @@ namespace BlacksmithWorkshopDatabaseImplement.Implements { using var context = new BlacksmithWorkshopDataBase(); return context.Manufactures - .Include(x => x.Components) - .ThenInclude(x => x.Component) - .ToList() - .Select(x => x.GetViewModel) - .ToList(); + .Include(x => x.Components) + .ThenInclude(x => x.Component) + .ToList() + .Select(x => x.GetViewModel) + .ToList(); } public List GetFilteredList(ManufactureSearchModel model) { @@ -32,11 +32,11 @@ namespace BlacksmithWorkshopDatabaseImplement.Implements } using var context = new BlacksmithWorkshopDataBase(); return context.Manufactures.Include(x => x.Components) - .ThenInclude(x => x.Component) - .Where(x => x.ManufactureName.Contains(model.ManufactureName)) - .ToList() - .Select(x => x.GetViewModel) - .ToList(); + .ThenInclude(x => x.Component) + .Where(x => x.ManufactureName.Contains(model.ManufactureName)) + .ToList() + .Select(x => x.GetViewModel) + .ToList(); } public ManufactureViewModel? GetElement(ManufactureSearchModel model) { @@ -47,9 +47,9 @@ namespace BlacksmithWorkshopDatabaseImplement.Implements } using var context = new BlacksmithWorkshopDataBase(); return context.Manufactures - .Include(x => x.Components) - .ThenInclude(x => x.Component) - .FirstOrDefault(x => (!string.IsNullOrEmpty(model.ManufactureName) && + .Include(x => x.Components) + .ThenInclude(x => x.Component) + .FirstOrDefault(x => (!string.IsNullOrEmpty(model.ManufactureName) && x.ManufactureName == model.ManufactureName) || (model.Id.HasValue && x.Id == model.Id)) @@ -95,8 +95,8 @@ namespace BlacksmithWorkshopDatabaseImplement.Implements { using var context = new BlacksmithWorkshopDataBase(); var element = context.Manufactures - .Include(x => x.Components) - .FirstOrDefault(rec => rec.Id == model.Id); + .Include(x => x.Components) + .FirstOrDefault(rec => rec.Id == model.Id); if (element != null) { context.Manufactures.Remove(element); diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Implements/OrderStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Implements/OrderStorage.cs index d2383c0..f489a4e 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Implements/OrderStorage.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Implements/OrderStorage.cs @@ -3,6 +3,7 @@ using BlacksmithWorkshopContracts.SearchModels; using BlacksmithWorkshopContracts.StoragesContracts; using BlacksmithWorkshopContracts.ViewModels; using BlacksmithWorkshopDatabaseImplement.Models; +using Microsoft.EntityFrameworkCore; using System; using System.Collections.Generic; using System.Linq; @@ -17,8 +18,9 @@ namespace BlacksmithWorkshopDatabaseImplement.Implements { using var context = new BlacksmithWorkshopDataBase(); return context.Orders - .Select(x => x.GetViewModel) - .ToList(); + .Include(x => x.Manufacture) + .Select(x => x.GetViewModel) + .ToList(); } public List GetFilteredList(OrderSearchModel model) { @@ -28,9 +30,9 @@ namespace BlacksmithWorkshopDatabaseImplement.Implements } using var context = new BlacksmithWorkshopDataBase(); return context.Orders - .Where(x => x.Id == model.Id) - .Select(x => x.GetViewModel) - .ToList(); + .Where(x => x.Id == model.Id) + .Select(x => x.GetViewModel) + .ToList(); } public OrderViewModel? GetElement(OrderSearchModel model) { @@ -44,7 +46,7 @@ namespace BlacksmithWorkshopDatabaseImplement.Implements public OrderViewModel? Insert(OrderBindingModel model) { using var context = new BlacksmithWorkshopDataBase(); - var newOrder = Order.Create(context, model); + var newOrder = Order.Create(model); if (newOrder == null) { return null; diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20240313061254_InitialCreate.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20240324164611_InitialCreate.Designer.cs similarity index 97% rename from BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20240313061254_InitialCreate.Designer.cs rename to BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20240324164611_InitialCreate.Designer.cs index eafb33a..1629012 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20240313061254_InitialCreate.Designer.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20240324164611_InitialCreate.Designer.cs @@ -12,7 +12,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion; namespace BlacksmithWorkshopDatabaseImplement.Migrations { [DbContext(typeof(BlacksmithWorkshopDataBase))] - [Migration("20240313061254_InitialCreate")] + [Migration("20240324164611_InitialCreate")] partial class InitialCreate { /// @@ -145,11 +145,13 @@ namespace BlacksmithWorkshopDatabaseImplement.Migrations modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Order", b => { - b.HasOne("BlacksmithWorkshopDatabaseImplement.Models.Manufacture", null) + b.HasOne("BlacksmithWorkshopDatabaseImplement.Models.Manufacture", "Manufacture") .WithMany("Orders") .HasForeignKey("ManufactureId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); + + b.Navigation("Manufacture"); }); modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Component", b => diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20240313061254_InitialCreate.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20240324164611_InitialCreate.cs similarity index 100% rename from BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20240313061254_InitialCreate.cs rename to BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20240324164611_InitialCreate.cs diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/BlacksmithWorkshopDataBaseModelSnapshot.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/BlacksmithWorkshopDataBaseModelSnapshot.cs index ca4928d..e3ce109 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/BlacksmithWorkshopDataBaseModelSnapshot.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/BlacksmithWorkshopDataBaseModelSnapshot.cs @@ -142,11 +142,13 @@ namespace BlacksmithWorkshopDatabaseImplement.Migrations modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Order", b => { - b.HasOne("BlacksmithWorkshopDatabaseImplement.Models.Manufacture", null) + b.HasOne("BlacksmithWorkshopDatabaseImplement.Models.Manufacture", "Manufacture") .WithMany("Orders") .HasForeignKey("ManufactureId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); + + b.Navigation("Manufacture"); }); modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Component", b => diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Order.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Order.cs index bfa8c1e..8a5b48d 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Order.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Order.cs @@ -27,7 +27,7 @@ namespace BlacksmithWorkshopDatabaseImplement.Models public int ManufactureId { get; private set; } public virtual Manufacture Manufacture { get; set; } = new(); - public static Order? Create(BlacksmithWorkshopDataBase context, OrderBindingModel model) + public static Order? Create(OrderBindingModel model) { return new Order() { @@ -38,7 +38,6 @@ namespace BlacksmithWorkshopDatabaseImplement.Models DateCreate = model.DateCreate, DateImplement = model.DateImplement, ManufactureId = model.ManufactureId, - Manufacture = context.Manufactures.First(y => y.Id == model.ManufactureId) }; } public void Update(OrderBindingModel? model) -- 2.25.1 From 67ac969279fdaf07da820482aa39942f01a9b9c0 Mon Sep 17 00:00:00 2001 From: Zakharov_Rostislav Date: Mon, 25 Mar 2024 20:58:39 +0400 Subject: [PATCH 05/10] lab-3-hard in process --- .../BlacksmithWorkshopDataBase.cs | 4 +- .../Implements/OrderStorage.cs | 15 +- .../Implements/ShopStorage.cs | 153 ++++++++++++++++++ ... 20240325164926_InitialCreate.Designer.cs} | 81 +++++++++- ...ate.cs => 20240325164926_InitialCreate.cs} | 59 +++++++ ...BlacksmithWorkshopDataBaseModelSnapshot.cs | 79 +++++++++ .../Models/Manufacture.cs | 3 + .../Models/Shop.cs | 115 +++++++++++++ .../Models/ShopManufacture.cs | 22 +++ 9 files changed, 524 insertions(+), 7 deletions(-) create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Implements/ShopStorage.cs rename BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/{20240324164611_InitialCreate.Designer.cs => 20240325164926_InitialCreate.Designer.cs} (67%) rename BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/{20240324164611_InitialCreate.cs => 20240325164926_InitialCreate.cs} (66%) create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Shop.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/ShopManufacture.cs diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/BlacksmithWorkshopDataBase.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/BlacksmithWorkshopDataBase.cs index c7639ab..df1a0c7 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/BlacksmithWorkshopDataBase.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/BlacksmithWorkshopDataBase.cs @@ -14,7 +14,7 @@ namespace BlacksmithWorkshopDatabaseImplement { if (optionsBuilder.IsConfigured == false) { - optionsBuilder.UseSqlServer(@"Data Source=localhost\SQLEXPRESS;Initial Catalog=BlacksmithWorkshopDataBase;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); + optionsBuilder.UseSqlServer(@"Data Source=localhost\SQLEXPRESS;Initial Catalog=BlacksmithWorkshopDataBaseHard;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); } base.OnConfiguring(optionsBuilder); } @@ -22,5 +22,7 @@ namespace BlacksmithWorkshopDatabaseImplement public virtual DbSet Manufactures { set; get; } public virtual DbSet ManufactureComponents { set; get; } public virtual DbSet Orders { set; get; } + public virtual DbSet Shops { set; get; } + public virtual DbSet ShopManufactures { set; get; } } } diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Implements/OrderStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Implements/OrderStorage.cs index f489a4e..99c81c5 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Implements/OrderStorage.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Implements/OrderStorage.cs @@ -30,6 +30,7 @@ namespace BlacksmithWorkshopDatabaseImplement.Implements } using var context = new BlacksmithWorkshopDataBase(); return context.Orders + .Include(x => x.Manufacture) .Where(x => x.Id == model.Id) .Select(x => x.GetViewModel) .ToList(); @@ -41,7 +42,9 @@ namespace BlacksmithWorkshopDatabaseImplement.Implements return null; } using var context = new BlacksmithWorkshopDataBase(); - return context.Orders.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel; + return context.Orders + .Include(x => x.Manufacture) + .FirstOrDefault(x => x.Id == model.Id)?.GetViewModel; } public OrderViewModel? Insert(OrderBindingModel model) { @@ -58,8 +61,9 @@ namespace BlacksmithWorkshopDatabaseImplement.Implements public OrderViewModel? Update(OrderBindingModel model) { using var context = new BlacksmithWorkshopDataBase(); - var order = context.Orders.FirstOrDefault(x => x.Id == - model.Id); + var order = context.Orders + .Include(x => x.Manufacture) + .FirstOrDefault(x => x.Id == model.Id); if (order == null) { return null; @@ -71,8 +75,9 @@ namespace BlacksmithWorkshopDatabaseImplement.Implements public OrderViewModel? Delete(OrderBindingModel model) { using var context = new BlacksmithWorkshopDataBase(); - var element = context.Orders.FirstOrDefault(rec => rec.Id == - model.Id); + var element = context.Orders + .Include(x => x.Manufacture) + .FirstOrDefault(rec => rec.Id == model.Id); if (element != null) { context.Orders.Remove(element); diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Implements/ShopStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Implements/ShopStorage.cs new file mode 100644 index 0000000..9c5bf2f --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Implements/ShopStorage.cs @@ -0,0 +1,153 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.SearchModels; +using BlacksmithWorkshopContracts.StoragesContracts; +using BlacksmithWorkshopContracts.ViewModels; +using BlacksmithWorkshopDatabaseImplement.Models; +using BlacksmithWorkshopDataModels.Models; +using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopDatabaseImplement.Implements +{ + public class ShopStorage : IShopStorage + { + public ShopViewModel? Delete(ShopBindingModel model) + { + using var context = new BlacksmithWorkshopDataBase(); + var element = context.Shops.FirstOrDefault(x => x.Id == model.Id); + if (element != null) + { + context.Shops.Remove(element); + context.SaveChanges(); + return element.GetViewModel; + } + return null; + } + + public ShopViewModel? GetElement(ShopSearchModel model) + { + if (string.IsNullOrEmpty(model.ShopName) && !model.Id.HasValue) + { + return null; + } + using var context = new BlacksmithWorkshopDataBase(); + return context.Shops + .Include(x => x.Manufactures) + .ThenInclude(x => x.Manufacture) + .FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id) + ?.GetViewModel; + } + + public List GetFilteredList(ShopSearchModel model) + { + if (string.IsNullOrEmpty(model.ShopName)) + { + return new(); + } + using var context = new BlacksmithWorkshopDataBase(); + return context.Shops + .Include(x => x.Manufactures) + .ThenInclude(x => x.Manufacture) + .Select(x => x.GetViewModel) + .Where(x => x.ShopName.Contains(model.ShopName ?? string.Empty)) + .ToList(); + } + + public List GetFullList() + { + using var context = new BlacksmithWorkshopDataBase(); + return context.Shops + .Include(x => x.Manufactures) + .ThenInclude(x => x.Manufacture) + .Select(x => x.GetViewModel) + .ToList(); + } + + public ShopViewModel? Insert(ShopBindingModel model) + { + using var context = new BlacksmithWorkshopDataBase(); + try + { + var newShop = Shop.Create(context, model); + if (newShop == null) + { + return null; + } + if (context.Shops.Any(x => x.ShopName == newShop.ShopName)) + { + throw new Exception("Не должно быть два магазина с одним названием"); + } + context.Shops.Add(newShop); + context.SaveChanges(); + return newShop.GetViewModel; + } + catch + { + throw; + } + } + + public ShopViewModel? Update(ShopBindingModel model) + { + using var context = new BlacksmithWorkshopDataBase(); + var shop = context.Shops.FirstOrDefault(x => x.Id == model.Id); + if (shop == null) + { + return null; + } + try + { + if (context.Shops.Any(x => (x.ShopName == model.ShopName && x.Id != model.Id))) + { + throw new Exception("Не должно быть два магазина с одним названием"); + } + shop.Update(model); + shop.UpdateManufactures(context, model); + context.SaveChanges(); + return shop.GetViewModel; + } + catch + { + throw; + } + } + public bool SellManufactures(IManufactureModel model, int count) + { + if (model == null) + return false; + using var context = new BlacksmithWorkshopDataBase(); + using var transaction = context.Database.BeginTransaction(); + List lst = new List(); + foreach (var el in context.ShopManufactures.Where(x => x.ManufactureId == model.Id)) + { + int dif = count; + if (el.Count < dif) + dif = el.Count; + el.Count -= dif; + count -= dif; + if (el.Count == 0) + { + lst.Add(el); + } + if (count == 0) + break; + } + if (count > 0) + { + transaction.Rollback(); + return false; + } + foreach (var el in lst) + { + context.ShopManufactures.Remove(el); + } + context.SaveChanges(); + transaction.Commit(); + return true; + } + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20240324164611_InitialCreate.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20240325164926_InitialCreate.Designer.cs similarity index 67% rename from BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20240324164611_InitialCreate.Designer.cs rename to BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20240325164926_InitialCreate.Designer.cs index 1629012..7f1e4bb 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20240324164611_InitialCreate.Designer.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20240325164926_InitialCreate.Designer.cs @@ -12,7 +12,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion; namespace BlacksmithWorkshopDatabaseImplement.Migrations { [DbContext(typeof(BlacksmithWorkshopDataBase))] - [Migration("20240324164611_InitialCreate")] + [Migration("20240325164926_InitialCreate")] partial class InitialCreate { /// @@ -124,6 +124,59 @@ namespace BlacksmithWorkshopDatabaseImplement.Migrations b.ToTable("Orders"); }); + modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Shop", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Address") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("MaxCapacity") + .HasColumnType("int"); + + b.Property("OpeningDate") + .HasColumnType("datetime2"); + + b.Property("ShopName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Shops"); + }); + + modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.ShopManufacture", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("ManufactureId") + .HasColumnType("int"); + + b.Property("ShopId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ManufactureId"); + + b.HasIndex("ShopId"); + + b.ToTable("ShopManufactures"); + }); + modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.ManufactureComponent", b => { b.HasOne("BlacksmithWorkshopDatabaseImplement.Models.Component", "Component") @@ -154,6 +207,25 @@ namespace BlacksmithWorkshopDatabaseImplement.Migrations b.Navigation("Manufacture"); }); + modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.ShopManufacture", b => + { + b.HasOne("BlacksmithWorkshopDatabaseImplement.Models.Manufacture", "Manufacture") + .WithMany("ShopManufactures") + .HasForeignKey("ManufactureId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("BlacksmithWorkshopDatabaseImplement.Models.Shop", "Shop") + .WithMany("Manufactures") + .HasForeignKey("ShopId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Manufacture"); + + b.Navigation("Shop"); + }); + modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Component", b => { b.Navigation("ManufactureComponents"); @@ -164,6 +236,13 @@ namespace BlacksmithWorkshopDatabaseImplement.Migrations b.Navigation("Components"); b.Navigation("Orders"); + + b.Navigation("ShopManufactures"); + }); + + modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Shop", b => + { + b.Navigation("Manufactures"); }); #pragma warning restore 612, 618 } diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20240324164611_InitialCreate.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20240325164926_InitialCreate.cs similarity index 66% rename from BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20240324164611_InitialCreate.cs rename to BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20240325164926_InitialCreate.cs index 7a57164..b5ebbf5 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20240324164611_InitialCreate.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20240325164926_InitialCreate.cs @@ -39,6 +39,22 @@ namespace BlacksmithWorkshopDatabaseImplement.Migrations table.PrimaryKey("PK_Manufactures", x => x.Id); }); + migrationBuilder.CreateTable( + name: "Shops", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ShopName = table.Column(type: "nvarchar(max)", nullable: false), + Address = table.Column(type: "nvarchar(max)", nullable: false), + OpeningDate = table.Column(type: "datetime2", nullable: false), + MaxCapacity = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Shops", x => x.Id); + }); + migrationBuilder.CreateTable( name: "ManufactureComponents", columns: table => new @@ -90,6 +106,33 @@ namespace BlacksmithWorkshopDatabaseImplement.Migrations onDelete: ReferentialAction.Cascade); }); + migrationBuilder.CreateTable( + name: "ShopManufactures", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ManufactureId = table.Column(type: "int", nullable: false), + ShopId = table.Column(type: "int", nullable: false), + Count = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_ShopManufactures", x => x.Id); + table.ForeignKey( + name: "FK_ShopManufactures_Manufactures_ManufactureId", + column: x => x.ManufactureId, + principalTable: "Manufactures", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_ShopManufactures_Shops_ShopId", + column: x => x.ShopId, + principalTable: "Shops", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + migrationBuilder.CreateIndex( name: "IX_ManufactureComponents_ComponentId", table: "ManufactureComponents", @@ -104,6 +147,16 @@ namespace BlacksmithWorkshopDatabaseImplement.Migrations name: "IX_Orders_ManufactureId", table: "Orders", column: "ManufactureId"); + + migrationBuilder.CreateIndex( + name: "IX_ShopManufactures_ManufactureId", + table: "ShopManufactures", + column: "ManufactureId"); + + migrationBuilder.CreateIndex( + name: "IX_ShopManufactures_ShopId", + table: "ShopManufactures", + column: "ShopId"); } /// @@ -115,11 +168,17 @@ namespace BlacksmithWorkshopDatabaseImplement.Migrations migrationBuilder.DropTable( name: "Orders"); + migrationBuilder.DropTable( + name: "ShopManufactures"); + migrationBuilder.DropTable( name: "Components"); migrationBuilder.DropTable( name: "Manufactures"); + + migrationBuilder.DropTable( + name: "Shops"); } } } diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/BlacksmithWorkshopDataBaseModelSnapshot.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/BlacksmithWorkshopDataBaseModelSnapshot.cs index e3ce109..e0bce8b 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/BlacksmithWorkshopDataBaseModelSnapshot.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/BlacksmithWorkshopDataBaseModelSnapshot.cs @@ -121,6 +121,59 @@ namespace BlacksmithWorkshopDatabaseImplement.Migrations b.ToTable("Orders"); }); + modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Shop", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Address") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("MaxCapacity") + .HasColumnType("int"); + + b.Property("OpeningDate") + .HasColumnType("datetime2"); + + b.Property("ShopName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Shops"); + }); + + modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.ShopManufacture", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("ManufactureId") + .HasColumnType("int"); + + b.Property("ShopId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ManufactureId"); + + b.HasIndex("ShopId"); + + b.ToTable("ShopManufactures"); + }); + modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.ManufactureComponent", b => { b.HasOne("BlacksmithWorkshopDatabaseImplement.Models.Component", "Component") @@ -151,6 +204,25 @@ namespace BlacksmithWorkshopDatabaseImplement.Migrations b.Navigation("Manufacture"); }); + modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.ShopManufacture", b => + { + b.HasOne("BlacksmithWorkshopDatabaseImplement.Models.Manufacture", "Manufacture") + .WithMany("ShopManufactures") + .HasForeignKey("ManufactureId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("BlacksmithWorkshopDatabaseImplement.Models.Shop", "Shop") + .WithMany("Manufactures") + .HasForeignKey("ShopId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Manufacture"); + + b.Navigation("Shop"); + }); + modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Component", b => { b.Navigation("ManufactureComponents"); @@ -161,6 +233,13 @@ namespace BlacksmithWorkshopDatabaseImplement.Migrations b.Navigation("Components"); b.Navigation("Orders"); + + b.Navigation("ShopManufactures"); + }); + + modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Shop", b => + { + b.Navigation("Manufactures"); }); #pragma warning restore 612, 618 } diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Manufacture.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Manufacture.cs index 24f00be..6238a08 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Manufacture.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Manufacture.cs @@ -38,6 +38,9 @@ namespace BlacksmithWorkshopDatabaseImplement.Models public virtual List Components { get; set; } = new(); [ForeignKey("ManufactureId")] public virtual List Orders { get; set; } = new(); + + [ForeignKey("ManufactureId")] + public virtual List ShopManufactures { get; set; } = new(); public static Manufacture Create(BlacksmithWorkshopDataBase context, ManufactureBindingModel model) { diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Shop.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Shop.cs new file mode 100644 index 0000000..cc3f118 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Shop.cs @@ -0,0 +1,115 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.ViewModels; +using BlacksmithWorkshopDataModels.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 BlacksmithWorkshopDatabaseImplement.Models +{ + public class Shop : IShopModel + { + public int Id { get; private set; } + [Required] + public string ShopName { get; private set; } = string.Empty; + [Required] + public string Address { get; private set; } = string.Empty; + [Required] + public DateTime OpeningDate { get; private set; } + [Required] + public int MaxCapacity { get; private set; } + private Dictionary? _ShopManufacture = null; + [NotMapped] + public Dictionary ShopManufactures + { + get + { + if (_ShopManufacture == null) + { + _ShopManufacture = Manufactures + .ToDictionary(x => x.ManufactureId, x => + (x.Manufacture as IManufactureModel, x.Count)); + } + return _ShopManufacture; + } + } + [ForeignKey("ShopId")] + public virtual List Manufactures { get; set; } = new(); + public static Shop? Create(BlacksmithWorkshopDataBase context, ShopBindingModel model) + { + if (model == null) + return null; + return new Shop() + { + Id = model.Id, + ShopName = model.ShopName, + Address = model.Address, + OpeningDate = model.OpeningDate, + MaxCapacity = model.MaxCapacity, + Manufactures = model.ShopManufactures.Select(x => new ShopManufacture + { + Manufacture = context.Manufactures.First(y => y.Id == x.Key), + Count = x.Value.Item2 + }).ToList() + }; + } + + public void Update(ShopBindingModel? model) + { + if (model == null) + { + return; + } + ShopName = model.ShopName; + Address = model.Address; + OpeningDate = model.OpeningDate; + MaxCapacity = model.MaxCapacity; + } + + public ShopViewModel GetViewModel => new() + { + Id = Id, + ShopName = ShopName, + Address = Address, + OpeningDate = OpeningDate, + ShopManufactures = ShopManufactures, + MaxCapacity = MaxCapacity + }; + + public void UpdateManufactures(BlacksmithWorkshopDataBase context, ShopBindingModel model) + { + var ShopManufacture = context.ShopManufactures.Where(rec => + rec.ShopId == model.Id).ToList(); + if (ShopManufacture != null && ShopManufacture.Count > 0) + { + context.ShopManufactures.RemoveRange(ShopManufacture.Where(rec + => !model.ShopManufactures.ContainsKey(rec.ShopId))); + + context.SaveChanges(); + foreach (var updateManufacture in ShopManufacture) + { + updateManufacture.Count = + model.ShopManufactures[updateManufacture.ManufactureId].Item2; + model.ShopManufactures.Remove(updateManufacture.ManufactureId); + } + context.SaveChanges(); + } + var shop = context.Shops.First(x => x.Id == Id); + foreach (var pc in model.ShopManufactures) + { + context.ShopManufactures.Add(new ShopManufacture + { + Shop = shop, + Manufacture = context.Manufactures.First(x => x.Id == pc.Key), + Count = pc.Value.Item2 + }); + context.SaveChanges(); + } + _ShopManufacture = null; + } + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/ShopManufacture.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/ShopManufacture.cs new file mode 100644 index 0000000..ff1b725 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/ShopManufacture.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopDatabaseImplement.Models +{ + public class ShopManufacture + { + public int Id { get; set; } + [Required] + public int ManufactureId { get; set; } + [Required] + public int ShopId { get; set; } + [Required] + public int Count { get; set; } + public virtual Shop Shop { get; set; } = new(); + public virtual Manufacture Manufacture { get; set; } = new(); + } +} -- 2.25.1 From 6d197bee0cb7005f70fa14bf75701df22fae64b0 Mon Sep 17 00:00:00 2001 From: Zakharov_Rostislav Date: Mon, 25 Mar 2024 20:59:47 +0400 Subject: [PATCH 06/10] lab-3 is it finish? --- .../Implements/OrderStorage.cs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Implements/OrderStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Implements/OrderStorage.cs index f489a4e..58abc02 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Implements/OrderStorage.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Implements/OrderStorage.cs @@ -30,6 +30,7 @@ namespace BlacksmithWorkshopDatabaseImplement.Implements } using var context = new BlacksmithWorkshopDataBase(); return context.Orders + .Include(x => x.Manufacture) .Where(x => x.Id == model.Id) .Select(x => x.GetViewModel) .ToList(); @@ -41,7 +42,9 @@ namespace BlacksmithWorkshopDatabaseImplement.Implements return null; } using var context = new BlacksmithWorkshopDataBase(); - return context.Orders.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel; + return context.Orders + .Include(x => x.Manufacture) + .FirstOrDefault(x => x.Id == model.Id)?.GetViewModel; } public OrderViewModel? Insert(OrderBindingModel model) { @@ -58,8 +61,9 @@ namespace BlacksmithWorkshopDatabaseImplement.Implements public OrderViewModel? Update(OrderBindingModel model) { using var context = new BlacksmithWorkshopDataBase(); - var order = context.Orders.FirstOrDefault(x => x.Id == - model.Id); + var order = context.Orders + .Include(x => x.Manufacture) + .FirstOrDefault(x => x.Id == model.Id); if (order == null) { return null; @@ -71,8 +75,9 @@ namespace BlacksmithWorkshopDatabaseImplement.Implements public OrderViewModel? Delete(OrderBindingModel model) { using var context = new BlacksmithWorkshopDataBase(); - var element = context.Orders.FirstOrDefault(rec => rec.Id == - model.Id); + var element = context.Orders + .Include(x => x.Manufacture) + .FirstOrDefault(rec => rec.Id == model.Id); if (element != null) { context.Orders.Remove(element); -- 2.25.1 From 51c263ca230fd2296f14d941d3e0bfb262fe37bc Mon Sep 17 00:00:00 2001 From: Zakharov_Rostislav Date: Mon, 25 Mar 2024 21:46:50 +0400 Subject: [PATCH 07/10] lab-3 it is finish --- ...Designer.cs => 20240325174141_InitialCreate.Designer.cs} | 2 +- ...611_InitialCreate.cs => 20240325174141_InitialCreate.cs} | 0 .../BlacksmithWorkshopDatabaseImplement/Models/Order.cs | 6 +++--- 3 files changed, 4 insertions(+), 4 deletions(-) rename BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/{20240324164611_InitialCreate.Designer.cs => 20240325174141_InitialCreate.Designer.cs} (99%) rename BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/{20240324164611_InitialCreate.cs => 20240325174141_InitialCreate.cs} (100%) diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20240324164611_InitialCreate.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20240325174141_InitialCreate.Designer.cs similarity index 99% rename from BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20240324164611_InitialCreate.Designer.cs rename to BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20240325174141_InitialCreate.Designer.cs index 1629012..4643766 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20240324164611_InitialCreate.Designer.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20240325174141_InitialCreate.Designer.cs @@ -12,7 +12,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion; namespace BlacksmithWorkshopDatabaseImplement.Migrations { [DbContext(typeof(BlacksmithWorkshopDataBase))] - [Migration("20240324164611_InitialCreate")] + [Migration("20240325174141_InitialCreate")] partial class InitialCreate { /// diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20240324164611_InitialCreate.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20240325174141_InitialCreate.cs similarity index 100% rename from BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20240324164611_InitialCreate.cs rename to BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20240325174141_InitialCreate.cs diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Order.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Order.cs index 8a5b48d..4d6fd5b 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Order.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Order.cs @@ -25,9 +25,9 @@ namespace BlacksmithWorkshopDatabaseImplement.Models public DateTime? DateImplement { get; private set; } [Required] public int ManufactureId { get; private set; } - public virtual Manufacture Manufacture { get; set; } = new(); + public virtual Manufacture? Manufacture { get; set; } - public static Order? Create(OrderBindingModel model) + public static Order Create(OrderBindingModel model) { return new Order() { @@ -52,7 +52,7 @@ namespace BlacksmithWorkshopDatabaseImplement.Models public OrderViewModel GetViewModel => new() { ManufactureId = ManufactureId, - ManufactureName = Manufacture.ManufactureName, + ManufactureName = Manufacture?.ManufactureName ?? string.Empty, Count = Count, Sum = Sum, Status = Status, -- 2.25.1 From 43f8c79203a0667276ad985dff6c180d6a327c81 Mon Sep 17 00:00:00 2001 From: Zakharov_Rostislav Date: Mon, 25 Mar 2024 21:54:40 +0400 Subject: [PATCH 08/10] lab-3-hard in process --- .../20240324164611_InitialCreate.Designer.cs | 171 ------------ .../20240324164611_InitialCreate.cs | 125 --------- .../20240325174141_InitialCreate.Designer.cs | 254 ------------------ .../20240325174141_InitialCreate.cs | 184 ------------- ...BlacksmithWorkshopDataBaseModelSnapshot.cs | 247 ----------------- 5 files changed, 981 deletions(-) delete mode 100644 BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20240324164611_InitialCreate.Designer.cs delete mode 100644 BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20240324164611_InitialCreate.cs delete mode 100644 BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20240325174141_InitialCreate.Designer.cs delete mode 100644 BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20240325174141_InitialCreate.cs delete mode 100644 BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/BlacksmithWorkshopDataBaseModelSnapshot.cs diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20240324164611_InitialCreate.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20240324164611_InitialCreate.Designer.cs deleted file mode 100644 index 1629012..0000000 --- a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20240324164611_InitialCreate.Designer.cs +++ /dev/null @@ -1,171 +0,0 @@ -// -using System; -using BlacksmithWorkshopDatabaseImplement; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; - -#nullable disable - -namespace BlacksmithWorkshopDatabaseImplement.Migrations -{ - [DbContext(typeof(BlacksmithWorkshopDataBase))] - [Migration("20240324164611_InitialCreate")] - partial class InitialCreate - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "7.0.16") - .HasAnnotation("Relational:MaxIdentifierLength", 128); - - SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); - - modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Component", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("ComponentName") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("Cost") - .HasColumnType("float"); - - b.HasKey("Id"); - - b.ToTable("Components"); - }); - - modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Manufacture", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("ManufactureName") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("Price") - .HasColumnType("float"); - - b.HasKey("Id"); - - b.ToTable("Manufactures"); - }); - - modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.ManufactureComponent", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("ComponentId") - .HasColumnType("int"); - - b.Property("Count") - .HasColumnType("int"); - - b.Property("ManufactureId") - .HasColumnType("int"); - - b.HasKey("Id"); - - b.HasIndex("ComponentId"); - - b.HasIndex("ManufactureId"); - - b.ToTable("ManufactureComponents"); - }); - - modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Order", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("Count") - .HasColumnType("int"); - - b.Property("DateCreate") - .HasColumnType("datetime2"); - - b.Property("DateImplement") - .HasColumnType("datetime2"); - - b.Property("ManufactureId") - .HasColumnType("int"); - - b.Property("Status") - .HasColumnType("int"); - - b.Property("Sum") - .HasColumnType("float"); - - b.HasKey("Id"); - - b.HasIndex("ManufactureId"); - - b.ToTable("Orders"); - }); - - modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.ManufactureComponent", b => - { - b.HasOne("BlacksmithWorkshopDatabaseImplement.Models.Component", "Component") - .WithMany("ManufactureComponents") - .HasForeignKey("ComponentId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("BlacksmithWorkshopDatabaseImplement.Models.Manufacture", "Manufacture") - .WithMany("Components") - .HasForeignKey("ManufactureId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Component"); - - b.Navigation("Manufacture"); - }); - - modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Order", b => - { - b.HasOne("BlacksmithWorkshopDatabaseImplement.Models.Manufacture", "Manufacture") - .WithMany("Orders") - .HasForeignKey("ManufactureId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Manufacture"); - }); - - modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Component", b => - { - b.Navigation("ManufactureComponents"); - }); - - modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Manufacture", b => - { - b.Navigation("Components"); - - b.Navigation("Orders"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20240324164611_InitialCreate.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20240324164611_InitialCreate.cs deleted file mode 100644 index 7a57164..0000000 --- a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20240324164611_InitialCreate.cs +++ /dev/null @@ -1,125 +0,0 @@ -using System; -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace BlacksmithWorkshopDatabaseImplement.Migrations -{ - /// - public partial class InitialCreate : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.CreateTable( - name: "Components", - columns: table => new - { - Id = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - ComponentName = table.Column(type: "nvarchar(max)", nullable: false), - Cost = table.Column(type: "float", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Components", x => x.Id); - }); - - migrationBuilder.CreateTable( - name: "Manufactures", - columns: table => new - { - Id = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - ManufactureName = table.Column(type: "nvarchar(max)", nullable: false), - Price = table.Column(type: "float", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Manufactures", x => x.Id); - }); - - migrationBuilder.CreateTable( - name: "ManufactureComponents", - columns: table => new - { - Id = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - ManufactureId = table.Column(type: "int", nullable: false), - ComponentId = table.Column(type: "int", nullable: false), - Count = table.Column(type: "int", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_ManufactureComponents", x => x.Id); - table.ForeignKey( - name: "FK_ManufactureComponents_Components_ComponentId", - column: x => x.ComponentId, - principalTable: "Components", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - table.ForeignKey( - name: "FK_ManufactureComponents_Manufactures_ManufactureId", - column: x => x.ManufactureId, - principalTable: "Manufactures", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "Orders", - columns: table => new - { - Id = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - Count = table.Column(type: "int", nullable: false), - Sum = table.Column(type: "float", nullable: false), - Status = table.Column(type: "int", nullable: false), - DateCreate = table.Column(type: "datetime2", nullable: false), - DateImplement = table.Column(type: "datetime2", nullable: true), - ManufactureId = table.Column(type: "int", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Orders", x => x.Id); - table.ForeignKey( - name: "FK_Orders_Manufactures_ManufactureId", - column: x => x.ManufactureId, - principalTable: "Manufactures", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateIndex( - name: "IX_ManufactureComponents_ComponentId", - table: "ManufactureComponents", - column: "ComponentId"); - - migrationBuilder.CreateIndex( - name: "IX_ManufactureComponents_ManufactureId", - table: "ManufactureComponents", - column: "ManufactureId"); - - migrationBuilder.CreateIndex( - name: "IX_Orders_ManufactureId", - table: "Orders", - column: "ManufactureId"); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropTable( - name: "ManufactureComponents"); - - migrationBuilder.DropTable( - name: "Orders"); - - migrationBuilder.DropTable( - name: "Components"); - - migrationBuilder.DropTable( - name: "Manufactures"); - } - } -} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20240325174141_InitialCreate.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20240325174141_InitialCreate.Designer.cs deleted file mode 100644 index da95485..0000000 --- a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20240325174141_InitialCreate.Designer.cs +++ /dev/null @@ -1,254 +0,0 @@ -// -using System; -using BlacksmithWorkshopDatabaseImplement; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; - -#nullable disable - -namespace BlacksmithWorkshopDatabaseImplement.Migrations -{ - [DbContext(typeof(BlacksmithWorkshopDataBase))] -<<<<<<<< HEAD:BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20240325164926_InitialCreate.Designer.cs - [Migration("20240325164926_InitialCreate")] -======== - [Migration("20240325174141_InitialCreate")] ->>>>>>>> lab-3:BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20240325174141_InitialCreate.Designer.cs - partial class InitialCreate - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "7.0.16") - .HasAnnotation("Relational:MaxIdentifierLength", 128); - - SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); - - modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Component", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("ComponentName") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("Cost") - .HasColumnType("float"); - - b.HasKey("Id"); - - b.ToTable("Components"); - }); - - modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Manufacture", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("ManufactureName") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("Price") - .HasColumnType("float"); - - b.HasKey("Id"); - - b.ToTable("Manufactures"); - }); - - modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.ManufactureComponent", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("ComponentId") - .HasColumnType("int"); - - b.Property("Count") - .HasColumnType("int"); - - b.Property("ManufactureId") - .HasColumnType("int"); - - b.HasKey("Id"); - - b.HasIndex("ComponentId"); - - b.HasIndex("ManufactureId"); - - b.ToTable("ManufactureComponents"); - }); - - modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Order", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("Count") - .HasColumnType("int"); - - b.Property("DateCreate") - .HasColumnType("datetime2"); - - b.Property("DateImplement") - .HasColumnType("datetime2"); - - b.Property("ManufactureId") - .HasColumnType("int"); - - b.Property("Status") - .HasColumnType("int"); - - b.Property("Sum") - .HasColumnType("float"); - - b.HasKey("Id"); - - b.HasIndex("ManufactureId"); - - b.ToTable("Orders"); - }); - - modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Shop", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("Address") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("MaxCapacity") - .HasColumnType("int"); - - b.Property("OpeningDate") - .HasColumnType("datetime2"); - - b.Property("ShopName") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.HasKey("Id"); - - b.ToTable("Shops"); - }); - - modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.ShopManufacture", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("Count") - .HasColumnType("int"); - - b.Property("ManufactureId") - .HasColumnType("int"); - - b.Property("ShopId") - .HasColumnType("int"); - - b.HasKey("Id"); - - b.HasIndex("ManufactureId"); - - b.HasIndex("ShopId"); - - b.ToTable("ShopManufactures"); - }); - - modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.ManufactureComponent", b => - { - b.HasOne("BlacksmithWorkshopDatabaseImplement.Models.Component", "Component") - .WithMany("ManufactureComponents") - .HasForeignKey("ComponentId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("BlacksmithWorkshopDatabaseImplement.Models.Manufacture", "Manufacture") - .WithMany("Components") - .HasForeignKey("ManufactureId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Component"); - - b.Navigation("Manufacture"); - }); - - modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Order", b => - { - b.HasOne("BlacksmithWorkshopDatabaseImplement.Models.Manufacture", "Manufacture") - .WithMany("Orders") - .HasForeignKey("ManufactureId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Manufacture"); - }); - - modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.ShopManufacture", b => - { - b.HasOne("BlacksmithWorkshopDatabaseImplement.Models.Manufacture", "Manufacture") - .WithMany("ShopManufactures") - .HasForeignKey("ManufactureId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("BlacksmithWorkshopDatabaseImplement.Models.Shop", "Shop") - .WithMany("Manufactures") - .HasForeignKey("ShopId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Manufacture"); - - b.Navigation("Shop"); - }); - - modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Component", b => - { - b.Navigation("ManufactureComponents"); - }); - - modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Manufacture", b => - { - b.Navigation("Components"); - - b.Navigation("Orders"); - - b.Navigation("ShopManufactures"); - }); - - modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Shop", b => - { - b.Navigation("Manufactures"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20240325174141_InitialCreate.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20240325174141_InitialCreate.cs deleted file mode 100644 index b5ebbf5..0000000 --- a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20240325174141_InitialCreate.cs +++ /dev/null @@ -1,184 +0,0 @@ -using System; -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace BlacksmithWorkshopDatabaseImplement.Migrations -{ - /// - public partial class InitialCreate : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.CreateTable( - name: "Components", - columns: table => new - { - Id = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - ComponentName = table.Column(type: "nvarchar(max)", nullable: false), - Cost = table.Column(type: "float", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Components", x => x.Id); - }); - - migrationBuilder.CreateTable( - name: "Manufactures", - columns: table => new - { - Id = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - ManufactureName = table.Column(type: "nvarchar(max)", nullable: false), - Price = table.Column(type: "float", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Manufactures", x => x.Id); - }); - - migrationBuilder.CreateTable( - name: "Shops", - columns: table => new - { - Id = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - ShopName = table.Column(type: "nvarchar(max)", nullable: false), - Address = table.Column(type: "nvarchar(max)", nullable: false), - OpeningDate = table.Column(type: "datetime2", nullable: false), - MaxCapacity = table.Column(type: "int", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Shops", x => x.Id); - }); - - migrationBuilder.CreateTable( - name: "ManufactureComponents", - columns: table => new - { - Id = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - ManufactureId = table.Column(type: "int", nullable: false), - ComponentId = table.Column(type: "int", nullable: false), - Count = table.Column(type: "int", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_ManufactureComponents", x => x.Id); - table.ForeignKey( - name: "FK_ManufactureComponents_Components_ComponentId", - column: x => x.ComponentId, - principalTable: "Components", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - table.ForeignKey( - name: "FK_ManufactureComponents_Manufactures_ManufactureId", - column: x => x.ManufactureId, - principalTable: "Manufactures", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "Orders", - columns: table => new - { - Id = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - Count = table.Column(type: "int", nullable: false), - Sum = table.Column(type: "float", nullable: false), - Status = table.Column(type: "int", nullable: false), - DateCreate = table.Column(type: "datetime2", nullable: false), - DateImplement = table.Column(type: "datetime2", nullable: true), - ManufactureId = table.Column(type: "int", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Orders", x => x.Id); - table.ForeignKey( - name: "FK_Orders_Manufactures_ManufactureId", - column: x => x.ManufactureId, - principalTable: "Manufactures", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "ShopManufactures", - columns: table => new - { - Id = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - ManufactureId = table.Column(type: "int", nullable: false), - ShopId = table.Column(type: "int", nullable: false), - Count = table.Column(type: "int", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_ShopManufactures", x => x.Id); - table.ForeignKey( - name: "FK_ShopManufactures_Manufactures_ManufactureId", - column: x => x.ManufactureId, - principalTable: "Manufactures", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - table.ForeignKey( - name: "FK_ShopManufactures_Shops_ShopId", - column: x => x.ShopId, - principalTable: "Shops", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateIndex( - name: "IX_ManufactureComponents_ComponentId", - table: "ManufactureComponents", - column: "ComponentId"); - - migrationBuilder.CreateIndex( - name: "IX_ManufactureComponents_ManufactureId", - table: "ManufactureComponents", - column: "ManufactureId"); - - migrationBuilder.CreateIndex( - name: "IX_Orders_ManufactureId", - table: "Orders", - column: "ManufactureId"); - - migrationBuilder.CreateIndex( - name: "IX_ShopManufactures_ManufactureId", - table: "ShopManufactures", - column: "ManufactureId"); - - migrationBuilder.CreateIndex( - name: "IX_ShopManufactures_ShopId", - table: "ShopManufactures", - column: "ShopId"); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropTable( - name: "ManufactureComponents"); - - migrationBuilder.DropTable( - name: "Orders"); - - migrationBuilder.DropTable( - name: "ShopManufactures"); - - migrationBuilder.DropTable( - name: "Components"); - - migrationBuilder.DropTable( - name: "Manufactures"); - - migrationBuilder.DropTable( - name: "Shops"); - } - } -} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/BlacksmithWorkshopDataBaseModelSnapshot.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/BlacksmithWorkshopDataBaseModelSnapshot.cs deleted file mode 100644 index e0bce8b..0000000 --- a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/BlacksmithWorkshopDataBaseModelSnapshot.cs +++ /dev/null @@ -1,247 +0,0 @@ -// -using System; -using BlacksmithWorkshopDatabaseImplement; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; - -#nullable disable - -namespace BlacksmithWorkshopDatabaseImplement.Migrations -{ - [DbContext(typeof(BlacksmithWorkshopDataBase))] - partial class BlacksmithWorkshopDataBaseModelSnapshot : ModelSnapshot - { - protected override void BuildModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "7.0.16") - .HasAnnotation("Relational:MaxIdentifierLength", 128); - - SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); - - modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Component", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("ComponentName") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("Cost") - .HasColumnType("float"); - - b.HasKey("Id"); - - b.ToTable("Components"); - }); - - modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Manufacture", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("ManufactureName") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("Price") - .HasColumnType("float"); - - b.HasKey("Id"); - - b.ToTable("Manufactures"); - }); - - modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.ManufactureComponent", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("ComponentId") - .HasColumnType("int"); - - b.Property("Count") - .HasColumnType("int"); - - b.Property("ManufactureId") - .HasColumnType("int"); - - b.HasKey("Id"); - - b.HasIndex("ComponentId"); - - b.HasIndex("ManufactureId"); - - b.ToTable("ManufactureComponents"); - }); - - modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Order", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("Count") - .HasColumnType("int"); - - b.Property("DateCreate") - .HasColumnType("datetime2"); - - b.Property("DateImplement") - .HasColumnType("datetime2"); - - b.Property("ManufactureId") - .HasColumnType("int"); - - b.Property("Status") - .HasColumnType("int"); - - b.Property("Sum") - .HasColumnType("float"); - - b.HasKey("Id"); - - b.HasIndex("ManufactureId"); - - b.ToTable("Orders"); - }); - - modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Shop", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("Address") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("MaxCapacity") - .HasColumnType("int"); - - b.Property("OpeningDate") - .HasColumnType("datetime2"); - - b.Property("ShopName") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.HasKey("Id"); - - b.ToTable("Shops"); - }); - - modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.ShopManufacture", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("Count") - .HasColumnType("int"); - - b.Property("ManufactureId") - .HasColumnType("int"); - - b.Property("ShopId") - .HasColumnType("int"); - - b.HasKey("Id"); - - b.HasIndex("ManufactureId"); - - b.HasIndex("ShopId"); - - b.ToTable("ShopManufactures"); - }); - - modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.ManufactureComponent", b => - { - b.HasOne("BlacksmithWorkshopDatabaseImplement.Models.Component", "Component") - .WithMany("ManufactureComponents") - .HasForeignKey("ComponentId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("BlacksmithWorkshopDatabaseImplement.Models.Manufacture", "Manufacture") - .WithMany("Components") - .HasForeignKey("ManufactureId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Component"); - - b.Navigation("Manufacture"); - }); - - modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Order", b => - { - b.HasOne("BlacksmithWorkshopDatabaseImplement.Models.Manufacture", "Manufacture") - .WithMany("Orders") - .HasForeignKey("ManufactureId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Manufacture"); - }); - - modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.ShopManufacture", b => - { - b.HasOne("BlacksmithWorkshopDatabaseImplement.Models.Manufacture", "Manufacture") - .WithMany("ShopManufactures") - .HasForeignKey("ManufactureId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("BlacksmithWorkshopDatabaseImplement.Models.Shop", "Shop") - .WithMany("Manufactures") - .HasForeignKey("ShopId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Manufacture"); - - b.Navigation("Shop"); - }); - - modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Component", b => - { - b.Navigation("ManufactureComponents"); - }); - - modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Manufacture", b => - { - b.Navigation("Components"); - - b.Navigation("Orders"); - - b.Navigation("ShopManufactures"); - }); - - modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Shop", b => - { - b.Navigation("Manufactures"); - }); -#pragma warning restore 612, 618 - } - } -} -- 2.25.1 From aeea01acb8765cb02bd244a34a829bebb352d976 Mon Sep 17 00:00:00 2001 From: Zakharov_Rostislav Date: Mon, 25 Mar 2024 22:02:44 +0400 Subject: [PATCH 09/10] lab-3-hard finish --- .../20240325175852_InitialCreate.Designer.cs | 250 ++++++++++++++++++ .../20240325175852_InitialCreate.cs | 184 +++++++++++++ ...BlacksmithWorkshopDataBaseModelSnapshot.cs | 247 +++++++++++++++++ 3 files changed, 681 insertions(+) create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20240325175852_InitialCreate.Designer.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20240325175852_InitialCreate.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/BlacksmithWorkshopDataBaseModelSnapshot.cs diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20240325175852_InitialCreate.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20240325175852_InitialCreate.Designer.cs new file mode 100644 index 0000000..084b47e --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20240325175852_InitialCreate.Designer.cs @@ -0,0 +1,250 @@ +// +using System; +using BlacksmithWorkshopDatabaseImplement; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace BlacksmithWorkshopDatabaseImplement.Migrations +{ + [DbContext(typeof(BlacksmithWorkshopDataBase))] + [Migration("20240325175852_InitialCreate")] + partial class InitialCreate + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.16") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Component", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ComponentName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Cost") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.ToTable("Components"); + }); + + modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Manufacture", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ManufactureName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Price") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.ToTable("Manufactures"); + }); + + modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.ManufactureComponent", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ComponentId") + .HasColumnType("int"); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("ManufactureId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ComponentId"); + + b.HasIndex("ManufactureId"); + + b.ToTable("ManufactureComponents"); + }); + + modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Order", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("DateCreate") + .HasColumnType("datetime2"); + + b.Property("DateImplement") + .HasColumnType("datetime2"); + + b.Property("ManufactureId") + .HasColumnType("int"); + + b.Property("Status") + .HasColumnType("int"); + + b.Property("Sum") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.HasIndex("ManufactureId"); + + b.ToTable("Orders"); + }); + + modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Shop", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Address") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("MaxCapacity") + .HasColumnType("int"); + + b.Property("OpeningDate") + .HasColumnType("datetime2"); + + b.Property("ShopName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Shops"); + }); + + modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.ShopManufacture", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("ManufactureId") + .HasColumnType("int"); + + b.Property("ShopId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ManufactureId"); + + b.HasIndex("ShopId"); + + b.ToTable("ShopManufactures"); + }); + + modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.ManufactureComponent", b => + { + b.HasOne("BlacksmithWorkshopDatabaseImplement.Models.Component", "Component") + .WithMany("ManufactureComponents") + .HasForeignKey("ComponentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("BlacksmithWorkshopDatabaseImplement.Models.Manufacture", "Manufacture") + .WithMany("Components") + .HasForeignKey("ManufactureId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Component"); + + b.Navigation("Manufacture"); + }); + + modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Order", b => + { + b.HasOne("BlacksmithWorkshopDatabaseImplement.Models.Manufacture", "Manufacture") + .WithMany("Orders") + .HasForeignKey("ManufactureId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Manufacture"); + }); + + modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.ShopManufacture", b => + { + b.HasOne("BlacksmithWorkshopDatabaseImplement.Models.Manufacture", "Manufacture") + .WithMany("ShopManufactures") + .HasForeignKey("ManufactureId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("BlacksmithWorkshopDatabaseImplement.Models.Shop", "Shop") + .WithMany("Manufactures") + .HasForeignKey("ShopId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Manufacture"); + + b.Navigation("Shop"); + }); + + modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Component", b => + { + b.Navigation("ManufactureComponents"); + }); + + modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Manufacture", b => + { + b.Navigation("Components"); + + b.Navigation("Orders"); + + b.Navigation("ShopManufactures"); + }); + + modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Shop", b => + { + b.Navigation("Manufactures"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20240325175852_InitialCreate.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20240325175852_InitialCreate.cs new file mode 100644 index 0000000..b5ebbf5 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20240325175852_InitialCreate.cs @@ -0,0 +1,184 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace BlacksmithWorkshopDatabaseImplement.Migrations +{ + /// + public partial class InitialCreate : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Components", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ComponentName = table.Column(type: "nvarchar(max)", nullable: false), + Cost = table.Column(type: "float", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Components", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Manufactures", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ManufactureName = table.Column(type: "nvarchar(max)", nullable: false), + Price = table.Column(type: "float", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Manufactures", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Shops", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ShopName = table.Column(type: "nvarchar(max)", nullable: false), + Address = table.Column(type: "nvarchar(max)", nullable: false), + OpeningDate = table.Column(type: "datetime2", nullable: false), + MaxCapacity = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Shops", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "ManufactureComponents", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ManufactureId = table.Column(type: "int", nullable: false), + ComponentId = table.Column(type: "int", nullable: false), + Count = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_ManufactureComponents", x => x.Id); + table.ForeignKey( + name: "FK_ManufactureComponents_Components_ComponentId", + column: x => x.ComponentId, + principalTable: "Components", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_ManufactureComponents_Manufactures_ManufactureId", + column: x => x.ManufactureId, + principalTable: "Manufactures", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "Orders", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + Count = table.Column(type: "int", nullable: false), + Sum = table.Column(type: "float", nullable: false), + Status = table.Column(type: "int", nullable: false), + DateCreate = table.Column(type: "datetime2", nullable: false), + DateImplement = table.Column(type: "datetime2", nullable: true), + ManufactureId = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Orders", x => x.Id); + table.ForeignKey( + name: "FK_Orders_Manufactures_ManufactureId", + column: x => x.ManufactureId, + principalTable: "Manufactures", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "ShopManufactures", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ManufactureId = table.Column(type: "int", nullable: false), + ShopId = table.Column(type: "int", nullable: false), + Count = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_ShopManufactures", x => x.Id); + table.ForeignKey( + name: "FK_ShopManufactures_Manufactures_ManufactureId", + column: x => x.ManufactureId, + principalTable: "Manufactures", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_ShopManufactures_Shops_ShopId", + column: x => x.ShopId, + principalTable: "Shops", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_ManufactureComponents_ComponentId", + table: "ManufactureComponents", + column: "ComponentId"); + + migrationBuilder.CreateIndex( + name: "IX_ManufactureComponents_ManufactureId", + table: "ManufactureComponents", + column: "ManufactureId"); + + migrationBuilder.CreateIndex( + name: "IX_Orders_ManufactureId", + table: "Orders", + column: "ManufactureId"); + + migrationBuilder.CreateIndex( + name: "IX_ShopManufactures_ManufactureId", + table: "ShopManufactures", + column: "ManufactureId"); + + migrationBuilder.CreateIndex( + name: "IX_ShopManufactures_ShopId", + table: "ShopManufactures", + column: "ShopId"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "ManufactureComponents"); + + migrationBuilder.DropTable( + name: "Orders"); + + migrationBuilder.DropTable( + name: "ShopManufactures"); + + migrationBuilder.DropTable( + name: "Components"); + + migrationBuilder.DropTable( + name: "Manufactures"); + + migrationBuilder.DropTable( + name: "Shops"); + } + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/BlacksmithWorkshopDataBaseModelSnapshot.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/BlacksmithWorkshopDataBaseModelSnapshot.cs new file mode 100644 index 0000000..e0bce8b --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/BlacksmithWorkshopDataBaseModelSnapshot.cs @@ -0,0 +1,247 @@ +// +using System; +using BlacksmithWorkshopDatabaseImplement; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace BlacksmithWorkshopDatabaseImplement.Migrations +{ + [DbContext(typeof(BlacksmithWorkshopDataBase))] + partial class BlacksmithWorkshopDataBaseModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.16") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Component", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ComponentName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Cost") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.ToTable("Components"); + }); + + modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Manufacture", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ManufactureName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Price") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.ToTable("Manufactures"); + }); + + modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.ManufactureComponent", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ComponentId") + .HasColumnType("int"); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("ManufactureId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ComponentId"); + + b.HasIndex("ManufactureId"); + + b.ToTable("ManufactureComponents"); + }); + + modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Order", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("DateCreate") + .HasColumnType("datetime2"); + + b.Property("DateImplement") + .HasColumnType("datetime2"); + + b.Property("ManufactureId") + .HasColumnType("int"); + + b.Property("Status") + .HasColumnType("int"); + + b.Property("Sum") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.HasIndex("ManufactureId"); + + b.ToTable("Orders"); + }); + + modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Shop", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Address") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("MaxCapacity") + .HasColumnType("int"); + + b.Property("OpeningDate") + .HasColumnType("datetime2"); + + b.Property("ShopName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Shops"); + }); + + modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.ShopManufacture", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("ManufactureId") + .HasColumnType("int"); + + b.Property("ShopId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ManufactureId"); + + b.HasIndex("ShopId"); + + b.ToTable("ShopManufactures"); + }); + + modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.ManufactureComponent", b => + { + b.HasOne("BlacksmithWorkshopDatabaseImplement.Models.Component", "Component") + .WithMany("ManufactureComponents") + .HasForeignKey("ComponentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("BlacksmithWorkshopDatabaseImplement.Models.Manufacture", "Manufacture") + .WithMany("Components") + .HasForeignKey("ManufactureId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Component"); + + b.Navigation("Manufacture"); + }); + + modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Order", b => + { + b.HasOne("BlacksmithWorkshopDatabaseImplement.Models.Manufacture", "Manufacture") + .WithMany("Orders") + .HasForeignKey("ManufactureId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Manufacture"); + }); + + modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.ShopManufacture", b => + { + b.HasOne("BlacksmithWorkshopDatabaseImplement.Models.Manufacture", "Manufacture") + .WithMany("ShopManufactures") + .HasForeignKey("ManufactureId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("BlacksmithWorkshopDatabaseImplement.Models.Shop", "Shop") + .WithMany("Manufactures") + .HasForeignKey("ShopId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Manufacture"); + + b.Navigation("Shop"); + }); + + modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Component", b => + { + b.Navigation("ManufactureComponents"); + }); + + modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Manufacture", b => + { + b.Navigation("Components"); + + b.Navigation("Orders"); + + b.Navigation("ShopManufactures"); + }); + + modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Shop", b => + { + b.Navigation("Manufactures"); + }); +#pragma warning restore 612, 618 + } + } +} -- 2.25.1 From 08d8b3e6c5c2bfed0258c8f3a31822c99f50d905 Mon Sep 17 00:00:00 2001 From: Zakharov_Rostislav Date: Mon, 25 Mar 2024 22:13:44 +0400 Subject: [PATCH 10/10] lab-3-hard some minor fixes --- .../Implements/ShopStorage.cs | 5 ----- .../BlacksmithWorkshopDatabaseImplement/Models/Shop.cs | 3 --- 2 files changed, 8 deletions(-) diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Implements/ShopStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Implements/ShopStorage.cs index 9c5bf2f..01ab771 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Implements/ShopStorage.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Implements/ShopStorage.cs @@ -27,7 +27,6 @@ namespace BlacksmithWorkshopDatabaseImplement.Implements } return null; } - public ShopViewModel? GetElement(ShopSearchModel model) { if (string.IsNullOrEmpty(model.ShopName) && !model.Id.HasValue) @@ -41,7 +40,6 @@ namespace BlacksmithWorkshopDatabaseImplement.Implements .FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id) ?.GetViewModel; } - public List GetFilteredList(ShopSearchModel model) { if (string.IsNullOrEmpty(model.ShopName)) @@ -56,7 +54,6 @@ namespace BlacksmithWorkshopDatabaseImplement.Implements .Where(x => x.ShopName.Contains(model.ShopName ?? string.Empty)) .ToList(); } - public List GetFullList() { using var context = new BlacksmithWorkshopDataBase(); @@ -66,7 +63,6 @@ namespace BlacksmithWorkshopDatabaseImplement.Implements .Select(x => x.GetViewModel) .ToList(); } - public ShopViewModel? Insert(ShopBindingModel model) { using var context = new BlacksmithWorkshopDataBase(); @@ -90,7 +86,6 @@ namespace BlacksmithWorkshopDatabaseImplement.Implements throw; } } - public ShopViewModel? Update(ShopBindingModel model) { using var context = new BlacksmithWorkshopDataBase(); diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Shop.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Shop.cs index cc3f118..dd05faa 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Shop.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Shop.cs @@ -57,7 +57,6 @@ namespace BlacksmithWorkshopDatabaseImplement.Models }).ToList() }; } - public void Update(ShopBindingModel? model) { if (model == null) @@ -69,7 +68,6 @@ namespace BlacksmithWorkshopDatabaseImplement.Models OpeningDate = model.OpeningDate; MaxCapacity = model.MaxCapacity; } - public ShopViewModel GetViewModel => new() { Id = Id, @@ -79,7 +77,6 @@ namespace BlacksmithWorkshopDatabaseImplement.Models ShopManufactures = ShopManufactures, MaxCapacity = MaxCapacity }; - public void UpdateManufactures(BlacksmithWorkshopDataBase context, ShopBindingModel model) { var ShopManufacture = context.ShopManufactures.Where(rec => -- 2.25.1