Почти всё
This commit is contained in:
parent
32c42afffa
commit
7f95f9d161
@ -0,0 +1,14 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace JewelryStoreContracts.ViewModels
|
||||||
|
{
|
||||||
|
public class JewelCount
|
||||||
|
{
|
||||||
|
public JewelViewModel Jewel { get; set; }
|
||||||
|
public int Count { get; set; } = new();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,14 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace JewelryStoreContracts.ViewModels
|
||||||
|
{
|
||||||
|
public class ShopJewelViewModel
|
||||||
|
{
|
||||||
|
public StoreViewModel Shop { get; set; } = new();
|
||||||
|
public Dictionary<int, JewelCount> ShopJewel { get; set; } = new();
|
||||||
|
}
|
||||||
|
}
|
@ -5,121 +5,75 @@ using Microsoft.EntityFrameworkCore.Migrations;
|
|||||||
|
|
||||||
namespace JewelryStoreDatabaseImplement.Migrations
|
namespace JewelryStoreDatabaseImplement.Migrations
|
||||||
{
|
{
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public partial class InitialCreate : Migration
|
public partial class Hard_init : Migration
|
||||||
{
|
{
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
protected override void Up(MigrationBuilder migrationBuilder)
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
{
|
{
|
||||||
migrationBuilder.CreateTable(
|
migrationBuilder.CreateTable(
|
||||||
name: "Components",
|
name: "Shops",
|
||||||
columns: table => new
|
columns: table => new
|
||||||
{
|
{
|
||||||
Id = table.Column<int>(type: "int", nullable: false)
|
Id = table.Column<int>(type: "int", nullable: false)
|
||||||
.Annotation("SqlServer:Identity", "1, 1"),
|
.Annotation("SqlServer:Identity", "1, 1"),
|
||||||
ComponentName = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
ShopName = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||||
Cost = table.Column<double>(type: "float", nullable: false)
|
Adress = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||||
},
|
OpeningDate = table.Column<DateTime>(type: "datetime2", nullable: false),
|
||||||
constraints: table =>
|
JewelMaxCount = table.Column<int>(type: "int", nullable: false)
|
||||||
{
|
},
|
||||||
table.PrimaryKey("PK_Components", x => x.Id);
|
constraints: table =>
|
||||||
});
|
{
|
||||||
|
table.PrimaryKey("PK_Shops", x => x.Id);
|
||||||
|
});
|
||||||
|
|
||||||
migrationBuilder.CreateTable(
|
migrationBuilder.CreateTable(
|
||||||
name: "Jewels",
|
name: "ShopJewels",
|
||||||
columns: table => new
|
columns: table => new
|
||||||
{
|
{
|
||||||
Id = table.Column<int>(type: "int", nullable: false)
|
Id = table.Column<int>(type: "int", nullable: false)
|
||||||
.Annotation("SqlServer:Identity", "1, 1"),
|
.Annotation("SqlServer:Identity", "1, 1"),
|
||||||
JewelName = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
JewelId = table.Column<int>(type: "int", nullable: false),
|
||||||
Price = table.Column<double>(type: "float", nullable: false)
|
ShopId = table.Column<int>(type: "int", nullable: false),
|
||||||
},
|
Count = table.Column<int>(type: "int", nullable: false)
|
||||||
constraints: table =>
|
},
|
||||||
{
|
constraints: table =>
|
||||||
table.PrimaryKey("PK_Jewels", x => x.Id);
|
{
|
||||||
});
|
table.PrimaryKey("PK_ShopJewels", x => x.Id);
|
||||||
|
table.ForeignKey(
|
||||||
|
name: "FK_ShopJewels_Jewels_JewelId",
|
||||||
|
column: x => x.JewelId,
|
||||||
|
principalTable: "Jewels",
|
||||||
|
principalColumn: "Id",
|
||||||
|
onDelete: ReferentialAction.Cascade);
|
||||||
|
table.ForeignKey(
|
||||||
|
name: "FK_ShopJewels_Shops_ShopId",
|
||||||
|
column: x => x.ShopId,
|
||||||
|
principalTable: "Shops",
|
||||||
|
principalColumn: "Id",
|
||||||
|
onDelete: ReferentialAction.Cascade);
|
||||||
|
});
|
||||||
|
|
||||||
migrationBuilder.CreateTable(
|
migrationBuilder.CreateIndex(
|
||||||
name: "JewelComponents",
|
name: "IX_ShopJewels_JewelId",
|
||||||
columns: table => new
|
table: "ShopJewels",
|
||||||
{
|
column: "JewelId");
|
||||||
Id = table.Column<int>(type: "int", nullable: false)
|
|
||||||
.Annotation("SqlServer:Identity", "1, 1"),
|
|
||||||
JewelId = table.Column<int>(type: "int", nullable: false),
|
|
||||||
ComponentId = table.Column<int>(type: "int", nullable: false),
|
|
||||||
Count = table.Column<int>(type: "int", nullable: false)
|
|
||||||
},
|
|
||||||
constraints: table =>
|
|
||||||
{
|
|
||||||
table.PrimaryKey("PK_JewelComponents", x => x.Id);
|
|
||||||
table.ForeignKey(
|
|
||||||
name: "FK_JewelComponents_Components_ComponentId",
|
|
||||||
column: x => x.ComponentId,
|
|
||||||
principalTable: "Components",
|
|
||||||
principalColumn: "Id",
|
|
||||||
onDelete: ReferentialAction.Cascade);
|
|
||||||
table.ForeignKey(
|
|
||||||
name: "FK_JewelComponents_Jewels_JewelId",
|
|
||||||
column: x => x.JewelId,
|
|
||||||
principalTable: "Jewels",
|
|
||||||
principalColumn: "Id",
|
|
||||||
onDelete: ReferentialAction.Cascade);
|
|
||||||
});
|
|
||||||
|
|
||||||
migrationBuilder.CreateTable(
|
migrationBuilder.CreateIndex(
|
||||||
name: "Orders",
|
name: "IX_ShopJewels_ShopId",
|
||||||
columns: table => new
|
table: "ShopJewels",
|
||||||
{
|
column: "ShopId");
|
||||||
Id = table.Column<int>(type: "int", nullable: false)
|
}
|
||||||
.Annotation("SqlServer:Identity", "1, 1"),
|
|
||||||
JewelId = table.Column<int>(type: "int", nullable: false),
|
|
||||||
Count = table.Column<int>(type: "int", nullable: false),
|
|
||||||
Sum = table.Column<double>(type: "float", nullable: false),
|
|
||||||
Status = table.Column<int>(type: "int", nullable: false),
|
|
||||||
DateCreate = table.Column<DateTime>(type: "datetime2", nullable: false),
|
|
||||||
DateImplement = table.Column<DateTime>(type: "datetime2", nullable: true)
|
|
||||||
},
|
|
||||||
constraints: table =>
|
|
||||||
{
|
|
||||||
table.PrimaryKey("PK_Orders", x => x.Id);
|
|
||||||
table.ForeignKey(
|
|
||||||
name: "FK_Orders_Jewels_JewelId",
|
|
||||||
column: x => x.JewelId,
|
|
||||||
principalTable: "Jewels",
|
|
||||||
principalColumn: "Id",
|
|
||||||
onDelete: ReferentialAction.Cascade);
|
|
||||||
});
|
|
||||||
|
|
||||||
migrationBuilder.CreateIndex(
|
/// <inheritdoc />
|
||||||
name: "IX_JewelComponents_ComponentId",
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
table: "JewelComponents",
|
{
|
||||||
column: "ComponentId");
|
migrationBuilder.DropTable(
|
||||||
|
name: "ShopJewels");
|
||||||
|
|
||||||
migrationBuilder.CreateIndex(
|
migrationBuilder.DropTable(
|
||||||
name: "IX_JewelComponents_JewelId",
|
name: "Shops");
|
||||||
table: "JewelComponents",
|
}
|
||||||
column: "JewelId");
|
}
|
||||||
|
}
|
||||||
migrationBuilder.CreateIndex(
|
|
||||||
name: "IX_Orders_JewelId",
|
|
||||||
table: "Orders",
|
|
||||||
column: "JewelId");
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
protected override void Down(MigrationBuilder migrationBuilder)
|
|
||||||
{
|
|
||||||
migrationBuilder.DropTable(
|
|
||||||
name: "JewelComponents");
|
|
||||||
|
|
||||||
migrationBuilder.DropTable(
|
|
||||||
name: "Orders");
|
|
||||||
|
|
||||||
migrationBuilder.DropTable(
|
|
||||||
name: "Components");
|
|
||||||
|
|
||||||
migrationBuilder.DropTable(
|
|
||||||
name: "Jewels");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -10,202 +10,279 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
|||||||
|
|
||||||
namespace JewelryStoreDatabaseImplement.Migrations
|
namespace JewelryStoreDatabaseImplement.Migrations
|
||||||
{
|
{
|
||||||
[DbContext(typeof(JewelryStoreDatabase))]
|
[DbContext(typeof(JewelryStoreDatabase))]
|
||||||
partial class JewelryStoreDatabaseModelSnapshot : ModelSnapshot
|
partial class JewelryStoreDatabaseModelSnapshot : ModelSnapshot
|
||||||
{
|
{
|
||||||
protected override void BuildModel(ModelBuilder modelBuilder)
|
protected override void BuildModel(ModelBuilder modelBuilder)
|
||||||
{
|
{
|
||||||
#pragma warning disable 612, 618
|
#pragma warning disable 612, 618
|
||||||
modelBuilder
|
modelBuilder
|
||||||
.HasAnnotation("ProductVersion", "7.0.4")
|
.HasAnnotation("ProductVersion", "7.0.3")
|
||||||
.HasAnnotation("Relational:MaxIdentifierLength", 128);
|
.HasAnnotation("Relational:MaxIdentifierLength", 128);
|
||||||
|
|
||||||
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
|
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
|
||||||
|
|
||||||
modelBuilder.Entity("JewelryStoreDatabaseImplement.Models.Client", b =>
|
modelBuilder.Entity("JewelryStoreDatabaseImplement.Models.Client", b =>
|
||||||
{
|
{
|
||||||
b.Property<int>("Id")
|
b.Property<int>("Id")
|
||||||
.ValueGeneratedOnAdd()
|
.ValueGeneratedOnAdd()
|
||||||
.HasColumnType("int");
|
.HasColumnType("int");
|
||||||
|
|
||||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
b.Property<string>("ClientFIO")
|
b.Property<string>("ClientFIO")
|
||||||
.IsRequired()
|
.IsRequired()
|
||||||
.HasColumnType("nvarchar(max)");
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
b.Property<string>("Email")
|
b.Property<string>("Email")
|
||||||
.IsRequired()
|
.IsRequired()
|
||||||
.HasColumnType("nvarchar(max)");
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
b.Property<string>("Password")
|
b.Property<string>("Password")
|
||||||
.IsRequired()
|
.IsRequired()
|
||||||
.HasColumnType("nvarchar(max)");
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
b.HasKey("Id");
|
b.HasKey("Id");
|
||||||
|
|
||||||
b.ToTable("Clients");
|
b.ToTable("Clients");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("JewelryStoreDatabaseImplement.Models.Component", b =>
|
modelBuilder.Entity("JewelryStoreDatabaseImplement.Models.Component", b =>
|
||||||
{
|
{
|
||||||
b.Property<int>("Id")
|
b.Property<int>("Id")
|
||||||
.ValueGeneratedOnAdd()
|
.ValueGeneratedOnAdd()
|
||||||
.HasColumnType("int");
|
.HasColumnType("int");
|
||||||
|
|
||||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
b.Property<string>("ComponentName")
|
b.Property<string>("ComponentName")
|
||||||
.IsRequired()
|
.IsRequired()
|
||||||
.HasColumnType("nvarchar(max)");
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
b.Property<double>("Cost")
|
b.Property<double>("Cost")
|
||||||
.HasColumnType("float");
|
.HasColumnType("float");
|
||||||
|
|
||||||
b.HasKey("Id");
|
b.HasKey("Id");
|
||||||
|
|
||||||
b.ToTable("Components");
|
b.ToTable("Components");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("JewelryStoreDatabaseImplement.Models.Jewel", b =>
|
modelBuilder.Entity("JewelryStoreDatabaseImplement.Models.Order", b =>
|
||||||
{
|
{
|
||||||
b.Property<int>("Id")
|
b.Property<int>("Id")
|
||||||
.ValueGeneratedOnAdd()
|
.ValueGeneratedOnAdd()
|
||||||
.HasColumnType("int");
|
.HasColumnType("int");
|
||||||
|
|
||||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
b.Property<string>("JewelName")
|
b.Property<int>("ClientId")
|
||||||
.IsRequired()
|
.HasColumnType("int");
|
||||||
.HasColumnType("nvarchar(max)");
|
|
||||||
|
|
||||||
b.Property<double>("Price")
|
b.Property<int>("Count")
|
||||||
.HasColumnType("float");
|
.HasColumnType("int");
|
||||||
|
|
||||||
b.HasKey("Id");
|
b.Property<DateTime>("DateCreate")
|
||||||
|
.HasColumnType("datetime2");
|
||||||
|
|
||||||
b.ToTable("Jewels");
|
b.Property<DateTime?>("DateImplement")
|
||||||
});
|
.HasColumnType("datetime2");
|
||||||
|
|
||||||
modelBuilder.Entity("JewelryStoreDatabaseImplement.Models.JewelComponent", b =>
|
b.Property<int>("JewelId")
|
||||||
{
|
.HasColumnType("int");
|
||||||
b.Property<int>("Id")
|
|
||||||
.ValueGeneratedOnAdd()
|
|
||||||
.HasColumnType("int");
|
|
||||||
|
|
||||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
b.Property<int>("Status")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
b.Property<int>("ComponentId")
|
b.Property<double>("Sum")
|
||||||
.HasColumnType("int");
|
.HasColumnType("float");
|
||||||
|
|
||||||
b.Property<int>("Count")
|
b.HasKey("Id");
|
||||||
.HasColumnType("int");
|
|
||||||
|
|
||||||
b.Property<int>("JewelId")
|
b.HasIndex("ClientId");
|
||||||
.HasColumnType("int");
|
|
||||||
|
|
||||||
b.HasKey("Id");
|
b.HasIndex("JewelId");
|
||||||
|
|
||||||
b.HasIndex("ComponentId");
|
b.ToTable("Orders");
|
||||||
|
});
|
||||||
|
|
||||||
b.HasIndex("JewelId");
|
modelBuilder.Entity("JewelryStoreDatabaseImplement.Models.Jewel", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
b.ToTable("JewelComponents");
|
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("JewelryStoreDatabaseImplement.Models.Order", b =>
|
b.Property<string>("JewelName")
|
||||||
{
|
.IsRequired()
|
||||||
b.Property<int>("Id")
|
.HasColumnType("nvarchar(max)");
|
||||||
.ValueGeneratedOnAdd()
|
|
||||||
.HasColumnType("int");
|
|
||||||
|
|
||||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
b.Property<double>("Price")
|
||||||
|
.HasColumnType("float");
|
||||||
|
|
||||||
b.Property<int>("ClientId")
|
b.HasKey("Id");
|
||||||
.HasColumnType("int");
|
|
||||||
|
|
||||||
b.Property<int>("Count")
|
b.ToTable("Jewels");
|
||||||
.HasColumnType("int");
|
});
|
||||||
|
|
||||||
b.Property<DateTime>("DateCreate")
|
modelBuilder.Entity("JewelryStoreDatabaseImplement.Models.JewelComponent", b =>
|
||||||
.HasColumnType("datetime2");
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
b.Property<DateTime?>("DateImplement")
|
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||||
.HasColumnType("datetime2");
|
|
||||||
|
|
||||||
b.Property<int>("JewelId")
|
b.Property<int>("ComponentId")
|
||||||
.HasColumnType("int");
|
.HasColumnType("int");
|
||||||
|
|
||||||
b.Property<int>("Status")
|
b.Property<int>("Count")
|
||||||
.HasColumnType("int");
|
.HasColumnType("int");
|
||||||
|
|
||||||
b.Property<double>("Sum")
|
b.Property<int>("JewelId")
|
||||||
.HasColumnType("float");
|
.HasColumnType("int");
|
||||||
|
|
||||||
b.HasKey("Id");
|
b.HasKey("Id");
|
||||||
|
|
||||||
b.HasIndex("ClientId");
|
b.HasIndex("ComponentId");
|
||||||
|
|
||||||
b.HasIndex("JewelId");
|
b.HasIndex("JewelId");
|
||||||
|
|
||||||
b.ToTable("Orders");
|
b.ToTable("JewelComponents");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("JewelryStoreDatabaseImplement.Models.JewelComponent", b =>
|
modelBuilder.Entity("JewelryStoreDatabaseImplement.Models.Shop", b =>
|
||||||
{
|
{
|
||||||
b.HasOne("JewelryStoreDatabaseImplement.Models.Component", "Component")
|
b.Property<int>("Id")
|
||||||
.WithMany("JewelComponents")
|
.ValueGeneratedOnAdd()
|
||||||
.HasForeignKey("ComponentId")
|
.HasColumnType("int");
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
|
||||||
.IsRequired();
|
|
||||||
|
|
||||||
b.HasOne("JewelryStoreDatabaseImplement.Models.Jewel", "Jewel")
|
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||||
.WithMany("Components")
|
|
||||||
.HasForeignKey("JewelId")
|
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
|
||||||
.IsRequired();
|
|
||||||
|
|
||||||
b.Navigation("Component");
|
b.Property<string>("Adress")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
b.Navigation("Jewel");
|
b.Property<DateTime>("OpeningDate")
|
||||||
});
|
.HasColumnType("datetime2");
|
||||||
|
|
||||||
modelBuilder.Entity("JewelryStoreDatabaseImplement.Models.Order", b =>
|
b.Property<int>("JewelMaxCount")
|
||||||
{
|
.HasColumnType("int");
|
||||||
b.HasOne("JewelryStoreDatabaseImplement.Models.Client", "Client")
|
|
||||||
.WithMany("Orders")
|
|
||||||
.HasForeignKey("ClientId")
|
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
|
||||||
.IsRequired();
|
|
||||||
|
|
||||||
b.HasOne("JewelryStoreDatabaseImplement.Models.Jewel", "Jewel")
|
b.Property<string>("ShopName")
|
||||||
.WithMany("Orders")
|
.IsRequired()
|
||||||
.HasForeignKey("JewelId")
|
.HasColumnType("nvarchar(max)");
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
|
||||||
.IsRequired();
|
|
||||||
|
|
||||||
b.Navigation("Client");
|
b.HasKey("Id");
|
||||||
|
|
||||||
b.Navigation("Jewel");
|
b.ToTable("Shops");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("JewelryStoreDatabaseImplement.Models.Client", b =>
|
modelBuilder.Entity("JewelryStoreDatabaseImplement.Models.ShopJewels", b =>
|
||||||
{
|
{
|
||||||
b.Navigation("Orders");
|
b.Property<int>("Id")
|
||||||
});
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
modelBuilder.Entity("JewelryStoreDatabaseImplement.Models.Component", b =>
|
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||||
{
|
|
||||||
b.Navigation("JewelComponents");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("JewelryStoreDatabaseImplement.Models.Jewel", b =>
|
b.Property<int>("Count")
|
||||||
{
|
.HasColumnType("int");
|
||||||
b.Navigation("Components");
|
|
||||||
|
|
||||||
b.Navigation("Orders");
|
b.Property<int>("JewelId")
|
||||||
});
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<int>("ShopId")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("JewelId");
|
||||||
|
|
||||||
|
b.HasIndex("ShopId");
|
||||||
|
|
||||||
|
b.ToTable("ShopJewels");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("JewelryStoreDatabaseImplement.Models.Order", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("JewelryStoreDatabaseImplement.Models.Client", "Client")
|
||||||
|
.WithMany("Orders")
|
||||||
|
.HasForeignKey("ClientId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.HasOne("JewelryStoreDatabaseImplement.Models.Jewel", "Jewel")
|
||||||
|
.WithMany("Orders")
|
||||||
|
.HasForeignKey("JewelId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("Client");
|
||||||
|
|
||||||
|
b.Navigation("Jewel");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("JewelryStoreDatabaseImplement.Models.JewelComponent", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("JewelryStoreDatabaseImplement.Models.Component", "Component")
|
||||||
|
.WithMany("JewelComponents")
|
||||||
|
.HasForeignKey("ComponentId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.HasOne("JewelryStoreDatabaseImplement.Models.Jewel", "Jewel")
|
||||||
|
.WithMany("Components")
|
||||||
|
.HasForeignKey("JewelId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("Component");
|
||||||
|
|
||||||
|
b.Navigation("Jewel");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("JewelryStoreDatabaseImplement.Models.ShopJewels", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("JewelryStoreDatabaseImplement.Models.Jewel", "Jewel")
|
||||||
|
.WithMany("ShopJewels")
|
||||||
|
.HasForeignKey("JewelId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.HasOne("JewelryStoreDatabaseImplement.Models.Shop", "Shop")
|
||||||
|
.WithMany("Jewels")
|
||||||
|
.HasForeignKey("ShopId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("Jewel");
|
||||||
|
|
||||||
|
b.Navigation("Shop");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("JewelryStoreDatabaseImplement.Models.Client", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("Orders");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("JewelryStoreDatabaseImplement.Models.Component", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("JewelComponents");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("JewelryStoreDatabaseImplement.Models.Jewel", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("Components");
|
||||||
|
|
||||||
|
b.Navigation("Orders");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("JewelryStoreDatabaseImplement.Models.Shop", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("Jewels");
|
||||||
|
});
|
||||||
#pragma warning restore 612, 618
|
#pragma warning restore 612, 618
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,12 +10,14 @@ namespace JewelryStoreFileImplement
|
|||||||
private readonly string OrderFileName = "Order.xml";
|
private readonly string OrderFileName = "Order.xml";
|
||||||
private readonly string JewelFileName = "Jewel.xml";
|
private readonly string JewelFileName = "Jewel.xml";
|
||||||
private readonly string ClientFileName = "Client.xml";
|
private readonly string ClientFileName = "Client.xml";
|
||||||
public List<Component> Components { get; private set; }
|
private readonly string ShopFileName = "Shop.xml";
|
||||||
|
public List<Component> Components { get; private set; }
|
||||||
public List<Order> Orders { get; private set; }
|
public List<Order> Orders { get; private set; }
|
||||||
public List<Jewel> Jewels { get; private set; }
|
public List<Jewel> Jewels { get; private set; }
|
||||||
public List<Client> Clients { get; private set; }
|
public List<Client> Clients { get; private set; }
|
||||||
|
public List<Store> Shops { get; private set; }
|
||||||
|
|
||||||
public static DataFileSingleton GetInstance()
|
public static DataFileSingleton GetInstance()
|
||||||
{
|
{
|
||||||
if (instance == null)
|
if (instance == null)
|
||||||
{
|
{
|
||||||
@ -31,14 +33,16 @@ namespace JewelryStoreFileImplement
|
|||||||
public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement);
|
public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement);
|
||||||
|
|
||||||
public void SaveClients() => SaveData(Clients, OrderFileName, "Clients", x => x.GetXElement);
|
public void SaveClients() => SaveData(Clients, OrderFileName, "Clients", x => x.GetXElement);
|
||||||
|
public void SaveShops() => SaveData(Shops, ShopFileName, "Shops", x => x.GetXElement);
|
||||||
|
|
||||||
private DataFileSingleton()
|
private DataFileSingleton()
|
||||||
{
|
{
|
||||||
Components = LoadData(ComponentFileName, "Component", x => Component.Create(x)!)!;
|
Components = LoadData(ComponentFileName, "Component", x => Component.Create(x)!)!;
|
||||||
Jewels = LoadData(JewelFileName, "Jewel", x => Jewel.Create(x)!)!;
|
Jewels = LoadData(JewelFileName, "Jewel", x => Jewel.Create(x)!)!;
|
||||||
Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!;
|
Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!;
|
||||||
Clients = LoadData(ClientFileName, "Client", x => Client.Create(x)!)!;
|
Clients = LoadData(ClientFileName, "Client", x => Client.Create(x)!)!;
|
||||||
}
|
Shops = LoadData(ShopFileName, "Shop", x => Shop.Create(x)!)!;
|
||||||
|
}
|
||||||
|
|
||||||
private static List<T>? LoadData<T>(string filename, string xmlNodeName, Func<XElement, T> selectFunction)
|
private static List<T>? LoadData<T>(string filename, string xmlNodeName, Func<XElement, T> selectFunction)
|
||||||
{
|
{
|
||||||
|
@ -0,0 +1,12 @@
|
|||||||
|
namespace JewelryStoreRestApi
|
||||||
|
{
|
||||||
|
public class APIConfig
|
||||||
|
{
|
||||||
|
public static string? ShopPassword;
|
||||||
|
|
||||||
|
public static void LoadData(IConfiguration configuration)
|
||||||
|
{
|
||||||
|
ShopPassword = configuration["ShopAPIPassword"];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,157 @@
|
|||||||
|
using JewelryStoreContracts.BindingModels;
|
||||||
|
using JewelryStoreContracts.BusinessLogicsContracts;
|
||||||
|
using JewelryStoreContracts.SearchModels;
|
||||||
|
using JewelryStoreContracts.ViewModels;
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
|
namespace JewelryStoreRestApi.Controllers
|
||||||
|
{
|
||||||
|
[Route("api/[controller]/[action]")]
|
||||||
|
[ApiController]
|
||||||
|
public class ShopController : Controller
|
||||||
|
{
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
private readonly IStoreLogic _shopLogic;
|
||||||
|
|
||||||
|
public ShopController(ILogger<ShopController> logger, IStoreLogic shopLogic)
|
||||||
|
{
|
||||||
|
_logger = logger;
|
||||||
|
_shopLogic = shopLogic;
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet]
|
||||||
|
public bool Authentication(string password)
|
||||||
|
{
|
||||||
|
return CheckPassword(password);
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet]
|
||||||
|
public List<StoreViewModel>? GetShopList(string password)
|
||||||
|
{
|
||||||
|
if (!CheckPassword(password))
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return _shopLogic.ReadList(null);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка получения списка магазинов");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet]
|
||||||
|
public ShopJewelViewModel? GetShop(int shopId, string password)
|
||||||
|
{
|
||||||
|
if (!CheckPassword(password))
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var shop = _shopLogic.ReadElement(new StoreSearchModel { Id = shopId });
|
||||||
|
return new ShopJewelViewModel
|
||||||
|
{
|
||||||
|
Shop = shop,
|
||||||
|
ShopJewel = shop.ShopJewels.ToDictionary(x => x.Key, x => new JewelCount
|
||||||
|
{
|
||||||
|
Jewel = new JewelViewModel()
|
||||||
|
{
|
||||||
|
Id = x.Value.Item1.Id,
|
||||||
|
JewelName = x.Value.Item1.PizzaName,
|
||||||
|
JewelComponents = x.Value.Item1.JewelComponents,
|
||||||
|
Price = x.Value.Item1.Price,
|
||||||
|
},
|
||||||
|
Count = x.Value.Item2
|
||||||
|
})
|
||||||
|
};
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка получения магазина");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost]
|
||||||
|
public void CreateShop(StoreBindingModel model, string password)
|
||||||
|
{
|
||||||
|
if (!CheckPassword(password))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_shopLogic.Create(model);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка создания магазина");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost]
|
||||||
|
public void UpdateShop(StoreBindingModel model, string password)
|
||||||
|
{
|
||||||
|
if (!CheckPassword(password))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_shopLogic.Update(model);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка обновления магазина");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpDelete]
|
||||||
|
public void DeleteShop(int shopId, string password)
|
||||||
|
{
|
||||||
|
if (!CheckPassword(password))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_shopLogic.Delete(new StoreBindingModel { Id = shopId });
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка удаления магазина");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost]
|
||||||
|
public void MakeSypply(SupplyBindingModel model, string password)
|
||||||
|
{
|
||||||
|
if (!CheckPassword(password))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_shopLogic.MakeSupply(model);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка создания поставки в магазин");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool CheckPassword(string password)
|
||||||
|
{
|
||||||
|
return APIConfig.ShopPassword == password;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -15,10 +15,11 @@ builder.Logging.AddLog4Net("log4net.config");
|
|||||||
builder.Services.AddTransient<IClientStorage, ClientStorage>();
|
builder.Services.AddTransient<IClientStorage, ClientStorage>();
|
||||||
builder.Services.AddTransient<IOrderStorage, OrderStorage>();
|
builder.Services.AddTransient<IOrderStorage, OrderStorage>();
|
||||||
builder.Services.AddTransient<IJewelStorage, JewelStorage>();
|
builder.Services.AddTransient<IJewelStorage, JewelStorage>();
|
||||||
|
builder.Services.AddTransient<IStoreStorage, StoreStorage>();
|
||||||
builder.Services.AddTransient<IOrderLogic, OrderLogic>();
|
builder.Services.AddTransient<IOrderLogic, OrderLogic>();
|
||||||
builder.Services.AddTransient<IClientLogic, ClientLogic>();
|
builder.Services.AddTransient<IClientLogic, ClientLogic>();
|
||||||
builder.Services.AddTransient<IJewelLogic, JewelLogic>();
|
builder.Services.AddTransient<IJewelLogic, JewelLogic>();
|
||||||
|
builder.Services.AddTransient<IStoreLogic, StoreLogic>();
|
||||||
|
|
||||||
|
|
||||||
builder.Services.AddControllers();
|
builder.Services.AddControllers();
|
||||||
|
@ -5,5 +5,6 @@
|
|||||||
"Microsoft.AspNetCore": "Warning"
|
"Microsoft.AspNetCore": "Warning"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"AllowedHosts": "*"
|
"AllowedHosts": "*",
|
||||||
|
"ShopAPIPassword": "123456"
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user