IDK...
This commit is contained in:
parent
89eaf4c5b4
commit
156f8dc820
@ -21,7 +21,7 @@ namespace ComputerStoreDatabaseImplement
|
|||||||
|
|
||||||
public virtual DbSet<Component> Components { get; set; }
|
public virtual DbSet<Component> Components { get; set; }
|
||||||
public virtual DbSet<Product> Products { get; set; }
|
public virtual DbSet<Product> Products { get; set; }
|
||||||
public virtual DbSet<PC> PCs { get; set; }
|
public virtual DbSet<PC> PCS { get; set; }
|
||||||
public virtual DbSet<Employee> Employees { get; set; }
|
public virtual DbSet<Employee> Employees { get; set; }
|
||||||
public virtual DbSet<RequestComponent> RequestComponents { get; set; }
|
public virtual DbSet<RequestComponent> RequestComponents { get; set; }
|
||||||
public virtual DbSet<ProductComponent> ProductComponents { get; set; }
|
public virtual DbSet<ProductComponent> ProductComponents { get; set; }
|
||||||
|
@ -7,8 +7,8 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.4" />
|
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.5" />
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.4" />
|
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.5" />
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.4">
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.4">
|
||||||
<PrivateAssets>all</PrivateAssets>
|
<PrivateAssets>all</PrivateAssets>
|
||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
@ -20,4 +20,8 @@
|
|||||||
<ProjectReference Include="..\ComputerStoreDataModels\ComputerStoreDataModels.csproj" />
|
<ProjectReference Include="..\ComputerStoreDataModels\ComputerStoreDataModels.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Folder Include="Migrations\" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
@ -21,7 +21,7 @@ namespace ComputerStoreDatabaseImplement.Implements
|
|||||||
if (string.IsNullOrEmpty(model.Name) && !model.ID.HasValue) { return null; }
|
if (string.IsNullOrEmpty(model.Name) && !model.ID.HasValue) { return null; }
|
||||||
|
|
||||||
using var context = new ComputerStoreDatabase();
|
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)
|
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<PCViewModel> GetFullList()
|
public List<PCViewModel> GetFullList()
|
||||||
{
|
{
|
||||||
using var context = new ComputerStoreDatabase();
|
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)
|
public PCViewModel? Insert(PCBindingModel model)
|
||||||
@ -52,10 +52,15 @@ namespace ComputerStoreDatabaseImplement.Implements
|
|||||||
var newPC = PC.Create(context, model);
|
var newPC = PC.Create(context, model);
|
||||||
if(newPC == null) { return null; }
|
if(newPC == null) { return null; }
|
||||||
|
|
||||||
context.PCs.Add(newPC);
|
context.PCS.Add(newPC);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
context.SaveChanges();
|
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);
|
PC.EnterPCID(context, pc);
|
||||||
|
|
||||||
return newPC.GetViewModel;
|
return newPC.GetViewModel;
|
||||||
@ -67,7 +72,7 @@ namespace ComputerStoreDatabaseImplement.Implements
|
|||||||
using var transaction = context.Database.BeginTransaction();
|
using var transaction = context.Database.BeginTransaction();
|
||||||
try
|
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; }
|
if(specPC == null) { return null; }
|
||||||
|
|
||||||
specPC.Update(model);
|
specPC.Update(model);
|
||||||
@ -86,9 +91,9 @@ namespace ComputerStoreDatabaseImplement.Implements
|
|||||||
public PCViewModel? Delete(PCBindingModel model)
|
public PCViewModel? Delete(PCBindingModel model)
|
||||||
{
|
{
|
||||||
using var context = new ComputerStoreDatabase();
|
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;}
|
if(specPC == null) { return null;}
|
||||||
context.PCs.Remove(specPC);
|
context.PCS.Remove(specPC);
|
||||||
context.SaveChanges();
|
context.SaveChanges();
|
||||||
return specPC.GetViewModel;
|
return specPC.GetViewModel;
|
||||||
}
|
}
|
||||||
|
496
ComputerStoreDatabaseImplement/Migrations/20230517180637_NamingFixes.Designer.cs
generated
Normal file
496
ComputerStoreDatabaseImplement/Migrations/20230517180637_NamingFixes.Designer.cs
generated
Normal file
@ -0,0 +1,496 @@
|
|||||||
|
// <auto-generated />
|
||||||
|
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
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
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<int>("ID")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("ID"));
|
||||||
|
|
||||||
|
b.Property<string>("Name")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.Property<double>("Price")
|
||||||
|
.HasColumnType("float");
|
||||||
|
|
||||||
|
b.HasKey("ID");
|
||||||
|
|
||||||
|
b.ToTable("Components");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Consignment", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("ID")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("ID"));
|
||||||
|
|
||||||
|
b.Property<int>("OrderID")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<double>("Price")
|
||||||
|
.HasColumnType("float");
|
||||||
|
|
||||||
|
b.Property<int?>("ProductID")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.HasKey("ID");
|
||||||
|
|
||||||
|
b.HasIndex("OrderID");
|
||||||
|
|
||||||
|
b.HasIndex("ProductID");
|
||||||
|
|
||||||
|
b.ToTable("Consignments");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.ConsignmentProduct", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("ID")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("ID"));
|
||||||
|
|
||||||
|
b.Property<int>("ConsignmentID")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<int>("Count")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<int>("ProductID")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.HasKey("ID");
|
||||||
|
|
||||||
|
b.HasIndex("ConsignmentID");
|
||||||
|
|
||||||
|
b.HasIndex("ProductID");
|
||||||
|
|
||||||
|
b.ToTable("ConsignmentProducts");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Employee", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("ID")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("ID"));
|
||||||
|
|
||||||
|
b.Property<string>("FirstName")
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.Property<string>("LastName")
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.Property<string>("MiddleName")
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.Property<string>("Password")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.Property<string>("Username")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.HasKey("ID");
|
||||||
|
|
||||||
|
b.ToTable("Employees");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Order", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("ID")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("ID"));
|
||||||
|
|
||||||
|
b.Property<DateTime>("DateCreate")
|
||||||
|
.HasColumnType("datetime2");
|
||||||
|
|
||||||
|
b.Property<DateTime?>("DateImplement")
|
||||||
|
.HasColumnType("datetime2");
|
||||||
|
|
||||||
|
b.Property<double>("Price")
|
||||||
|
.HasColumnType("float");
|
||||||
|
|
||||||
|
b.Property<int>("SellerID")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<int>("Status")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.HasKey("ID");
|
||||||
|
|
||||||
|
b.HasIndex("SellerID");
|
||||||
|
|
||||||
|
b.ToTable("Orders");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.PC", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("ID")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("ID"));
|
||||||
|
|
||||||
|
b.Property<int>("EmployeeID")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<string>("Name")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.Property<double>("Price")
|
||||||
|
.HasColumnType("float");
|
||||||
|
|
||||||
|
b.Property<int>("RequestID")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.HasKey("ID");
|
||||||
|
|
||||||
|
b.HasIndex("EmployeeID");
|
||||||
|
|
||||||
|
b.ToTable("PCS");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Product", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("ID")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("ID"));
|
||||||
|
|
||||||
|
b.Property<int>("EmployeeID")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<string>("Name")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.Property<double>("Price")
|
||||||
|
.HasColumnType("float");
|
||||||
|
|
||||||
|
b.HasKey("ID");
|
||||||
|
|
||||||
|
b.HasIndex("EmployeeID");
|
||||||
|
|
||||||
|
b.ToTable("Products");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.ProductComponent", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("ID")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("ID"));
|
||||||
|
|
||||||
|
b.Property<int>("ComponentID")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<int>("Count")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<int>("ProductID")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.HasKey("ID");
|
||||||
|
|
||||||
|
b.HasIndex("ComponentID");
|
||||||
|
|
||||||
|
b.HasIndex("ProductID");
|
||||||
|
|
||||||
|
b.ToTable("ProductComponents");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Request", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("ID")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("ID"));
|
||||||
|
|
||||||
|
b.Property<int>("OrderID")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<int?>("PCID")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<double>("Price")
|
||||||
|
.HasColumnType("float");
|
||||||
|
|
||||||
|
b.HasKey("ID");
|
||||||
|
|
||||||
|
b.HasIndex("OrderID");
|
||||||
|
|
||||||
|
b.ToTable("Requests");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.RequestComponent", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("ID")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("ID"));
|
||||||
|
|
||||||
|
b.Property<int>("ComponentID")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<int>("Count")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<int?>("PCID")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<int>("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<int>("ID")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("ID"));
|
||||||
|
|
||||||
|
b.Property<string>("FirstName")
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.Property<string>("LastName")
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.Property<string>("MiddleName")
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.Property<string>("Password")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.Property<string>("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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,100 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace ComputerStoreDatabaseImplement.Migrations
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
public partial class NamingFixes : Migration
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
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");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
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");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -17,7 +17,7 @@ namespace ComputerStoreDatabaseImplement.Migrations
|
|||||||
{
|
{
|
||||||
#pragma warning disable 612, 618
|
#pragma warning disable 612, 618
|
||||||
modelBuilder
|
modelBuilder
|
||||||
.HasAnnotation("ProductVersion", "7.0.4")
|
.HasAnnotation("ProductVersion", "7.0.5")
|
||||||
.HasAnnotation("Relational:MaxIdentifierLength", 128);
|
.HasAnnotation("Relational:MaxIdentifierLength", 128);
|
||||||
|
|
||||||
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
|
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
|
||||||
@ -179,7 +179,7 @@ namespace ComputerStoreDatabaseImplement.Migrations
|
|||||||
|
|
||||||
b.HasIndex("EmployeeID");
|
b.HasIndex("EmployeeID");
|
||||||
|
|
||||||
b.ToTable("PCs");
|
b.ToTable("PCS");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Product", b =>
|
modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Product", b =>
|
||||||
|
@ -112,7 +112,7 @@ namespace ComputerStoreDatabaseImplement.Models
|
|||||||
context.SaveChanges();
|
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 )
|
foreach(var pcc in model.PCComponents )
|
||||||
{
|
{
|
||||||
context.RequestComponents.Add(new RequestComponent
|
context.RequestComponents.Add(new RequestComponent
|
||||||
|
@ -8,7 +8,6 @@ using System.ComponentModel.DataAnnotations;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Azure.Core;
|
|
||||||
using ComputerStoreContracts.SearchModels;
|
using ComputerStoreContracts.SearchModels;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using System.Xml.Linq;
|
using System.Xml.Linq;
|
||||||
@ -71,7 +70,7 @@ namespace ComputerStoreDatabaseImplement.Models
|
|||||||
OrderID = OrderID,
|
OrderID = OrderID,
|
||||||
Price = Price,
|
Price = Price,
|
||||||
PCID = PCID,
|
PCID = PCID,
|
||||||
PCName = context.PCs.FirstOrDefault(rec => rec.ID == PCID)?.Name
|
PCName = context.PCS.FirstOrDefault(rec => rec.ID == PCID)?.Name
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,10 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="6.0.0" />
|
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="6.0.0" />
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.5">
|
||||||
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
</PackageReference>
|
||||||
<PackageReference Include="Microsoft.Extensions.Logging.Log4Net.AspNetCore" Version="6.1.0" />
|
<PackageReference Include="Microsoft.Extensions.Logging.Log4Net.AspNetCore" Version="6.1.0" />
|
||||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
|
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
@ -1,7 +1,10 @@
|
|||||||
using ComputerStoreBusinessLogic.BusinessLogic;
|
using ComputerStoreBusinessLogic.BusinessLogic;
|
||||||
|
using ComputerStoreContracts.BindingModels;
|
||||||
using ComputerStoreContracts.BusinessLogicContracts;
|
using ComputerStoreContracts.BusinessLogicContracts;
|
||||||
using ComputerStoreContracts.StorageContracts;
|
using ComputerStoreContracts.StorageContracts;
|
||||||
|
using ComputerStoreDatabaseImplement;
|
||||||
using ComputerStoreDatabaseImplement.Implements;
|
using ComputerStoreDatabaseImplement.Implements;
|
||||||
|
using ComputerStoreDatabaseImplement.Models;
|
||||||
|
|
||||||
var builder = WebApplication.CreateBuilder(args);
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
|
|
||||||
@ -33,8 +36,22 @@ builder.Services.AddControllers().AddNewtonsoftJson(x => x.SerializerSettings.Re
|
|||||||
builder.Services.AddEndpointsApiExplorer();
|
builder.Services.AddEndpointsApiExplorer();
|
||||||
builder.Services.AddSwaggerGen();
|
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();
|
var app = builder.Build();
|
||||||
|
|
||||||
|
|
||||||
// Configure the HTTP request pipeline.
|
// Configure the HTTP request pipeline.
|
||||||
if (app.Environment.IsDevelopment())
|
if (app.Environment.IsDevelopment())
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user