From 523dcb88e5e156a2b359437b92a7a200742787d2 Mon Sep 17 00:00:00 2001 From: "kagbie3nn@mail.ru" Date: Wed, 8 May 2024 01:04:55 +0400 Subject: [PATCH] 5 --- .../ComputersShopClientApp/APIClient.cs | 3 +- .../ComputersShopDatabase.cs | 2 +- .../ComputersShopDatabaseImplement.csproj | 2 +- .../20240401150307_InitialCreate.Designer.cs | 214 ++++++++++++++++++ .../20240401150307_InitialCreate.cs | 156 +++++++++++++ .../Implements/ClientStorage.cs | 1 + .../Implements/ClientStorage.cs | 1 + ComputersShop/ComputersShopView/Program.cs | 2 +- 8 files changed, 377 insertions(+), 4 deletions(-) create mode 100644 ComputersShop/ComputersShopDatabaseImplement/Migrations/20240401150307_InitialCreate.Designer.cs create mode 100644 ComputersShop/ComputersShopDatabaseImplement/Migrations/20240401150307_InitialCreate.cs diff --git a/ComputersShop/ComputersShopClientApp/APIClient.cs b/ComputersShop/ComputersShopClientApp/APIClient.cs index aacd239..a15a863 100644 --- a/ComputersShop/ComputersShopClientApp/APIClient.cs +++ b/ComputersShop/ComputersShopClientApp/APIClient.cs @@ -1,4 +1,5 @@ -using Newtonsoft.Json; +using ComputersShopContracts.ViewModels; +using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Linq; diff --git a/ComputersShop/ComputersShopDatabaseImplement/ComputersShopDatabase.cs b/ComputersShop/ComputersShopDatabaseImplement/ComputersShopDatabase.cs index 53f09b1..cd0a0a8 100644 --- a/ComputersShop/ComputersShopDatabaseImplement/ComputersShopDatabase.cs +++ b/ComputersShop/ComputersShopDatabaseImplement/ComputersShopDatabase.cs @@ -15,7 +15,7 @@ namespace ComputersShopDatabaseImplement { if (optionsBuilder.IsConfigured == false) { - optionsBuilder.UseSqlServer(@"Data Source=.\SQLEXPRESS;Initial Catalog=ComputersShopDatabase;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); + optionsBuilder.UseNpgsql(@"Host=localhost;Port=5432;Database=ComputersShopDatabase;Username=postgres;Password=1212"); } base.OnConfiguring(optionsBuilder); } diff --git a/ComputersShop/ComputersShopDatabaseImplement/ComputersShopDatabaseImplement.csproj b/ComputersShop/ComputersShopDatabaseImplement/ComputersShopDatabaseImplement.csproj index b83ea69..74551a6 100644 --- a/ComputersShop/ComputersShopDatabaseImplement/ComputersShopDatabaseImplement.csproj +++ b/ComputersShop/ComputersShopDatabaseImplement/ComputersShopDatabaseImplement.csproj @@ -8,11 +8,11 @@ - all runtime; build; native; contentfiles; analyzers; buildtransitive + diff --git a/ComputersShop/ComputersShopDatabaseImplement/Migrations/20240401150307_InitialCreate.Designer.cs b/ComputersShop/ComputersShopDatabaseImplement/Migrations/20240401150307_InitialCreate.Designer.cs new file mode 100644 index 0000000..4e4844a --- /dev/null +++ b/ComputersShop/ComputersShopDatabaseImplement/Migrations/20240401150307_InitialCreate.Designer.cs @@ -0,0 +1,214 @@ +// +using System; +using ComputersShopDataBaseImplement; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace ComputersShopDataBaseImplement.Migrations +{ + [DbContext(typeof(ComputersShopDataBase))] + [Migration("20240401150307_InitialCreate")] + partial class InitialCreate + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.3") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("ComputersShopDataBaseImplement.Models.Client", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ClientFIO") + .IsRequired() + .HasColumnType("text"); + + b.Property("Email") + .IsRequired() + .HasColumnType("text"); + + b.Property("Password") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Clients"); + }); + + modelBuilder.Entity("ComputersShopDataBaseImplement.Models.Component", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ComponentName") + .IsRequired() + .HasColumnType("text"); + + b.Property("Cost") + .HasColumnType("double precision"); + + b.HasKey("Id"); + + b.ToTable("Components"); + }); + + modelBuilder.Entity("ComputersShopDataBaseImplement.Models.Computer", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ComputerName") + .IsRequired() + .HasColumnType("text"); + + b.Property("Price") + .HasColumnType("double precision"); + + b.HasKey("Id"); + + b.ToTable("Computers"); + }); + + modelBuilder.Entity("ComputersShopDataBaseImplement.Models.ComputerComponent", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ComponentId") + .HasColumnType("integer"); + + b.Property("ComputerId") + .HasColumnType("integer"); + + b.Property("Count") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("ComponentId"); + + b.HasIndex("ComputerId"); + + b.ToTable("ComputerComponents"); + }); + + modelBuilder.Entity("ComputersShopDataBaseImplement.Models.Order", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ClientId") + .HasColumnType("integer"); + + b.Property("ComputerId") + .HasColumnType("integer"); + + b.Property("Count") + .HasColumnType("integer"); + + b.Property("DateCreate") + .HasColumnType("timestamp with time zone"); + + b.Property("DateImplement") + .HasColumnType("timestamp with time zone"); + + b.Property("Status") + .HasColumnType("integer"); + + b.Property("Sum") + .HasColumnType("double precision"); + + b.HasKey("Id"); + + b.HasIndex("ClientId"); + + 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.Client", "Client") + .WithMany("Orders") + .HasForeignKey("ClientId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("ComputersShopDataBaseImplement.Models.Computer", "Computer") + .WithMany("Orders") + .HasForeignKey("ComputerId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Client"); + + b.Navigation("Computer"); + }); + + modelBuilder.Entity("ComputersShopDataBaseImplement.Models.Client", b => + { + b.Navigation("Orders"); + }); + + 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/20240401150307_InitialCreate.cs b/ComputersShop/ComputersShopDatabaseImplement/Migrations/20240401150307_InitialCreate.cs new file mode 100644 index 0000000..7bd9b7c --- /dev/null +++ b/ComputersShop/ComputersShopDatabaseImplement/Migrations/20240401150307_InitialCreate.cs @@ -0,0 +1,156 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace ComputersShopDataBaseImplement.Migrations +{ + /// + public partial class InitialCreate : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Clients", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + ClientFIO = table.Column(type: "text", nullable: false), + Email = table.Column(type: "text", nullable: false), + Password = table.Column(type: "text", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Clients", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Components", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + ComponentName = table.Column(type: "text", nullable: false), + Cost = table.Column(type: "double precision", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Components", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Computers", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + ComputerName = table.Column(type: "text", nullable: false), + Price = table.Column(type: "double precision", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Computers", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "ComputerComponents", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + ComputerId = table.Column(type: "integer", nullable: false), + ComponentId = table.Column(type: "integer", nullable: false), + Count = table.Column(type: "integer", 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: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + ComputerId = table.Column(type: "integer", nullable: false), + ClientId = table.Column(type: "integer", nullable: false), + Count = table.Column(type: "integer", nullable: false), + Sum = table.Column(type: "double precision", nullable: false), + Status = table.Column(type: "integer", nullable: false), + DateCreate = table.Column(type: "timestamp with time zone", nullable: false), + DateImplement = table.Column(type: "timestamp with time zone", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Orders", x => x.Id); + table.ForeignKey( + name: "FK_Orders_Clients_ClientId", + column: x => x.ClientId, + principalTable: "Clients", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + 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_ClientId", + table: "Orders", + column: "ClientId"); + + 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: "Clients"); + + migrationBuilder.DropTable( + name: "Computers"); + } + } +} diff --git a/ComputersShop/ComputersShopFileImplement/Implements/ClientStorage.cs b/ComputersShop/ComputersShopFileImplement/Implements/ClientStorage.cs index 5770e1c..610735e 100644 --- a/ComputersShop/ComputersShopFileImplement/Implements/ClientStorage.cs +++ b/ComputersShop/ComputersShopFileImplement/Implements/ClientStorage.cs @@ -2,6 +2,7 @@ using ComputersShopContracts.SearchModels; using ComputersShopContracts.StoragesContracts; using ComputersShopContracts.ViewModels; +using ComputersShopFileImplement.Models; using System; using System.Collections.Generic; using System.Linq; diff --git a/ComputersShop/ComputersShopListImplement/Implements/ClientStorage.cs b/ComputersShop/ComputersShopListImplement/Implements/ClientStorage.cs index 2ec5e00..155b43b 100644 --- a/ComputersShop/ComputersShopListImplement/Implements/ClientStorage.cs +++ b/ComputersShop/ComputersShopListImplement/Implements/ClientStorage.cs @@ -2,6 +2,7 @@ using ComputersShopContracts.SearchModels; using ComputersShopContracts.StoragesContracts; using ComputersShopContracts.ViewModels; +using ComputersShopListImplement.Models; using System; using System.Collections.Generic; using System.Linq; diff --git a/ComputersShop/ComputersShopView/Program.cs b/ComputersShop/ComputersShopView/Program.cs index 9b4d066..d6bf5de 100644 --- a/ComputersShop/ComputersShopView/Program.cs +++ b/ComputersShop/ComputersShopView/Program.cs @@ -4,7 +4,7 @@ using NLog.Extensions.Logging; using ComputersShopBusinessLogic.BusinessLogic; using ComputersShopContracts.BusinessLogicsContracts; using ComputersShopContracts.StoragesContracts; -using ComputersShopFileImplement.Implements; +using ComputersShopDatabaseImplement.Implements; using ComputersShopView; using ComputersShopBusinessLogic.OfficePackage.Implements; using ComputersShopBusinessLogic.OfficePackage;