Compare commits
3 Commits
525d9fe140
...
2f8ac27943
Author | SHA1 | Date | |
---|---|---|---|
2f8ac27943 | |||
4e68232dfd | |||
1f7fb4f849 |
@ -14,7 +14,7 @@ namespace ComputerShopContracts.BindingModels
|
||||
|
||||
public string Category { get; set; } = string.Empty;
|
||||
|
||||
public Dictionary<int, (IComponentModel, int)> AssemblyComponents { get; set; } = new();
|
||||
public Dictionary<int, IComponentModel> AssemblyComponents { get; set; } = new();
|
||||
|
||||
public Dictionary<int, int> Test { get; set; } = new();
|
||||
}
|
||||
|
@ -16,6 +16,6 @@ namespace ComputerShopContracts.BindingModels
|
||||
|
||||
public int Warranty { get; set; }
|
||||
|
||||
public Dictionary<int, (IComponentModel, int)> ProductComponents { get; set; } = new();
|
||||
public Dictionary<int, IComponentModel> ProductComponents { get; set; } = new();
|
||||
}
|
||||
}
|
||||
|
@ -18,6 +18,6 @@ namespace ComputerShopContracts.ViewModels
|
||||
[DisplayName("Категория")]
|
||||
public string Category { get; set; } = string.Empty;
|
||||
|
||||
public Dictionary<int, (IComponentModel, int)> AssemblyComponents { get; set; } = new();
|
||||
public Dictionary<int, IComponentModel> AssemblyComponents { get; set; } = new();
|
||||
}
|
||||
}
|
||||
|
@ -23,6 +23,6 @@ namespace ComputerShopContracts.ViewModels
|
||||
[DisplayName("Гарантия (мес.)")]
|
||||
public int Warranty { get; set; }
|
||||
|
||||
public Dictionary<int, (IComponentModel, int)> ProductComponents { get; set; } = new();
|
||||
public Dictionary<int, IComponentModel> ProductComponents { get; set; } = new();
|
||||
}
|
||||
}
|
||||
|
@ -28,6 +28,6 @@
|
||||
/// <summary>
|
||||
/// Список комплектующих
|
||||
/// </summary>
|
||||
Dictionary<int, (IComponentModel, int)> AssemblyComponents { get; }
|
||||
Dictionary<int, IComponentModel> AssemblyComponents { get; }
|
||||
}
|
||||
}
|
||||
|
@ -28,7 +28,7 @@
|
||||
/// <summary>
|
||||
/// Список комплектующих
|
||||
/// </summary>
|
||||
Dictionary<int, (IComponentModel, int)> ProductComponents { get; }
|
||||
Dictionary<int, IComponentModel> ProductComponents { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Привязка товара к партии товаров
|
||||
|
@ -24,7 +24,7 @@ namespace ComputerShopDatabaseImplement.Implements
|
||||
{
|
||||
using var Context = new ComputerShopDatabase();
|
||||
|
||||
// Optional search by Category name
|
||||
// Optional search by Category
|
||||
if (!string.IsNullOrEmpty(Model.Category))
|
||||
{
|
||||
return Context.Assemblies
|
||||
@ -35,6 +35,7 @@ namespace ComputerShopDatabaseImplement.Implements
|
||||
.ToList();
|
||||
}
|
||||
|
||||
// Search by UserId by default
|
||||
return Context.Assemblies
|
||||
.Include(x => x.Components)
|
||||
.ThenInclude(x => x.Component)
|
||||
|
@ -106,7 +106,7 @@ namespace ComputerShopDatabaseImplement.Implements
|
||||
ComponentName = x.ComponentName,
|
||||
ComponentCost = x.Cost,
|
||||
Shipments = x.ProductComponents
|
||||
.Select(y => (y.Count, y.Product.ProductName, y.Product.Price, y.Product.Shipment!.ProviderName, y.Product.Shipment.DateShipment))
|
||||
.Select(y => (0, y.Product.ProductName, y.Product.Price, y.Product.Shipment!.ProviderName, y.Product.Shipment.DateShipment))
|
||||
.ToList(),
|
||||
})
|
||||
.ToList();
|
||||
|
@ -37,6 +37,7 @@ namespace ComputerShopDatabaseImplement.Implements
|
||||
.ToList();
|
||||
}
|
||||
|
||||
// Search by UserId by default
|
||||
return Context.Products
|
||||
.Include(x => x.Shipment)
|
||||
.Include(x => x.Components)
|
||||
|
@ -0,0 +1,516 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using ComputerShopDatabaseImplement;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace ComputerShopDatabaseImplement.Migrations
|
||||
{
|
||||
[DbContext(typeof(ComputerShopDatabase))]
|
||||
[Migration("20240528105815_Edit AssemblyComponent and ProductComponent")]
|
||||
partial class EditAssemblyComponentandProductComponent
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "7.0.18")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||
|
||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("ComputerShopDatabaseImplement.Models.Assembly", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("AssemblyName")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("Category")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<double>("Price")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.Property<int>("UserId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("UserId");
|
||||
|
||||
b.ToTable("Assemblies");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ComputerShopDatabaseImplement.Models.AssemblyComponent", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("AssemblyId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("ComponentId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("AssemblyId");
|
||||
|
||||
b.HasIndex("ComponentId");
|
||||
|
||||
b.ToTable("AssemblyComponents");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ComputerShopDatabaseImplement.Models.Component", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("ComponentName")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<double>("Cost")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.Property<int>("UserId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("UserId");
|
||||
|
||||
b.ToTable("Components");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ComputerShopDatabaseImplement.Models.Order", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<DateTime>("DateCreate")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.Property<int>("Status")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<double>("Sum")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.Property<int>("UserId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("UserId");
|
||||
|
||||
b.ToTable("Orders");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ComputerShopDatabaseImplement.Models.Product", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<double>("Price")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.Property<string>("ProductName")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int?>("ShipmentId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("UserId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("Warranty")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ShipmentId");
|
||||
|
||||
b.HasIndex("UserId");
|
||||
|
||||
b.ToTable("Products");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ComputerShopDatabaseImplement.Models.ProductComponent", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("ComponentId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("ProductId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ComponentId");
|
||||
|
||||
b.HasIndex("ProductId");
|
||||
|
||||
b.ToTable("ProductComponents");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ComputerShopDatabaseImplement.Models.Request", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int?>("AssemblyId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<string>("ClientFIO")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTime>("DateRequest")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.Property<int>("UserId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("AssemblyId");
|
||||
|
||||
b.HasIndex("UserId");
|
||||
|
||||
b.ToTable("Requests");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ComputerShopDatabaseImplement.Models.RequestOrder", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("OrderId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("RequestId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("OrderId");
|
||||
|
||||
b.HasIndex("RequestId");
|
||||
|
||||
b.ToTable("RequestOrders");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ComputerShopDatabaseImplement.Models.Shipment", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<DateTime>("DateShipment")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.Property<string>("ProviderName")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int>("UserId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("UserId");
|
||||
|
||||
b.ToTable("Shipments");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ComputerShopDatabaseImplement.Models.ShipmentOrder", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("OrderId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("ShipmentId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("OrderId");
|
||||
|
||||
b.HasIndex("ShipmentId");
|
||||
|
||||
b.ToTable("ShipmentOrders");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ComputerShopDatabaseImplement.Models.User", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Email")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("Login")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("Password")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int>("Role")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Users");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ComputerShopDatabaseImplement.Models.Assembly", b =>
|
||||
{
|
||||
b.HasOne("ComputerShopDatabaseImplement.Models.User", null)
|
||||
.WithMany("Assemblies")
|
||||
.HasForeignKey("UserId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ComputerShopDatabaseImplement.Models.AssemblyComponent", b =>
|
||||
{
|
||||
b.HasOne("ComputerShopDatabaseImplement.Models.Assembly", "Assembly")
|
||||
.WithMany("Components")
|
||||
.HasForeignKey("AssemblyId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("ComputerShopDatabaseImplement.Models.Component", "Component")
|
||||
.WithMany("AssemblyComponents")
|
||||
.HasForeignKey("ComponentId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Assembly");
|
||||
|
||||
b.Navigation("Component");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ComputerShopDatabaseImplement.Models.Component", b =>
|
||||
{
|
||||
b.HasOne("ComputerShopDatabaseImplement.Models.User", null)
|
||||
.WithMany("Components")
|
||||
.HasForeignKey("UserId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ComputerShopDatabaseImplement.Models.Order", b =>
|
||||
{
|
||||
b.HasOne("ComputerShopDatabaseImplement.Models.User", null)
|
||||
.WithMany("Orders")
|
||||
.HasForeignKey("UserId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ComputerShopDatabaseImplement.Models.Product", b =>
|
||||
{
|
||||
b.HasOne("ComputerShopDatabaseImplement.Models.Shipment", "Shipment")
|
||||
.WithMany("Products")
|
||||
.HasForeignKey("ShipmentId");
|
||||
|
||||
b.HasOne("ComputerShopDatabaseImplement.Models.User", null)
|
||||
.WithMany("Products")
|
||||
.HasForeignKey("UserId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Shipment");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ComputerShopDatabaseImplement.Models.ProductComponent", b =>
|
||||
{
|
||||
b.HasOne("ComputerShopDatabaseImplement.Models.Component", "Component")
|
||||
.WithMany("ProductComponents")
|
||||
.HasForeignKey("ComponentId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("ComputerShopDatabaseImplement.Models.Product", "Product")
|
||||
.WithMany("Components")
|
||||
.HasForeignKey("ProductId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Component");
|
||||
|
||||
b.Navigation("Product");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ComputerShopDatabaseImplement.Models.Request", b =>
|
||||
{
|
||||
b.HasOne("ComputerShopDatabaseImplement.Models.Assembly", "Assembly")
|
||||
.WithMany("Requests")
|
||||
.HasForeignKey("AssemblyId");
|
||||
|
||||
b.HasOne("ComputerShopDatabaseImplement.Models.User", "User")
|
||||
.WithMany("Requests")
|
||||
.HasForeignKey("UserId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Assembly");
|
||||
|
||||
b.Navigation("User");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ComputerShopDatabaseImplement.Models.RequestOrder", b =>
|
||||
{
|
||||
b.HasOne("ComputerShopDatabaseImplement.Models.Order", "Order")
|
||||
.WithMany("Requests")
|
||||
.HasForeignKey("OrderId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("ComputerShopDatabaseImplement.Models.Request", "Request")
|
||||
.WithMany("Orders")
|
||||
.HasForeignKey("RequestId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Order");
|
||||
|
||||
b.Navigation("Request");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ComputerShopDatabaseImplement.Models.Shipment", b =>
|
||||
{
|
||||
b.HasOne("ComputerShopDatabaseImplement.Models.User", null)
|
||||
.WithMany("Shipments")
|
||||
.HasForeignKey("UserId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ComputerShopDatabaseImplement.Models.ShipmentOrder", b =>
|
||||
{
|
||||
b.HasOne("ComputerShopDatabaseImplement.Models.Order", "Order")
|
||||
.WithMany("Shipments")
|
||||
.HasForeignKey("OrderId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("ComputerShopDatabaseImplement.Models.Shipment", "Shipment")
|
||||
.WithMany("Orders")
|
||||
.HasForeignKey("ShipmentId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Order");
|
||||
|
||||
b.Navigation("Shipment");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ComputerShopDatabaseImplement.Models.Assembly", b =>
|
||||
{
|
||||
b.Navigation("Components");
|
||||
|
||||
b.Navigation("Requests");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ComputerShopDatabaseImplement.Models.Component", b =>
|
||||
{
|
||||
b.Navigation("AssemblyComponents");
|
||||
|
||||
b.Navigation("ProductComponents");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ComputerShopDatabaseImplement.Models.Order", b =>
|
||||
{
|
||||
b.Navigation("Requests");
|
||||
|
||||
b.Navigation("Shipments");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ComputerShopDatabaseImplement.Models.Product", b =>
|
||||
{
|
||||
b.Navigation("Components");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ComputerShopDatabaseImplement.Models.Request", b =>
|
||||
{
|
||||
b.Navigation("Orders");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ComputerShopDatabaseImplement.Models.Shipment", b =>
|
||||
{
|
||||
b.Navigation("Orders");
|
||||
|
||||
b.Navigation("Products");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ComputerShopDatabaseImplement.Models.User", b =>
|
||||
{
|
||||
b.Navigation("Assemblies");
|
||||
|
||||
b.Navigation("Components");
|
||||
|
||||
b.Navigation("Orders");
|
||||
|
||||
b.Navigation("Products");
|
||||
|
||||
b.Navigation("Requests");
|
||||
|
||||
b.Navigation("Shipments");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace ComputerShopDatabaseImplement.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class EditAssemblyComponentandProductComponent : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropColumn(
|
||||
name: "Count",
|
||||
table: "ProductComponents");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "Count",
|
||||
table: "AssemblyComponents");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AddColumn<int>(
|
||||
name: "Count",
|
||||
table: "ProductComponents",
|
||||
type: "integer",
|
||||
nullable: false,
|
||||
defaultValue: 0);
|
||||
|
||||
migrationBuilder.AddColumn<int>(
|
||||
name: "Count",
|
||||
table: "AssemblyComponents",
|
||||
type: "integer",
|
||||
nullable: false,
|
||||
defaultValue: 0);
|
||||
}
|
||||
}
|
||||
}
|
@ -65,9 +65,6 @@ namespace ComputerShopDatabaseImplement.Migrations
|
||||
b.Property<int>("ComponentId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("AssemblyId");
|
||||
@ -173,9 +170,6 @@ namespace ComputerShopDatabaseImplement.Migrations
|
||||
b.Property<int>("ComponentId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("ProductId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
@ -370,7 +364,7 @@ namespace ComputerShopDatabaseImplement.Migrations
|
||||
.HasForeignKey("ShipmentId");
|
||||
|
||||
b.HasOne("ComputerShopDatabaseImplement.Models.User", null)
|
||||
.WithMany("Proucts")
|
||||
.WithMany("Products")
|
||||
.HasForeignKey("UserId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
@ -507,7 +501,7 @@ namespace ComputerShopDatabaseImplement.Migrations
|
||||
|
||||
b.Navigation("Orders");
|
||||
|
||||
b.Navigation("Proucts");
|
||||
b.Navigation("Products");
|
||||
|
||||
b.Navigation("Requests");
|
||||
|
||||
|
@ -28,10 +28,10 @@ namespace ComputerShopDatabaseImplement.Models
|
||||
[ForeignKey("AssemblyId")]
|
||||
public virtual List<AssemblyComponent> Components { get; set; } = new();
|
||||
|
||||
private Dictionary<int, (IComponentModel, int)>? _assemblyComponents;
|
||||
private Dictionary<int, IComponentModel>? _assemblyComponents;
|
||||
|
||||
[NotMapped]
|
||||
public Dictionary<int, (IComponentModel, int)> AssemblyComponents
|
||||
public Dictionary<int, IComponentModel> AssemblyComponents
|
||||
{
|
||||
get
|
||||
{
|
||||
@ -39,7 +39,7 @@ namespace ComputerShopDatabaseImplement.Models
|
||||
{
|
||||
_assemblyComponents = Components.ToDictionary(
|
||||
AsmComp => AsmComp.ComponentId,
|
||||
AsmComp => (AsmComp.Component as IComponentModel, AsmComp.Count)
|
||||
AsmComp => AsmComp.Component as IComponentModel
|
||||
);
|
||||
}
|
||||
|
||||
@ -49,18 +49,22 @@ namespace ComputerShopDatabaseImplement.Models
|
||||
|
||||
public static Assembly Create(ComputerShopDatabase Context, AssemblyBindingModel Model)
|
||||
{
|
||||
return new()
|
||||
var Components = Model.AssemblyComponents
|
||||
.Select(x => new AssemblyComponent
|
||||
{
|
||||
Component = Context.Components.First(y => y.Id == x.Key)
|
||||
})
|
||||
.ToList();
|
||||
double Price = Components.Sum(x => x.Component.Cost);
|
||||
|
||||
return new Assembly()
|
||||
{
|
||||
Id = Model.Id,
|
||||
UserId = Model.UserId,
|
||||
AssemblyName = Model.AssemblyName,
|
||||
Price = Model.Price,
|
||||
Price = Price,
|
||||
Category = Model.Category,
|
||||
Components = Model.AssemblyComponents.Select(x => new AssemblyComponent
|
||||
{
|
||||
Component = Context.Components.First(y => y.Id == x.Key),
|
||||
Count = x.Value.Item2
|
||||
}).ToList(),
|
||||
Components = Components,
|
||||
};
|
||||
}
|
||||
|
||||
@ -75,8 +79,6 @@ namespace ComputerShopDatabaseImplement.Models
|
||||
{
|
||||
Category = Model.Category;
|
||||
}
|
||||
|
||||
Price = Model.Price;
|
||||
}
|
||||
|
||||
public AssemblyViewModel ViewModel => new()
|
||||
@ -91,17 +93,22 @@ namespace ComputerShopDatabaseImplement.Models
|
||||
|
||||
public void UpdateComponents(ComputerShopDatabase Context, AssemblyBindingModel Model)
|
||||
{
|
||||
// Сначала подсчитывается новая цена, т.к. Model.AssemblyComponents далее может измениться
|
||||
double NewPrice = Context.Components
|
||||
.Where(x => Model.AssemblyComponents.ContainsKey(x.Id))
|
||||
.Sum(x => x.Cost);
|
||||
|
||||
var AssemblyComponents = Context.AssemblyComponents.Where(x => x.AssemblyId == Model.Id).ToList();
|
||||
if (AssemblyComponents != null && AssemblyComponents.Count > 0)
|
||||
{
|
||||
// Удаление записей из таблицы AssemblyComponents тех компонентов, которых нет в модели
|
||||
Context.AssemblyComponents
|
||||
.RemoveRange(AssemblyComponents
|
||||
.Where(x => !Model.AssemblyComponents.ContainsKey(x.ComponentId)));
|
||||
.RemoveRange(AssemblyComponents.Where(x => !Model.AssemblyComponents.ContainsKey(x.ComponentId)));
|
||||
Context.SaveChanges();
|
||||
|
||||
// После этого в Model.AssemblyComponents останутся только те компоненты, записей о которых еще нет в БД
|
||||
foreach (var ComponentToUpdate in AssemblyComponents)
|
||||
{
|
||||
ComponentToUpdate.Count = Model.AssemblyComponents[ComponentToUpdate.ComponentId].Item2;
|
||||
Model.AssemblyComponents.Remove(ComponentToUpdate.ComponentId);
|
||||
}
|
||||
|
||||
@ -115,13 +122,31 @@ namespace ComputerShopDatabaseImplement.Models
|
||||
{
|
||||
Assembly = CurrentAssembly,
|
||||
Component = Context.Components.First(x => x.Id == AssemblyComponent.Key),
|
||||
Count = AssemblyComponent.Value.Item2
|
||||
});
|
||||
|
||||
Context.SaveChanges();
|
||||
}
|
||||
|
||||
Price = NewPrice;
|
||||
Context.SaveChanges();
|
||||
|
||||
_assemblyComponents = null;
|
||||
}
|
||||
|
||||
private void CalculatePrice(
|
||||
ComputerShopDatabase Context,
|
||||
Dictionary<int, IComponentModel> ModelComponents,
|
||||
out List<AssemblyComponent> OutComponents,
|
||||
out double OutPrice)
|
||||
{
|
||||
OutComponents = ModelComponents
|
||||
.Select(x => new AssemblyComponent
|
||||
{
|
||||
Component = Context.Components.First(y => y.Id == x.Key)
|
||||
})
|
||||
.ToList();
|
||||
|
||||
OutPrice = Components.Sum(x => x.Component.Cost);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -12,9 +12,6 @@ namespace ComputerShopDatabaseImplement.Models
|
||||
[Required]
|
||||
public int ComponentId { get; set; }
|
||||
|
||||
[Required]
|
||||
public int Count { get; set; }
|
||||
|
||||
public virtual Assembly Assembly { get; set; } = new();
|
||||
|
||||
public virtual Component Component { get; set; } = new();
|
||||
|
@ -29,10 +29,10 @@ namespace ComputerShopDatabaseImplement.Models
|
||||
[ForeignKey("ProductId")]
|
||||
public virtual List<ProductComponent> Components { get; set; } = new();
|
||||
|
||||
private Dictionary<int, (IComponentModel, int)>? _productComponents;
|
||||
private Dictionary<int, IComponentModel>? _productComponents;
|
||||
|
||||
[NotMapped]
|
||||
public Dictionary<int, (IComponentModel, int)> ProductComponents
|
||||
public Dictionary<int, IComponentModel> ProductComponents
|
||||
{
|
||||
get
|
||||
{
|
||||
@ -40,7 +40,7 @@ namespace ComputerShopDatabaseImplement.Models
|
||||
{
|
||||
_productComponents = Components.ToDictionary(
|
||||
ProdComp => ProdComp.ComponentId,
|
||||
ProdComp => (ProdComp.Component as IComponentModel, ProdComp.Count)
|
||||
ProdComp => ProdComp.Component as IComponentModel
|
||||
);
|
||||
}
|
||||
|
||||
@ -50,7 +50,15 @@ namespace ComputerShopDatabaseImplement.Models
|
||||
|
||||
public static Product Create(ComputerShopDatabase Context, ProductBindingModel Model)
|
||||
{
|
||||
return new()
|
||||
var Components = Model.ProductComponents
|
||||
.Select(x => new ProductComponent
|
||||
{
|
||||
Component = Context.Components.First(y => y.Id == x.Key)
|
||||
})
|
||||
.ToList();
|
||||
double Price = Components.Sum(x => x.Component.Cost);
|
||||
|
||||
return new Product()
|
||||
{
|
||||
Id = Model.Id,
|
||||
UserId = Model.UserId,
|
||||
@ -58,11 +66,7 @@ namespace ComputerShopDatabaseImplement.Models
|
||||
ProductName = Model.ProductName,
|
||||
Price = Model.Price,
|
||||
Warranty = Model.Warranty,
|
||||
Components = Model.ProductComponents.Select(x => new ProductComponent
|
||||
{
|
||||
Component = Context.Components.First(y => y.Id == x.Key),
|
||||
Count = x.Value.Item2
|
||||
}).ToList(),
|
||||
Components = Components,
|
||||
};
|
||||
}
|
||||
|
||||
@ -74,7 +78,6 @@ namespace ComputerShopDatabaseImplement.Models
|
||||
}
|
||||
|
||||
ShipmentId = Model.ShipmentId;
|
||||
Price = Model.Price;
|
||||
Warranty = Model.Warranty;
|
||||
}
|
||||
|
||||
@ -91,17 +94,22 @@ namespace ComputerShopDatabaseImplement.Models
|
||||
|
||||
public void UpdateComponents(ComputerShopDatabase Context, ProductBindingModel Model)
|
||||
{
|
||||
// Сначала подсчитывается новая цена, т.к. Model.ProductComponents далее может измениться
|
||||
double NewPrice = Context.Components
|
||||
.Where(x => Model.ProductComponents.ContainsKey(x.Id))
|
||||
.Sum(x => x.Cost);
|
||||
|
||||
var ProductComponents = Context.ProductComponents.Where(x => x.ProductId == Model.Id).ToList();
|
||||
if (ProductComponents != null && ProductComponents.Count > 0)
|
||||
{
|
||||
// Удаление записей из таблицы ProductComponents тех компонентов, которых нет в модели
|
||||
Context.ProductComponents
|
||||
.RemoveRange(ProductComponents
|
||||
.Where(x => !Model.ProductComponents.ContainsKey(x.ComponentId)));
|
||||
.RemoveRange(ProductComponents.Where(x => !Model.ProductComponents.ContainsKey(x.ComponentId)));
|
||||
Context.SaveChanges();
|
||||
|
||||
// После этого в Model.ProductComponents останутся только те компоненты, записей о которых еще нет в БД
|
||||
foreach (var ComponentToUpdate in ProductComponents)
|
||||
{
|
||||
ComponentToUpdate.Count = Model.ProductComponents[ComponentToUpdate.ComponentId].Item2;
|
||||
Model.ProductComponents.Remove(ComponentToUpdate.ComponentId);
|
||||
}
|
||||
|
||||
@ -115,12 +123,14 @@ namespace ComputerShopDatabaseImplement.Models
|
||||
{
|
||||
Product = CurrentProduct,
|
||||
Component = Context.Components.First(x => x.Id == ProductComponent.Key),
|
||||
Count = ProductComponent.Value.Item2
|
||||
});
|
||||
|
||||
Context.SaveChanges();
|
||||
}
|
||||
|
||||
Price = NewPrice;
|
||||
Context.SaveChanges();
|
||||
|
||||
_productComponents = null;
|
||||
}
|
||||
}
|
||||
|
@ -12,9 +12,6 @@ namespace ComputerShopDatabaseImplement.Models
|
||||
[Required]
|
||||
public int ComponentId { get; set; }
|
||||
|
||||
[Required]
|
||||
public int Count { get; set; }
|
||||
|
||||
public virtual Product Product { get; set; } = new();
|
||||
|
||||
public virtual Component Component { get; set; } = new();
|
||||
|
@ -2,13 +2,8 @@
|
||||
using ComputerShopContracts.ViewModels;
|
||||
using ComputerShopDataModels.Enums;
|
||||
using ComputerShopDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ComputerShopDatabaseImplement.Models
|
||||
{
|
||||
@ -30,19 +25,21 @@ namespace ComputerShopDatabaseImplement.Models
|
||||
|
||||
[ForeignKey("UserId")]
|
||||
public virtual List<Shipment> Shipments { get; set; } = new();
|
||||
|
||||
[ForeignKey("UserId")]
|
||||
public virtual List<Order> Orders { get; set; } = new();
|
||||
|
||||
[ForeignKey("UserId")]
|
||||
public virtual List<Request> Requests { get; set; } = new();
|
||||
|
||||
[ForeignKey("UserId")]
|
||||
public virtual List<Assembly> Assemblies { get; set; } = new();
|
||||
|
||||
[ForeignKey("UserId")]
|
||||
public virtual List<Component> Components { get; set; } = new();
|
||||
|
||||
[ForeignKey("UserId")]
|
||||
public virtual List<Product> Proucts { get; set; } = new();
|
||||
|
||||
public virtual List<Product> Products { get; set; } = new();
|
||||
|
||||
public static User Create(UserBindingModel model)
|
||||
{
|
||||
|
49
ComputerShopGuarantorApp/ApiUser.cs
Normal file
49
ComputerShopGuarantorApp/ApiUser.cs
Normal file
@ -0,0 +1,49 @@
|
||||
using ComputerShopContracts.ViewModels;
|
||||
using Newtonsoft.Json;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Text;
|
||||
|
||||
namespace ComputerShopGuarantorApp
|
||||
{
|
||||
public static class ApiUser
|
||||
{
|
||||
private static readonly HttpClient _client = new();
|
||||
|
||||
public static UserViewModel? User { get; set; } = null;
|
||||
|
||||
public static void Connect(IConfiguration Configuration)
|
||||
{
|
||||
_client.BaseAddress = new Uri(Configuration["IPAddress"]);
|
||||
_client.DefaultRequestHeaders.Accept.Clear();
|
||||
_client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
|
||||
}
|
||||
|
||||
public static T? GetRequest<T>(string RequestUrl)
|
||||
{
|
||||
var Response = _client.GetAsync(RequestUrl);
|
||||
var Result = Response.Result.Content.ReadAsStringAsync().Result;
|
||||
|
||||
if (Response.Result.IsSuccessStatusCode)
|
||||
{
|
||||
return JsonConvert.DeserializeObject<T>(Result);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception(Result);
|
||||
}
|
||||
}
|
||||
|
||||
public static void PostRequest<T>(string RequestUrl, T Model)
|
||||
{
|
||||
var Json = JsonConvert.SerializeObject(Model);
|
||||
var Data = new StringContent(Json, Encoding.UTF8, "application/json");
|
||||
var Response = _client.PostAsync(RequestUrl, Data);
|
||||
var Result = Response.Result.Content.ReadAsStringAsync().Result;
|
||||
|
||||
if (!Response.Result.IsSuccessStatusCode)
|
||||
{
|
||||
throw new Exception(Result);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -6,4 +6,12 @@
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\ComputerShopContracts\ComputerShopContracts.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
@ -1,27 +1,30 @@
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
using ComputerShopGuarantorApp;
|
||||
|
||||
var Builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
// Add services to the container.
|
||||
builder.Services.AddControllersWithViews();
|
||||
Builder.Services.AddControllersWithViews();
|
||||
|
||||
var app = builder.Build();
|
||||
var App = Builder.Build();
|
||||
ApiUser.Connect(Builder.Configuration);
|
||||
|
||||
// Configure the HTTP request pipeline.
|
||||
if (!app.Environment.IsDevelopment())
|
||||
if (!App.Environment.IsDevelopment())
|
||||
{
|
||||
app.UseExceptionHandler("/Home/Error");
|
||||
App.UseExceptionHandler("/Home/Error");
|
||||
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
|
||||
app.UseHsts();
|
||||
App.UseHsts();
|
||||
}
|
||||
|
||||
app.UseHttpsRedirection();
|
||||
app.UseStaticFiles();
|
||||
App.UseHttpsRedirection();
|
||||
App.UseStaticFiles();
|
||||
|
||||
app.UseRouting();
|
||||
App.UseRouting();
|
||||
|
||||
app.UseAuthorization();
|
||||
App.UseAuthorization();
|
||||
|
||||
app.MapControllerRoute(
|
||||
App.MapControllerRoute(
|
||||
name: "default",
|
||||
pattern: "{controller=Home}/{action=Index}/{id?}");
|
||||
|
||||
app.Run();
|
||||
App.Run();
|
||||
|
@ -3,34 +3,40 @@
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>@ViewData["Title"] - ComputerShopGuarantorApp</title>
|
||||
<title>@ViewData["Title"] - Поручитель</title>
|
||||
<link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css" />
|
||||
<link rel="stylesheet" href="~/css/site.css" asp-append-version="true" />
|
||||
<link rel="stylesheet" href="~/ComputerShopGuarantorApp.styles.css" asp-append-version="true" />
|
||||
</head>
|
||||
<body>
|
||||
<body class="d-flex flex-column min-vh-100" padding="56px">
|
||||
<header>
|
||||
<nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light bg-white border-bottom box-shadow mb-3">
|
||||
<div class="container-fluid">
|
||||
<a class="navbar-brand" asp-area="" asp-controller="Home" asp-action="Index">ComputerShopGuarantorApp</a>
|
||||
<nav class="navbar fixed-top navbar-expand-lg navbar-dark bg-dark">
|
||||
<div class="container-md">
|
||||
<a class="navbar-brand" asp-area="" asp-controller="Home" asp-action="Index"><span class="fw-bold text-uppercase ms-2">Приложение поручителя</span></a>
|
||||
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target=".navbar-collapse" aria-controls="navbarSupportedContent"
|
||||
aria-expanded="false" aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
<div class="navbar-collapse collapse d-sm-inline-flex justify-content-between">
|
||||
<ul class="navbar-nav flex-grow-1">
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Index">Home</a>
|
||||
<div class="collapse navbar-collapse justify-content-end align-center" id="main-nav">
|
||||
<ul class="navbar-nav">
|
||||
<li class="nav-item me-3">
|
||||
<a class="nav-link" asp-area="" asp-controller="Home" asp-action="Index">Главная</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Privacy">Privacy</a>
|
||||
<li class="nav-item me-3">
|
||||
<a class="nav-link" asp-area="" asp-controller="Home" asp-action="Privacy">Privacy</a>
|
||||
</li>
|
||||
<li class="nav-item d-lg-none">
|
||||
<a class="nav-link text-light" asp-area="" asp-controller="Home" asp-action="Privacy">Вход в аккаунт</a>
|
||||
</li>
|
||||
<li class="nav-item d-none d-lg-inline">
|
||||
<a class="btn btn-light" asp-area="" asp-controller="Home" asp-action="Privacy">Вход в аккаунт</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
</header>
|
||||
<div class="container">
|
||||
<div class="container-md py-4 mb-4">
|
||||
<main role="main" class="pb-3">
|
||||
@RenderBody()
|
||||
</main>
|
||||
|
@ -1,6 +1,10 @@
|
||||
/* Please see documentation at https://docs.microsoft.com/aspnet/core/client-side/bundling-and-minification
|
||||
for details on configuring this project to bundle and minify static web assets. */
|
||||
|
||||
body {
|
||||
background-color: #ff0000;
|
||||
}
|
||||
|
||||
a.navbar-brand {
|
||||
white-space: normal;
|
||||
text-align: center;
|
||||
@ -46,3 +50,4 @@ button.accept-policy {
|
||||
white-space: nowrap;
|
||||
line-height: 60px;
|
||||
}
|
||||
|
@ -5,5 +5,6 @@
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*"
|
||||
"AllowedHosts": "*",
|
||||
"IPAddress": "http://localhost:5024"
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user