fix models in DatabaseImplement

This commit is contained in:
DavidMakarov 2024-05-17 15:02:32 +04:00
parent 2726b6e623
commit 7fea674731
6 changed files with 66 additions and 19 deletions

View File

@ -21,8 +21,4 @@
<ProjectReference Include="..\FlowerShopDataModels\FlowerShopDataModels.csproj" />
</ItemGroup>
<ItemGroup>
<Folder Include="Migrations\" />
</ItemGroup>
</Project>

View File

@ -12,7 +12,7 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
namespace FlowerShopDatabaseImplement.Migrations
{
[DbContext(typeof(FlowerShopDatabase))]
[Migration("20240516204422_InitCreate")]
[Migration("20240517110214_InitCreate")]
partial class InitCreate
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
@ -130,10 +130,10 @@ namespace FlowerShopDatabaseImplement.Migrations
.HasColumnType("integer");
b.Property<DateTime>("DateCreate")
.HasColumnType("timestamp with time zone");
.HasColumnType("timestamp without time zone");
b.Property<DateTime?>("DateImplement")
.HasColumnType("timestamp with time zone");
.HasColumnType("timestamp without time zone");
b.Property<int>("FlowerId")
.HasColumnType("integer");
@ -146,6 +146,8 @@ namespace FlowerShopDatabaseImplement.Migrations
b.HasKey("Id");
b.HasIndex("ClientId");
b.HasIndex("FlowerId");
b.ToTable("Orders");
@ -164,7 +166,7 @@ namespace FlowerShopDatabaseImplement.Migrations
.HasColumnType("text");
b.Property<DateTime>("DateOpening")
.HasColumnType("timestamp with time zone");
.HasColumnType("timestamp without time zone");
b.Property<int>("MaximumFlowers")
.HasColumnType("integer");
@ -225,11 +227,21 @@ namespace FlowerShopDatabaseImplement.Migrations
modelBuilder.Entity("FlowerShopDatabaseImplement.Models.Order", b =>
{
b.HasOne("FlowerShopDatabaseImplement.Models.Flower", null)
b.HasOne("FlowerShopDatabaseImplement.Models.Client", "Client")
.WithMany("Orders")
.HasForeignKey("ClientId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("FlowerShopDatabaseImplement.Models.Flower", "Flower")
.WithMany("Orders")
.HasForeignKey("FlowerId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Client");
b.Navigation("Flower");
});
modelBuilder.Entity("FlowerShopDatabaseImplement.Models.ShopFlower", b =>
@ -251,6 +263,11 @@ namespace FlowerShopDatabaseImplement.Migrations
b.Navigation("Shop");
});
modelBuilder.Entity("FlowerShopDatabaseImplement.Models.Client", b =>
{
b.Navigation("Orders");
});
modelBuilder.Entity("FlowerShopDatabaseImplement.Models.Component", b =>
{
b.Navigation("FlowerComponents");

View File

@ -61,7 +61,7 @@ namespace FlowerShopDatabaseImplement.Migrations
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
ShopName = table.Column<string>(type: "text", nullable: false),
Address = table.Column<string>(type: "text", nullable: false),
DateOpening = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
DateOpening = table.Column<DateTime>(type: "timestamp without time zone", nullable: false),
MaximumFlowers = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
@ -107,12 +107,18 @@ namespace FlowerShopDatabaseImplement.Migrations
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)
DateCreate = table.Column<DateTime>(type: "timestamp without time zone", nullable: false),
DateImplement = table.Column<DateTime>(type: "timestamp without time zone", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Orders", x => x.Id);
table.ForeignKey(
name: "FK_Orders_Clients_ClientId",
column: x => x.ClientId,
principalTable: "Clients",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_Orders_Flowers_FlowerId",
column: x => x.FlowerId,
@ -158,6 +164,11 @@ namespace FlowerShopDatabaseImplement.Migrations
table: "FlowerComponents",
column: "FlowerId");
migrationBuilder.CreateIndex(
name: "IX_Orders_ClientId",
table: "Orders",
column: "ClientId");
migrationBuilder.CreateIndex(
name: "IX_Orders_FlowerId",
table: "Orders",
@ -176,9 +187,6 @@ namespace FlowerShopDatabaseImplement.Migrations
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Clients");
migrationBuilder.DropTable(
name: "FlowerComponents");
@ -191,6 +199,9 @@ namespace FlowerShopDatabaseImplement.Migrations
migrationBuilder.DropTable(
name: "Components");
migrationBuilder.DropTable(
name: "Clients");
migrationBuilder.DropTable(
name: "Flowers");

View File

@ -128,10 +128,10 @@ namespace FlowerShopDatabaseImplement.Migrations
.HasColumnType("integer");
b.Property<DateTime>("DateCreate")
.HasColumnType("timestamp with time zone");
.HasColumnType("timestamp without time zone");
b.Property<DateTime?>("DateImplement")
.HasColumnType("timestamp with time zone");
.HasColumnType("timestamp without time zone");
b.Property<int>("FlowerId")
.HasColumnType("integer");
@ -144,6 +144,8 @@ namespace FlowerShopDatabaseImplement.Migrations
b.HasKey("Id");
b.HasIndex("ClientId");
b.HasIndex("FlowerId");
b.ToTable("Orders");
@ -162,7 +164,7 @@ namespace FlowerShopDatabaseImplement.Migrations
.HasColumnType("text");
b.Property<DateTime>("DateOpening")
.HasColumnType("timestamp with time zone");
.HasColumnType("timestamp without time zone");
b.Property<int>("MaximumFlowers")
.HasColumnType("integer");
@ -223,11 +225,21 @@ namespace FlowerShopDatabaseImplement.Migrations
modelBuilder.Entity("FlowerShopDatabaseImplement.Models.Order", b =>
{
b.HasOne("FlowerShopDatabaseImplement.Models.Flower", null)
b.HasOne("FlowerShopDatabaseImplement.Models.Client", "Client")
.WithMany("Orders")
.HasForeignKey("ClientId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("FlowerShopDatabaseImplement.Models.Flower", "Flower")
.WithMany("Orders")
.HasForeignKey("FlowerId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Client");
b.Navigation("Flower");
});
modelBuilder.Entity("FlowerShopDatabaseImplement.Models.ShopFlower", b =>
@ -249,6 +261,11 @@ namespace FlowerShopDatabaseImplement.Migrations
b.Navigation("Shop");
});
modelBuilder.Entity("FlowerShopDatabaseImplement.Models.Client", b =>
{
b.Navigation("Orders");
});
modelBuilder.Entity("FlowerShopDatabaseImplement.Models.Component", b =>
{
b.Navigation("FlowerComponents");

View File

@ -15,6 +15,8 @@ namespace FlowerShopDatabaseImplement.Models
public string Email { get; private set; } = string.Empty;
[Required]
public string Password { get; private set; } = string.Empty;
[ForeignKey("ClientId")]
public virtual List<Order> Orders { get; set; } = new();
public static Client? Create(ClientBindingModel model)
{
if (model == null)

View File

@ -9,8 +9,12 @@ namespace FlowerShopDatabaseImplement.Models
public class Order : IOrderModel
{
public int Id { get; private set; }
[Required]
public int FlowerId { get; private set; }
public virtual Flower Flower { get; set; }
[Required]
public int ClientId { get; private set; }
public virtual Client Client { get; set; }
[Required]
public int Count { get; set; }
[Required]