Почти всё
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
|
||||
{
|
||||
|
||||
/// <inheritdoc />
|
||||
public partial class InitialCreate : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Components",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
ComponentName = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
Cost = table.Column<double>(type: "float", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Components", x => x.Id);
|
||||
});
|
||||
public partial class Hard_init : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Shops",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
ShopName = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
Adress = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
OpeningDate = table.Column<DateTime>(type: "datetime2", nullable: false),
|
||||
JewelMaxCount = table.Column<int>(type: "int", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Shops", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Jewels",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
JewelName = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
Price = table.Column<double>(type: "float", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Jewels", x => x.Id);
|
||||
});
|
||||
migrationBuilder.CreateTable(
|
||||
name: "ShopJewels",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
JewelId = table.Column<int>(type: "int", nullable: false),
|
||||
ShopId = table.Column<int>(type: "int", nullable: false),
|
||||
Count = table.Column<int>(type: "int", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
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(
|
||||
name: "JewelComponents",
|
||||
columns: table => new
|
||||
{
|
||||
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.CreateIndex(
|
||||
name: "IX_ShopJewels_JewelId",
|
||||
table: "ShopJewels",
|
||||
column: "JewelId");
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Orders",
|
||||
columns: table => new
|
||||
{
|
||||
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(
|
||||
name: "IX_ShopJewels_ShopId",
|
||||
table: "ShopJewels",
|
||||
column: "ShopId");
|
||||
}
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_JewelComponents_ComponentId",
|
||||
table: "JewelComponents",
|
||||
column: "ComponentId");
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "ShopJewels");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_JewelComponents_JewelId",
|
||||
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");
|
||||
}
|
||||
}
|
||||
}
|
||||
migrationBuilder.DropTable(
|
||||
name: "Shops");
|
||||
}
|
||||
}
|
||||
}
|
@ -10,202 +10,279 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
|
||||
namespace JewelryStoreDatabaseImplement.Migrations
|
||||
{
|
||||
[DbContext(typeof(JewelryStoreDatabase))]
|
||||
partial class JewelryStoreDatabaseModelSnapshot : ModelSnapshot
|
||||
{
|
||||
protected override void BuildModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
[DbContext(typeof(JewelryStoreDatabase))]
|
||||
partial class JewelryStoreDatabaseModelSnapshot : ModelSnapshot
|
||||
{
|
||||
protected override void BuildModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "7.0.4")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 128);
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "7.0.3")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 128);
|
||||
|
||||
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
|
||||
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("JewelryStoreDatabaseImplement.Models.Client", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
modelBuilder.Entity("JewelryStoreDatabaseImplement.Models.Client", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("ClientFIO")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
b.Property<string>("ClientFIO")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("Email")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
b.Property<string>("Email")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("Password")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
b.Property<string>("Password")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.HasKey("Id");
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Clients");
|
||||
});
|
||||
b.ToTable("Clients");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("JewelryStoreDatabaseImplement.Models.Component", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
modelBuilder.Entity("JewelryStoreDatabaseImplement.Models.Component", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("ComponentName")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
b.Property<string>("ComponentName")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<double>("Cost")
|
||||
.HasColumnType("float");
|
||||
b.Property<double>("Cost")
|
||||
.HasColumnType("float");
|
||||
|
||||
b.HasKey("Id");
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Components");
|
||||
});
|
||||
b.ToTable("Components");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("JewelryStoreDatabaseImplement.Models.Jewel", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
modelBuilder.Entity("JewelryStoreDatabaseImplement.Models.Order", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("JewelName")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
b.Property<int>("ClientId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<double>("Price")
|
||||
.HasColumnType("float");
|
||||
b.Property<int>("Count")
|
||||
.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>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
b.Property<int>("JewelId")
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
b.Property<int>("Status")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("ComponentId")
|
||||
.HasColumnType("int");
|
||||
b.Property<double>("Sum")
|
||||
.HasColumnType("float");
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("int");
|
||||
b.HasKey("Id");
|
||||
|
||||
b.Property<int>("JewelId")
|
||||
.HasColumnType("int");
|
||||
b.HasIndex("ClientId");
|
||||
|
||||
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<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
b.Property<string>("JewelName")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
b.Property<double>("Price")
|
||||
.HasColumnType("float");
|
||||
|
||||
b.Property<int>("ClientId")
|
||||
.HasColumnType("int");
|
||||
b.HasKey("Id");
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("int");
|
||||
b.ToTable("Jewels");
|
||||
});
|
||||
|
||||
b.Property<DateTime>("DateCreate")
|
||||
.HasColumnType("datetime2");
|
||||
modelBuilder.Entity("JewelryStoreDatabaseImplement.Models.JewelComponent", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<DateTime?>("DateImplement")
|
||||
.HasColumnType("datetime2");
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("JewelId")
|
||||
.HasColumnType("int");
|
||||
b.Property<int>("ComponentId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("Status")
|
||||
.HasColumnType("int");
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<double>("Sum")
|
||||
.HasColumnType("float");
|
||||
b.Property<int>("JewelId")
|
||||
.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 =>
|
||||
{
|
||||
b.HasOne("JewelryStoreDatabaseImplement.Models.Component", "Component")
|
||||
.WithMany("JewelComponents")
|
||||
.HasForeignKey("ComponentId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
modelBuilder.Entity("JewelryStoreDatabaseImplement.Models.Shop", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasOne("JewelryStoreDatabaseImplement.Models.Jewel", "Jewel")
|
||||
.WithMany("Components")
|
||||
.HasForeignKey("JewelId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
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.HasOne("JewelryStoreDatabaseImplement.Models.Client", "Client")
|
||||
.WithMany("Orders")
|
||||
.HasForeignKey("ClientId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
b.Property<int>("JewelMaxCount")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasOne("JewelryStoreDatabaseImplement.Models.Jewel", "Jewel")
|
||||
.WithMany("Orders")
|
||||
.HasForeignKey("JewelId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
b.Property<string>("ShopName")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Navigation("Client");
|
||||
b.HasKey("Id");
|
||||
|
||||
b.Navigation("Jewel");
|
||||
});
|
||||
b.ToTable("Shops");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("JewelryStoreDatabaseImplement.Models.Client", b =>
|
||||
{
|
||||
b.Navigation("Orders");
|
||||
});
|
||||
modelBuilder.Entity("JewelryStoreDatabaseImplement.Models.ShopJewels", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
modelBuilder.Entity("JewelryStoreDatabaseImplement.Models.Component", b =>
|
||||
{
|
||||
b.Navigation("JewelComponents");
|
||||
});
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
modelBuilder.Entity("JewelryStoreDatabaseImplement.Models.Jewel", b =>
|
||||
{
|
||||
b.Navigation("Components");
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("int");
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -10,12 +10,14 @@ namespace JewelryStoreFileImplement
|
||||
private readonly string OrderFileName = "Order.xml";
|
||||
private readonly string JewelFileName = "Jewel.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<Jewel> Jewels { 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)
|
||||
{
|
||||
@ -31,14 +33,16 @@ namespace JewelryStoreFileImplement
|
||||
public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", 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)!)!;
|
||||
Jewels = LoadData(JewelFileName, "Jewel", x => Jewel.Create(x)!)!;
|
||||
Orders = LoadData(OrderFileName, "Order", x => Order.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)
|
||||
{
|
||||
|
@ -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<IOrderStorage, OrderStorage>();
|
||||
builder.Services.AddTransient<IJewelStorage, JewelStorage>();
|
||||
|
||||
builder.Services.AddTransient<IStoreStorage, StoreStorage>();
|
||||
builder.Services.AddTransient<IOrderLogic, OrderLogic>();
|
||||
builder.Services.AddTransient<IClientLogic, ClientLogic>();
|
||||
builder.Services.AddTransient<IJewelLogic, JewelLogic>();
|
||||
builder.Services.AddTransient<IStoreLogic, StoreLogic>();
|
||||
|
||||
|
||||
builder.Services.AddControllers();
|
||||
|
@ -5,5 +5,6 @@
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*"
|
||||
"AllowedHosts": "*",
|
||||
"ShopAPIPassword": "123456"
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user