ClientApp+, Миграции

This commit is contained in:
Leozillo73 2024-04-28 18:17:38 +04:00
parent d594175a41
commit 0d4201259e
8 changed files with 611 additions and 14 deletions

View File

@ -8,6 +8,17 @@
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.18">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ZooDataBaseImplement\ZooDataBaseImplement.csproj" />
</ItemGroup>
<ItemGroup>
<Compile Update="Properties\Resources.Designer.cs">
<DesignTime>True</DesignTime>

View File

@ -1,10 +1,12 @@
var builder = WebApplication.CreateBuilder(args);
using ZooClientApp;
using Microsoft.EntityFrameworkCore.Infrastructure;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddControllersWithViews();
var app = builder.Build();
APIClient.Connect(builder.Configuration);
// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
@ -12,16 +14,12 @@ if (!app.Environment.IsDevelopment())
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.UseAuthorization();
app.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
app.Run();

View File

@ -6,13 +6,14 @@ using System.Text;
using System.Threading.Tasks;
using ZooContracts.BindingModels;
using ZooContracts.SearchModels;
using ZooContracts.StorageContracts;
using ZooContracts.ViewModels;
using ZooDataBaseImplement.Models;
namespace ZooDataBaseImplement.Implements
{
public class EmployeeStorage : DbContext
{
public class EmployeeStorage : IEmployeeStorage
{
public EmployeeViewModel? Delete(EmployeeBindingModel model)
{
using var context = new ZooDatabase();

View File

@ -0,0 +1,220 @@
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using ZooDataBaseImplement;
#nullable disable
namespace ZooDataBaseImplement.Migrations
{
[DbContext(typeof(ZooDatabase))]
[Migration("20240428140917_InitialCreate")]
partial class InitialCreate
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "7.0.18")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
modelBuilder.Entity("ZooDataBaseImplement.Models.Client", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("ClientFIO")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("EMail")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Password")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("Clients");
});
modelBuilder.Entity("ZooDataBaseImplement.Models.Employee", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("EmployeeFIO")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Login")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Password")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("Employees");
});
modelBuilder.Entity("ZooDataBaseImplement.Models.Preserve", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int?>("EmployeeId")
.HasColumnType("int");
b.Property<string>("PreserveName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<double>("PreservePrice")
.HasColumnType("float");
b.HasKey("Id");
b.HasIndex("EmployeeId");
b.ToTable("Preserves");
});
modelBuilder.Entity("ZooDataBaseImplement.Models.Route", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("ClientId")
.HasColumnType("int");
b.Property<DateTime>("DateFinish")
.HasColumnType("datetime2");
b.Property<DateTime>("DateStart")
.HasColumnType("datetime2");
b.Property<string>("RouteName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<double>("RoutePrice")
.HasColumnType("float");
b.Property<int>("Status")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("ClientId");
b.ToTable("Routes");
});
modelBuilder.Entity("ZooDataBaseImplement.Models.RoutePreserve", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("Count")
.HasColumnType("int");
b.Property<int>("PreserveID")
.HasColumnType("int");
b.Property<int>("RouteID")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("PreserveID");
b.ToTable("RoutePreserves");
});
modelBuilder.Entity("ZooDataBaseImplement.Models.Preserve", b =>
{
b.HasOne("ZooDataBaseImplement.Models.Employee", null)
.WithMany("Preserves")
.HasForeignKey("EmployeeId");
});
modelBuilder.Entity("ZooDataBaseImplement.Models.Route", b =>
{
b.HasOne("ZooDataBaseImplement.Models.Client", "Client")
.WithMany("Routes")
.HasForeignKey("ClientId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Client");
});
modelBuilder.Entity("ZooDataBaseImplement.Models.RoutePreserve", b =>
{
b.HasOne("ZooDataBaseImplement.Models.Preserve", "Preserve")
.WithMany("RoutePreserves")
.HasForeignKey("PreserveID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("ZooDataBaseImplement.Models.Route", "Route")
.WithMany("Preserves")
.HasForeignKey("PreserveID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Preserve");
b.Navigation("Route");
});
modelBuilder.Entity("ZooDataBaseImplement.Models.Client", b =>
{
b.Navigation("Routes");
});
modelBuilder.Entity("ZooDataBaseImplement.Models.Employee", b =>
{
b.Navigation("Preserves");
});
modelBuilder.Entity("ZooDataBaseImplement.Models.Preserve", b =>
{
b.Navigation("RoutePreserves");
});
modelBuilder.Entity("ZooDataBaseImplement.Models.Route", b =>
{
b.Navigation("Preserves");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -0,0 +1,150 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace ZooDataBaseImplement.Migrations
{
/// <inheritdoc />
public partial class InitialCreate : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Clients",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
ClientFIO = table.Column<string>(type: "nvarchar(max)", nullable: false),
EMail = table.Column<string>(type: "nvarchar(max)", nullable: false),
Password = table.Column<string>(type: "nvarchar(max)", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Clients", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Employees",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
EmployeeFIO = table.Column<string>(type: "nvarchar(max)", nullable: false),
Login = table.Column<string>(type: "nvarchar(max)", nullable: false),
Password = table.Column<string>(type: "nvarchar(max)", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Employees", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Routes",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
ClientId = table.Column<int>(type: "int", nullable: false),
RouteName = table.Column<string>(type: "nvarchar(max)", nullable: false),
RoutePrice = table.Column<double>(type: "float", nullable: false),
Status = table.Column<int>(type: "int", nullable: false),
DateStart = table.Column<DateTime>(type: "datetime2", nullable: false),
DateFinish = table.Column<DateTime>(type: "datetime2", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Routes", x => x.Id);
table.ForeignKey(
name: "FK_Routes_Clients_ClientId",
column: x => x.ClientId,
principalTable: "Clients",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "Preserves",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
PreserveName = table.Column<string>(type: "nvarchar(max)", nullable: false),
PreservePrice = table.Column<double>(type: "float", nullable: false),
EmployeeId = table.Column<int>(type: "int", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Preserves", x => x.Id);
table.ForeignKey(
name: "FK_Preserves_Employees_EmployeeId",
column: x => x.EmployeeId,
principalTable: "Employees",
principalColumn: "Id");
});
migrationBuilder.CreateTable(
name: "RoutePreserves",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
RouteID = table.Column<int>(type: "int", nullable: false),
PreserveID = table.Column<int>(type: "int", nullable: false),
Count = table.Column<int>(type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_RoutePreserves", x => x.Id);
table.ForeignKey(
name: "FK_RoutePreserves_Preserves_PreserveID",
column: x => x.PreserveID,
principalTable: "Preserves",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_RoutePreserves_Routes_PreserveID",
column: x => x.PreserveID,
principalTable: "Routes",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_Preserves_EmployeeId",
table: "Preserves",
column: "EmployeeId");
migrationBuilder.CreateIndex(
name: "IX_RoutePreserves_PreserveID",
table: "RoutePreserves",
column: "PreserveID");
migrationBuilder.CreateIndex(
name: "IX_Routes_ClientId",
table: "Routes",
column: "ClientId");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "RoutePreserves");
migrationBuilder.DropTable(
name: "Preserves");
migrationBuilder.DropTable(
name: "Routes");
migrationBuilder.DropTable(
name: "Employees");
migrationBuilder.DropTable(
name: "Clients");
}
}
}

View File

@ -0,0 +1,217 @@
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using ZooDataBaseImplement;
#nullable disable
namespace ZooDataBaseImplement.Migrations
{
[DbContext(typeof(ZooDatabase))]
partial class ZooDatabaseModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "7.0.18")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
modelBuilder.Entity("ZooDataBaseImplement.Models.Client", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("ClientFIO")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("EMail")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Password")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("Clients");
});
modelBuilder.Entity("ZooDataBaseImplement.Models.Employee", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("EmployeeFIO")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Login")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Password")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("Employees");
});
modelBuilder.Entity("ZooDataBaseImplement.Models.Preserve", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int?>("EmployeeId")
.HasColumnType("int");
b.Property<string>("PreserveName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<double>("PreservePrice")
.HasColumnType("float");
b.HasKey("Id");
b.HasIndex("EmployeeId");
b.ToTable("Preserves");
});
modelBuilder.Entity("ZooDataBaseImplement.Models.Route", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("ClientId")
.HasColumnType("int");
b.Property<DateTime>("DateFinish")
.HasColumnType("datetime2");
b.Property<DateTime>("DateStart")
.HasColumnType("datetime2");
b.Property<string>("RouteName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<double>("RoutePrice")
.HasColumnType("float");
b.Property<int>("Status")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("ClientId");
b.ToTable("Routes");
});
modelBuilder.Entity("ZooDataBaseImplement.Models.RoutePreserve", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("Count")
.HasColumnType("int");
b.Property<int>("PreserveID")
.HasColumnType("int");
b.Property<int>("RouteID")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("PreserveID");
b.ToTable("RoutePreserves");
});
modelBuilder.Entity("ZooDataBaseImplement.Models.Preserve", b =>
{
b.HasOne("ZooDataBaseImplement.Models.Employee", null)
.WithMany("Preserves")
.HasForeignKey("EmployeeId");
});
modelBuilder.Entity("ZooDataBaseImplement.Models.Route", b =>
{
b.HasOne("ZooDataBaseImplement.Models.Client", "Client")
.WithMany("Routes")
.HasForeignKey("ClientId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Client");
});
modelBuilder.Entity("ZooDataBaseImplement.Models.RoutePreserve", b =>
{
b.HasOne("ZooDataBaseImplement.Models.Preserve", "Preserve")
.WithMany("RoutePreserves")
.HasForeignKey("PreserveID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("ZooDataBaseImplement.Models.Route", "Route")
.WithMany("Preserves")
.HasForeignKey("PreserveID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Preserve");
b.Navigation("Route");
});
modelBuilder.Entity("ZooDataBaseImplement.Models.Client", b =>
{
b.Navigation("Routes");
});
modelBuilder.Entity("ZooDataBaseImplement.Models.Employee", b =>
{
b.Navigation("Preserves");
});
modelBuilder.Entity("ZooDataBaseImplement.Models.Preserve", b =>
{
b.Navigation("RoutePreserves");
});
modelBuilder.Entity("ZooDataBaseImplement.Models.Route", b =>
{
b.Navigation("Preserves");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -18,7 +18,7 @@ namespace ZooDataBaseImplement.Models
public string PreserveName { get; set; } = string.Empty;
[Required]
public double PreservePrice { get; set; }
[ForeignKey("PreserveId")]
[ForeignKey("PreserveID")]
public virtual List<RoutePreserve> RoutePreserves{ get; set; } =
new();
public static Preserve? Create(PreserveBindingModel model)

View File

@ -6,6 +6,6 @@
}
},
"AllowedHosts": "*",
"IPAddress": "http://localhost:5044/"
"IPAddress": "http://localhost:7230/"
}