This commit is contained in:
Leozillo73 2024-06-01 02:15:33 +04:00
parent aa057fcc8f
commit 3b849acc34
9 changed files with 43 additions and 20 deletions

View File

@ -12,6 +12,7 @@ namespace ZooContracts.BindingModels
{
public int Id { get; set; }
public int ClientId { get; set; }
public int CostId { get; set; }
public string RouteName { get; set; } = string.Empty;
public double RoutePrice { get; set; }
public RouteStatus Status { get; set; } = RouteStatus.Неоплачен;

View File

@ -15,6 +15,7 @@ namespace ZooContracts.ViewModels
[DisplayName("Номер")]
public int Id { get; set; }
public int ClientId { get; set; }
public int CostId { get; set; }
[DisplayName("ФИО клиента")]
public string ClientFIO { get; set; } = string.Empty;

View File

@ -12,15 +12,15 @@ using ZooDataBaseImplement;
namespace ZooDataBaseImplement.Migrations
{
[DbContext(typeof(ZooDatabase))]
[Migration("20240531115435_initialcreate")]
partial class initialcreate
[Migration("20240531220930_InitialCreate")]
partial class InitialCreate
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "7.0.3")
.HasAnnotation("ProductVersion", "7.0.18")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
@ -65,6 +65,9 @@ namespace ZooDataBaseImplement.Migrations
b.Property<double>("CostPrice")
.HasColumnType("double precision");
b.Property<int>("EmployeeId")
.HasColumnType("integer");
b.HasKey("Id");
b.ToTable("Costs");
@ -131,7 +134,7 @@ namespace ZooDataBaseImplement.Migrations
b.Property<int>("ClientId")
.HasColumnType("integer");
b.Property<int?>("CostID")
b.Property<int>("CostId")
.HasColumnType("integer");
b.Property<DateTime>("DateFinish")
@ -154,7 +157,7 @@ namespace ZooDataBaseImplement.Migrations
b.HasIndex("ClientId");
b.HasIndex("CostID");
b.HasIndex("CostId");
b.ToTable("Routes");
});
@ -201,7 +204,9 @@ namespace ZooDataBaseImplement.Migrations
b.HasOne("ZooDataBaseImplement.Models.Cost", null)
.WithMany("Routes")
.HasForeignKey("CostID");
.HasForeignKey("CostId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Client");
});

View File

@ -7,7 +7,7 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
namespace ZooDataBaseImplement.Migrations
{
/// <inheritdoc />
public partial class initialcreate : Migration
public partial class InitialCreate : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
@ -33,6 +33,7 @@ namespace ZooDataBaseImplement.Migrations
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
EmployeeId = table.Column<int>(type: "integer", nullable: false),
CostName = table.Column<string>(type: "text", nullable: false),
CostPrice = table.Column<double>(type: "double precision", nullable: false)
},
@ -63,12 +64,12 @@ namespace ZooDataBaseImplement.Migrations
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
ClientId = table.Column<int>(type: "integer", nullable: false),
CostId = table.Column<int>(type: "integer", nullable: false),
RouteName = table.Column<string>(type: "text", nullable: false),
RoutePrice = table.Column<double>(type: "double precision", nullable: false),
Status = table.Column<int>(type: "integer", nullable: false),
DateStart = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
DateFinish = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
CostID = table.Column<int>(type: "integer", nullable: true)
DateFinish = table.Column<DateTime>(type: "timestamp with time zone", nullable: false)
},
constraints: table =>
{
@ -80,10 +81,11 @@ namespace ZooDataBaseImplement.Migrations
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_Routes_Costs_CostID",
column: x => x.CostID,
name: "FK_Routes_Costs_CostId",
column: x => x.CostId,
principalTable: "Costs",
principalColumn: "Id");
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
@ -154,9 +156,9 @@ namespace ZooDataBaseImplement.Migrations
column: "ClientId");
migrationBuilder.CreateIndex(
name: "IX_Routes_CostID",
name: "IX_Routes_CostId",
table: "Routes",
column: "CostID");
column: "CostId");
}
/// <inheritdoc />

View File

@ -17,7 +17,7 @@ namespace ZooDataBaseImplement.Migrations
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "7.0.3")
.HasAnnotation("ProductVersion", "7.0.18")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
@ -62,6 +62,9 @@ namespace ZooDataBaseImplement.Migrations
b.Property<double>("CostPrice")
.HasColumnType("double precision");
b.Property<int>("EmployeeId")
.HasColumnType("integer");
b.HasKey("Id");
b.ToTable("Costs");
@ -128,7 +131,7 @@ namespace ZooDataBaseImplement.Migrations
b.Property<int>("ClientId")
.HasColumnType("integer");
b.Property<int?>("CostID")
b.Property<int>("CostId")
.HasColumnType("integer");
b.Property<DateTime>("DateFinish")
@ -151,7 +154,7 @@ namespace ZooDataBaseImplement.Migrations
b.HasIndex("ClientId");
b.HasIndex("CostID");
b.HasIndex("CostId");
b.ToTable("Routes");
});
@ -198,7 +201,9 @@ namespace ZooDataBaseImplement.Migrations
b.HasOne("ZooDataBaseImplement.Models.Cost", null)
.WithMany("Routes")
.HasForeignKey("CostID");
.HasForeignKey("CostId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Client");
});

View File

@ -21,8 +21,9 @@ namespace ZooDataBaseImplement.Models
public string CostName { get; set; } = string.Empty;
[Required]
public double CostPrice { get; set; }
public static Cost? Create(CostBindingModel model)
[ForeignKey("CostId")]
public virtual List<Route> Routes { get; set; } = new();
public static Cost? Create(CostBindingModel model)
{
if (model == null)
{

View File

@ -13,6 +13,7 @@ namespace ZooDataBaseImplement.Models
public int Id { get; private set; }
[Required]
public int ClientId { get; private set; }
public int CostId { get; private set; }
public virtual Client Client { get; private set; } = new();
[Required]
public string RouteName { get; set; } = string.Empty;
@ -48,6 +49,7 @@ namespace ZooDataBaseImplement.Models
{
Id = model.Id,
ClientId = model.ClientId,
CostId = model.CostId,
Client = context.Clients.First(x => x.Id == model.ClientId),
RouteName = model.RouteName,
RoutePrice = model.RoutePrice,
@ -77,6 +79,7 @@ namespace ZooDataBaseImplement.Models
{
Id = Id,
ClientId = ClientId,
CostId = CostId,
ClientFIO = Client.ClientFIO,
RouteName = RouteName,
RoutePrice = RoutePrice,

View File

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

View File

@ -10,6 +10,7 @@ namespace ZooDataModels.Models
public interface IRouteModel : IId
{
int ClientId { get; }
int CostId { get; }
string RouteName { get; }
double RoutePrice { get; }
RouteStatus Status { get; }