From 909e1e1e176d33f374f3a26912a72ca012dcb388 Mon Sep 17 00:00:00 2001 From: Artyom_Yashin Date: Thu, 14 Mar 2024 18:44:09 +0400 Subject: [PATCH] =?UTF-8?q?Revert=20"=D0=A1=D0=B4=D0=B5=D0=BB=D0=B0=D0=BD?= =?UTF-8?q?=D0=BE"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 620b03a4b3a5931bdd0e5a424f134d2c570dec6f. --- ComputersShop/ComputersShop.sln | 8 +- .../ComputersShop/ComputersShop.csproj | 5 - .../ComputersShop/FormMain.Designer.cs | 4 +- ComputersShop/ComputersShop/Program.cs | 2 +- .../ComputersShopDatabase.cs | 22 --- .../ComputersShopDatabaseImplement.csproj | 24 --- .../Implements/ComponentStorage.cs | 90 ---------- .../Implements/ComputerStorage.cs | 111 ------------ .../Implements/OrderStorage.cs | 99 ---------- .../20240312150451_InitialCreate.Designer.cs | 169 ------------------ .../20240312150451_InitialCreate.cs | 125 ------------- .../ComputersShopDatabaseModelSnapshot.cs | 166 ----------------- .../Models/Component.cs | 62 ------- .../Models/Computer.cs | 97 ---------- .../Models/ComputerComponent.cs | 23 --- .../Models/Order.cs | 63 ------- .../DataListSingleton.cs | 1 - 17 files changed, 4 insertions(+), 1067 deletions(-) delete mode 100644 ComputersShop/ComputersShopDatabaseImplement/ComputersShopDatabase.cs delete mode 100644 ComputersShop/ComputersShopDatabaseImplement/ComputersShopDatabaseImplement.csproj delete mode 100644 ComputersShop/ComputersShopDatabaseImplement/Implements/ComponentStorage.cs delete mode 100644 ComputersShop/ComputersShopDatabaseImplement/Implements/ComputerStorage.cs delete mode 100644 ComputersShop/ComputersShopDatabaseImplement/Implements/OrderStorage.cs delete mode 100644 ComputersShop/ComputersShopDatabaseImplement/Migrations/20240312150451_InitialCreate.Designer.cs delete mode 100644 ComputersShop/ComputersShopDatabaseImplement/Migrations/20240312150451_InitialCreate.cs delete mode 100644 ComputersShop/ComputersShopDatabaseImplement/Migrations/ComputersShopDatabaseModelSnapshot.cs delete mode 100644 ComputersShop/ComputersShopDatabaseImplement/Models/Component.cs delete mode 100644 ComputersShop/ComputersShopDatabaseImplement/Models/Computer.cs delete mode 100644 ComputersShop/ComputersShopDatabaseImplement/Models/ComputerComponent.cs delete mode 100644 ComputersShop/ComputersShopDatabaseImplement/Models/Order.cs diff --git a/ComputersShop/ComputersShop.sln b/ComputersShop/ComputersShop.sln index 46486d7..56f494a 100644 --- a/ComputersShop/ComputersShop.sln +++ b/ComputersShop/ComputersShop.sln @@ -13,9 +13,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ComputersShopBusinessLogic" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ComputersShopListImplement", "ComputersShopListImplement\ComputersShopListImplement.csproj", "{97A1B877-DBB2-44B3-AB63-A32946B07EDE}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ComputersShopFileImplement", "ComputersShopFileImplement\ComputersShopFileImplement.csproj", "{5F53624A-971A-4EED-ADA5-5D1713C741A9}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ComputersShopDatabaseImplement", "ComputersShopDatabaseImplement\ComputersShopDatabaseImplement.csproj", "{BD267930-AE32-482F-89C5-589EBEB6D292}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ComputersShopFileImplement", "ComputersShopFileImplement\ComputersShopFileImplement.csproj", "{5F53624A-971A-4EED-ADA5-5D1713C741A9}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -47,10 +45,6 @@ Global {5F53624A-971A-4EED-ADA5-5D1713C741A9}.Debug|Any CPU.Build.0 = Debug|Any CPU {5F53624A-971A-4EED-ADA5-5D1713C741A9}.Release|Any CPU.ActiveCfg = Release|Any CPU {5F53624A-971A-4EED-ADA5-5D1713C741A9}.Release|Any CPU.Build.0 = Release|Any CPU - {BD267930-AE32-482F-89C5-589EBEB6D292}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {BD267930-AE32-482F-89C5-589EBEB6D292}.Debug|Any CPU.Build.0 = Debug|Any CPU - {BD267930-AE32-482F-89C5-589EBEB6D292}.Release|Any CPU.ActiveCfg = Release|Any CPU - {BD267930-AE32-482F-89C5-589EBEB6D292}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/ComputersShop/ComputersShop/ComputersShop.csproj b/ComputersShop/ComputersShop/ComputersShop.csproj index 1a00870..3bb059b 100644 --- a/ComputersShop/ComputersShop/ComputersShop.csproj +++ b/ComputersShop/ComputersShop/ComputersShop.csproj @@ -9,10 +9,6 @@ - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - @@ -24,7 +20,6 @@ - diff --git a/ComputersShop/ComputersShop/FormMain.Designer.cs b/ComputersShop/ComputersShop/FormMain.Designer.cs index b0fd856..bd23346 100644 --- a/ComputersShop/ComputersShop/FormMain.Designer.cs +++ b/ComputersShop/ComputersShop/FormMain.Designer.cs @@ -62,14 +62,14 @@ // компонентыToolStripMenuItem // компонентыToolStripMenuItem.Name = "компонентыToolStripMenuItem"; - компонентыToolStripMenuItem.Size = new Size(224, 26); + компонентыToolStripMenuItem.Size = new Size(184, 26); компонентыToolStripMenuItem.Text = "Компоненты"; компонентыToolStripMenuItem.Click += ComponentsStripMenuItem_Click; // // компьютерыToolStripMenuItem // компьютерыToolStripMenuItem.Name = "компьютерыToolStripMenuItem"; - компьютерыToolStripMenuItem.Size = new Size(224, 26); + компьютерыToolStripMenuItem.Size = new Size(184, 26); компьютерыToolStripMenuItem.Text = "Компьютеры"; компьютерыToolStripMenuItem.Click += ComputersStripMenuItem_Click; // diff --git a/ComputersShop/ComputersShop/Program.cs b/ComputersShop/ComputersShop/Program.cs index 272046c..8131e37 100644 --- a/ComputersShop/ComputersShop/Program.cs +++ b/ComputersShop/ComputersShop/Program.cs @@ -1,7 +1,7 @@ using ComputersShopBusinessLogic.BusinessLogics; using ComputersShopContracts.BisnessLogicsContracts; using ComputersShopContracts.StoragesContracts; -using ComputersShopDatabaseImplement.Implements; +using ComputersShopFileImplement.Implements; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using NLog.Extensions.Logging; diff --git a/ComputersShop/ComputersShopDatabaseImplement/ComputersShopDatabase.cs b/ComputersShop/ComputersShopDatabaseImplement/ComputersShopDatabase.cs deleted file mode 100644 index f40121d..0000000 --- a/ComputersShop/ComputersShopDatabaseImplement/ComputersShopDatabase.cs +++ /dev/null @@ -1,22 +0,0 @@ -using ComputersShopDatabaseImplement.Models; -using Microsoft.EntityFrameworkCore; - -namespace ComputersShopDatabaseImplement -{ - public class ComputersShopDatabase : DbContext - { - protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) - { - if (optionsBuilder.IsConfigured == false) - { - optionsBuilder.UseSqlServer(@"Data Source=localhost\SQLEXPRESS;Initial Catalog=ComputersShopDataBase;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True" - ); - } - base.OnConfiguring(optionsBuilder); - } - public virtual DbSet Components { set; get; } - public virtual DbSet Computers { set; get; } - public virtual DbSet ComputerComponents { set; get; } - public virtual DbSet Orders { set; get; } - } -} \ No newline at end of file diff --git a/ComputersShop/ComputersShopDatabaseImplement/ComputersShopDatabaseImplement.csproj b/ComputersShop/ComputersShopDatabaseImplement/ComputersShopDatabaseImplement.csproj deleted file mode 100644 index 967ef28..0000000 --- a/ComputersShop/ComputersShopDatabaseImplement/ComputersShopDatabaseImplement.csproj +++ /dev/null @@ -1,24 +0,0 @@ - - - - net6.0-windows - enable - true - enable - - - - - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - - - - - - - diff --git a/ComputersShop/ComputersShopDatabaseImplement/Implements/ComponentStorage.cs b/ComputersShop/ComputersShopDatabaseImplement/Implements/ComponentStorage.cs deleted file mode 100644 index 8f66b48..0000000 --- a/ComputersShop/ComputersShopDatabaseImplement/Implements/ComponentStorage.cs +++ /dev/null @@ -1,90 +0,0 @@ -using ComputersShopContracts.BindingModels; -using ComputersShopContracts.SearchModels; -using ComputersShopContracts.StoragesContracts; -using ComputersShopContracts.ViewModels; -using ComputersShopDatabaseImplement.Models; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace ComputersShopDatabaseImplement.Implements -{ - public class ComponentStorage : IComponentStorage - { - public List GetFullList() - { - using var context = new ComputersShopDatabase(); - return context.Components - .Select(x => x.GetViewModel) - .ToList(); - } - public List GetFilteredList(ComponentSearchModel - model) - { - if (string.IsNullOrEmpty(model.ComponentName)) - { - return new(); - } - using var context = new ComputersShopDatabase(); - 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 ComputersShopDatabase(); - 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 ComputersShopDatabase(); - context.Components.Add(newComponent); - context.SaveChanges(); - return newComponent.GetViewModel; - } - public ComponentViewModel? Update(ComponentBindingModel model) - { - using var context = new ComputersShopDatabase(); - 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 ComputersShopDatabase(); - 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/ComputersShop/ComputersShopDatabaseImplement/Implements/ComputerStorage.cs b/ComputersShop/ComputersShopDatabaseImplement/Implements/ComputerStorage.cs deleted file mode 100644 index 86dce7b..0000000 --- a/ComputersShop/ComputersShopDatabaseImplement/Implements/ComputerStorage.cs +++ /dev/null @@ -1,111 +0,0 @@ -using ComputersShopContracts.BindingModels; -using ComputersShopContracts.SearchModels; -using ComputersShopContracts.StoragesContracts; -using ComputersShopContracts.ViewModels; -using ComputersShopDatabaseImplement.Models; -using Microsoft.EntityFrameworkCore; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace ComputersShopDatabaseImplement.Implements -{ - public class ComputerStorage : IComputerStorage - { - public List GetFullList() - { - using var context = new ComputersShopDatabase(); - return context.Computers - .Include(x => x.Components) - .ThenInclude(x => x.Component) - .ToList() - .Select(x => x.GetViewModel) - .ToList(); - } - public List GetFilteredList(ComputerSearchModel model) - { - if (string.IsNullOrEmpty(model.ComputerName)) - { - return new(); - } - using var context = new ComputersShopDatabase(); - return context.Computers - .Include(x => x.Components) - .ThenInclude(x => x.Component) - .Where(x => x.ComputerName.Contains(model.ComputerName)) - .ToList() - .Select(x => x.GetViewModel) - .ToList(); - } - public ComputerViewModel? GetElement(ComputerSearchModel model) - { - if (string.IsNullOrEmpty(model.ComputerName) && - !model.Id.HasValue) - { - return null; - } - using var context = new ComputersShopDatabase(); - return context.Computers - .Include(x => x.Components) - .ThenInclude(x => x.Component) - .FirstOrDefault(x => (!string.IsNullOrEmpty(model.ComputerName) && - x.ComputerName == model.ComputerName) || - (model.Id.HasValue && x.Id == - model.Id)) - ?.GetViewModel; - } - public ComputerViewModel? Insert(ComputerBindingModel model) - { - using var context = new ComputersShopDatabase(); - var newComputer = Computer.Create(context, model); - if (newComputer == null) - { - return null; - } - context.Computers.Add(newComputer); - context.SaveChanges(); - return newComputer.GetViewModel; - } - public ComputerViewModel? Update(ComputerBindingModel model) - { - using var context = new ComputersShopDatabase(); - using var transaction = context.Database.BeginTransaction(); - try - { - var Computer = context.Computers.FirstOrDefault(rec => - rec.Id == model.Id); - if (Computer == null) - { - return null; - } - Computer.Update(model); - context.SaveChanges(); - Computer.UpdateComponents(context, model); - transaction.Commit(); - return Computer.GetViewModel; - } - catch - { - transaction.Rollback(); - throw; - } - } - public ComputerViewModel? Delete(ComputerBindingModel model) - { - using var context = new ComputersShopDatabase(); - var element = context.Computers - .Include(x => x.Components) - .FirstOrDefault(rec => rec.Id == model.Id); - if (element != null) - { - context.Computers.Remove(element); - context.SaveChanges(); - return element.GetViewModel; - } - return null; - } - - } -} diff --git a/ComputersShop/ComputersShopDatabaseImplement/Implements/OrderStorage.cs b/ComputersShop/ComputersShopDatabaseImplement/Implements/OrderStorage.cs deleted file mode 100644 index 31a2bc2..0000000 --- a/ComputersShop/ComputersShopDatabaseImplement/Implements/OrderStorage.cs +++ /dev/null @@ -1,99 +0,0 @@ -using ComputersShopContracts.BindingModels; -using ComputersShopContracts.SearchModels; -using ComputersShopContracts.StoragesContracts; -using ComputersShopContracts.ViewModels; -using ComputersShopDatabaseImplement.Models; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace ComputersShopDatabaseImplement.Implements -{ - public class OrderStorage :IOrderStorage - { - public List GetFullList() - { - using var context = new ComputersShopDatabase(); - return context.Orders - .Select(x => AccessComputersStorage(x.GetViewModel)) - .ToList(); - } - public List GetFilteredList(OrderSearchModel model) - { - if (!model.Id.HasValue) - { - return new(); - } - using var context = new ComputersShopDatabase(); - return context.Orders - .Where(x => x.Id == model.Id) - .Select(x => AccessComputersStorage(x.GetViewModel)) - .ToList(); - } - public OrderViewModel? GetElement(OrderSearchModel model) - { - if (!model.Id.HasValue) - { - return null; - } - using var context = new ComputersShopDatabase(); - return AccessComputersStorage(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 ComputersShopDatabase(); - context.Orders.Add(newOrder); - context.SaveChanges(); - return AccessComputersStorage(newOrder.GetViewModel); - } - public OrderViewModel? Update(OrderBindingModel model) - { - using var context = new ComputersShopDatabase(); - var order = context.Orders.FirstOrDefault(x => x.Id == - model.Id); - if (order == null) - { - return null; - } - order.Update(model); - context.SaveChanges(); - return AccessComputersStorage(order.GetViewModel); - } - public OrderViewModel? Delete(OrderBindingModel model) - { - using var context = new ComputersShopDatabase(); - var element = context.Orders.FirstOrDefault(rec => rec.Id == - model.Id); - if (element != null) - { - context.Orders.Remove(element); - context.SaveChanges(); - return AccessComputersStorage(element.GetViewModel); - } - return null; - } - - public static OrderViewModel AccessComputersStorage(OrderViewModel model) - { - if (model == null) - return null; - using var context = new ComputersShopDatabase(); - foreach (var Computers in context.Computers) - { - if (Computers.Id == model.ComputerId) - { - model.ComputerName = Computers.ComputerName; - break; - } - } - return model; - } - } -} diff --git a/ComputersShop/ComputersShopDatabaseImplement/Migrations/20240312150451_InitialCreate.Designer.cs b/ComputersShop/ComputersShopDatabaseImplement/Migrations/20240312150451_InitialCreate.Designer.cs deleted file mode 100644 index 0cb2d33..0000000 --- a/ComputersShop/ComputersShopDatabaseImplement/Migrations/20240312150451_InitialCreate.Designer.cs +++ /dev/null @@ -1,169 +0,0 @@ -// -using System; -using ComputersShopDatabaseImplement; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; - -#nullable disable - -namespace ComputersShopDatabaseImplement.Migrations -{ - [DbContext(typeof(ComputersShopDatabase))] - [Migration("20240312150451_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("ComputersShopDatabaseImplement.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("ComputersShopDatabaseImplement.Models.Computer", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("ComputerName") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("Price") - .HasColumnType("float"); - - b.HasKey("Id"); - - b.ToTable("Computers"); - }); - - modelBuilder.Entity("ComputersShopDatabaseImplement.Models.ComputerComponent", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("ComponentId") - .HasColumnType("int"); - - b.Property("ComputerId") - .HasColumnType("int"); - - b.Property("Count") - .HasColumnType("int"); - - b.HasKey("Id"); - - b.HasIndex("ComponentId"); - - b.HasIndex("ComputerId"); - - b.ToTable("ComputerComponents"); - }); - - modelBuilder.Entity("ComputersShopDatabaseImplement.Models.Order", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("ComputerId") - .HasColumnType("int"); - - b.Property("Count") - .HasColumnType("int"); - - b.Property("DateCreate") - .HasColumnType("datetime2"); - - b.Property("DateImplement") - .HasColumnType("datetime2"); - - b.Property("Status") - .HasColumnType("int"); - - b.Property("Sum") - .HasColumnType("float"); - - b.HasKey("Id"); - - b.HasIndex("ComputerId"); - - b.ToTable("Orders"); - }); - - modelBuilder.Entity("ComputersShopDatabaseImplement.Models.ComputerComponent", b => - { - b.HasOne("ComputersShopDatabaseImplement.Models.Component", "Component") - .WithMany("ComputerComponents") - .HasForeignKey("ComponentId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("ComputersShopDatabaseImplement.Models.Computer", "Computer") - .WithMany("Components") - .HasForeignKey("ComputerId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Component"); - - b.Navigation("Computer"); - }); - - modelBuilder.Entity("ComputersShopDatabaseImplement.Models.Order", b => - { - b.HasOne("ComputersShopDatabaseImplement.Models.Computer", null) - .WithMany("Orders") - .HasForeignKey("ComputerId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("ComputersShopDatabaseImplement.Models.Component", b => - { - b.Navigation("ComputerComponents"); - }); - - modelBuilder.Entity("ComputersShopDatabaseImplement.Models.Computer", b => - { - b.Navigation("Components"); - - b.Navigation("Orders"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/ComputersShop/ComputersShopDatabaseImplement/Migrations/20240312150451_InitialCreate.cs b/ComputersShop/ComputersShopDatabaseImplement/Migrations/20240312150451_InitialCreate.cs deleted file mode 100644 index 6ef9716..0000000 --- a/ComputersShop/ComputersShopDatabaseImplement/Migrations/20240312150451_InitialCreate.cs +++ /dev/null @@ -1,125 +0,0 @@ -using System; -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace ComputersShopDatabaseImplement.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: "Computers", - columns: table => new - { - Id = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - ComputerName = table.Column(type: "nvarchar(max)", nullable: false), - Price = table.Column(type: "float", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Computers", x => x.Id); - }); - - migrationBuilder.CreateTable( - name: "ComputerComponents", - columns: table => new - { - Id = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - ComputerId = 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_ComputerComponents", x => x.Id); - table.ForeignKey( - name: "FK_ComputerComponents_Components_ComponentId", - column: x => x.ComponentId, - principalTable: "Components", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - table.ForeignKey( - name: "FK_ComputerComponents_Computers_ComputerId", - column: x => x.ComputerId, - principalTable: "Computers", - 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), - ComputerId = table.Column(type: "int", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Orders", x => x.Id); - table.ForeignKey( - name: "FK_Orders_Computers_ComputerId", - column: x => x.ComputerId, - principalTable: "Computers", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateIndex( - name: "IX_ComputerComponents_ComponentId", - table: "ComputerComponents", - column: "ComponentId"); - - migrationBuilder.CreateIndex( - name: "IX_ComputerComponents_ComputerId", - table: "ComputerComponents", - column: "ComputerId"); - - migrationBuilder.CreateIndex( - name: "IX_Orders_ComputerId", - table: "Orders", - column: "ComputerId"); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropTable( - name: "ComputerComponents"); - - migrationBuilder.DropTable( - name: "Orders"); - - migrationBuilder.DropTable( - name: "Components"); - - migrationBuilder.DropTable( - name: "Computers"); - } - } -} diff --git a/ComputersShop/ComputersShopDatabaseImplement/Migrations/ComputersShopDatabaseModelSnapshot.cs b/ComputersShop/ComputersShopDatabaseImplement/Migrations/ComputersShopDatabaseModelSnapshot.cs deleted file mode 100644 index 8b53269..0000000 --- a/ComputersShop/ComputersShopDatabaseImplement/Migrations/ComputersShopDatabaseModelSnapshot.cs +++ /dev/null @@ -1,166 +0,0 @@ -// -using System; -using ComputersShopDatabaseImplement; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; - -#nullable disable - -namespace ComputersShopDatabaseImplement.Migrations -{ - [DbContext(typeof(ComputersShopDatabase))] - partial class ComputersShopDatabaseModelSnapshot : 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("ComputersShopDatabaseImplement.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("ComputersShopDatabaseImplement.Models.Computer", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("ComputerName") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("Price") - .HasColumnType("float"); - - b.HasKey("Id"); - - b.ToTable("Computers"); - }); - - modelBuilder.Entity("ComputersShopDatabaseImplement.Models.ComputerComponent", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("ComponentId") - .HasColumnType("int"); - - b.Property("ComputerId") - .HasColumnType("int"); - - b.Property("Count") - .HasColumnType("int"); - - b.HasKey("Id"); - - b.HasIndex("ComponentId"); - - b.HasIndex("ComputerId"); - - b.ToTable("ComputerComponents"); - }); - - modelBuilder.Entity("ComputersShopDatabaseImplement.Models.Order", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("ComputerId") - .HasColumnType("int"); - - b.Property("Count") - .HasColumnType("int"); - - b.Property("DateCreate") - .HasColumnType("datetime2"); - - b.Property("DateImplement") - .HasColumnType("datetime2"); - - b.Property("Status") - .HasColumnType("int"); - - b.Property("Sum") - .HasColumnType("float"); - - b.HasKey("Id"); - - b.HasIndex("ComputerId"); - - b.ToTable("Orders"); - }); - - modelBuilder.Entity("ComputersShopDatabaseImplement.Models.ComputerComponent", b => - { - b.HasOne("ComputersShopDatabaseImplement.Models.Component", "Component") - .WithMany("ComputerComponents") - .HasForeignKey("ComponentId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("ComputersShopDatabaseImplement.Models.Computer", "Computer") - .WithMany("Components") - .HasForeignKey("ComputerId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Component"); - - b.Navigation("Computer"); - }); - - modelBuilder.Entity("ComputersShopDatabaseImplement.Models.Order", b => - { - b.HasOne("ComputersShopDatabaseImplement.Models.Computer", null) - .WithMany("Orders") - .HasForeignKey("ComputerId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("ComputersShopDatabaseImplement.Models.Component", b => - { - b.Navigation("ComputerComponents"); - }); - - modelBuilder.Entity("ComputersShopDatabaseImplement.Models.Computer", b => - { - b.Navigation("Components"); - - b.Navigation("Orders"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/ComputersShop/ComputersShopDatabaseImplement/Models/Component.cs b/ComputersShop/ComputersShopDatabaseImplement/Models/Component.cs deleted file mode 100644 index cf484bc..0000000 --- a/ComputersShop/ComputersShopDatabaseImplement/Models/Component.cs +++ /dev/null @@ -1,62 +0,0 @@ -using ComputersShopContracts.BindingModels; -using ComputersShopContracts.ViewModels; -using ComputersShopDataModels; -using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations.Schema; -using System.ComponentModel.DataAnnotations; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace ComputersShopDatabaseImplement.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 ComputerComponents { 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/ComputersShop/ComputersShopDatabaseImplement/Models/Computer.cs b/ComputersShop/ComputersShopDatabaseImplement/Models/Computer.cs deleted file mode 100644 index 3862d87..0000000 --- a/ComputersShop/ComputersShopDatabaseImplement/Models/Computer.cs +++ /dev/null @@ -1,97 +0,0 @@ -using ComputersShopContracts.BindingModels; -using ComputersShopContracts.ViewModels; -using ComputersShopDataModels; -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 ComputersShopDatabaseImplement.Models -{ - public class Computer : IComputerModel - { - public int Id { get; set; } - [Required] - public string ComputerName { get; set; } = string.Empty; - [Required] - public double Price { get; set; } - private Dictionary? _computerComponents = null; - [NotMapped] - public Dictionary ComputerComponents - { - get - { - if (_computerComponents == null) - { - _computerComponents = Components - .ToDictionary(recPC => recPC.ComponentId, recPC => - (recPC.Component as IComponentModel, recPC.Count)); - } - return _computerComponents; - } - } - [ForeignKey("ComputerId")] - public virtual List Components { get; set; } = new(); - [ForeignKey("ComputerId")] - public virtual List Orders { get; set; } = new(); - public static Computer Create(ComputersShopDatabase context, ComputerBindingModel model) - { - return new Computer() - { - Id = model.Id, - ComputerName = model.ComputerName, - Price = model.Price, - Components = model.ComputerComponents.Select(x => new ComputerComponent - { - Component = context.Components.First(y => y.Id == x.Key), - Count = x.Value.Item2 - }).ToList() - }; - } - public void Update(ComputerBindingModel model) - { - ComputerName = model.ComputerName; - Price = model.Price; - } - public ComputerViewModel GetViewModel => new() - { - Id = Id, - ComputerName = ComputerName, - Price = Price, - ComputerComponents = ComputerComponents - }; - public void UpdateComponents(ComputersShopDatabase context, - ComputerBindingModel model) - { - var ComputerComponents = context.ComputerComponents.Where(rec => rec.ComputerId == model.Id).ToList(); - if (ComputerComponents != null && ComputerComponents.Count > 0) - { // удалили те, которых нет в модели - context.ComputerComponents.RemoveRange(ComputerComponents.Where(rec - => !model.ComputerComponents.ContainsKey(rec.ComponentId))); - context.SaveChanges(); - // обновили количество у существующих записей - foreach (var updateComponent in ComputerComponents) - { - updateComponent.Count = model.ComputerComponents[updateComponent.ComponentId].Item2; - model.ComputerComponents.Remove(updateComponent.ComponentId); - } - context.SaveChanges(); - } - var Computer = context.Computers.First(x => x.Id == Id); - foreach (var pc in model.ComputerComponents) - { - context.ComputerComponents.Add(new ComputerComponent - { - Computer = Computer, - Component = context.Components.First(x => x.Id == pc.Key), - Count = pc.Value.Item2 - }); - context.SaveChanges(); - } - _computerComponents = null; - } - } -} diff --git a/ComputersShop/ComputersShopDatabaseImplement/Models/ComputerComponent.cs b/ComputersShop/ComputersShopDatabaseImplement/Models/ComputerComponent.cs deleted file mode 100644 index 827434a..0000000 --- a/ComputersShop/ComputersShopDatabaseImplement/Models/ComputerComponent.cs +++ /dev/null @@ -1,23 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace ComputersShopDatabaseImplement.Models -{ - public class ComputerComponent - { - public int Id { get; set; } - [Required] - public int ComputerId { get; set; } - [Required] - public int ComponentId { get; set; } - [Required] - public int Count { get; set; } - public virtual Component Component { get; set; } = new(); - public virtual Computer Computer { get; set; } = new(); - - } -} diff --git a/ComputersShop/ComputersShopDatabaseImplement/Models/Order.cs b/ComputersShop/ComputersShopDatabaseImplement/Models/Order.cs deleted file mode 100644 index a2539c0..0000000 --- a/ComputersShop/ComputersShopDatabaseImplement/Models/Order.cs +++ /dev/null @@ -1,63 +0,0 @@ -using ComputersShopContracts.BindingModels; -using ComputersShopContracts.ViewModels; -using ComputersShopDataModels.Enums; - -using System.ComponentModel.DataAnnotations; - -namespace ComputersShopDatabaseImplement.Models -{ - public class Order - { - 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 ComputerId { 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, - ComputerId = model.ComputerId, - }; - } - - public void Update(OrderBindingModel? model) - { - if (model == null) - { - return; - } - Status = model.Status; - DateImplement = model.DateImplement; - } - - public OrderViewModel GetViewModel => new() - { - ComputerId = ComputerId, - Count = Count, - Sum = Sum, - Status = Status, - DateCreate = DateCreate, - DateImplement = DateImplement, - Id = Id, - }; - } -} diff --git a/ComputersShop/ComputersShopListImplement/DataListSingleton.cs b/ComputersShop/ComputersShopListImplement/DataListSingleton.cs index fe66e99..1b0012b 100644 --- a/ComputersShop/ComputersShopListImplement/DataListSingleton.cs +++ b/ComputersShop/ComputersShopListImplement/DataListSingleton.cs @@ -8,7 +8,6 @@ namespace ComputersShopListImplement public List Components { get; set; } public List Orders { get; set; } public List Computers { get; set; } - private DataListSingleton() { Components = new List();