From 156f8dc8201a82e9b0c169886e8a9da9f6df8290 Mon Sep 17 00:00:00 2001 From: Yuee Shiness Date: Wed, 17 May 2023 22:27:48 +0400 Subject: [PATCH] IDK... --- .../ComputerStoreDatabase.cs | 2 +- .../ComputerStoreDatabaseImplement.csproj | 8 +- .../Implements/PCStorage.cs | 23 +- .../20230517180637_NamingFixes.Designer.cs | 496 ++++++++++++++++++ .../Migrations/20230517180637_NamingFixes.cs | 100 ++++ .../ComputerStoreDatabaseModelSnapshot.cs | 4 +- ComputerStoreDatabaseImplement/Models/PC.cs | 2 +- .../Models/Request.cs | 3 +- .../ComputerStoreRestAPI.csproj | 4 + ComputerStoreRestAPI/Program.cs | 17 + 10 files changed, 642 insertions(+), 17 deletions(-) create mode 100644 ComputerStoreDatabaseImplement/Migrations/20230517180637_NamingFixes.Designer.cs create mode 100644 ComputerStoreDatabaseImplement/Migrations/20230517180637_NamingFixes.cs diff --git a/ComputerStoreDatabaseImplement/ComputerStoreDatabase.cs b/ComputerStoreDatabaseImplement/ComputerStoreDatabase.cs index 8d120be..16dc182 100644 --- a/ComputerStoreDatabaseImplement/ComputerStoreDatabase.cs +++ b/ComputerStoreDatabaseImplement/ComputerStoreDatabase.cs @@ -21,7 +21,7 @@ namespace ComputerStoreDatabaseImplement public virtual DbSet Components { get; set; } public virtual DbSet Products { get; set; } - public virtual DbSet PCs { get; set; } + public virtual DbSet PCS { get; set; } public virtual DbSet Employees { get; set; } public virtual DbSet RequestComponents { get; set; } public virtual DbSet ProductComponents { get; set; } diff --git a/ComputerStoreDatabaseImplement/ComputerStoreDatabaseImplement.csproj b/ComputerStoreDatabaseImplement/ComputerStoreDatabaseImplement.csproj index b23bbfb..0b06908 100644 --- a/ComputerStoreDatabaseImplement/ComputerStoreDatabaseImplement.csproj +++ b/ComputerStoreDatabaseImplement/ComputerStoreDatabaseImplement.csproj @@ -7,8 +7,8 @@ - - + + all runtime; build; native; contentfiles; analyzers; buildtransitive @@ -20,4 +20,8 @@ + + + + diff --git a/ComputerStoreDatabaseImplement/Implements/PCStorage.cs b/ComputerStoreDatabaseImplement/Implements/PCStorage.cs index 30582b5..e9513ce 100644 --- a/ComputerStoreDatabaseImplement/Implements/PCStorage.cs +++ b/ComputerStoreDatabaseImplement/Implements/PCStorage.cs @@ -21,7 +21,7 @@ namespace ComputerStoreDatabaseImplement.Implements if (string.IsNullOrEmpty(model.Name) && !model.ID.HasValue) { return null; } using var context = new ComputerStoreDatabase(); - return context.PCs.Include(x => x.Employee).Include(x => x.Components).ThenInclude(x => x.Component).FirstOrDefault(x => (!string.IsNullOrEmpty(model.Name) && model.Name.Equals(x.Name)) || (model.ID.HasValue && model.ID == x.ID))?.GetViewModel; + return context.PCS.Include(x => x.Employee).Include(x => x.Components).ThenInclude(x => x.Component).FirstOrDefault(x => (!string.IsNullOrEmpty(model.Name) && model.Name.Equals(x.Name)) || (model.ID.HasValue && model.ID == x.ID))?.GetViewModel; } @@ -35,15 +35,15 @@ namespace ComputerStoreDatabaseImplement.Implements if(model.EmployeeID.HasValue) { - return context.PCs.Include(x => x.Employee).Where(x => x.EmployeeID == model.EmployeeID).Select(x => x.GetViewModel).ToList(); + return context.PCS.Include(x => x.Employee).Where(x => x.EmployeeID == model.EmployeeID).Select(x => x.GetViewModel).ToList(); } - return context.PCs.Include(x => x.Employee).Include(x => x.Components).ThenInclude(x => x.Component).Where(p => context.Requests.Where(r => context.Orders.Where(o => o.DateCreate >= model.DateFrom && o.DateCreate <= model.DateTo).Select(o => o.ID).Contains(r.OrderID)).Select(r => r.ID).Contains(p.RequestID)).ToList().Select(x => x.GetViewModel).ToList(); + return context.PCS.Include(x => x.Employee).Include(x => x.Components).ThenInclude(x => x.Component).Where(p => context.Requests.Where(r => context.Orders.Where(o => o.DateCreate >= model.DateFrom && o.DateCreate <= model.DateTo).Select(o => o.ID).Contains(r.OrderID)).Select(r => r.ID).Contains(p.RequestID)).ToList().Select(x => x.GetViewModel).ToList(); } public List GetFullList() { using var context = new ComputerStoreDatabase(); - return context.PCs.Include(x => x.Employee).Include(x => x.Components).ThenInclude(x => x.Component).ToList().Select(x => x.GetViewModel).ToList(); + return context.PCS.Include(x => x.Employee).Include(x => x.Components).ThenInclude(x => x.Component).ToList().Select(x => x.GetViewModel).ToList(); } public PCViewModel? Insert(PCBindingModel model) @@ -52,10 +52,15 @@ namespace ComputerStoreDatabaseImplement.Implements var newPC = PC.Create(context, model); if(newPC == null) { return null; } - context.PCs.Add(newPC); + context.PCS.Add(newPC); + + + context.SaveChanges(); - var pc = context.PCs.FirstOrDefault(x => x.Name.Equals(model.Name)); + + + var pc = context.PCS.FirstOrDefault(x => x.Name.Equals(model.Name)); PC.EnterPCID(context, pc); return newPC.GetViewModel; @@ -67,7 +72,7 @@ namespace ComputerStoreDatabaseImplement.Implements using var transaction = context.Database.BeginTransaction(); try { - var specPC = context.PCs.FirstOrDefault(x => x.ID == model.ID); + var specPC = context.PCS.FirstOrDefault(x => x.ID == model.ID); if(specPC == null) { return null; } specPC.Update(model); @@ -86,9 +91,9 @@ namespace ComputerStoreDatabaseImplement.Implements public PCViewModel? Delete(PCBindingModel model) { using var context = new ComputerStoreDatabase(); - var specPC = context.PCs.Include(x => x.Components).FirstOrDefault(x => x.ID == model.ID); + var specPC = context.PCS.Include(x => x.Components).FirstOrDefault(x => x.ID == model.ID); if(specPC == null) { return null;} - context.PCs.Remove(specPC); + context.PCS.Remove(specPC); context.SaveChanges(); return specPC.GetViewModel; } diff --git a/ComputerStoreDatabaseImplement/Migrations/20230517180637_NamingFixes.Designer.cs b/ComputerStoreDatabaseImplement/Migrations/20230517180637_NamingFixes.Designer.cs new file mode 100644 index 0000000..b3b3a49 --- /dev/null +++ b/ComputerStoreDatabaseImplement/Migrations/20230517180637_NamingFixes.Designer.cs @@ -0,0 +1,496 @@ +// +using System; +using ComputerStoreDatabaseImplement; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace ComputerStoreDatabaseImplement.Migrations +{ + [DbContext(typeof(ComputerStoreDatabase))] + [Migration("20230517180637_NamingFixes")] + partial class NamingFixes + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.5") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Component", b => + { + b.Property("ID") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("ID")); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Price") + .HasColumnType("float"); + + b.HasKey("ID"); + + b.ToTable("Components"); + }); + + modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Consignment", b => + { + b.Property("ID") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("ID")); + + b.Property("OrderID") + .HasColumnType("int"); + + b.Property("Price") + .HasColumnType("float"); + + b.Property("ProductID") + .HasColumnType("int"); + + b.HasKey("ID"); + + b.HasIndex("OrderID"); + + b.HasIndex("ProductID"); + + b.ToTable("Consignments"); + }); + + modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.ConsignmentProduct", b => + { + b.Property("ID") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("ID")); + + b.Property("ConsignmentID") + .HasColumnType("int"); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("ProductID") + .HasColumnType("int"); + + b.HasKey("ID"); + + b.HasIndex("ConsignmentID"); + + b.HasIndex("ProductID"); + + b.ToTable("ConsignmentProducts"); + }); + + modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Employee", b => + { + b.Property("ID") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("ID")); + + b.Property("FirstName") + .HasColumnType("nvarchar(max)"); + + b.Property("LastName") + .HasColumnType("nvarchar(max)"); + + b.Property("MiddleName") + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Username") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("ID"); + + b.ToTable("Employees"); + }); + + modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Order", b => + { + b.Property("ID") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("ID")); + + b.Property("DateCreate") + .HasColumnType("datetime2"); + + b.Property("DateImplement") + .HasColumnType("datetime2"); + + b.Property("Price") + .HasColumnType("float"); + + b.Property("SellerID") + .HasColumnType("int"); + + b.Property("Status") + .HasColumnType("int"); + + b.HasKey("ID"); + + b.HasIndex("SellerID"); + + b.ToTable("Orders"); + }); + + modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.PC", b => + { + b.Property("ID") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("ID")); + + b.Property("EmployeeID") + .HasColumnType("int"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Price") + .HasColumnType("float"); + + b.Property("RequestID") + .HasColumnType("int"); + + b.HasKey("ID"); + + b.HasIndex("EmployeeID"); + + b.ToTable("PCS"); + }); + + modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Product", b => + { + b.Property("ID") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("ID")); + + b.Property("EmployeeID") + .HasColumnType("int"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Price") + .HasColumnType("float"); + + b.HasKey("ID"); + + b.HasIndex("EmployeeID"); + + b.ToTable("Products"); + }); + + modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.ProductComponent", b => + { + b.Property("ID") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("ID")); + + b.Property("ComponentID") + .HasColumnType("int"); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("ProductID") + .HasColumnType("int"); + + b.HasKey("ID"); + + b.HasIndex("ComponentID"); + + b.HasIndex("ProductID"); + + b.ToTable("ProductComponents"); + }); + + modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Request", b => + { + b.Property("ID") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("ID")); + + b.Property("OrderID") + .HasColumnType("int"); + + b.Property("PCID") + .HasColumnType("int"); + + b.Property("Price") + .HasColumnType("float"); + + b.HasKey("ID"); + + b.HasIndex("OrderID"); + + b.ToTable("Requests"); + }); + + modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.RequestComponent", b => + { + b.Property("ID") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("ID")); + + b.Property("ComponentID") + .HasColumnType("int"); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("PCID") + .HasColumnType("int"); + + b.Property("RequestID") + .HasColumnType("int"); + + b.HasKey("ID"); + + b.HasIndex("ComponentID"); + + b.HasIndex("PCID"); + + b.HasIndex("RequestID"); + + b.ToTable("RequestComponents"); + }); + + modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Seller", b => + { + b.Property("ID") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("ID")); + + b.Property("FirstName") + .HasColumnType("nvarchar(max)"); + + b.Property("LastName") + .HasColumnType("nvarchar(max)"); + + b.Property("MiddleName") + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Username") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("ID"); + + b.ToTable("Sellers"); + }); + + modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Consignment", b => + { + b.HasOne("ComputerStoreDatabaseImplement.Models.Order", "Order") + .WithMany("_consignments") + .HasForeignKey("OrderID") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("ComputerStoreDatabaseImplement.Models.Product", null) + .WithMany("Consignments") + .HasForeignKey("ProductID"); + + b.Navigation("Order"); + }); + + modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.ConsignmentProduct", b => + { + b.HasOne("ComputerStoreDatabaseImplement.Models.Consignment", "Consignment") + .WithMany("Products") + .HasForeignKey("ConsignmentID") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("ComputerStoreDatabaseImplement.Models.Product", "Product") + .WithMany() + .HasForeignKey("ProductID") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Consignment"); + + b.Navigation("Product"); + }); + + modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Order", b => + { + b.HasOne("ComputerStoreDatabaseImplement.Models.Seller", "Seller") + .WithMany("Orders") + .HasForeignKey("SellerID") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Seller"); + }); + + modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.PC", b => + { + b.HasOne("ComputerStoreDatabaseImplement.Models.Employee", "Employee") + .WithMany("PCs") + .HasForeignKey("EmployeeID") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Employee"); + }); + + modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Product", b => + { + b.HasOne("ComputerStoreDatabaseImplement.Models.Employee", "Employee") + .WithMany("Products") + .HasForeignKey("EmployeeID") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Employee"); + }); + + modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.ProductComponent", b => + { + b.HasOne("ComputerStoreDatabaseImplement.Models.Component", "Component") + .WithMany("ConsignmentComponents") + .HasForeignKey("ComponentID") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("ComputerStoreDatabaseImplement.Models.Product", "Product") + .WithMany("Components") + .HasForeignKey("ProductID") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Component"); + + b.Navigation("Product"); + }); + + modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Request", b => + { + b.HasOne("ComputerStoreDatabaseImplement.Models.Order", "Order") + .WithMany("_requests") + .HasForeignKey("OrderID") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Order"); + }); + + modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.RequestComponent", b => + { + b.HasOne("ComputerStoreDatabaseImplement.Models.Component", "Component") + .WithMany("RequestComponents") + .HasForeignKey("ComponentID") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("ComputerStoreDatabaseImplement.Models.PC", "PC") + .WithMany("Components") + .HasForeignKey("PCID"); + + b.HasOne("ComputerStoreDatabaseImplement.Models.Request", "Request") + .WithMany("PCs") + .HasForeignKey("RequestID") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Component"); + + b.Navigation("PC"); + + b.Navigation("Request"); + }); + + modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Component", b => + { + b.Navigation("ConsignmentComponents"); + + b.Navigation("RequestComponents"); + }); + + modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Consignment", b => + { + b.Navigation("Products"); + }); + + modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Employee", b => + { + b.Navigation("PCs"); + + b.Navigation("Products"); + }); + + modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Order", b => + { + b.Navigation("_consignments"); + + b.Navigation("_requests"); + }); + + modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.PC", b => + { + b.Navigation("Components"); + }); + + modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Product", b => + { + b.Navigation("Components"); + + b.Navigation("Consignments"); + }); + + modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Request", b => + { + b.Navigation("PCs"); + }); + + modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Seller", b => + { + b.Navigation("Orders"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/ComputerStoreDatabaseImplement/Migrations/20230517180637_NamingFixes.cs b/ComputerStoreDatabaseImplement/Migrations/20230517180637_NamingFixes.cs new file mode 100644 index 0000000..7aeb063 --- /dev/null +++ b/ComputerStoreDatabaseImplement/Migrations/20230517180637_NamingFixes.cs @@ -0,0 +1,100 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace ComputerStoreDatabaseImplement.Migrations +{ + /// + public partial class NamingFixes : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_PCs_Employees_EmployeeID", + table: "PCs"); + + migrationBuilder.DropForeignKey( + name: "FK_RequestComponents_PCs_PCID", + table: "RequestComponents"); + + migrationBuilder.DropPrimaryKey( + name: "PK_PCs", + table: "PCs"); + + migrationBuilder.RenameTable( + name: "PCs", + newName: "PCS"); + + migrationBuilder.RenameIndex( + name: "IX_PCs_EmployeeID", + table: "PCS", + newName: "IX_PCS_EmployeeID"); + + migrationBuilder.AddPrimaryKey( + name: "PK_PCS", + table: "PCS", + column: "ID"); + + migrationBuilder.AddForeignKey( + name: "FK_PCS_Employees_EmployeeID", + table: "PCS", + column: "EmployeeID", + principalTable: "Employees", + principalColumn: "ID", + onDelete: ReferentialAction.Cascade); + + migrationBuilder.AddForeignKey( + name: "FK_RequestComponents_PCS_PCID", + table: "RequestComponents", + column: "PCID", + principalTable: "PCS", + principalColumn: "ID"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_PCS_Employees_EmployeeID", + table: "PCS"); + + migrationBuilder.DropForeignKey( + name: "FK_RequestComponents_PCS_PCID", + table: "RequestComponents"); + + migrationBuilder.DropPrimaryKey( + name: "PK_PCS", + table: "PCS"); + + migrationBuilder.RenameTable( + name: "PCS", + newName: "PCs"); + + migrationBuilder.RenameIndex( + name: "IX_PCS_EmployeeID", + table: "PCs", + newName: "IX_PCs_EmployeeID"); + + migrationBuilder.AddPrimaryKey( + name: "PK_PCs", + table: "PCs", + column: "ID"); + + migrationBuilder.AddForeignKey( + name: "FK_PCs_Employees_EmployeeID", + table: "PCs", + column: "EmployeeID", + principalTable: "Employees", + principalColumn: "ID", + onDelete: ReferentialAction.Cascade); + + migrationBuilder.AddForeignKey( + name: "FK_RequestComponents_PCs_PCID", + table: "RequestComponents", + column: "PCID", + principalTable: "PCs", + principalColumn: "ID"); + } + } +} diff --git a/ComputerStoreDatabaseImplement/Migrations/ComputerStoreDatabaseModelSnapshot.cs b/ComputerStoreDatabaseImplement/Migrations/ComputerStoreDatabaseModelSnapshot.cs index f6b3b2d..e71bf33 100644 --- a/ComputerStoreDatabaseImplement/Migrations/ComputerStoreDatabaseModelSnapshot.cs +++ b/ComputerStoreDatabaseImplement/Migrations/ComputerStoreDatabaseModelSnapshot.cs @@ -17,7 +17,7 @@ namespace ComputerStoreDatabaseImplement.Migrations { #pragma warning disable 612, 618 modelBuilder - .HasAnnotation("ProductVersion", "7.0.4") + .HasAnnotation("ProductVersion", "7.0.5") .HasAnnotation("Relational:MaxIdentifierLength", 128); SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); @@ -179,7 +179,7 @@ namespace ComputerStoreDatabaseImplement.Migrations b.HasIndex("EmployeeID"); - b.ToTable("PCs"); + b.ToTable("PCS"); }); modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Product", b => diff --git a/ComputerStoreDatabaseImplement/Models/PC.cs b/ComputerStoreDatabaseImplement/Models/PC.cs index 172ee89..6872c9e 100644 --- a/ComputerStoreDatabaseImplement/Models/PC.cs +++ b/ComputerStoreDatabaseImplement/Models/PC.cs @@ -112,7 +112,7 @@ namespace ComputerStoreDatabaseImplement.Models context.SaveChanges(); } - var pc = context.PCs.First(rec => model.ID == ID); + var pc = context.PCS.First(rec => model.ID == ID); foreach(var pcc in model.PCComponents ) { context.RequestComponents.Add(new RequestComponent diff --git a/ComputerStoreDatabaseImplement/Models/Request.cs b/ComputerStoreDatabaseImplement/Models/Request.cs index ba7a768..9dfe196 100644 --- a/ComputerStoreDatabaseImplement/Models/Request.cs +++ b/ComputerStoreDatabaseImplement/Models/Request.cs @@ -8,7 +8,6 @@ using System.ComponentModel.DataAnnotations; using System.Linq; using System.Text; using System.Threading.Tasks; -using Azure.Core; using ComputerStoreContracts.SearchModels; using Microsoft.EntityFrameworkCore; using System.Xml.Linq; @@ -71,7 +70,7 @@ namespace ComputerStoreDatabaseImplement.Models OrderID = OrderID, Price = Price, PCID = PCID, - PCName = context.PCs.FirstOrDefault(rec => rec.ID == PCID)?.Name + PCName = context.PCS.FirstOrDefault(rec => rec.ID == PCID)?.Name }; } } diff --git a/ComputerStoreRestAPI/ComputerStoreRestAPI.csproj b/ComputerStoreRestAPI/ComputerStoreRestAPI.csproj index 13bf231..6dc7a2b 100644 --- a/ComputerStoreRestAPI/ComputerStoreRestAPI.csproj +++ b/ComputerStoreRestAPI/ComputerStoreRestAPI.csproj @@ -8,6 +8,10 @@ + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + diff --git a/ComputerStoreRestAPI/Program.cs b/ComputerStoreRestAPI/Program.cs index ea66968..9ca0a4e 100644 --- a/ComputerStoreRestAPI/Program.cs +++ b/ComputerStoreRestAPI/Program.cs @@ -1,7 +1,10 @@ using ComputerStoreBusinessLogic.BusinessLogic; +using ComputerStoreContracts.BindingModels; using ComputerStoreContracts.BusinessLogicContracts; using ComputerStoreContracts.StorageContracts; +using ComputerStoreDatabaseImplement; using ComputerStoreDatabaseImplement.Implements; +using ComputerStoreDatabaseImplement.Models; var builder = WebApplication.CreateBuilder(args); @@ -33,8 +36,22 @@ builder.Services.AddControllers().AddNewtonsoftJson(x => x.SerializerSettings.Re builder.Services.AddEndpointsApiExplorer(); builder.Services.AddSwaggerGen(); +AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true); + +using (var context = new ComputerStoreDatabase()) +{ + context.RequestComponents.Add(new RequestComponent { RequestID = 1, ComponentID = 1, Count = 1 }); + context.RequestComponents.Add(new RequestComponent { RequestID = 1, ComponentID = 2, Count = 2 }); + context.RequestComponents.Add(new RequestComponent { RequestID = 1, ComponentID = 3, Count = 3 }); + context.RequestComponents.Add(new RequestComponent { RequestID = 2, ComponentID = 1, Count = 1 }); + context.RequestComponents.Add(new RequestComponent { RequestID = 2, ComponentID = 2, Count = 1 }); + context.SaveChanges(); +} + + var app = builder.Build(); + // Configure the HTTP request pipeline. if (app.Environment.IsDevelopment()) {