Подсчет суммы и цены

This commit is contained in:
dasha 2023-04-02 19:27:58 +04:00
parent 6789b86723
commit 3db96eaaa1
8 changed files with 1480 additions and 9 deletions

View File

@ -85,7 +85,7 @@ namespace HardwareShopDatabaseImplement.Implements.Storekeeper
public ComponentViewModel? Insert(ComponentBindingModel model) public ComponentViewModel? Insert(ComponentBindingModel model)
{ {
using var context = new HardwareShopDatabase(); using var context = new HardwareShopDatabase();
var newComponent = Component.Create(context, model); var newComponent = Component.Create(model);
if (newComponent == null) if (newComponent == null)
{ {
return null; return null;

View File

@ -0,0 +1,508 @@
// <auto-generated />
using System;
using HardwareShopDatabaseImplement;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace HardwareShopDatabaseImplement.Migrations
{
[DbContext(typeof(HardwareShopDatabase))]
[Migration("20230402135808_init")]
partial class init
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "7.0.4")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("HardwareShopDatabaseImplement.Models.ManyToMany.ComponentBuild", b =>
{
b.Property<int>("ComponentId")
.HasColumnType("integer");
b.Property<int>("BuildId")
.HasColumnType("integer");
b.Property<int>("Count")
.HasColumnType("integer");
b.HasKey("ComponentId", "BuildId");
b.HasIndex("BuildId");
b.ToTable("ComponentsBuilds");
});
modelBuilder.Entity("HardwareShopDatabaseImplement.Models.ManyToMany.GoodComponent", b =>
{
b.Property<int>("GoodId")
.HasColumnType("integer");
b.Property<int>("ComponentId")
.HasColumnType("integer");
b.Property<int>("Count")
.HasColumnType("integer");
b.HasKey("GoodId", "ComponentId");
b.HasIndex("ComponentId");
b.ToTable("GoodsComponents");
});
modelBuilder.Entity("HardwareShopDatabaseImplement.Models.ManyToMany.PurchaseBuild", b =>
{
b.Property<int>("PurchaseId")
.HasColumnType("integer");
b.Property<int>("BuildId")
.HasColumnType("integer");
b.Property<int>("Count")
.HasColumnType("integer");
b.HasKey("PurchaseId", "BuildId");
b.HasIndex("BuildId");
b.ToTable("PurchasesBuilds");
});
modelBuilder.Entity("HardwareShopDatabaseImplement.Models.ManyToMany.PurchaseGood", b =>
{
b.Property<int>("PurchaseId")
.HasColumnType("integer");
b.Property<int>("GoodId")
.HasColumnType("integer");
b.Property<int>("Count")
.HasColumnType("integer");
b.HasKey("PurchaseId", "GoodId");
b.HasIndex("GoodId");
b.ToTable("PurchasesGoods");
});
modelBuilder.Entity("HardwareShopDatabaseImplement.Models.Storekeeper.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("HardwareShopDatabaseImplement.Models.Storekeeper.Good", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("GoodName")
.IsRequired()
.HasColumnType("text");
b.Property<double>("Price")
.HasColumnType("double precision");
b.Property<int>("UserId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("Goods");
});
modelBuilder.Entity("HardwareShopDatabaseImplement.Models.Storekeeper.Order", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<int>("Count")
.HasColumnType("integer");
b.Property<DateTime>("DateCreate")
.HasColumnType("timestamp with time zone");
b.Property<DateTime?>("DateImplement")
.HasColumnType("timestamp with time zone");
b.Property<int>("GoodId")
.HasColumnType("integer");
b.Property<int>("Status")
.HasColumnType("integer");
b.Property<double>("Sum")
.HasColumnType("double precision");
b.Property<int>("UserId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("GoodId");
b.HasIndex("UserId");
b.ToTable("Orders");
});
modelBuilder.Entity("HardwareShopDatabaseImplement.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.HasIndex("Email")
.IsUnique();
b.HasIndex("Login")
.IsUnique();
b.ToTable("Users");
});
modelBuilder.Entity("HardwareShopDatabaseImplement.Models.Worker.Build", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("BuildName")
.IsRequired()
.HasColumnType("text");
b.Property<double>("Price")
.HasColumnType("double precision");
b.Property<int>("UserId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("Builds");
});
modelBuilder.Entity("HardwareShopDatabaseImplement.Models.Worker.Comment", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<int>("BuildId")
.HasColumnType("integer");
b.Property<string>("Text")
.IsRequired()
.HasColumnType("text");
b.Property<int>("UserId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("BuildId");
b.HasIndex("UserId");
b.ToTable("Comments");
});
modelBuilder.Entity("HardwareShopDatabaseImplement.Models.Worker.Purchase", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<DateTime?>("DatePurchase")
.HasColumnType("timestamp with time zone");
b.Property<int>("PurchaseStatus")
.HasColumnType("integer");
b.Property<double>("Sum")
.HasColumnType("double precision");
b.Property<int>("UserId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("Purchases");
});
modelBuilder.Entity("HardwareShopDatabaseImplement.Models.ManyToMany.ComponentBuild", b =>
{
b.HasOne("HardwareShopDatabaseImplement.Models.Worker.Build", "Build")
.WithMany("Components")
.HasForeignKey("BuildId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("HardwareShopDatabaseImplement.Models.Storekeeper.Component", "Component")
.WithMany("Builds")
.HasForeignKey("ComponentId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Build");
b.Navigation("Component");
});
modelBuilder.Entity("HardwareShopDatabaseImplement.Models.ManyToMany.GoodComponent", b =>
{
b.HasOne("HardwareShopDatabaseImplement.Models.Storekeeper.Component", "Component")
.WithMany("Goods")
.HasForeignKey("ComponentId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("HardwareShopDatabaseImplement.Models.Storekeeper.Good", "Good")
.WithMany("Components")
.HasForeignKey("GoodId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Component");
b.Navigation("Good");
});
modelBuilder.Entity("HardwareShopDatabaseImplement.Models.ManyToMany.PurchaseBuild", b =>
{
b.HasOne("HardwareShopDatabaseImplement.Models.Worker.Build", "Build")
.WithMany("Purchases")
.HasForeignKey("BuildId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("HardwareShopDatabaseImplement.Models.Worker.Purchase", "Purchase")
.WithMany("Builds")
.HasForeignKey("PurchaseId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Build");
b.Navigation("Purchase");
});
modelBuilder.Entity("HardwareShopDatabaseImplement.Models.ManyToMany.PurchaseGood", b =>
{
b.HasOne("HardwareShopDatabaseImplement.Models.Storekeeper.Good", "Good")
.WithMany("Purchases")
.HasForeignKey("GoodId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("HardwareShopDatabaseImplement.Models.Worker.Purchase", "Purchase")
.WithMany("Goods")
.HasForeignKey("PurchaseId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Good");
b.Navigation("Purchase");
});
modelBuilder.Entity("HardwareShopDatabaseImplement.Models.Storekeeper.Component", b =>
{
b.HasOne("HardwareShopDatabaseImplement.Models.User", "User")
.WithMany("Components")
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("User");
});
modelBuilder.Entity("HardwareShopDatabaseImplement.Models.Storekeeper.Good", b =>
{
b.HasOne("HardwareShopDatabaseImplement.Models.User", "User")
.WithMany("Goods")
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("User");
});
modelBuilder.Entity("HardwareShopDatabaseImplement.Models.Storekeeper.Order", b =>
{
b.HasOne("HardwareShopDatabaseImplement.Models.Storekeeper.Good", "Good")
.WithMany("Orders")
.HasForeignKey("GoodId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("HardwareShopDatabaseImplement.Models.User", "User")
.WithMany("Orders")
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Good");
b.Navigation("User");
});
modelBuilder.Entity("HardwareShopDatabaseImplement.Models.Worker.Build", b =>
{
b.HasOne("HardwareShopDatabaseImplement.Models.User", "User")
.WithMany("Builds")
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("User");
});
modelBuilder.Entity("HardwareShopDatabaseImplement.Models.Worker.Comment", b =>
{
b.HasOne("HardwareShopDatabaseImplement.Models.Worker.Build", "Build")
.WithMany("Comments")
.HasForeignKey("BuildId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("HardwareShopDatabaseImplement.Models.User", "User")
.WithMany("Comments")
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Build");
b.Navigation("User");
});
modelBuilder.Entity("HardwareShopDatabaseImplement.Models.Worker.Purchase", b =>
{
b.HasOne("HardwareShopDatabaseImplement.Models.User", "User")
.WithMany("Purchases")
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("User");
});
modelBuilder.Entity("HardwareShopDatabaseImplement.Models.Storekeeper.Component", b =>
{
b.Navigation("Builds");
b.Navigation("Goods");
});
modelBuilder.Entity("HardwareShopDatabaseImplement.Models.Storekeeper.Good", b =>
{
b.Navigation("Components");
b.Navigation("Orders");
b.Navigation("Purchases");
});
modelBuilder.Entity("HardwareShopDatabaseImplement.Models.User", b =>
{
b.Navigation("Builds");
b.Navigation("Comments");
b.Navigation("Components");
b.Navigation("Goods");
b.Navigation("Orders");
b.Navigation("Purchases");
});
modelBuilder.Entity("HardwareShopDatabaseImplement.Models.Worker.Build", b =>
{
b.Navigation("Comments");
b.Navigation("Components");
b.Navigation("Purchases");
});
modelBuilder.Entity("HardwareShopDatabaseImplement.Models.Worker.Purchase", b =>
{
b.Navigation("Builds");
b.Navigation("Goods");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -0,0 +1,384 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace HardwareShopDatabaseImplement.Migrations
{
/// <inheritdoc />
public partial class init : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Users",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
Login = table.Column<string>(type: "text", nullable: false),
Email = table.Column<string>(type: "text", nullable: false),
Password = table.Column<string>(type: "text", nullable: false),
Role = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Users", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Builds",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
Price = table.Column<double>(type: "double precision", nullable: false),
BuildName = table.Column<string>(type: "text", nullable: false),
UserId = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Builds", x => x.Id);
table.ForeignKey(
name: "FK_Builds_Users_UserId",
column: x => x.UserId,
principalTable: "Users",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "Components",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
ComponentName = table.Column<string>(type: "text", nullable: false),
Cost = table.Column<double>(type: "double precision", nullable: false),
UserId = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Components", x => x.Id);
table.ForeignKey(
name: "FK_Components_Users_UserId",
column: x => x.UserId,
principalTable: "Users",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "Goods",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
GoodName = table.Column<string>(type: "text", nullable: false),
Price = table.Column<double>(type: "double precision", nullable: false),
UserId = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Goods", x => x.Id);
table.ForeignKey(
name: "FK_Goods_Users_UserId",
column: x => x.UserId,
principalTable: "Users",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "Purchases",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
Sum = table.Column<double>(type: "double precision", nullable: false),
PurchaseStatus = table.Column<int>(type: "integer", nullable: false),
DatePurchase = table.Column<DateTime>(type: "timestamp with time zone", nullable: true),
UserId = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Purchases", x => x.Id);
table.ForeignKey(
name: "FK_Purchases_Users_UserId",
column: x => x.UserId,
principalTable: "Users",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "Comments",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
Text = table.Column<string>(type: "text", nullable: false),
BuildId = table.Column<int>(type: "integer", nullable: false),
UserId = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Comments", x => x.Id);
table.ForeignKey(
name: "FK_Comments_Builds_BuildId",
column: x => x.BuildId,
principalTable: "Builds",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_Comments_Users_UserId",
column: x => x.UserId,
principalTable: "Users",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "ComponentsBuilds",
columns: table => new
{
BuildId = table.Column<int>(type: "integer", nullable: false),
ComponentId = table.Column<int>(type: "integer", nullable: false),
Count = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_ComponentsBuilds", x => new { x.ComponentId, x.BuildId });
table.ForeignKey(
name: "FK_ComponentsBuilds_Builds_BuildId",
column: x => x.BuildId,
principalTable: "Builds",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_ComponentsBuilds_Components_ComponentId",
column: x => x.ComponentId,
principalTable: "Components",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "GoodsComponents",
columns: table => new
{
GoodId = table.Column<int>(type: "integer", nullable: false),
ComponentId = table.Column<int>(type: "integer", nullable: false),
Count = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_GoodsComponents", x => new { x.GoodId, x.ComponentId });
table.ForeignKey(
name: "FK_GoodsComponents_Components_ComponentId",
column: x => x.ComponentId,
principalTable: "Components",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_GoodsComponents_Goods_GoodId",
column: x => x.GoodId,
principalTable: "Goods",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "Orders",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
GoodId = table.Column<int>(type: "integer", nullable: false),
UserId = table.Column<int>(type: "integer", nullable: false),
Count = table.Column<int>(type: "integer", nullable: false),
Sum = table.Column<double>(type: "double precision", nullable: false),
Status = table.Column<int>(type: "integer", nullable: false),
DateCreate = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
DateImplement = table.Column<DateTime>(type: "timestamp with time zone", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Orders", x => x.Id);
table.ForeignKey(
name: "FK_Orders_Goods_GoodId",
column: x => x.GoodId,
principalTable: "Goods",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_Orders_Users_UserId",
column: x => x.UserId,
principalTable: "Users",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "PurchasesBuilds",
columns: table => new
{
BuildId = table.Column<int>(type: "integer", nullable: false),
PurchaseId = table.Column<int>(type: "integer", nullable: false),
Count = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_PurchasesBuilds", x => new { x.PurchaseId, x.BuildId });
table.ForeignKey(
name: "FK_PurchasesBuilds_Builds_BuildId",
column: x => x.BuildId,
principalTable: "Builds",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_PurchasesBuilds_Purchases_PurchaseId",
column: x => x.PurchaseId,
principalTable: "Purchases",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "PurchasesGoods",
columns: table => new
{
PurchaseId = table.Column<int>(type: "integer", nullable: false),
GoodId = table.Column<int>(type: "integer", nullable: false),
Count = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_PurchasesGoods", x => new { x.PurchaseId, x.GoodId });
table.ForeignKey(
name: "FK_PurchasesGoods_Goods_GoodId",
column: x => x.GoodId,
principalTable: "Goods",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_PurchasesGoods_Purchases_PurchaseId",
column: x => x.PurchaseId,
principalTable: "Purchases",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_Builds_UserId",
table: "Builds",
column: "UserId");
migrationBuilder.CreateIndex(
name: "IX_Comments_BuildId",
table: "Comments",
column: "BuildId");
migrationBuilder.CreateIndex(
name: "IX_Comments_UserId",
table: "Comments",
column: "UserId");
migrationBuilder.CreateIndex(
name: "IX_Components_UserId",
table: "Components",
column: "UserId");
migrationBuilder.CreateIndex(
name: "IX_ComponentsBuilds_BuildId",
table: "ComponentsBuilds",
column: "BuildId");
migrationBuilder.CreateIndex(
name: "IX_Goods_UserId",
table: "Goods",
column: "UserId");
migrationBuilder.CreateIndex(
name: "IX_GoodsComponents_ComponentId",
table: "GoodsComponents",
column: "ComponentId");
migrationBuilder.CreateIndex(
name: "IX_Orders_GoodId",
table: "Orders",
column: "GoodId");
migrationBuilder.CreateIndex(
name: "IX_Orders_UserId",
table: "Orders",
column: "UserId");
migrationBuilder.CreateIndex(
name: "IX_Purchases_UserId",
table: "Purchases",
column: "UserId");
migrationBuilder.CreateIndex(
name: "IX_PurchasesBuilds_BuildId",
table: "PurchasesBuilds",
column: "BuildId");
migrationBuilder.CreateIndex(
name: "IX_PurchasesGoods_GoodId",
table: "PurchasesGoods",
column: "GoodId");
migrationBuilder.CreateIndex(
name: "IX_Users_Email",
table: "Users",
column: "Email",
unique: true);
migrationBuilder.CreateIndex(
name: "IX_Users_Login",
table: "Users",
column: "Login",
unique: true);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Comments");
migrationBuilder.DropTable(
name: "ComponentsBuilds");
migrationBuilder.DropTable(
name: "GoodsComponents");
migrationBuilder.DropTable(
name: "Orders");
migrationBuilder.DropTable(
name: "PurchasesBuilds");
migrationBuilder.DropTable(
name: "PurchasesGoods");
migrationBuilder.DropTable(
name: "Components");
migrationBuilder.DropTable(
name: "Builds");
migrationBuilder.DropTable(
name: "Goods");
migrationBuilder.DropTable(
name: "Purchases");
migrationBuilder.DropTable(
name: "Users");
}
}
}

View File

@ -0,0 +1,505 @@
// <auto-generated />
using System;
using HardwareShopDatabaseImplement;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace HardwareShopDatabaseImplement.Migrations
{
[DbContext(typeof(HardwareShopDatabase))]
partial class HardwareShopDatabaseModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "7.0.4")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("HardwareShopDatabaseImplement.Models.ManyToMany.ComponentBuild", b =>
{
b.Property<int>("ComponentId")
.HasColumnType("integer");
b.Property<int>("BuildId")
.HasColumnType("integer");
b.Property<int>("Count")
.HasColumnType("integer");
b.HasKey("ComponentId", "BuildId");
b.HasIndex("BuildId");
b.ToTable("ComponentsBuilds");
});
modelBuilder.Entity("HardwareShopDatabaseImplement.Models.ManyToMany.GoodComponent", b =>
{
b.Property<int>("GoodId")
.HasColumnType("integer");
b.Property<int>("ComponentId")
.HasColumnType("integer");
b.Property<int>("Count")
.HasColumnType("integer");
b.HasKey("GoodId", "ComponentId");
b.HasIndex("ComponentId");
b.ToTable("GoodsComponents");
});
modelBuilder.Entity("HardwareShopDatabaseImplement.Models.ManyToMany.PurchaseBuild", b =>
{
b.Property<int>("PurchaseId")
.HasColumnType("integer");
b.Property<int>("BuildId")
.HasColumnType("integer");
b.Property<int>("Count")
.HasColumnType("integer");
b.HasKey("PurchaseId", "BuildId");
b.HasIndex("BuildId");
b.ToTable("PurchasesBuilds");
});
modelBuilder.Entity("HardwareShopDatabaseImplement.Models.ManyToMany.PurchaseGood", b =>
{
b.Property<int>("PurchaseId")
.HasColumnType("integer");
b.Property<int>("GoodId")
.HasColumnType("integer");
b.Property<int>("Count")
.HasColumnType("integer");
b.HasKey("PurchaseId", "GoodId");
b.HasIndex("GoodId");
b.ToTable("PurchasesGoods");
});
modelBuilder.Entity("HardwareShopDatabaseImplement.Models.Storekeeper.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("HardwareShopDatabaseImplement.Models.Storekeeper.Good", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("GoodName")
.IsRequired()
.HasColumnType("text");
b.Property<double>("Price")
.HasColumnType("double precision");
b.Property<int>("UserId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("Goods");
});
modelBuilder.Entity("HardwareShopDatabaseImplement.Models.Storekeeper.Order", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<int>("Count")
.HasColumnType("integer");
b.Property<DateTime>("DateCreate")
.HasColumnType("timestamp with time zone");
b.Property<DateTime?>("DateImplement")
.HasColumnType("timestamp with time zone");
b.Property<int>("GoodId")
.HasColumnType("integer");
b.Property<int>("Status")
.HasColumnType("integer");
b.Property<double>("Sum")
.HasColumnType("double precision");
b.Property<int>("UserId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("GoodId");
b.HasIndex("UserId");
b.ToTable("Orders");
});
modelBuilder.Entity("HardwareShopDatabaseImplement.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.HasIndex("Email")
.IsUnique();
b.HasIndex("Login")
.IsUnique();
b.ToTable("Users");
});
modelBuilder.Entity("HardwareShopDatabaseImplement.Models.Worker.Build", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("BuildName")
.IsRequired()
.HasColumnType("text");
b.Property<double>("Price")
.HasColumnType("double precision");
b.Property<int>("UserId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("Builds");
});
modelBuilder.Entity("HardwareShopDatabaseImplement.Models.Worker.Comment", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<int>("BuildId")
.HasColumnType("integer");
b.Property<string>("Text")
.IsRequired()
.HasColumnType("text");
b.Property<int>("UserId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("BuildId");
b.HasIndex("UserId");
b.ToTable("Comments");
});
modelBuilder.Entity("HardwareShopDatabaseImplement.Models.Worker.Purchase", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<DateTime?>("DatePurchase")
.HasColumnType("timestamp with time zone");
b.Property<int>("PurchaseStatus")
.HasColumnType("integer");
b.Property<double>("Sum")
.HasColumnType("double precision");
b.Property<int>("UserId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("Purchases");
});
modelBuilder.Entity("HardwareShopDatabaseImplement.Models.ManyToMany.ComponentBuild", b =>
{
b.HasOne("HardwareShopDatabaseImplement.Models.Worker.Build", "Build")
.WithMany("Components")
.HasForeignKey("BuildId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("HardwareShopDatabaseImplement.Models.Storekeeper.Component", "Component")
.WithMany("Builds")
.HasForeignKey("ComponentId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Build");
b.Navigation("Component");
});
modelBuilder.Entity("HardwareShopDatabaseImplement.Models.ManyToMany.GoodComponent", b =>
{
b.HasOne("HardwareShopDatabaseImplement.Models.Storekeeper.Component", "Component")
.WithMany("Goods")
.HasForeignKey("ComponentId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("HardwareShopDatabaseImplement.Models.Storekeeper.Good", "Good")
.WithMany("Components")
.HasForeignKey("GoodId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Component");
b.Navigation("Good");
});
modelBuilder.Entity("HardwareShopDatabaseImplement.Models.ManyToMany.PurchaseBuild", b =>
{
b.HasOne("HardwareShopDatabaseImplement.Models.Worker.Build", "Build")
.WithMany("Purchases")
.HasForeignKey("BuildId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("HardwareShopDatabaseImplement.Models.Worker.Purchase", "Purchase")
.WithMany("Builds")
.HasForeignKey("PurchaseId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Build");
b.Navigation("Purchase");
});
modelBuilder.Entity("HardwareShopDatabaseImplement.Models.ManyToMany.PurchaseGood", b =>
{
b.HasOne("HardwareShopDatabaseImplement.Models.Storekeeper.Good", "Good")
.WithMany("Purchases")
.HasForeignKey("GoodId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("HardwareShopDatabaseImplement.Models.Worker.Purchase", "Purchase")
.WithMany("Goods")
.HasForeignKey("PurchaseId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Good");
b.Navigation("Purchase");
});
modelBuilder.Entity("HardwareShopDatabaseImplement.Models.Storekeeper.Component", b =>
{
b.HasOne("HardwareShopDatabaseImplement.Models.User", "User")
.WithMany("Components")
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("User");
});
modelBuilder.Entity("HardwareShopDatabaseImplement.Models.Storekeeper.Good", b =>
{
b.HasOne("HardwareShopDatabaseImplement.Models.User", "User")
.WithMany("Goods")
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("User");
});
modelBuilder.Entity("HardwareShopDatabaseImplement.Models.Storekeeper.Order", b =>
{
b.HasOne("HardwareShopDatabaseImplement.Models.Storekeeper.Good", "Good")
.WithMany("Orders")
.HasForeignKey("GoodId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("HardwareShopDatabaseImplement.Models.User", "User")
.WithMany("Orders")
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Good");
b.Navigation("User");
});
modelBuilder.Entity("HardwareShopDatabaseImplement.Models.Worker.Build", b =>
{
b.HasOne("HardwareShopDatabaseImplement.Models.User", "User")
.WithMany("Builds")
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("User");
});
modelBuilder.Entity("HardwareShopDatabaseImplement.Models.Worker.Comment", b =>
{
b.HasOne("HardwareShopDatabaseImplement.Models.Worker.Build", "Build")
.WithMany("Comments")
.HasForeignKey("BuildId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("HardwareShopDatabaseImplement.Models.User", "User")
.WithMany("Comments")
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Build");
b.Navigation("User");
});
modelBuilder.Entity("HardwareShopDatabaseImplement.Models.Worker.Purchase", b =>
{
b.HasOne("HardwareShopDatabaseImplement.Models.User", "User")
.WithMany("Purchases")
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("User");
});
modelBuilder.Entity("HardwareShopDatabaseImplement.Models.Storekeeper.Component", b =>
{
b.Navigation("Builds");
b.Navigation("Goods");
});
modelBuilder.Entity("HardwareShopDatabaseImplement.Models.Storekeeper.Good", b =>
{
b.Navigation("Components");
b.Navigation("Orders");
b.Navigation("Purchases");
});
modelBuilder.Entity("HardwareShopDatabaseImplement.Models.User", b =>
{
b.Navigation("Builds");
b.Navigation("Comments");
b.Navigation("Components");
b.Navigation("Goods");
b.Navigation("Orders");
b.Navigation("Purchases");
});
modelBuilder.Entity("HardwareShopDatabaseImplement.Models.Worker.Build", b =>
{
b.Navigation("Comments");
b.Navigation("Components");
b.Navigation("Purchases");
});
modelBuilder.Entity("HardwareShopDatabaseImplement.Models.Worker.Purchase", b =>
{
b.Navigation("Builds");
b.Navigation("Goods");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -1,6 +1,7 @@
using HardwareShopContracts.BindingModels; using HardwareShopContracts.BindingModels;
using HardwareShopContracts.ViewModels; using HardwareShopContracts.ViewModels;
using HardwareShopDatabaseImplement.Models.ManyToMany; using HardwareShopDatabaseImplement.Models.ManyToMany;
using HardwareShopDatabaseImplement.Models.Worker;
using HardwareShopDataModels.Models; using HardwareShopDataModels.Models;
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema; using System.ComponentModel.DataAnnotations.Schema;
@ -103,6 +104,12 @@ namespace HardwareShopDatabaseImplement.Models.Storekeeper
Build = context.Builds.First(x => x.Id == cb.Key), Build = context.Builds.First(x => x.Id == cb.Key),
Count = cb.Value.Item2 Count = cb.Value.Item2
}); });
var build = context.Builds.First(x => x.Id == cb.Key);
if (build != null)
{
build.Price += cb.Value.Item2 * component.Cost;
}
context.SaveChanges(); context.SaveChanges();
} }
_componentsBuilds = null; _componentsBuilds = null;

View File

@ -25,22 +25,22 @@ namespace HardwareShopDatabaseImplement.Models
[Required] [Required]
public UserRole Role { get; set; } = UserRole.Неизвестен; public UserRole Role { get; set; } = UserRole.Неизвестен;
[ForeignKey("ClientId")] [ForeignKey("UserId")]
public virtual List<Order> Orders { get; set; } = new(); public virtual List<Order> Orders { get; set; } = new();
[ForeignKey("ClientId")] [ForeignKey("UserId")]
public virtual List<Build> Builds { get; set; } = new(); public virtual List<Build> Builds { get; set; } = new();
[ForeignKey("ClientId")] [ForeignKey("UserId")]
public virtual List<Comment> Comments { get; set; } = new(); public virtual List<Comment> Comments { get; set; } = new();
[ForeignKey("ClientId")] [ForeignKey("UserId")]
public virtual List<Purchase> Purchases { get; set; } = new(); public virtual List<Purchase> Purchases { get; set; } = new();
[ForeignKey("ClientId")] [ForeignKey("UserId")]
public virtual List<Component> Components { get; set; } = new(); public virtual List<Component> Components { get; set; } = new();
[ForeignKey("ClientId")] [ForeignKey("UserId")]
public virtual List<Good> Goods { get; set; } = new(); public virtual List<Good> Goods { get; set; } = new();

View File

@ -55,6 +55,7 @@ namespace HardwareShopDatabaseImplement.Models.Worker
Id = model.Id, Id = model.Id,
BuildName = model.BuildName, BuildName = model.BuildName,
UserId = model.UserId, UserId = model.UserId,
Price = model.Price
}; };
} }
@ -90,7 +91,7 @@ namespace HardwareShopDatabaseImplement.Models.Worker
context.SaveChanges(); context.SaveChanges();
} }
var build = context.Builds.First(x => x.Id == Id); var build = context.Builds.First(x => x.Id == Id);
//добавляем в бд блюда которые есть в моделе, но ещё нет в бд //добавляем в бд элементы которые есть в модели, но ещё нет в бд
foreach (var bp in model.BuildPurchases) foreach (var bp in model.BuildPurchases)
{ {
context.PurchasesBuilds.Add(new PurchaseBuild context.PurchasesBuilds.Add(new PurchaseBuild
@ -102,7 +103,7 @@ namespace HardwareShopDatabaseImplement.Models.Worker
var purchase = context.Purchases.First(x => x.Id == bp.Key); var purchase = context.Purchases.First(x => x.Id == bp.Key);
if (purchase != null) if (purchase != null)
{ {
purchase.Sum += bp.Value.Item2* build.Price; purchase.Sum += bp.Value.Item2 * build.Price;
} }
context.SaveChanges(); context.SaveChanges();

View File

@ -0,0 +1,66 @@
using HardwareShopContracts.BindingModels;
using HardwareShopContracts.BusinessLogicsContracts;
using Microsoft.AspNetCore.Mvc;
namespace HardwareShopRestApi.Controllers
{
[Route("api/[controller]/[action]")]
[ApiController]
public class MainController : Controller
{
private readonly ILogger _logger;
private readonly IPurchaseLogic _purchase;
private readonly IBuildLogic _build;
public MainController(ILogger<MainController> logger, IPurchaseLogic pur, IBuildLogic build)
{
_logger = logger;
_purchase = pur;
_build = build;
}
[HttpPost]
public void CreateBuild(BuildBindingModel model)
{
try
{
_build.Create(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка создания");
throw;
}
}
[HttpPost]
public void CreatePurchase(PurchaseBindingModel model)
{
try
{
_purchase.Create(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка создания");
throw;
}
}
[HttpPut]
public void UpdateBuild(BuildBindingModel model)
{
try
{
_build.Update(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка обновления");
throw;
}
}
}
}